()
| 57 | } |
| 58 | |
| 59 | func (r *RootCmd) secretCreate() *serpent.Command { |
| 60 | var ( |
| 61 | value string |
| 62 | description string |
| 63 | env string |
| 64 | file string |
| 65 | ) |
| 66 | |
| 67 | cmd := &serpent.Command{ |
| 68 | Use: "create <name>", |
| 69 | Short: "Create a secret", |
| 70 | Long: "Provide the secret value with --value or non-interactive stdin (pipe or redirect).", |
| 71 | Middleware: serpent.Chain( |
| 72 | serpent.RequireNArgs(1), |
| 73 | ), |
| 74 | Options: serpent.OptionSet{ |
| 75 | { |
| 76 | Name: "value", |
| 77 | Flag: "value", |
| 78 | Description: "Set the secret value. For security reasons, prefer non-interactive stdin (pipe or redirect).", |
| 79 | Value: serpent.StringOf(&value), |
| 80 | }, |
| 81 | { |
| 82 | Name: "description", |
| 83 | Flag: "description", |
| 84 | Description: "Set the secret description.", |
| 85 | Value: serpent.StringOf(&description), |
| 86 | }, |
| 87 | { |
| 88 | Name: "env", |
| 89 | Flag: "env", |
| 90 | Description: "Name of the workspace environment variable that this secret will set.", |
| 91 | Value: serpent.StringOf(&env), |
| 92 | }, |
| 93 | { |
| 94 | Name: "file", |
| 95 | Flag: "file", |
| 96 | Description: "Workspace file path where this secret will be written. Must start with ~/ or /.", |
| 97 | Value: serpent.StringOf(&file), |
| 98 | }, |
| 99 | }, |
| 100 | Handler: func(inv *serpent.Invocation) error { |
| 101 | client, err := r.InitClient(inv) |
| 102 | if err != nil { |
| 103 | return err |
| 104 | } |
| 105 | |
| 106 | resolvedValue, ok, err := secretValue(inv, value) |
| 107 | if err != nil { |
| 108 | return err |
| 109 | } |
| 110 | if !ok { |
| 111 | if isTTYIn(inv) { |
| 112 | return xerrors.New("secret value must be provided with --value or stdin via pipe or redirect") |
| 113 | } |
| 114 | return xerrors.New("secret value must be provided by exactly one of --value or non-interactive stdin (pipe or redirect)") |
| 115 | } |
| 116 |
no test coverage detected