Skip to content

Commit 89a3c86

Browse files
scaleway-botyfodil
andauthored
feat(iam): enable CLI for IAM logs (#3519)
Co-authored-by: Yacine Fodil <[email protected]>
1 parent 9b9f56a commit 89a3c86

File tree

8 files changed

+234
-3
lines changed

8 files changed

+234
-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+
Retrieve information about a log, specified by the `log_id` parameter. The log's full details, including `id`, `ip`, `user_agent`, `action`, `bearer_id`, `resource_type` and `resource_id` are returned in the response.
4+
5+
USAGE:
6+
scw iam log get <log-id ...> [arg=value ...]
7+
8+
ARGS:
9+
log-id ID of the log
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
List logs available for given Organization. You must define the `organization_id` in the query path of your request.
4+
5+
USAGE:
6+
scw iam log list [arg=value ...]
7+
8+
ARGS:
9+
[order-by=created_at_asc] Criteria for sorting results (created_at_asc | created_at_desc)
10+
[created-after] Defined whether or not to filter out logs created after this timestamp
11+
[created-before] Defined whether or not to filter out logs created before this timestamp
12+
[action] Defined whether or not to filter out by a specific action (unknown_action | created | updated | deleted)
13+
[resource-type] Defined whether or not to filter out by a specific type of resource (unknown_resource_type | api_key | user | application | group | policy)
14+
[search] Defined whether or not to filter out log by bearer ID or resource ID
15+
[organization-id] Organization ID to use. If none is passed the default organization ID will be used
16+
17+
FLAGS:
18+
-h, --help help for list
19+
20+
GLOBAL FLAGS:
21+
-c, --config string The path to the config file
22+
-D, --debug Enable debug mode
23+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
24+
-p, --profile string The config profile to use
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Log management commands.
4+
5+
USAGE:
6+
scw iam log <command>
7+
8+
AVAILABLE COMMANDS:
9+
get Get a log
10+
list List logs
11+
12+
FLAGS:
13+
-h, --help help for log
14+
15+
GLOBAL FLAGS:
16+
-c, --config string The path to the config file
17+
-D, --debug Enable debug mode
18+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
19+
-p, --profile string The config profile to use
20+
21+
Use "scw iam log [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
@@ -10,6 +10,7 @@ AVAILABLE COMMANDS:
1010
application Applications management commands
1111
group Groups management commands
1212
jwt JWTs management commands
13+
log Log management commands
1314
permission-set Permission sets management commands
1415
policy Policies management commands
1516
rule Rules management commands

docs/commands/iam.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ IAM API.
2828
- [Delete a JWT](#delete-a-jwt)
2929
- [Get a JWT](#get-a-jwt)
3030
- [List JWTs](#list-jwts)
31+
- [Log management commands](#log-management-commands)
32+
- [Get a log](#get-a-log)
33+
- [List logs](#list-logs)
3134
- [Permission sets management commands](#permission-sets-management-commands)
3235
- [List permission sets](#list-permission-sets)
3336
- [Policies management commands](#policies-management-commands)
@@ -570,6 +573,55 @@ scw iam jwt list <audience-id ...> [arg=value ...]
570573

571574

572575

576+
## Log management commands
577+
578+
Log management commands.
579+
580+
581+
### Get a log
582+
583+
Retrieve information about a log, specified by the `log_id` parameter. The log's full details, including `id`, `ip`, `user_agent`, `action`, `bearer_id`, `resource_type` and `resource_id` are returned in the response.
584+
585+
**Usage:**
586+
587+
```
588+
scw iam log get <log-id ...> [arg=value ...]
589+
```
590+
591+
592+
**Args:**
593+
594+
| Name | | Description |
595+
|------|---|-------------|
596+
| log-id | Required | ID of the log |
597+
598+
599+
600+
### List logs
601+
602+
List logs available for given Organization. You must define the `organization_id` in the query path of your request.
603+
604+
**Usage:**
605+
606+
```
607+
scw iam log list [arg=value ...]
608+
```
609+
610+
611+
**Args:**
612+
613+
| Name | | Description |
614+
|------|---|-------------|
615+
| order-by | Default: `created_at_asc`<br />One of: `created_at_asc`, `created_at_desc` | Criteria for sorting results |
616+
| created-after | | Defined whether or not to filter out logs created after this timestamp |
617+
| created-before | | Defined whether or not to filter out logs created before this timestamp |
618+
| action | One of: `unknown_action`, `created`, `updated`, `deleted` | Defined whether or not to filter out by a specific action |
619+
| resource-type | One of: `unknown_resource_type`, `api_key`, `user`, `application`, `group`, `policy` | Defined whether or not to filter out by a specific type of resource |
620+
| search | | Defined whether or not to filter out log by bearer ID or resource ID |
621+
| organization-id | | Organization ID to use. If none is passed the default organization ID will be used |
622+
623+
624+
573625
## Permission sets management commands
574626

575627
Permission sets management commands.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/moby/buildkit v0.11.6
2525
github.com/opencontainers/go-digest v1.0.0
2626
github.com/pkg/errors v0.9.1
27-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231124161744-cd76ffab43fb
27+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231128131307-c646e1e0b2cd
2828
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
2929
github.com/spf13/cobra v1.8.0
3030
github.com/spf13/pflag v1.0.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
490490
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
491491
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
492492
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
493-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231124161744-cd76ffab43fb h1:2pthrdJYF/LhWQAQQ44w0QVVfSwyGg6AagyUy+pOUP8=
494-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231124161744-cd76ffab43fb/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
493+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231128131307-c646e1e0b2cd h1:6dpfWGj/wJKaSsFXYV2Rx7TlyLrEZkFIzv/zqjwtjSU=
494+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231128131307-c646e1e0b2cd/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
495495
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
496496
github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE=
497497
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=

internal/namespaces/iam/v1alpha1/iam_cli.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func GetGeneratedCommands() *core.Commands {
2929
iamRule(),
3030
iamPermissionSet(),
3131
iamJwt(),
32+
iamLog(),
3233
iamSSHKeyList(),
3334
iamSSHKeyCreate(),
3435
iamSSHKeyGet(),
@@ -69,6 +70,8 @@ func GetGeneratedCommands() *core.Commands {
6970
iamJwtList(),
7071
iamJwtGet(),
7172
iamJwtDelete(),
73+
iamLogList(),
74+
iamLogGet(),
7275
)
7376
}
7477
func iamRoot() *core.Command {
@@ -160,6 +163,15 @@ func iamJwt() *core.Command {
160163
}
161164
}
162165

166+
func iamLog() *core.Command {
167+
return &core.Command{
168+
Short: `Log management commands`,
169+
Long: `Log management commands.`,
170+
Namespace: "iam",
171+
Resource: "log",
172+
}
173+
}
174+
163175
func iamSSHKeyList() *core.Command {
164176
return &core.Command{
165177
Short: `List SSH keys`,
@@ -2175,3 +2187,106 @@ func iamJwtDelete() *core.Command {
21752187
},
21762188
}
21772189
}
2190+
2191+
func iamLogList() *core.Command {
2192+
return &core.Command{
2193+
Short: `List logs`,
2194+
Long: `List logs available for given Organization. You must define the ` + "`" + `organization_id` + "`" + ` in the query path of your request.`,
2195+
Namespace: "iam",
2196+
Resource: "log",
2197+
Verb: "list",
2198+
// Deprecated: false,
2199+
ArgsType: reflect.TypeOf(iam.ListLogsRequest{}),
2200+
ArgSpecs: core.ArgSpecs{
2201+
{
2202+
Name: "order-by",
2203+
Short: `Criteria for sorting results`,
2204+
Required: false,
2205+
Deprecated: false,
2206+
Positional: false,
2207+
Default: core.DefaultValueSetter("created_at_asc"),
2208+
EnumValues: []string{"created_at_asc", "created_at_desc"},
2209+
},
2210+
{
2211+
Name: "created-after",
2212+
Short: `Defined whether or not to filter out logs created after this timestamp`,
2213+
Required: false,
2214+
Deprecated: false,
2215+
Positional: false,
2216+
},
2217+
{
2218+
Name: "created-before",
2219+
Short: `Defined whether or not to filter out logs created before this timestamp`,
2220+
Required: false,
2221+
Deprecated: false,
2222+
Positional: false,
2223+
},
2224+
{
2225+
Name: "action",
2226+
Short: `Defined whether or not to filter out by a specific action`,
2227+
Required: false,
2228+
Deprecated: false,
2229+
Positional: false,
2230+
EnumValues: []string{"unknown_action", "created", "updated", "deleted"},
2231+
},
2232+
{
2233+
Name: "resource-type",
2234+
Short: `Defined whether or not to filter out by a specific type of resource`,
2235+
Required: false,
2236+
Deprecated: false,
2237+
Positional: false,
2238+
EnumValues: []string{"unknown_resource_type", "api_key", "user", "application", "group", "policy"},
2239+
},
2240+
{
2241+
Name: "search",
2242+
Short: `Defined whether or not to filter out log by bearer ID or resource ID`,
2243+
Required: false,
2244+
Deprecated: false,
2245+
Positional: false,
2246+
},
2247+
core.OrganizationIDArgSpec(),
2248+
},
2249+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
2250+
request := args.(*iam.ListLogsRequest)
2251+
2252+
client := core.ExtractClient(ctx)
2253+
api := iam.NewAPI(client)
2254+
opts := []scw.RequestOption{scw.WithAllPages()}
2255+
resp, err := api.ListLogs(request, opts...)
2256+
if err != nil {
2257+
return nil, err
2258+
}
2259+
return resp.Logs, nil
2260+
2261+
},
2262+
}
2263+
}
2264+
2265+
func iamLogGet() *core.Command {
2266+
return &core.Command{
2267+
Short: `Get a log`,
2268+
Long: `Retrieve information about a log, specified by the ` + "`" + `log_id` + "`" + ` parameter. The log's full details, including ` + "`" + `id` + "`" + `, ` + "`" + `ip` + "`" + `, ` + "`" + `user_agent` + "`" + `, ` + "`" + `action` + "`" + `, ` + "`" + `bearer_id` + "`" + `, ` + "`" + `resource_type` + "`" + ` and ` + "`" + `resource_id` + "`" + ` are returned in the response.`,
2269+
Namespace: "iam",
2270+
Resource: "log",
2271+
Verb: "get",
2272+
// Deprecated: false,
2273+
ArgsType: reflect.TypeOf(iam.GetLogRequest{}),
2274+
ArgSpecs: core.ArgSpecs{
2275+
{
2276+
Name: "log-id",
2277+
Short: `ID of the log`,
2278+
Required: true,
2279+
Deprecated: false,
2280+
Positional: true,
2281+
},
2282+
},
2283+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
2284+
request := args.(*iam.GetLogRequest)
2285+
2286+
client := core.ExtractClient(ctx)
2287+
api := iam.NewAPI(client)
2288+
return api.GetLog(request)
2289+
2290+
},
2291+
}
2292+
}

0 commit comments

Comments
 (0)