| 118 | } |
| 119 | |
| 120 | func CreateRun(opts *CreateOptions) error { |
| 121 | if !opts.NoPrompt { |
| 122 | if err := PromptMissing(opts); err != nil { |
| 123 | return err |
| 124 | } |
| 125 | } |
| 126 | sshAccount, err := accounts.NewSSHKeyAccount( |
| 127 | opts.Name.Value, |
| 128 | opts.Username.Value, |
| 129 | core.NewSensitiveValue(b64.StdEncoding.EncodeToString(opts.KeyFileData)), |
| 130 | ) |
| 131 | if err != nil { |
| 132 | return err |
| 133 | } |
| 134 | sshAccount.Description = opts.Description.Value |
| 135 | sshAccount.EnvironmentIDs = opts.Environments.Value |
| 136 | if opts.Passphrase.Value != "" { |
| 137 | sshAccount.PrivateKeyPassphrase = core.NewSensitiveValue(opts.Passphrase.Value) |
| 138 | } |
| 139 | |
| 140 | createdAccount, err := opts.Client.Accounts.Add(sshAccount) |
| 141 | if err != nil { |
| 142 | return err |
| 143 | } |
| 144 | |
| 145 | _, err = fmt.Fprintf(opts.Out, "Successfully created SSH account %s %s.\n", createdAccount.GetName(), output.Dimf("(%s)", createdAccount.GetSlug())) |
| 146 | if err != nil { |
| 147 | return err |
| 148 | } |
| 149 | link := output.Bluef("%s/app#/%s/infrastructure/accounts/%s", opts.Host, opts.Space.GetID(), createdAccount.GetID()) |
| 150 | _, _ = fmt.Fprintf(opts.Out, "\nView this account on Octopus Deploy: %s\n", link) |
| 151 | if !opts.NoPrompt { |
| 152 | autoCmd := flag.GenerateAutomationCmd(opts.CmdPath, opts.GetSpaceNameOrEmpty(), opts.Name, opts.KeyFilePath, opts.Passphrase, opts.Description, opts.Environments) |
| 153 | _, _ = fmt.Fprintf(opts.Out, "\nAutomation Command: %s\n", autoCmd) |
| 154 | } |
| 155 | return nil |
| 156 | } |
| 157 | |
| 158 | func PromptMissing(opts *CreateOptions) error { |
| 159 | if opts.Name.Value == "" { |