Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Create folder.

USAGE:
scw secret folder create [arg=value ...]

ARGS:
[project-id] Project ID to use. If none is passed the default project ID will be used
[name] Name of the folder
[path] Path of the folder
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for create

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Delete a given folder specified by the `region` and `folder_id` parameters.

USAGE:
scw secret folder delete [arg=value ...]

ARGS:
folder-id ID of the folder
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for delete

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
21 changes: 21 additions & 0 deletions cmd/scw/testdata/test-all-usage-secret-folder-list-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Retrieve the list of folders created within a Project.

USAGE:
scw secret folder list [arg=value ...]

ARGS:
[project-id] Filter by Project ID (optional)
[path] Filter by path (optional)
[order-by] (created_at_asc | created_at_desc | name_asc | name_desc)
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | all)

FLAGS:
-h, --help help for list

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
22 changes: 22 additions & 0 deletions cmd/scw/testdata/test-all-usage-secret-folder-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Location of the secret in the directory structure.

USAGE:
scw secret folder <command>

AVAILABLE COMMANDS:
create Create folder
delete Delete a given folder specified by the `region` and `folder_id` parameters
list List folders

FLAGS:
-h, --help help for folder

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use

Use "scw secret folder [command] --help" for more information about a command.
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-secret-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ USAGE:
scw secret <command>

AVAILABLE COMMANDS:
folder Folder management commands
secret Secret management commands
version Secret Version management commands

Expand Down
73 changes: 73 additions & 0 deletions docs/commands/secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Documentation for `scw secret`
This API allows you to conveniently store, access and share sensitive data.

- [Folder management commands](#folder-management-commands)
- [Create folder](#create-folder)
- [Delete a given folder specified by the `region` and `folder_id` parameters](#delete-a-given-folder-specified-by-the-`region`-and-`folder_id`-parameters)
- [List folders](#list-folders)
- [Secret management commands](#secret-management-commands)
- [Create a secret](#create-a-secret)
- [Delete a secret](#delete-a-secret)
Expand All @@ -20,6 +24,75 @@ This API allows you to conveniently store, access and share sensitive data.
- [Update metadata of a version](#update-metadata-of-a-version)


## Folder management commands

Location of the secret in the directory structure.


### Create folder

Create folder.

**Usage:**

```
scw secret folder create [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| project-id | | Project ID to use. If none is passed the default project ID will be used |
| name | | Name of the folder |
| path | | Path of the folder |
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |



### Delete a given folder specified by the `region` and `folder_id` parameters

Delete a given folder specified by the `region` and `folder_id` parameters.

**Usage:**

```
scw secret folder delete [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| folder-id | Required | ID of the folder |
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |



### List folders

Retrieve the list of folders created within a Project.

**Usage:**

```
scw secret folder list [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| project-id | | Filter by Project ID (optional) |
| path | | Filter by path (optional) |
| order-by | One of: `created_at_asc`, `created_at_desc`, `name_asc`, `name_desc` | |
| region | Default: `fr-par`<br />One of: `fr-par`, `all` | Region to target. If none is passed will use default region from the config |



## Secret management commands

Secrets are logical containers made up of zero or more immutable versions, that contain sensitive data.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/moby/buildkit v0.11.6
github.com/opencontainers/go-digest v1.0.0
github.com/pkg/errors v0.9.1
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20230918151823-4f048611ed7c
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20230919140146-a731a0058f98
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20230918151823-4f048611ed7c h1:HM3dPr4NWDAAJDt3mmJGLZ+1SqvQNbRM0zBvBB4UHmU=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20230918151823-4f048611ed7c/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20230919140146-a731a0058f98 h1:iqhgEyhgtkgQzptcemy9csJIzdg7RS64a9Przn2ZDGk=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20230919140146-a731a0058f98/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down
140 changes: 140 additions & 0 deletions internal/namespaces/secret/v1alpha1/secret_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ var (
func GetGeneratedCommands() *core.Commands {
return core.NewCommands(
secretRoot(),
secretFolder(),
secretSecret(),
secretVersion(),
secretSecretCreate(),
secretFolderCreate(),
secretSecretGet(),
secretSecretUpdate(),
secretSecretList(),
secretFolderList(),
secretSecretDelete(),
secretFolderDelete(),
secretVersionCreate(),
secretVersionGeneratePassword(),
secretVersionGet(),
Expand All @@ -46,6 +50,15 @@ func secretRoot() *core.Command {
}
}

func secretFolder() *core.Command {
return &core.Command{
Short: `Folder management commands`,
Long: `Location of the secret in the directory structure.`,
Namespace: "secret",
Resource: "folder",
}
}

func secretSecret() *core.Command {
return &core.Command{
Short: `Secret management commands`,
Expand Down Expand Up @@ -130,6 +143,44 @@ func secretSecretCreate() *core.Command {
}
}

func secretFolderCreate() *core.Command {
return &core.Command{
Short: `Create folder`,
Long: `Create folder.`,
Namespace: "secret",
Resource: "folder",
Verb: "create",
// Deprecated: false,
ArgsType: reflect.TypeOf(secret.CreateFolderRequest{}),
ArgSpecs: core.ArgSpecs{
core.ProjectIDArgSpec(),
{
Name: "name",
Short: `Name of the folder`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "path",
Short: `Path of the folder`,
Required: false,
Deprecated: false,
Positional: false,
},
core.RegionArgSpec(scw.RegionFrPar),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*secret.CreateFolderRequest)

client := core.ExtractClient(ctx)
api := secret.NewAPI(client)
return api.CreateFolder(request)

},
}
}

func secretSecretGet() *core.Command {
return &core.Command{
Short: `Get metadata using the secret's ID`,
Expand Down Expand Up @@ -299,6 +350,59 @@ func secretSecretList() *core.Command {
}
}

func secretFolderList() *core.Command {
return &core.Command{
Short: `List folders`,
Long: `Retrieve the list of folders created within a Project.`,
Namespace: "secret",
Resource: "folder",
Verb: "list",
// Deprecated: false,
ArgsType: reflect.TypeOf(secret.ListFoldersRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "project-id",
Short: `Filter by Project ID (optional)`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "path",
Short: `Filter by path (optional)`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "order-by",
Required: false,
Deprecated: false,
Positional: false,
EnumValues: []string{"created_at_asc", "created_at_desc", "name_asc", "name_desc"},
},
core.RegionArgSpec(scw.RegionFrPar, scw.Region(core.AllLocalities)),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*secret.ListFoldersRequest)

client := core.ExtractClient(ctx)
api := secret.NewAPI(client)
opts := []scw.RequestOption{scw.WithAllPages()}
if request.Region == scw.Region(core.AllLocalities) {
opts = append(opts, scw.WithRegions(api.Regions()...))
request.Region = ""
}
resp, err := api.ListFolders(request, opts...)
if err != nil {
return nil, err
}
return resp.Folders, nil

},
}
}

func secretSecretDelete() *core.Command {
return &core.Command{
Short: `Delete a secret`,
Expand Down Expand Up @@ -341,6 +445,42 @@ func secretSecretDelete() *core.Command {
}
}

func secretFolderDelete() *core.Command {
return &core.Command{
Short: `Delete a given folder specified by the ` + "`" + `region` + "`" + ` and ` + "`" + `folder_id` + "`" + ` parameters`,
Long: `Delete a given folder specified by the ` + "`" + `region` + "`" + ` and ` + "`" + `folder_id` + "`" + ` parameters.`,
Namespace: "secret",
Resource: "folder",
Verb: "delete",
// Deprecated: false,
ArgsType: reflect.TypeOf(secret.DeleteFolderRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "folder-id",
Short: `ID of the folder`,
Required: true,
Deprecated: false,
Positional: false,
},
core.RegionArgSpec(scw.RegionFrPar),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*secret.DeleteFolderRequest)

client := core.ExtractClient(ctx)
api := secret.NewAPI(client)
e = api.DeleteFolder(request)
if e != nil {
return nil, e
}
return &core.SuccessResult{
Resource: "folder",
Verb: "delete",
}, nil
},
}
}

func secretVersionCreate() *core.Command {
return &core.Command{
Short: `Create a version`,
Expand Down