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
3 changes: 2 additions & 1 deletion cmd/scw/testdata/test-all-usage-login-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ USAGE:
scw login [arg=value ...]

ARGS:
[port] The port number used to wait for browser's response
[port] The port number used to wait for browser's response
[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.

FLAGS:
-h, --help help for login
Expand Down
14 changes: 12 additions & 2 deletions internal/namespaces/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type loginArgs struct {
Port int `json:"port"`
// PrintURL will print the account url instead of trying to open it with a browser
PrintURL bool `json:"print_url"`
// ExpiresAt is the expiration date of the API key created during login
ExpiresAt *time.Time `json:"expires_at"`
}

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

api := iam.NewAPI(client)
apiKey, err := api.CreateAPIKey(&iam.CreateAPIKeyRequest{
req := &iam.CreateAPIKeyRequest{
UserID: &tt.Jwt.AudienceID,
Description: "Generated by the Scaleway CLI",
})
}
if args.ExpiresAt != nil {
req.ExpiresAt = args.ExpiresAt
}
apiKey, err := api.CreateAPIKey(req)
if err != nil {
return nil, err
}
Expand Down
Loading