Skip to content

Commit fd66ebe

Browse files
authored
feat(iam): enable cli commands for new JWT IAM (#2843)
1 parent 11954d4 commit fd66ebe

File tree

9 files changed

+277
-3
lines changed

9 files changed

+277
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Delete a JWT.
4+
5+
USAGE:
6+
scw iam jwt delete <jti ...> [arg=value ...]
7+
8+
ARGS:
9+
jti JWT ID of the JWT to delete
10+
11+
FLAGS:
12+
-h, --help help for delete
13+
14+
GLOBAL FLAGS:
15+
-c, --config string The path to the config file
16+
-D, --debug Enable debug mode
17+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
18+
-p, --profile string The config profile to use
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Get a JWT.
4+
5+
USAGE:
6+
scw iam jwt get <jti ...> [arg=value ...]
7+
8+
ARGS:
9+
jti JWT ID of the JWT to get
10+
11+
FLAGS:
12+
-h, --help help for get
13+
14+
GLOBAL FLAGS:
15+
-c, --config string The path to the config file
16+
-D, --debug Enable debug mode
17+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
18+
-p, --profile string The config profile to use
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
List JWTs.
4+
5+
USAGE:
6+
scw iam jwt list <audience-id ...> [arg=value ...]
7+
8+
ARGS:
9+
[order-by=created_at_asc] Criteria for sorting results (created_at_asc | created_at_desc | updated_at_asc | updated_at_desc)
10+
audience-id ID of the user to search
11+
[expired] Filter out expired JWTs or not
12+
13+
FLAGS:
14+
-h, --help help for list
15+
16+
GLOBAL FLAGS:
17+
-c, --config string The path to the config file
18+
-D, --debug Enable debug mode
19+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
20+
-p, --profile string The config profile to use
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+
JWTs management commands.
4+
5+
USAGE:
6+
scw iam jwt <command>
7+
8+
AVAILABLE COMMANDS:
9+
delete Delete a JWT
10+
get Get a JWT
11+
list List JWTs
12+
13+
FLAGS:
14+
-h, --help help for jwt
15+
16+
GLOBAL FLAGS:
17+
-c, --config string The path to the config file
18+
-D, --debug Enable debug mode
19+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
20+
-p, --profile string The config profile to use
21+
22+
Use "scw iam jwt [command] --help" for more information about a command.

cmd/scw/testdata/test-all-usage-iam-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ AVAILABLE COMMANDS:
99
api-key API keys management commands
1010
application Applications management commands
1111
group Groups management commands
12+
jwt JWTs management commands
1213
permission-set Permission sets management commands
1314
policy Policies management commands
1415
rule Rules management commands

docs/commands/iam.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ IAM API.
2222
- [List groups](#list-groups)
2323
- [Remove a user or an application from a group](#remove-a-user-or-an-application-from-a-group)
2424
- [Update a group](#update-a-group)
25+
- [JWTs management commands](#jwts-management-commands)
26+
- [Delete a JWT](#delete-a-jwt)
27+
- [Get a JWT](#get-a-jwt)
28+
- [List JWTs](#list-jwts)
2529
- [Permission sets management commands](#permission-sets-management-commands)
2630
- [List permission sets](#list-permission-sets)
2731
- [Policies management commands](#policies-management-commands)
@@ -450,6 +454,70 @@ scw iam group update <group-id ...> [arg=value ...]
450454

451455

452456

457+
## JWTs management commands
458+
459+
JWTs management commands.
460+
461+
462+
### Delete a JWT
463+
464+
Delete a JWT.
465+
466+
**Usage:**
467+
468+
```
469+
scw iam jwt delete <jti ...> [arg=value ...]
470+
```
471+
472+
473+
**Args:**
474+
475+
| Name | | Description |
476+
|------|---|-------------|
477+
| jti | Required | JWT ID of the JWT to delete |
478+
479+
480+
481+
### Get a JWT
482+
483+
Get a JWT.
484+
485+
**Usage:**
486+
487+
```
488+
scw iam jwt get <jti ...> [arg=value ...]
489+
```
490+
491+
492+
**Args:**
493+
494+
| Name | | Description |
495+
|------|---|-------------|
496+
| jti | Required | JWT ID of the JWT to get |
497+
498+
499+
500+
### List JWTs
501+
502+
List JWTs.
503+
504+
**Usage:**
505+
506+
```
507+
scw iam jwt list <audience-id ...> [arg=value ...]
508+
```
509+
510+
511+
**Args:**
512+
513+
| Name | | Description |
514+
|------|---|-------------|
515+
| order-by | Default: `created_at_asc`<br />One of: `created_at_asc`, `created_at_desc`, `updated_at_asc`, `updated_at_desc` | Criteria for sorting results |
516+
| audience-id | Required | ID of the user to search |
517+
| expired | | Filter out expired JWTs or not |
518+
519+
520+
453521
## Permission sets management commands
454522

455523
Permission sets management commands.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/kubernetes-client/go-base v0.0.0-20190205182333-3d0e39759d98
1919
github.com/mattn/go-colorable v0.1.13
2020
github.com/mattn/go-isatty v0.0.17
21-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.13.0.20230306133533-4d68c6d85168
21+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.13.0.20230306094809-4ec1978c9301
2222
github.com/spf13/cobra v1.6.1
2323
github.com/spf13/pflag v1.0.5
2424
github.com/stretchr/testify v1.8.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw
7070
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7171
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7272
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
73-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.13.0.20230306133533-4d68c6d85168 h1:bUf4bR8Ye8gjF6i7ZyPLmmIQ9C4U2G/5PopVCY0LYUo=
74-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.13.0.20230306133533-4d68c6d85168/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
73+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.13.0.20230306094809-4ec1978c9301 h1:HdxHfgHbFFeBZ2oMeA7KJf3N20zBaGEiq9i51vjuDrM=
74+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.13.0.20230306094809-4ec1978c9301/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
7575
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
7676
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
7777
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=

internal/namespaces/iam/v1alpha1/iam_cli.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func GetGeneratedCommands() *core.Commands {
2828
iamPolicy(),
2929
iamRule(),
3030
iamPermissionSet(),
31+
iamJwt(),
3132
iamSSHKeyList(),
3233
iamSSHKeyCreate(),
3334
iamSSHKeyGet(),
@@ -61,6 +62,9 @@ func GetGeneratedCommands() *core.Commands {
6162
iamAPIKeyGet(),
6263
iamAPIKeyUpdate(),
6364
iamAPIKeyDelete(),
65+
iamJwtList(),
66+
iamJwtGet(),
67+
iamJwtDelete(),
6468
)
6569
}
6670
func iamRoot() *core.Command {
@@ -143,6 +147,15 @@ func iamPermissionSet() *core.Command {
143147
}
144148
}
145149

150+
func iamJwt() *core.Command {
151+
return &core.Command{
152+
Short: `JWTs management commands`,
153+
Long: `JWTs management commands.`,
154+
Namespace: "iam",
155+
Resource: "jwt",
156+
}
157+
}
158+
146159
func iamSSHKeyList() *core.Command {
147160
return &core.Command{
148161
Short: `List SSH keys`,
@@ -1827,3 +1840,117 @@ func iamAPIKeyDelete() *core.Command {
18271840
},
18281841
}
18291842
}
1843+
1844+
func iamJwtList() *core.Command {
1845+
return &core.Command{
1846+
Short: `List JWTs`,
1847+
Long: `List JWTs.`,
1848+
Namespace: "iam",
1849+
Resource: "jwt",
1850+
Verb: "list",
1851+
// Deprecated: false,
1852+
ArgsType: reflect.TypeOf(iam.ListJWTsRequest{}),
1853+
ArgSpecs: core.ArgSpecs{
1854+
{
1855+
Name: "order-by",
1856+
Short: `Criteria for sorting results`,
1857+
Required: false,
1858+
Deprecated: false,
1859+
Positional: false,
1860+
Default: core.DefaultValueSetter("created_at_asc"),
1861+
EnumValues: []string{"created_at_asc", "created_at_desc", "updated_at_asc", "updated_at_desc"},
1862+
},
1863+
{
1864+
Name: "audience-id",
1865+
Short: `ID of the user to search`,
1866+
Required: true,
1867+
Deprecated: false,
1868+
Positional: true,
1869+
},
1870+
{
1871+
Name: "expired",
1872+
Short: `Filter out expired JWTs or not`,
1873+
Required: false,
1874+
Deprecated: false,
1875+
Positional: false,
1876+
},
1877+
},
1878+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
1879+
request := args.(*iam.ListJWTsRequest)
1880+
1881+
client := core.ExtractClient(ctx)
1882+
api := iam.NewAPI(client)
1883+
opts := []scw.RequestOption{scw.WithAllPages()}
1884+
resp, err := api.ListJWTs(request, opts...)
1885+
if err != nil {
1886+
return nil, err
1887+
}
1888+
return resp.Jwts, nil
1889+
1890+
},
1891+
}
1892+
}
1893+
1894+
func iamJwtGet() *core.Command {
1895+
return &core.Command{
1896+
Short: `Get a JWT`,
1897+
Long: `Get a JWT.`,
1898+
Namespace: "iam",
1899+
Resource: "jwt",
1900+
Verb: "get",
1901+
// Deprecated: false,
1902+
ArgsType: reflect.TypeOf(iam.GetJWTRequest{}),
1903+
ArgSpecs: core.ArgSpecs{
1904+
{
1905+
Name: "jti",
1906+
Short: `JWT ID of the JWT to get`,
1907+
Required: true,
1908+
Deprecated: false,
1909+
Positional: true,
1910+
},
1911+
},
1912+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
1913+
request := args.(*iam.GetJWTRequest)
1914+
1915+
client := core.ExtractClient(ctx)
1916+
api := iam.NewAPI(client)
1917+
return api.GetJWT(request)
1918+
1919+
},
1920+
}
1921+
}
1922+
1923+
func iamJwtDelete() *core.Command {
1924+
return &core.Command{
1925+
Short: `Delete a JWT`,
1926+
Long: `Delete a JWT.`,
1927+
Namespace: "iam",
1928+
Resource: "jwt",
1929+
Verb: "delete",
1930+
// Deprecated: false,
1931+
ArgsType: reflect.TypeOf(iam.DeleteJWTRequest{}),
1932+
ArgSpecs: core.ArgSpecs{
1933+
{
1934+
Name: "jti",
1935+
Short: `JWT ID of the JWT to delete`,
1936+
Required: true,
1937+
Deprecated: false,
1938+
Positional: true,
1939+
},
1940+
},
1941+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
1942+
request := args.(*iam.DeleteJWTRequest)
1943+
1944+
client := core.ExtractClient(ctx)
1945+
api := iam.NewAPI(client)
1946+
e = api.DeleteJWT(request)
1947+
if e != nil {
1948+
return nil, e
1949+
}
1950+
return &core.SuccessResult{
1951+
Resource: "jwt",
1952+
Verb: "delete",
1953+
}, nil
1954+
},
1955+
}
1956+
}

0 commit comments

Comments
 (0)