Skip to content

Commit

Permalink
Merge pull request #939 from CircleCI-Public/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
JulesFaucherre authored May 16, 2023
2 parents 63d68f9 + ead2360 commit f990e38
Show file tree
Hide file tree
Showing 9 changed files with 414 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ commands:
parameters:
GORELEASER_URL:
type: string
default: https://github.com/goreleaser/goreleaser/releases/download/v0.127.0/goreleaser_amd64.deb
default: https://github.com/goreleaser/goreleaser/releases/download/v0.184.0/goreleaser_amd64.deb
steps:
- restore_cache:
keys: [v5-goreleaser-]
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,8 @@ Development instructions for the CircleCI CLI can be found in [HACKING.md](HACKI

Please see the [documentation](https://circleci-public.github.io/circleci-cli) or `circleci help` for more.

## Server compatibility

There are some difference of behavior depending on the version you use:
- config validation will use the GraphQL API until **Server v4.0.5, v4.1.3, v4.2.0**. The above versions will use the new route `compile-config-with-defaults`
- `circleci orb validate` will only allow you to validate orbs using other private orbs with the option `--org-slug` from version **Server v4.2.0**
126 changes: 106 additions & 20 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,28 @@ func OrbQuery(cl *graphql.Client, configPath string, ownerId string) (*ConfigRes
return nil, err
}

query := `
request, err := makeOrbRequest(cl, config, ownerId)
if err != nil {
return nil, err
}

err = cl.Run(request, &response)
if err != nil {
return nil, errors.Wrap(err, "Unable to validate config")
}

if len(response.OrbConfig.ConfigResponse.Errors) > 0 {
return nil, response.OrbConfig.ConfigResponse.Errors
}

return &response.OrbConfig.ConfigResponse, nil
}

func makeOrbRequest(cl *graphql.Client, configContent string, ownerId string) (*graphql.Request, error) {
handlesOwner := orbQueryHandleOwnerId(cl)

if handlesOwner {
query := `
query ValidateOrb ($config: String!, $owner: UUID) {
orbConfig(orbYaml: $config, ownerId: $owner) {
valid,
Expand All @@ -531,26 +552,91 @@ func OrbQuery(cl *graphql.Client, configPath string, ownerId string) (*ConfigRes
}
}`

request := graphql.NewRequest(query)
request.Var("config", config)
request := graphql.NewRequest(query)
request.Var("config", configContent)

if ownerId != "" {
request.Var("owner", ownerId)
}

request.SetToken(cl.Token)
return request, nil
}

if ownerId != "" {
request.Var("owner", ownerId)
return nil, errors.Errorf("Your version of Server does not support validating orbs that refer to other private orbs. Please see the README for more information on server compatibility: https://github.com/CircleCI-Public/circleci-cli#server-compatibility")
}
query := `
query ValidateOrb ($config: String!) {
orbConfig(orbYaml: $config) {
valid,
errors { message },
sourceYaml,
outputYaml
}
}`

request := graphql.NewRequest(query)
request.Var("config", configContent)

request.SetToken(cl.Token)
return request, nil
}

err = cl.Run(request, &response)
type OrbIntrospectionResponse struct {
Schema struct {
Query struct {
Fields []struct {
Name string `json:"name"`
Args []struct {
Name string `json:"name"`
} `json:"args"`
} `json:"fields"`
} `json:"queryType"`
} `json:"__schema"`
}

func orbQueryHandleOwnerId(cl *graphql.Client) bool {
query := `
query ValidateOrb {
__schema {
queryType {
fields(includeDeprecated: true) {
name
args {
name
__typename
type {
name
}
}
}
}
}
}`
request := graphql.NewRequest(query)
response := OrbIntrospectionResponse{}
err := cl.Run(request, &response)
if err != nil {
return nil, errors.Wrap(err, "Unable to validate config")
return false
}

if len(response.OrbConfig.ConfigResponse.Errors) > 0 {
return nil, response.OrbConfig.ConfigResponse.Errors
request.SetToken(cl.Token)

// Find the orbConfig query method, look at its arguments, if it has the "ownerId" argument, return true
for _, field := range response.Schema.Query.Fields {
if field.Name == "orbConfig" {
for _, arg := range field.Args {
if arg.Name == "ownerId" {
return true
}
}
}
}

return &response.OrbConfig.ConfigResponse, nil
// else return false, ownerId is not supported

return false
}

// OrbImportVersion publishes a new version of an orb using the provided source and id.
Expand Down Expand Up @@ -1239,18 +1325,18 @@ func OrbSetOrbListStatus(cl *graphql.Client, namespace string, orb string, list
var response OrbSetOrbListStatusResponse

query := `
mutation($orbId: UUID!, $list: Boolean!) {
setOrbListStatus(
orbId: $orbId,
list: $list
) {
listed
errors {
message
type
}
}
mutation($orbId: UUID!, $list: Boolean!) {
setOrbListStatus(
orbId: $orbId,
list: $list
) {
listed
errors {
message
type
}
}
}
`

request := graphql.NewRequest(query)
Expand Down
11 changes: 11 additions & 0 deletions clitest/data/orb_with_private.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2.1

orbs:
vuln-scanner: cci-internal/[email protected]

jobs:
some-job:
executor: vuln-scanner/default
steps:
- run:
command: echo "Hello world"
4 changes: 3 additions & 1 deletion cmd/disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/CircleCI-Public/circleci-cli/settings"
"github.com/CircleCI-Public/circleci-cli/version"
"github.com/fatih/color"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -39,7 +40,8 @@ func newDisabledCommand(config *settings.Config, command string) *cobra.Command
}

func disableCommand(opts disableOptions) {
fmt.Printf("`%s` is not available because this tool was installed using `%s`.\n", opts.command, version.PackageManager())
bold := color.New(color.Bold).SprintFunc()
fmt.Printf("%s is not available because this tool was installed using %s.\n", bold(opts.command), bold(version.PackageManager()))

if opts.command == "update" {
fmt.Println("Please consult the package manager's documentation on how to update the CLI.")
Expand Down
17 changes: 16 additions & 1 deletion cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,22 @@ func inlineIncludes(node *yaml.Node, orbRoot string) error {
func initOrb(opts orbOptions) error {
orbPath := opts.args[0]
var err error
fmt.Println("Note: This command is in preview. Please report any bugs! https://github.com/CircleCI-Public/circleci-cli/issues/new/choose")

if !opts.private {
prompt := &survey.Select{
Message: "Would you like to create a public or private orb?",
Options: []string{"Public", "Private"},
}
var selectedOption string
err := survey.AskOne(prompt, &selectedOption)
if err != nil {
return errors.Wrap(err, "Unexpected error")
}

if selectedOption == "Private" {
opts.private = true
}
}

orbInformThatOrbCannotBeDeletedMessage()

Expand Down
Loading

0 comments on commit f990e38

Please sign in to comment.