Skip to content

Commit

Permalink
feat: remove silence whitelist errors flag (runatlantis#3923)
Browse files Browse the repository at this point in the history
Co-authored-by: PePe Amengual <[email protected]>
  • Loading branch information
lukemassa and jamengual authored Nov 9, 2023
1 parent ea1dbbd commit 9bc94de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 77 deletions.
13 changes: 0 additions & 13 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ const (
SilenceForkPRErrorsFlag = "silence-fork-pr-errors"
SilenceVCSStatusNoPlans = "silence-vcs-status-no-plans"
SilenceAllowlistErrorsFlag = "silence-allowlist-errors"
// SilenceWhitelistErrorsFlag is deprecated for SilenceAllowlistErrorsFlag.
SilenceWhitelistErrorsFlag = "silence-whitelist-errors"
SkipCloneNoChanges = "skip-clone-no-changes"
SlackTokenFlag = "slack-token"
SSLCertFileFlag = "ssl-cert-file"
Expand Down Expand Up @@ -537,11 +535,6 @@ var boolFlags = map[string]boolFlag{
description: "Silences the posting of allowlist error comments.",
defaultValue: false,
},
SilenceWhitelistErrorsFlag: {
description: "[Deprecated for --silence-allowlist-errors].",
defaultValue: false,
hidden: true,
},
DisableMarkdownFoldingFlag: {
description: "Toggle off folding in markdown output.",
defaultValue: false,
Expand Down Expand Up @@ -938,9 +931,6 @@ func (s *ServerCmd) validate(userConfig server.UserConfig) error {
if strings.Contains(userConfig.RepoAllowlist, "://") {
return fmt.Errorf("--%s cannot contain ://, should be hostnames only", RepoAllowlistFlag)
}
if userConfig.SilenceAllowlistErrors && userConfig.SilenceWhitelistErrors {
return fmt.Errorf("both --%s and --%s cannot be set–use --%s", SilenceAllowlistErrorsFlag, SilenceWhitelistErrorsFlag, SilenceAllowlistErrorsFlag)
}

if userConfig.BitbucketBaseURL == DefaultBitbucketBaseURL && userConfig.BitbucketWebhookSecret != "" {
return fmt.Errorf("--%s cannot be specified for Bitbucket Cloud because it is not supported by Bitbucket", BitbucketWebhookSecretFlag)
Expand Down Expand Up @@ -1143,9 +1133,6 @@ func (s *ServerCmd) deprecationWarnings(userConfig *server.UserConfig) error {
}

// Handle repo whitelist deprecation.
if userConfig.SilenceWhitelistErrors {
userConfig.SilenceAllowlistErrors = true
}
if userConfig.RepoWhitelist != "" {
userConfig.RepoAllowlist = userConfig.RepoWhitelist
}
Expand Down
40 changes: 0 additions & 40 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,18 +752,6 @@ func TestExecute_TFEHostnameOnly(t *testing.T) {
ErrEquals(t, "if setting --tfe-hostname, must set --tfe-token", err)
}

// Can't use both --repo-allowlist and --repo-whitelist
func TestExecute_BothAllowAndWhitelist(t *testing.T) {
c := setup(map[string]interface{}{
GHUserFlag: "user",
GHTokenFlag: "token",
RepoAllowlistFlag: "github.com",
RepoWhitelistFlag: "github.com",
}, t)
err := c.Execute()
ErrEquals(t, "both --repo-allowlist and --repo-whitelist cannot be set–use --repo-allowlist", err)
}

// Must set allow or whitelist.
func TestExecute_AllowAndWhitelist(t *testing.T) {
c := setup(map[string]interface{}{
Expand All @@ -774,19 +762,6 @@ func TestExecute_AllowAndWhitelist(t *testing.T) {
ErrEquals(t, "--repo-allowlist must be set for security purposes", err)
}

// Can't use both --silence-whitelist-errors and --silence-allowlist-errors
func TestExecute_BothSilenceAllowAndWhitelistErrors(t *testing.T) {
c := setup(map[string]interface{}{
GHUserFlag: "user",
GHTokenFlag: "token",
RepoAllowlistFlag: "*",
SilenceWhitelistErrorsFlag: true,
SilenceAllowlistErrorsFlag: true,
}, t)
err := c.Execute()
ErrEquals(t, "both --silence-allowlist-errors and --silence-whitelist-errors cannot be set–use --silence-allowlist-errors", err)
}

func TestExecute_DisableApplyDeprecation(t *testing.T) {
c := setupWithDefaults(map[string]interface{}{
DisableApplyFlag: true,
Expand All @@ -797,21 +772,6 @@ func TestExecute_DisableApplyDeprecation(t *testing.T) {
Equals(t, "plan,unlock", passedConfig.AllowCommands)
}

// Test that we set the corresponding allow list values on the userConfig
// struct if the deprecated whitelist flags are used.
func TestExecute_RepoWhitelistDeprecation(t *testing.T) {
c := setup(map[string]interface{}{
GHUserFlag: "user",
GHTokenFlag: "token",
RepoWhitelistFlag: "*",
SilenceWhitelistErrorsFlag: true,
}, t)
err := c.Execute()
Ok(t, err)
Equals(t, true, passedConfig.SilenceAllowlistErrors)
Equals(t, "*", passedConfig.RepoAllowlist)
}

func TestExecute_AutoDetectModulesFromProjects_Env(t *testing.T) {
t.Setenv("ATLANTIS_AUTOPLAN_MODULES_FROM_PROJECTS", "**/init.tf")
c := setupWithDefaults(map[string]interface{}{}, t)
Expand Down
46 changes: 22 additions & 24 deletions server/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,28 @@ type UserConfig struct {
SilenceVCSStatusNoPlans bool `mapstructure:"silence-vcs-status-no-plans"`
// SilenceVCSStatusNoProjects is whether autoplan should set commit status if no projects
// are found.
SilenceVCSStatusNoProjects bool `mapstructure:"silence-vcs-status-no-projects"`
SilenceAllowlistErrors bool `mapstructure:"silence-allowlist-errors"`
// SilenceWhitelistErrors is deprecated in favour of SilenceAllowlistErrors
SilenceWhitelistErrors bool `mapstructure:"silence-whitelist-errors"`
SkipCloneNoChanges bool `mapstructure:"skip-clone-no-changes"`
SlackToken string `mapstructure:"slack-token"`
SSLCertFile string `mapstructure:"ssl-cert-file"`
SSLKeyFile string `mapstructure:"ssl-key-file"`
RestrictFileList bool `mapstructure:"restrict-file-list"`
TFDownload bool `mapstructure:"tf-download"`
TFDownloadURL string `mapstructure:"tf-download-url"`
TFEHostname string `mapstructure:"tfe-hostname"`
TFELocalExecutionMode bool `mapstructure:"tfe-local-execution-mode"`
TFEToken string `mapstructure:"tfe-token"`
VarFileAllowlist string `mapstructure:"var-file-allowlist"`
VCSStatusName string `mapstructure:"vcs-status-name"`
DefaultTFVersion string `mapstructure:"default-tf-version"`
Webhooks []WebhookConfig `mapstructure:"webhooks"`
WebBasicAuth bool `mapstructure:"web-basic-auth"`
WebUsername string `mapstructure:"web-username"`
WebPassword string `mapstructure:"web-password"`
WriteGitCreds bool `mapstructure:"write-git-creds"`
WebsocketCheckOrigin bool `mapstructure:"websocket-check-origin"`
UseTFPluginCache bool `mapstructure:"use-tf-plugin-cache"`
SilenceVCSStatusNoProjects bool `mapstructure:"silence-vcs-status-no-projects"`
SilenceAllowlistErrors bool `mapstructure:"silence-allowlist-errors"`
SkipCloneNoChanges bool `mapstructure:"skip-clone-no-changes"`
SlackToken string `mapstructure:"slack-token"`
SSLCertFile string `mapstructure:"ssl-cert-file"`
SSLKeyFile string `mapstructure:"ssl-key-file"`
RestrictFileList bool `mapstructure:"restrict-file-list"`
TFDownload bool `mapstructure:"tf-download"`
TFDownloadURL string `mapstructure:"tf-download-url"`
TFEHostname string `mapstructure:"tfe-hostname"`
TFELocalExecutionMode bool `mapstructure:"tfe-local-execution-mode"`
TFEToken string `mapstructure:"tfe-token"`
VarFileAllowlist string `mapstructure:"var-file-allowlist"`
VCSStatusName string `mapstructure:"vcs-status-name"`
DefaultTFVersion string `mapstructure:"default-tf-version"`
Webhooks []WebhookConfig `mapstructure:"webhooks"`
WebBasicAuth bool `mapstructure:"web-basic-auth"`
WebUsername string `mapstructure:"web-username"`
WebPassword string `mapstructure:"web-password"`
WriteGitCreds bool `mapstructure:"write-git-creds"`
WebsocketCheckOrigin bool `mapstructure:"websocket-check-origin"`
UseTFPluginCache bool `mapstructure:"use-tf-plugin-cache"`
}

// ToAllowCommandNames parse AllowCommands into a slice of CommandName
Expand Down

0 comments on commit 9bc94de

Please sign in to comment.