feat: add flag for token lifetime (#5385)

This commit is contained in:
Garrett Delfosse
2022-12-12 15:39:31 -05:00
committed by GitHub
parent 760419a965
commit 40a5c0476f
9 changed files with 136 additions and 50 deletions
+6
View File
@@ -424,6 +424,12 @@ func newConfig() *codersdk.DeploymentConfig {
Flag: "update-check",
Default: flag.Lookup("test.v") == nil && !buildinfo.IsDev(),
},
MaxTokenLifetime: &codersdk.DeploymentConfigField[time.Duration]{
Name: "Max Token Lifetime",
Usage: "The maximum lifetime duration for any user creating a token.",
Flag: "max-token-lifetime",
Default: 24 * 30 * time.Hour,
},
}
}
+4
View File
@@ -65,6 +65,10 @@ Flags:
production.
Consumes $CODER_EXPERIMENTAL
-h, --help help for server
--max-token-lifetime duration The maximum lifetime duration for any
user creating a token.
Consumes $CODER_MAX_TOKEN_LIFETIME
(default 720h0m0s)
--oauth2-github-allow-everyone Allow all logins, setting this option
means allowed orgs and teams must be
empty.
+9 -1
View File
@@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"
"golang.org/x/xerrors"
"github.com/coder/coder/cli/cliflag"
"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/codersdk"
)
@@ -46,6 +47,9 @@ func tokens() *cobra.Command {
}
func createToken() *cobra.Command {
var (
tokenLifetime time.Duration
)
cmd := &cobra.Command{
Use: "create",
Short: "Create a tokens",
@@ -55,7 +59,9 @@ func createToken() *cobra.Command {
return xerrors.Errorf("create codersdk client: %w", err)
}
res, err := client.CreateToken(cmd.Context(), codersdk.Me, codersdk.CreateTokenRequest{})
res, err := client.CreateToken(cmd.Context(), codersdk.Me, codersdk.CreateTokenRequest{
Lifetime: tokenLifetime,
})
if err != nil {
return xerrors.Errorf("create tokens: %w", err)
}
@@ -74,6 +80,8 @@ func createToken() *cobra.Command {
},
}
cliflag.DurationVarP(cmd.Flags(), &tokenLifetime, "lifetime", "", "CODER_TOKEN_LIFETIME", 30*24*time.Hour, "Specify a duration for the lifetime of the token.")
return cmd
}