(f factory.Factory)
| 61 | } |
| 62 | |
| 63 | func NewCmdCreate(f factory.Factory) *cobra.Command { |
| 64 | createFlags := NewCreateFlags() |
| 65 | descriptionFilePath := "" |
| 66 | |
| 67 | cmd := &cobra.Command{ |
| 68 | Use: "create", |
| 69 | Short: "Create an AWS account", |
| 70 | Long: "Create an AWS account in Octopus Deploy", |
| 71 | Example: heredoc.Docf("%s account aws create", constants.ExecutableName), |
| 72 | Aliases: []string{"new"}, |
| 73 | RunE: func(c *cobra.Command, _ []string) error { |
| 74 | opts := NewCreateOptions(createFlags, cmd.NewDependencies(f, c)) |
| 75 | if descriptionFilePath != "" { |
| 76 | if err := validation.IsExistingFile(descriptionFilePath); err != nil { |
| 77 | return err |
| 78 | } |
| 79 | data, err := os.ReadFile(descriptionFilePath) |
| 80 | if err != nil { |
| 81 | return err |
| 82 | } |
| 83 | opts.Description.Value = string(data) |
| 84 | } |
| 85 | if opts.Environments.Value != nil { |
| 86 | env, err := helper.ResolveEnvironmentNames(opts.Environments.Value, opts.Client) |
| 87 | if err != nil { |
| 88 | return err |
| 89 | } |
| 90 | opts.Environments.Value = env |
| 91 | } |
| 92 | return CreateRun(opts) |
| 93 | }, |
| 94 | } |
| 95 | |
| 96 | flags := cmd.Flags() |
| 97 | flags.StringVarP(&createFlags.Name.Value, createFlags.Name.Name, "n", "", "A short, memorable, unique name for this account.") |
| 98 | flags.StringVarP(&createFlags.Description.Value, createFlags.Description.Name, "d", "", "A summary explaining the use of the account to other users.") |
| 99 | flags.StringVar(&createFlags.AccessKey.Value, createFlags.AccessKey.Name, "", "The AWS access key to use when authenticating against Amazon Web Services.") |
| 100 | flags.StringVar(&createFlags.SecretKey.Value, createFlags.SecretKey.Name, "", "The AWS secret key to use when authenticating against Amazon Web Services.") |
| 101 | flags.StringVar(&createFlags.Region.Value, createFlags.Region.Name, "", "The AWS region to use for this account.") |
| 102 | flags.StringArrayVarP(&createFlags.Environments.Value, createFlags.Environments.Name, "e", nil, "The environments that are allowed to use this account") |
| 103 | flags.StringVarP(&descriptionFilePath, "description-file", "D", "", "Read the description from `file`") |
| 104 | |
| 105 | return cmd |
| 106 | } |
| 107 | |
| 108 | func CreateRun(opts *CreateOptions) error { |
| 109 | if !opts.NoPrompt { |
nothing calls this directly
no test coverage detected