diff --git a/go.mod b/go.mod index 1ab5fb2e40..c86df84780 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,6 @@ require ( github.com/xanzy/go-gitlab v0.79.1 go.etcd.io/bbolt v1.3.7 go.uber.org/zap v1.24.0 - golang.org/x/exp v0.0.0-20230131013936-aae9b4e6329d golang.org/x/term v0.4.0 golang.org/x/text v0.6.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 6a6e2eafce..4a1a364150 100644 --- a/go.sum +++ b/go.sum @@ -510,8 +510,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20230131013936-aae9b4e6329d h1:EdJVZdqCvJN8QvZSbrto8tf354qfT3cfBUPaxdWuOpQ= -golang.org/x/exp v0.0.0-20230131013936-aae9b4e6329d/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/server/core/config/valid/global_cfg.go b/server/core/config/valid/global_cfg.go index d8f0c0369e..5f7d497c8b 100644 --- a/server/core/config/valid/global_cfg.go +++ b/server/core/config/valid/global_cfg.go @@ -7,7 +7,7 @@ import ( version "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/logging" - "golang.org/x/exp/slices" + "github.com/runatlantis/atlantis/server/utils" ) const MergeableCommandReq = "mergeable" @@ -427,22 +427,22 @@ func (g GlobalCfg) ValidateRepoCfg(rCfg RepoCfg, repoID string) error { } } for _, p := range rCfg.Projects { - if p.WorkflowName != nil && !slices.Contains(allowedOverrides, WorkflowKey) { + if p.WorkflowName != nil && !utils.SlicesContains(allowedOverrides, WorkflowKey) { return fmt.Errorf("repo config not allowed to set '%s' key: server-side config needs '%s: [%s]'", WorkflowKey, AllowedOverridesKey, WorkflowKey) } - if p.ApplyRequirements != nil && !slices.Contains(allowedOverrides, ApplyRequirementsKey) { + if p.ApplyRequirements != nil && !utils.SlicesContains(allowedOverrides, ApplyRequirementsKey) { return fmt.Errorf("repo config not allowed to set '%s' key: server-side config needs '%s: [%s]'", ApplyRequirementsKey, AllowedOverridesKey, ApplyRequirementsKey) } - if p.PlanRequirements != nil && !slices.Contains(allowedOverrides, PlanRequirementsKey) { + if p.PlanRequirements != nil && !utils.SlicesContains(allowedOverrides, PlanRequirementsKey) { return fmt.Errorf("repo config not allowed to set '%s' key: server-side config needs '%s: [%s]'", PlanRequirementsKey, AllowedOverridesKey, PlanRequirementsKey) } - if p.ImportRequirements != nil && !slices.Contains(allowedOverrides, ImportRequirementsKey) { + if p.ImportRequirements != nil && !utils.SlicesContains(allowedOverrides, ImportRequirementsKey) { return fmt.Errorf("repo config not allowed to set '%s' key: server-side config needs '%s: [%s]'", ImportRequirementsKey, AllowedOverridesKey, ImportRequirementsKey) } - if p.DeleteSourceBranchOnMerge != nil && !slices.Contains(allowedOverrides, DeleteSourceBranchOnMergeKey) { + if p.DeleteSourceBranchOnMerge != nil && !utils.SlicesContains(allowedOverrides, DeleteSourceBranchOnMergeKey) { return fmt.Errorf("repo config not allowed to set '%s' key: server-side config needs '%s: [%s]'", DeleteSourceBranchOnMergeKey, AllowedOverridesKey, DeleteSourceBranchOnMergeKey) } - if p.RepoLocking != nil && !slices.Contains(allowedOverrides, RepoLockingKey) { + if p.RepoLocking != nil && !utils.SlicesContains(allowedOverrides, RepoLockingKey) { return fmt.Errorf("repo config not allowed to set '%s' key: server-side config needs '%s: [%s]'", RepoLockingKey, AllowedOverridesKey, RepoLockingKey) } } @@ -493,7 +493,7 @@ func (g GlobalCfg) ValidateRepoCfg(rCfg RepoCfg, repoID string) error { } } - if !slices.Contains(allowedWorkflows, name) { + if !utils.SlicesContains(allowedWorkflows, name) { return fmt.Errorf("workflow '%s' is not allowed for this repo", name) } } diff --git a/server/events/comment_parser.go b/server/events/comment_parser.go index 35fd4466f1..71bda2e52c 100644 --- a/server/events/comment_parser.go +++ b/server/events/comment_parser.go @@ -26,8 +26,8 @@ import ( "github.com/google/shlex" "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/utils" "github.com/spf13/pflag" - "golang.org/x/exp/slices" ) const ( @@ -324,7 +324,7 @@ func (e *CommentParser) parseArgs(name command.Name, args []string, flagSet *pfl return "", nil, e.errMarkdown("subcommand required", name.String(), flagSet) } subCommand, commandArgs = commandArgs[0], commandArgs[1:] - isAvailableSubCommand := slices.Contains(availableSubCommands, subCommand) + isAvailableSubCommand := utils.SlicesContains(availableSubCommands, subCommand) if !isAvailableSubCommand { errMsg := fmt.Sprintf("invalid subcommand %s (not %s)", subCommand, strings.Join(availableSubCommands, ", ")) return "", nil, e.errMarkdown(errMsg, name.String(), flagSet) diff --git a/server/utils/slices.go b/server/utils/slices.go new file mode 100644 index 0000000000..c2d67668ea --- /dev/null +++ b/server/utils/slices.go @@ -0,0 +1,12 @@ +package utils + +// SlicesContains reports whether v is present in s. +// https://pkg.go.dev/golang.org/x/exp/slices#Contains +func SlicesContains[E comparable](s []E, v E) bool { + for _, vs := range s { + if v == vs { + return true + } + } + return false +}