Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(account): support API token operations #363

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

Conversation

kangasta
Copy link
Contributor

@kangasta kangasta commented Jan 30, 2025

@@ -122,6 +123,13 @@ func BuildCommands(rootCmd *cobra.Command, conf *config.Config) {
permissionsCommand := commands.BuildCommand(permissions.BasePermissionsCommand(), accountCommand.Cobra(), conf)
commands.BuildCommand(permissions.ListCommand(), permissionsCommand.Cobra(), conf)

// Token
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be under account.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was on the verge with this, so up to you. If we want to have the tokens hierarchically under accounts like they are in the API (makes sense), we should have tokens under account as a subcommand, i.e. upctl account token create ....

On the other hand, it just feels better as a top level command/resource, i.e. upctl token create ....

In either case, we should follow the same hierarchy in code (style, packaging...).

type createParams struct {
request.CreateTokenRequest
name string
expiresIn time.Duration
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use support for d unit, e.g. 90d or 365d could be common values defined by user 🤔

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely should use as hours is not convenient. I suppose one could do it with some custom parser, but the current approach uses flags.DurationVarP which uses time.ParseDuration and only supports up to hours.

fs.StringVar(&dst.expiresAt, "expires-at", def.expiresAt, "Exact time when the token expires in RFC3339 format. e.g. 2025-01-01T00:00:00Z")
fs.DurationVar(&dst.expiresIn, "expires-in", def.expiresIn, "Duration until the token expires. e.g. 24h")
fs.BoolVar(&dst.canCreateTokens, "can-create-tokens", def.canCreateTokens, "Allow token to be used to create further tokens.")
fs.StringArrayVar(&dst.allowedIPRanges, "allowed-ip-ranges", def.allowedIPRanges, "Allowed IP ranges for the token.")
Copy link
Contributor Author

@kangasta kangasta Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs more documentation as token with empty list is invalid(?). Maybe this could be made required as well 🤔

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is technically not invalid, it just can't be used from anywhere to access API. We deliberately allow creating such tokens if one would like to use them as canary tokens. We could give a warning that the token will not be able to access any API though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants