Skip to content

Commit

Permalink
Merge pull request #535 from CircleCI-Public/create-private-orbs
Browse files Browse the repository at this point in the history
[CIRCLE-30179] Create Private Orbs
  • Loading branch information
skimke authored Jan 20, 2021
2 parents d29b23b + 4b2b36b commit e7b4dae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
12 changes: 7 additions & 5 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,13 +1005,14 @@ func RenameNamespace(cl *graphql.Client, oldName, newName string) (*RenameNamesp
return renameNamespaceWithNsID(cl, getNamespaceResponse.RegistryNamespace.ID, newName)
}

func createOrbWithNsID(cl *graphql.Client, name string, namespaceID string) (*CreateOrbResponse, error) {
func createOrbWithNsID(cl *graphql.Client, name string, namespaceID string, isPrivate bool) (*CreateOrbResponse, error) {
var response CreateOrbResponse

query := `mutation($name: String!, $registryNamespaceId: UUID!){
query := `mutation($name: String!, $registryNamespaceId: UUID!, $isPrivate: Boolean!){
createOrb(
name: $name,
registryNamespaceId: $registryNamespaceId
registryNamespaceId: $registryNamespaceId,
isPrivate: $isPrivate
){
orb {
id
Expand All @@ -1028,6 +1029,7 @@ func createOrbWithNsID(cl *graphql.Client, name string, namespaceID string) (*Cr

request.Var("name", name)
request.Var("registryNamespaceId", namespaceID)
request.Var("isPrivate", isPrivate)

err := cl.Run(request, &response)

Expand All @@ -1043,13 +1045,13 @@ func createOrbWithNsID(cl *graphql.Client, name string, namespaceID string) (*Cr
}

// CreateOrb creates (reserves) an orb within a namespace
func CreateOrb(cl *graphql.Client, namespace string, name string) (*CreateOrbResponse, error) {
func CreateOrb(cl *graphql.Client, namespace string, name string, isPrivate bool) (*CreateOrbResponse, error) {
response, err := GetNamespace(cl, namespace)
if err != nil {
return nil, err
}

return createOrbWithNsID(cl, name, response.RegistryNamespace.ID)
return createOrbWithNsID(cl, name, response.RegistryNamespace.ID, isPrivate)
}

// CreateImportedOrb creates (reserves) an imported orb within the provided namespace.
Expand Down
14 changes: 8 additions & 6 deletions cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type orbOptions struct {
listUncertified bool
listJSON bool
listDetails bool
private bool
sortBy string
// Allows user to skip y/n confirm when creating an orb
noPrompt bool
Expand Down Expand Up @@ -247,7 +248,7 @@ listing of the orb in the registry.`,
Use: "create <namespace>/<orb>",
Short: "Create an orb in the specified namespace",
Long: `Create an orb in the specified namespace
Please note that at this time all orbs created in the registry are world-readable.`,
Please note that at this time all orbs created in the registry are world-readable unless set as private using the optional flag.`,
RunE: func(_ *cobra.Command, _ []string) error {
if opts.integrationTesting {
opts.tty = createOrbTestUI{
Expand All @@ -262,6 +263,7 @@ Please note that at this time all orbs created in the registry are world-readabl
},
Args: cobra.ExactArgs(1),
}
orbCreate.PersistentFlags().BoolVarP(&opts.private, "private", "", false, "Specify that this orb is for private use within your org, unlisted from the public registry.")

orbPack := &cobra.Command{
Use: "pack <path>",
Expand Down Expand Up @@ -766,7 +768,7 @@ func promoteOrb(opts orbOptions) error {
func createOrb(opts orbOptions) error {
var err error

namespace, orb, err := references.SplitIntoOrbAndNamespace(opts.args[0])
namespace, orbName, err := references.SplitIntoOrbAndNamespace(opts.args[0])

if err != nil {
return err
Expand All @@ -779,13 +781,13 @@ You will not be able to change the name of this orb.
If you change your mind about the name, you will have to create a new orb with the new name.
`, namespace, orb)
`, namespace, orbName)
}

confirm := fmt.Sprintf("Are you sure you wish to create the orb: `%s/%s`", namespace, orb)
confirm := fmt.Sprintf("Are you sure you wish to create the orb: `%s/%s`", namespace, orbName)

if opts.noPrompt || opts.tty.askUserToConfirm(confirm) {
_, err = api.CreateOrb(opts.cl, namespace, orb)
_, err = api.CreateOrb(opts.cl, namespace, orbName, opts.private)

if err != nil {
return err
Expand Down Expand Up @@ -1284,7 +1286,7 @@ func initOrb(opts orbOptions) error {
}

// Push a dev version of the orb.
newOrb, err := api.CreateOrb(opts.cl, namespace, orbName)
newOrb, err := api.CreateOrb(opts.cl, namespace, orbName, false)
if err != nil {
return errors.Wrap(err, "Unable to create orb")
}
Expand Down
12 changes: 8 additions & 4 deletions cmd/orb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,9 @@ See a full explanation and documentation on orbs here: https://circleci.com/docs
}`

expectedOrbRequest := `{
"query": "mutation($name: String!, $registryNamespaceId: UUID!){\n\t\t\t\tcreateOrb(\n\t\t\t\t\tname: $name,\n\t\t\t\t\tregistryNamespaceId: $registryNamespaceId\n\t\t\t\t){\n\t\t\t\t orb {\n\t\t\t\t id\n\t\t\t\t }\n\t\t\t\t errors {\n\t\t\t\t message\n\t\t\t\t type\n\t\t\t\t }\n\t\t\t\t}\n}",
"query": "mutation($name: String!, $registryNamespaceId: UUID!, $isPrivate: Boolean!){\n\t\t\t\tcreateOrb(\n\t\t\t\t\tname: $name,\n\t\t\t\t\tregistryNamespaceId: $registryNamespaceId,\n\t\t\t\t\tisPrivate: $isPrivate\n\t\t\t\t){\n\t\t\t\t orb {\n\t\t\t\t id\n\t\t\t\t }\n\t\t\t\t errors {\n\t\t\t\t message\n\t\t\t\t type\n\t\t\t\t }\n\t\t\t\t}\n}",
"variables": {
"isPrivate": false,
"name": "foo-orb",
"registryNamespaceId": "bb604b45-b6b0-4b81-ad80-796f15eddf87"
}
Expand Down Expand Up @@ -1020,8 +1021,9 @@ You can now register versions of %s using %s`, "`bar-ns/foo-orb`", "`bar-ns/foo-
gqlErrors := `[ { "message": "ignored error" } ]`

expectedOrbRequest := `{
"query": "mutation($name: String!, $registryNamespaceId: UUID!){\n\t\t\t\tcreateOrb(\n\t\t\t\t\tname: $name,\n\t\t\t\t\tregistryNamespaceId: $registryNamespaceId\n\t\t\t\t){\n\t\t\t\t orb {\n\t\t\t\t id\n\t\t\t\t }\n\t\t\t\t errors {\n\t\t\t\t message\n\t\t\t\t type\n\t\t\t\t }\n\t\t\t\t}\n}",
"query": "mutation($name: String!, $registryNamespaceId: UUID!, $isPrivate: Boolean!){\n\t\t\t\tcreateOrb(\n\t\t\t\t\tname: $name,\n\t\t\t\t\tregistryNamespaceId: $registryNamespaceId,\n\t\t\t\t\tisPrivate: $isPrivate\n\t\t\t\t){\n\t\t\t\t orb {\n\t\t\t\t id\n\t\t\t\t }\n\t\t\t\t errors {\n\t\t\t\t message\n\t\t\t\t type\n\t\t\t\t }\n\t\t\t\t}\n}",
"variables": {
"isPrivate": false,
"name": "foo-orb",
"registryNamespaceId": "bb604b45-b6b0-4b81-ad80-796f15eddf87"
}
Expand Down Expand Up @@ -1087,8 +1089,9 @@ You can now register versions of %s using %s`, "`bar-ns/foo-orb`", "`bar-ns/foo-
}`

expectedOrbRequest := `{
"query": "mutation($name: String!, $registryNamespaceId: UUID!){\n\t\t\t\tcreateOrb(\n\t\t\t\t\tname: $name,\n\t\t\t\t\tregistryNamespaceId: $registryNamespaceId\n\t\t\t\t){\n\t\t\t\t orb {\n\t\t\t\t id\n\t\t\t\t }\n\t\t\t\t errors {\n\t\t\t\t message\n\t\t\t\t type\n\t\t\t\t }\n\t\t\t\t}\n}",
"query": "mutation($name: String!, $registryNamespaceId: UUID!, $isPrivate: Boolean!){\n\t\t\t\tcreateOrb(\n\t\t\t\t\tname: $name,\n\t\t\t\t\tregistryNamespaceId: $registryNamespaceId,\n\t\t\t\t\tisPrivate: $isPrivate\n\t\t\t\t){\n\t\t\t\t orb {\n\t\t\t\t id\n\t\t\t\t }\n\t\t\t\t errors {\n\t\t\t\t message\n\t\t\t\t type\n\t\t\t\t }\n\t\t\t\t}\n}",
"variables": {
"isPrivate": false,
"name": "foo-orb",
"registryNamespaceId": "bb604b45-b6b0-4b81-ad80-796f15eddf87"
}
Expand Down Expand Up @@ -1153,8 +1156,9 @@ You can now register versions of %s using %s.`,
gqlErrors := `[ { "message": "ignored error" } ]`

expectedOrbRequest := `{
"query": "mutation($name: String!, $registryNamespaceId: UUID!){\n\t\t\t\tcreateOrb(\n\t\t\t\t\tname: $name,\n\t\t\t\t\tregistryNamespaceId: $registryNamespaceId\n\t\t\t\t){\n\t\t\t\t orb {\n\t\t\t\t id\n\t\t\t\t }\n\t\t\t\t errors {\n\t\t\t\t message\n\t\t\t\t type\n\t\t\t\t }\n\t\t\t\t}\n}",
"query": "mutation($name: String!, $registryNamespaceId: UUID!, $isPrivate: Boolean!){\n\t\t\t\tcreateOrb(\n\t\t\t\t\tname: $name,\n\t\t\t\t\tregistryNamespaceId: $registryNamespaceId,\n\t\t\t\t\tisPrivate: $isPrivate\n\t\t\t\t){\n\t\t\t\t orb {\n\t\t\t\t id\n\t\t\t\t }\n\t\t\t\t errors {\n\t\t\t\t message\n\t\t\t\t type\n\t\t\t\t }\n\t\t\t\t}\n}",
"variables": {
"isPrivate": false,
"name": "foo-orb",
"registryNamespaceId": "bb604b45-b6b0-4b81-ad80-796f15eddf87"
}
Expand Down

0 comments on commit e7b4dae

Please sign in to comment.