Skip to content

Commit

Permalink
Merge pull request #1053 from CircleCI-Public/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
jvincent42 authored Mar 14, 2024
2 parents 314ca7a + 4279a96 commit 735ecd3
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cmd/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ This group of commands allows the management of polices to be verified against b
ConfigYaml: string(data),
Options: config.Options{
OwnerID: ownerID,
PipelineValues: pipelineValues,
PipelineValues: config.LocalPipelineValues(parameters),
PipelineParameters: parameters,
},
},
Expand Down
6 changes: 3 additions & 3 deletions config/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c *ConfigCompiler) ProcessConfig(opts ProcessConfigOpts) (response *Config
}

//if no orgId provided use org slug
values := LocalPipelineValues()
values := LocalPipelineValues(params)
if opts.VerboseOutput {
fmt.Fprintln(os.Stderr, "Processing config with following values:")
printValues(values)
Expand Down Expand Up @@ -126,7 +126,7 @@ func (c *ConfigCompiler) ValidateConfig(opts ValidateConfigOpts) error {
var response *ConfigResponse

//if no orgId provided use org slug
values := LocalPipelineValues()
values := LocalPipelineValues(nil)
if opts.VerboseOutput {
fmt.Fprintln(os.Stderr, "Validating config with following values:")
printValues(values)
Expand All @@ -141,7 +141,7 @@ func (c *ConfigCompiler) ValidateConfig(opts ValidateConfigOpts) error {
opts.ConfigPath,
orgID,
nil,
LocalPipelineValues(),
values,
)
if err != nil {
return err
Expand Down
7 changes: 5 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"io"
"os"

"github.com/pkg/errors"

"github.com/CircleCI-Public/circleci-cli/api/collaborators"
"github.com/CircleCI-Public/circleci-cli/settings"
"github.com/pkg/errors"
)

var (
Expand Down Expand Up @@ -71,7 +72,9 @@ type CompileConfigRequest struct {
}

type Options struct {
OwnerID string `json:"owner_id,omitempty"`
OwnerID string `json:"owner_id,omitempty"`
// PipelineParameters are deprecated and will be removed in the future.
// Use PipelineValues instead.
PipelineParameters map[string]interface{} `json:"pipeline_parameters,omitempty"`
PipelineValues map[string]interface{} `json:"pipeline_values,omitempty"`
}
Expand Down
26 changes: 15 additions & 11 deletions config/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type Values map[string]interface{}
// Static typing is bypassed using an empty interface here due to pipeline parameters supporting multiple types.
type Parameters map[string]interface{}

// vars should contain any pipeline parameters that should be accessible via
// << pipeline.parameters.foo >>
func LocalPipelineValues() Values {
// LocalPipelineValues returns a map of pipeline values that can be used for local validation.
// The given parameters will be prefixed with "pipeline.parameters." and accessible via << pipeline.parameters.foo >>.
func LocalPipelineValues(parameters Parameters) Values {
revision := git.Revision()
gitUrl := "https://github.com/CircleCI-Public/circleci-cli"
projectType := "github"
Expand All @@ -32,14 +32,18 @@ func LocalPipelineValues() Values {
}

vals := map[string]interface{}{
"id": "00000000-0000-0000-0000-000000000001",
"number": 1,
"project.git_url": gitUrl,
"project.type": projectType,
"git.tag": git.Tag(),
"git.branch": git.Branch(),
"git.revision": revision,
"git.base_revision": revision,
"pipeline.id": "00000000-0000-0000-0000-000000000001",
"pipeline.number": 1,
"pipeline.project.git_url": gitUrl,
"pipeline.project.type": projectType,
"pipeline.git.tag": git.Tag(),
"pipeline.git.branch": git.Branch(),
"pipeline.git.revision": revision,
"pipeline.git.base_revision": revision,
}

for k, v := range parameters {
vals[fmt.Sprintf("pipeline.parameters.%s", k)] = v
}

return vals
Expand Down
52 changes: 52 additions & 0 deletions config/pipeline_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package config

import (
"testing"

"github.com/stretchr/testify/assert"
"golang.org/x/exp/maps"
)

func TestLocalPipelineValues(t *testing.T) {
tests := []struct {
name string
parameters Parameters
wantKeys []string
}{
{
name: "standard values given nil parameters",
parameters: nil,
wantKeys: []string{
"pipeline.id",
"pipeline.number",
"pipeline.project.git_url",
"pipeline.project.type",
"pipeline.git.tag",
"pipeline.git.branch",
"pipeline.git.revision",
"pipeline.git.base_revision",
},
},
{
name: "standard and prefixed parameters given map of parameters",
parameters: Parameters{"foo": "bar", "baz": "buzz"},
wantKeys: []string{
"pipeline.id",
"pipeline.number",
"pipeline.project.git_url",
"pipeline.project.type",
"pipeline.git.tag",
"pipeline.git.branch",
"pipeline.git.revision",
"pipeline.git.base_revision",
"pipeline.parameters.foo",
"pipeline.parameters.baz",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.ElementsMatchf(t, tt.wantKeys, maps.Keys(LocalPipelineValues(tt.parameters)), "LocalPipelineValues(%v)", tt.parameters)
})
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ require (
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/CircleCI-Public/circle-policy-agent v0.0.702 h1:dEPPZs9j2pgVV1bZEnvthHprJTn8HB2KyMxCdeD6Z3g=
github.com/CircleCI-Public/circle-policy-agent v0.0.702/go.mod h1:72U4Q4OtvAGRGGo/GqlCCO0tARg1cSG9xwxWyz3ktQI=
github.com/CircleCI-Public/circle-policy-agent v0.0.727 h1:DS5QkuffkAO/EwNIN2mgQC4an73wfo/VR7ZurAA2qkc=
github.com/CircleCI-Public/circle-policy-agent v0.0.727/go.mod h1:72U4Q4OtvAGRGGo/GqlCCO0tARg1cSG9xwxWyz3ktQI=
github.com/CircleCI-Public/circleci-config v0.0.0-20231003143420-842d4b0025ef h1:Bhr3xH8/XV0CF8wHFxWgBkmDRTQIW5O1MiuL3n1AEug=
Expand Down Expand Up @@ -105,8 +103,6 @@ github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+
github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
github.com/go-git/go-git/v5 v5.10.1 h1:tu8/D8i+TWxgKpzQ3Vc43e+kkhXqtsZCKI/egajKnxk=
github.com/go-git/go-git/v5 v5.10.1/go.mod h1:uEuHjxkHap8kAl//V5F/nNWwqIYtP/402ddd05mp0wg=
github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4=
github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY=
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
Expand Down Expand Up @@ -454,8 +450,8 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
9 changes: 5 additions & 4 deletions local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"strings"
"syscall"

"github.com/CircleCI-Public/circleci-cli/config"
"github.com/CircleCI-Public/circleci-cli/settings"
"github.com/pkg/errors"
"github.com/spf13/pflag"

"github.com/CircleCI-Public/circleci-cli/config"
"github.com/CircleCI-Public/circleci-cli/settings"
)

var picardRepo = "circleci/picard"
Expand Down Expand Up @@ -46,13 +47,13 @@ func Execute(flags *pflag.FlagSet, cfg *settings.Config, args []string) error {
//if no orgId provided use org slug
orgID, _ := flags.GetString("org-id")
if strings.TrimSpace(orgID) != "" {
configResponse, err = compiler.ConfigQuery(configPath, orgID, nil, config.LocalPipelineValues())
configResponse, err = compiler.ConfigQuery(configPath, orgID, nil, config.LocalPipelineValues(nil))
if err != nil {
return err
}
} else {
orgSlug, _ := flags.GetString("org-slug")
configResponse, err = compiler.ConfigQuery(configPath, orgSlug, nil, config.LocalPipelineValues())
configResponse, err = compiler.ConfigQuery(configPath, orgSlug, nil, config.LocalPipelineValues(nil))
if err != nil {
return err
}
Expand Down

0 comments on commit 735ecd3

Please sign in to comment.