Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/MakeNowJust/heredoc/v2 v2.0.1
github.com/OctopusDeploy/go-octodiff v1.0.0
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.99.0
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.103.0
github.com/bmatcuk/doublestar/v4 v4.4.0
github.com/briandowns/spinner v1.19.0
github.com/google/uuid v1.3.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ github.com/OctopusDeploy/go-octodiff v1.0.0 h1:U+ORg6azniwwYo+O44giOw6TiD5USk8S4
github.com/OctopusDeploy/go-octodiff v1.0.0/go.mod h1:Mze0+EkOWTgTmi8++fyUc6r0aLZT7qD9gX+31t8MmIU=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.99.0 h1:0HzgNBPiOGY7ekP+uoRbX1DeMs0Y2JpJ3ecmUxFtC1o=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.99.0/go.mod h1:VkTXDoIPbwGFi5+goo1VSwFNdMVo784cVtJdKIEvfus=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.103.0 h1:yGQxxqm3lXgEFITtdhXC7FQPufTwdPgy0+aXMKw4uOw=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.103.0/go.mod h1:VkTXDoIPbwGFi5+goo1VSwFNdMVo784cVtJdKIEvfus=
github.com/bmatcuk/doublestar/v4 v4.4.0 h1:LmAwNwhjEbYtyVLzjcP/XeVw4nhuScHGkF/XWXnvIic=
github.com/bmatcuk/doublestar/v4 v4.4.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/briandowns/spinner v1.19.0 h1:s8aq38H+Qju89yhp89b4iIiMzMm8YN3p6vGpwyh/a8E=
Expand Down
15 changes: 14 additions & 1 deletion pkg/cmd/account/aws/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type CreateFlags struct {
Description *flag.Flag[string]
AccessKey *flag.Flag[string]
SecretKey *flag.Flag[string]
Region *flag.Flag[string]
Environments *flag.Flag[[]string]
}

Expand All @@ -43,6 +44,7 @@ func NewCreateFlags() *CreateFlags {
Description: flag.New[string]("description", false),
AccessKey: flag.New[string]("access-key", false),
SecretKey: flag.New[string]("secret-key", true),
Region: flag.New[string]("region", false),
Environments: flag.New[[]string]("environment", false),
}
}
Expand Down Expand Up @@ -95,6 +97,7 @@ func NewCmdCreate(f factory.Factory) *cobra.Command {
flags.StringVarP(&createFlags.Description.Value, createFlags.Description.Name, "d", "", "A summary explaining the use of the account to other users.")
flags.StringVar(&createFlags.AccessKey.Value, createFlags.AccessKey.Name, "", "The AWS access key to use when authenticating against Amazon Web Services.")
flags.StringVar(&createFlags.SecretKey.Value, createFlags.SecretKey.Name, "", "The AWS secret key to use when authenticating against Amazon Web Services.")
flags.StringVar(&createFlags.Region.Value, createFlags.Region.Name, "", "The AWS region to use for this account.")
flags.StringArrayVarP(&createFlags.Environments.Value, createFlags.Environments.Name, "e", nil, "The environments that are allowed to use this account")
flags.StringVarP(&descriptionFilePath, "description-file", "D", "", "Read the description from `file`")

Expand All @@ -112,6 +115,7 @@ func CreateRun(opts *CreateOptions) error {
return err
}
awsAccount.Description = opts.Description.Value
awsAccount.Region = opts.Region.Value
awsAccount.EnvironmentIDs = opts.Environments.Value

createdAccount, err := opts.Client.Accounts.Add(awsAccount)
Expand All @@ -126,7 +130,7 @@ func CreateRun(opts *CreateOptions) error {
link := output.Bluef("%s/app#/%s/infrastructure/accounts/%s", opts.Host, opts.Space.GetID(), createdAccount.GetID())
fmt.Fprintf(opts.Out, "\nView this account on Octopus Deploy: %s\n", link)
if !opts.NoPrompt {
autoCmd := flag.GenerateAutomationCmd(opts.CmdPath, opts.Name, opts.AccessKey, opts.SecretKey, opts.Description, opts.Environments)
autoCmd := flag.GenerateAutomationCmd(opts.CmdPath, opts.Name, opts.AccessKey, opts.SecretKey, opts.Region, opts.Description, opts.Environments)
fmt.Fprintf(opts.Out, "\nAutomation Command: %s\n", autoCmd)
}

Expand Down Expand Up @@ -182,6 +186,15 @@ func PromptMissing(opts *CreateOptions) error {
}
}

if opts.Region.Value == "" {
if err := opts.Ask(&survey.Input{
Message: "Region",
Help: "The AWS region to use for this account.",
}, &opts.Region.Value); err != nil {
return err
}
}

if opts.Environments.Value == nil {
envs, err := selectors.EnvironmentsMultiSelect(opts.Ask, opts.GetAllEnvironmentsCallback,
"Choose the environments that are allowed to use this account.\n"+
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/account/aws/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func TestAWSAccountCreatePromptMissing(t *testing.T) {
Help: "The AWS secret key to use when authenticating against Amazon Web Services.",
}).AnswerWith("testpassword124")

_ = qa.ExpectQuestion(t, &survey.Input{
Message: "Region",
Help: "The AWS region to use for this account.",
}).AnswerWith("us-east-1")

_ = qa.ExpectQuestion(t, &survey.MultiSelect{
Message: "Choose the environments that are allowed to use this account.\nIf nothing is selected, the account can be used for deployments to any environment.",
Options: []string{"testenv"},
Expand All @@ -89,6 +94,7 @@ func TestAWSAccountCreatePromptMissing(t *testing.T) {
assert.Equal(t, []string{envID}, opts.Environments.Value)
assert.Equal(t, "testpassword124", opts.SecretKey.Value)
assert.Equal(t, "testaccesskey123", opts.AccessKey.Value)
assert.Equal(t, "us-east-1", opts.Region.Value)
assert.Equal(t, "test 123", opts.Description.Value)
assert.Equal(t, "TestAccount", opts.Name.Value)
}
Expand All @@ -108,6 +114,7 @@ func TestAWSAccountCreateNoPrompt(t *testing.T) {
opts.Name.Value = "testaccount"
opts.AccessKey.Value = "testaccesskey123"
opts.SecretKey.Value = "testsecretkey123"
opts.Region.Value = "us-west-2"

errReceiver := testutil.GoBegin(func() error {
defer testutil.Close(api, qa)
Expand All @@ -128,6 +135,7 @@ func TestAWSAccountCreateNoPrompt(t *testing.T) {
testAccount.ID = "Account-1"
testAccount.Slug = "testaccount"
testAccount.SpaceID = spaceID
testAccount.Region = opts.Region.Value

api.ExpectRequest(t, "GET", "/api/").RespondWith(rootResource)
api.ExpectRequest(t, "GET", "/api/spaces").RespondWith(rootResource)
Expand Down
6 changes: 4 additions & 2 deletions pkg/cmd/account/aws/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,20 @@ func listAwsAccounts(client *client.Client, cmd *cobra.Command) error {
Slug string
Name string
AccessKey string
Region string
}{
Id: acc.GetID(),
Slug: acc.GetSlug(),
Name: acc.GetName(),
AccessKey: acc.AccessKey,
Region: acc.Region,
}
},
Table: output.TableDefinition[accounts.IAccount]{
Header: []string{"NAME", "SLUG", "ACCESS KEY"},
Header: []string{"NAME", "SLUG", "ACCESS KEY", "REGION"},
Row: func(item accounts.IAccount) []string {
acc := item.(*accounts.AmazonWebServicesAccount)
return []string{output.Bold(acc.GetName()), acc.GetSlug(), acc.AccessKey}
return []string{output.Bold(acc.GetName()), acc.GetSlug(), acc.AccessKey, acc.Region}
}},
Basic: func(item accounts.IAccount) string {
return item.GetName()
Expand Down