(f factory.Factory)
| 63 | } |
| 64 | |
| 65 | func NewCmdCreate(f factory.Factory) *cobra.Command { |
| 66 | createFlags := NewCreateFlags() |
| 67 | descriptionFilePath := "" |
| 68 | |
| 69 | cmd := &cobra.Command{ |
| 70 | Use: "create", |
| 71 | Short: "Create a SSH Key Pair account", |
| 72 | Long: "Create a SSH Key Pair account in Octopus Deploy", |
| 73 | Example: heredoc.Docf("%s account ssh create", constants.ExecutableName), |
| 74 | Aliases: []string{"new"}, |
| 75 | RunE: func(c *cobra.Command, _ []string) error { |
| 76 | opts := NewCreateOptions(createFlags, cmd.NewDependencies(f, c)) |
| 77 | if descriptionFilePath != "" { |
| 78 | if err := validation.IsExistingFile(descriptionFilePath); err != nil { |
| 79 | return err |
| 80 | } |
| 81 | data, err := os.ReadFile(descriptionFilePath) |
| 82 | if err != nil { |
| 83 | return err |
| 84 | } |
| 85 | opts.Description.Value = string(data) |
| 86 | } |
| 87 | if opts.KeyFilePath.Value != "" { |
| 88 | if err := validation.IsExistingFile(opts.KeyFilePath.Value); err != nil { |
| 89 | return err |
| 90 | } |
| 91 | data, err := os.ReadFile(opts.KeyFilePath.Value) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | opts.KeyFileData = data |
| 96 | } |
| 97 | if opts.Environments.Value != nil { |
| 98 | env, err := helper.ResolveEnvironmentNames(opts.Environments.Value, opts.Client) |
| 99 | if err != nil { |
| 100 | return err |
| 101 | } |
| 102 | opts.Environments.Value = env |
| 103 | } |
| 104 | return CreateRun(opts) |
| 105 | }, |
| 106 | } |
| 107 | |
| 108 | flags := cmd.Flags() |
| 109 | flags.StringVarP(&createFlags.Name.Value, createFlags.Name.Name, "n", "", "A short, memorable, unique name for this account.") |
| 110 | flags.StringVarP(&createFlags.Description.Value, createFlags.Description.Name, "d", "", "A summary explaining the use of the account to other users.") |
| 111 | flags.StringVarP(&createFlags.KeyFilePath.Value, createFlags.KeyFilePath.Name, "K", "", "Path to the private key file portion of the key pair.") |
| 112 | flags.StringVarP(&createFlags.Username.Value, createFlags.Username.Name, "u", "", "The username to use when authenticating against the remote host.") |
| 113 | flags.StringVarP(&createFlags.Passphrase.Value, createFlags.Passphrase.Name, "p", "", "The passphrase for the private key, if required.") |
| 114 | flags.StringArrayVarP(&createFlags.Environments.Value, createFlags.Environments.Name, "e", nil, "The environments that are allowed to use this account.") |
| 115 | flags.StringVarP(&descriptionFilePath, "description-file", "D", "", "Read the description from `file`.") |
| 116 | |
| 117 | return cmd |
| 118 | } |
| 119 | |
| 120 | func CreateRun(opts *CreateOptions) error { |
| 121 | if !opts.NoPrompt { |
nothing calls this directly
no test coverage detected