Skip to content

Commit df5c76c

Browse files
jremy42remyleone
andauthored
fix(login): add expires-at argument to scw login for API key expiration (#5398)
Co-authored-by: Rémy Léone <rleone@scaleway.com>
1 parent a4db779 commit df5c76c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ USAGE:
88
scw login [arg=value ...]
99

1010
ARGS:
11-
[port] The port number used to wait for browser's response
11+
[port] The port number used to wait for browser's response
12+
[expires-at] Expiration date of the API key (ISO 8601 or relative like +1y, +90d). Required when your organization enforces max-api-key-expiration-duration.
1213

1314
FLAGS:
1415
-h, --help help for login

internal/namespaces/login/login.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type loginArgs struct {
2525
Port int `json:"port"`
2626
// PrintURL will print the account url instead of trying to open it with a browser
2727
PrintURL bool `json:"print_url"`
28+
// ExpiresAt is the expiration date of the API key created during login
29+
ExpiresAt *time.Time `json:"expires_at"`
2830
}
2931

3032
func loginCommand() *core.Command {
@@ -43,6 +45,10 @@ Once you connected to Scaleway, the profile should be configured.
4345
Name: "port",
4446
Short: "The port number used to wait for browser's response",
4547
},
48+
{
49+
Name: "expires-at",
50+
Short: "Expiration date of the API key (ISO 8601 or relative like +1y, +90d). Required when your organization enforces max-api-key-expiration-duration.",
51+
},
4652
},
4753
SeeAlsos: []*core.SeeAlso{
4854
{
@@ -106,10 +112,14 @@ Once you connected to Scaleway, the profile should be configured.
106112
}
107113

108114
api := iam.NewAPI(client)
109-
apiKey, err := api.CreateAPIKey(&iam.CreateAPIKeyRequest{
115+
req := &iam.CreateAPIKeyRequest{
110116
UserID: &tt.Jwt.AudienceID,
111117
Description: "Generated by the Scaleway CLI",
112-
})
118+
}
119+
if args.ExpiresAt != nil {
120+
req.ExpiresAt = args.ExpiresAt
121+
}
122+
apiKey, err := api.CreateAPIKey(req)
113123
if err != nil {
114124
return nil, err
115125
}

0 commit comments

Comments
 (0)