Skip to content

Commit

Permalink
added the cli flags for azuredveops-timeout-seconds and azuredevops-h…
Browse files Browse the repository at this point in the history
…onor-retry-after
  • Loading branch information
oliverisaac committed Jul 23, 2021
1 parent d494ea7 commit c218198
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
19 changes: 17 additions & 2 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ import (
// 1. Add a const with the flag name (in alphabetic order).
// 2. Add a new field to server.UserConfig and set the mapstructure tag equal to the flag name.
// 3. Add your flag's description etc. to the stringFlags, intFlags, or boolFlags slices.
// 4. If appropriate, modify the setDefaults function to assign teh default value
const (
// Flag names.
ADWebhookPasswordFlag = "azuredevops-webhook-password" // nolint: gosec
ADWebhookUserFlag = "azuredevops-webhook-user"
ADHonorRetryAfter = "azuredevops-honor-retry-after"
ADTimeoutSeconds = "azuredevops-timeout-seconds"
ADTokenFlag = "azuredevops-token" // nolint: gosec
ADUserFlag = "azuredevops-user"
ADWebhookPasswordFlag = "azuredevops-webhook-password" // nolint: gosec
ADWebhookUserFlag = "azuredevops-webhook-user"
AllowForkPRsFlag = "allow-fork-prs"
AllowRepoConfigFlag = "allow-repo-config"
AtlantisURLFlag = "atlantis-url"
Expand Down Expand Up @@ -104,6 +107,7 @@ const (
// NOTE: Must manually set these as defaults in the setDefaults function.
DefaultADBasicUser = ""
DefaultADBasicPassword = ""
DefaultADTimeoutSeconds = 10
DefaultAutoplanFileList = "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl"
DefaultCheckoutStrategy = "branch"
DefaultBitbucketBaseURL = bitbucketcloud.BaseURL
Expand Down Expand Up @@ -278,6 +282,10 @@ var stringFlags = map[string]stringFlag{
}

var boolFlags = map[string]boolFlag{
ADHonorRetryAfter: {
description: "If set to true, the Azure DevOps client will sleep according to the Retry-After response header",
defaultValue: false,
},
AllowForkPRsFlag: {
description: "Allow Atlantis to run on pull requests from forks. A security issue for public repos.",
defaultValue: false,
Expand Down Expand Up @@ -371,6 +379,10 @@ var boolFlags = map[string]boolFlag{
},
}
var intFlags = map[string]intFlag{
ADTimeoutSeconds: {
description: "Sets timeout seconds for the Azure DevOps api client",
defaultValue: DefaultADTimeoutSeconds,
},
ParallelPoolSize: {
description: "Max size of the wait group that runs parallel plans and applies (if enabled).",
defaultValue: DefaultParallelPoolSize,
Expand Down Expand Up @@ -582,6 +594,9 @@ func (s *ServerCmd) setDefaults(c *server.UserConfig) {
if c.AutoplanFileList == "" {
c.AutoplanFileList = DefaultAutoplanFileList
}
if c.AzureDevopsTimeoutSeconds == 0 {
c.AzureDevopsTimeoutSeconds = DefaultADTimeoutSeconds
}
if c.CheckoutStrategy == "" {
c.CheckoutStrategy = DefaultCheckoutStrategy
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (s *ServerStarterMock) Start() error {
// Adding a new flag? Add it to this slice for testing in alphabetical
// order.
var testFlags = map[string]interface{}{
ADHonorRetryAfter: true,
ADTimeoutSeconds: 12,
ADTokenFlag: "ad-token",
ADUserFlag: "ad-user",
ADWebhookPasswordFlag: "ad-wh-pass",
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
}
if userConfig.AzureDevopsUser != "" {
azureDevopsTimeout := 10 * time.Second
if userConfig.AzureDevopsTimeoutSecondss != 0 {
azureDevopsTimeout = time.Duration(userConfig.AzureDevopsTimeoutSecondss) * time.Second
if userConfig.AzureDevopsTimeoutSeconds != 0 {
azureDevopsTimeout = time.Duration(userConfig.AzureDevopsTimeoutSeconds) * time.Second
}
supportedVCSHosts = append(supportedVCSHosts, models.AzureDevops)
var err error
Expand Down
2 changes: 1 addition & 1 deletion server/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type UserConfig struct {
Automerge bool `mapstructure:"automerge"`
AutoplanFileList string `mapstructure:"autoplan-file-list"`
AzureDevopsHonorRetryAfter bool `mapstructure:"azuredevops-honor-retry-after"`
AzureDevopsTimeoutSecondss int `mapstructure:"azuredevops-timeout-seconds"`
AzureDevopsTimeoutSeconds int `mapstructure:"azuredevops-timeout-seconds"`
AzureDevopsToken string `mapstructure:"azuredevops-token"`
AzureDevopsUser string `mapstructure:"azuredevops-user"`
AzureDevopsWebhookPassword string `mapstructure:"azuredevops-webhook-password"`
Expand Down

0 comments on commit c218198

Please sign in to comment.