Skip to content

Commit d35917b

Browse files
scaleway-botremyleoneCodelax
authored
feat(secret_manager): add cli command for AccessSecretVersionByPath (#3766)
Co-authored-by: Rémy Léone <[email protected]> Co-authored-by: Jules Castéran <[email protected]>
1 parent 182fb5b commit d35917b

File tree

6 files changed

+104
-11
lines changed

6 files changed

+104
-11
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Access sensitive data in a secret's version specified by the `region`, `secret_name`, `secret_path` and `revision` parameters.
4+
5+
USAGE:
6+
scw secret version access-by-path [arg=value ...]
7+
8+
ARGS:
9+
[secret-path] Secret's path
10+
[secret-name] Secret's name
11+
revision Version number
12+
[project-id] Project ID to use. If none is passed the default project ID will be used
13+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)
14+
15+
FLAGS:
16+
-h, --help help for access-by-path
17+
18+
GLOBAL FLAGS:
19+
-c, --config string The path to the config file
20+
-D, --debug Enable debug mode
21+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
22+
-p, --profile string The config profile to use

cmd/scw/testdata/test-all-usage-secret-version-usage.golden

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ USAGE:
66
scw secret version <command>
77

88
AVAILABLE COMMANDS:
9-
access Access a secret's version using the secret's ID
10-
create Create a version
11-
delete Delete a version
12-
disable Disable a version
13-
enable Enable a version
14-
get Get metadata of a secret's version using the secret's ID
15-
list List versions of a secret using the secret's ID
16-
update Update metadata of a version
9+
access Access a secret's version using the secret's ID
10+
access-by-path Access a secret's version using the secret's name and path
11+
create Create a version
12+
delete Delete a version
13+
disable Disable a version
14+
enable Enable a version
15+
get Get metadata of a secret's version using the secret's ID
16+
list List versions of a secret using the secret's ID
17+
update Update metadata of a version
1718

1819
FLAGS:
1920
-h, --help help for version

docs/commands/secret.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This API allows you to conveniently store, access and share sensitive data such
1313
- [Update metadata of a secret](#update-metadata-of-a-secret)
1414
- [Secret Version management commands](#secret-version-management-commands)
1515
- [Access a secret's version using the secret's ID](#access-a-secret's-version-using-the-secret's-id)
16+
- [Access a secret's version using the secret's name and path](#access-a-secret's-version-using-the-secret's-name-and-path)
1617
- [Create a version](#create-a-version)
1718
- [Delete a version](#delete-a-version)
1819
- [Disable a version](#disable-a-version)
@@ -289,6 +290,29 @@ scw secret version access 11111111-1111-1111-111111111111 revision=1 field=key r
289290

290291

291292

293+
### Access a secret's version using the secret's name and path
294+
295+
Access sensitive data in a secret's version specified by the `region`, `secret_name`, `secret_path` and `revision` parameters.
296+
297+
**Usage:**
298+
299+
```
300+
scw secret version access-by-path [arg=value ...]
301+
```
302+
303+
304+
**Args:**
305+
306+
| Name | | Description |
307+
|------|---|-------------|
308+
| secret-path | | Secret's path |
309+
| secret-name | | Secret's name |
310+
| revision | Required | Version number |
311+
| project-id | | Project ID to use. If none is passed the default project ID will be used |
312+
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config |
313+
314+
315+
292316
### Create a version
293317

294318
Create a version of a given secret specified by the `region` and `secret_id` parameters.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/mattn/go-isatty v0.0.20
2424
github.com/moby/buildkit v0.13.1
2525
github.com/opencontainers/go-digest v1.0.0
26-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.25.0.20240412091545-9f7b1dea216b
26+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.26
2727
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
2828
github.com/spf13/cobra v1.8.0
2929
github.com/spf13/pflag v1.0.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
451451
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
452452
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
453453
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
454-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.25.0.20240412091545-9f7b1dea216b h1:LQ/fJt1SC7g1l88/Dgz66KC9QP2SoWbGiR+y3oW7ivo=
455-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.25.0.20240412091545-9f7b1dea216b/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
454+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.26 h1:F+GIVtGqCFxPxO46ujf8cEOP574MBoRm3gNbPXECbxs=
455+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.26/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
456456
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
457457
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
458458
github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA=

internal/namespaces/secret/v1beta1/secret_cli.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func GetGeneratedCommands() *core.Commands {
3636
secretVersionDelete(),
3737
secretVersionList(),
3838
secretVersionAccess(),
39+
secretVersionAccessByPath(),
3940
secretVersionEnable(),
4041
secretVersionDisable(),
4142
)
@@ -812,6 +813,51 @@ func secretVersionAccess() *core.Command {
812813
}
813814
}
814815

816+
func secretVersionAccessByPath() *core.Command {
817+
return &core.Command{
818+
Short: `Access a secret's version using the secret's name and path`,
819+
Long: `Access sensitive data in a secret's version specified by the ` + "`" + `region` + "`" + `, ` + "`" + `secret_name` + "`" + `, ` + "`" + `secret_path` + "`" + ` and ` + "`" + `revision` + "`" + ` parameters.`,
820+
Namespace: "secret",
821+
Resource: "version",
822+
Verb: "access-by-path",
823+
// Deprecated: false,
824+
ArgsType: reflect.TypeOf(secret.AccessSecretVersionByPathRequest{}),
825+
ArgSpecs: core.ArgSpecs{
826+
{
827+
Name: "secret-path",
828+
Short: `Secret's path`,
829+
Required: false,
830+
Deprecated: false,
831+
Positional: false,
832+
},
833+
{
834+
Name: "secret-name",
835+
Short: `Secret's name`,
836+
Required: false,
837+
Deprecated: false,
838+
Positional: false,
839+
},
840+
{
841+
Name: "revision",
842+
Short: `Version number`,
843+
Required: true,
844+
Deprecated: false,
845+
Positional: false,
846+
},
847+
core.ProjectIDArgSpec(),
848+
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw),
849+
},
850+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
851+
request := args.(*secret.AccessSecretVersionByPathRequest)
852+
853+
client := core.ExtractClient(ctx)
854+
api := secret.NewAPI(client)
855+
return api.AccessSecretVersionByPath(request)
856+
857+
},
858+
}
859+
}
860+
815861
func secretVersionEnable() *core.Command {
816862
return &core.Command{
817863
Short: `Enable a version`,

0 commit comments

Comments
 (0)