Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Feat: Added token renew command

Daniel Hougaardf1805811aad7
diff --git a/cli/packages/cmd/token.go b/cli/packages/cmd/token.go
new file mode 100644
index 0000000000..3e5d42765e
--- /dev/null
+++ b/cli/packages/cmd/token.go
@@ -0,0 +1,63 @@
+/*
+Copyright (c) 2023 Infisical Inc.
+*/
+package cmd
+
+import (
+ "strings"
+ "time"
+
+ "github.com/Infisical/infisical-merge/packages/util"
+ "github.com/fatih/color"
+ "github.com/spf13/cobra"
+)
+
+var tokenCmd = &cobra.Command{
+ Use: "token",
+ Short: "Manage your access tokens",
+ DisableFlagsInUseLine: true,
+ Example: "infisical token",
+ Args: cobra.ExactArgs(0),
+ PreRun: func(cmd *cobra.Command, args []string) {
+ util.RequireLogin()
+ },
+ Run: func(cmd *cobra.Command, args []string) {
+ },
+}
+
+var tokenRenewCmd = &cobra.Command{
+ Use: "renew [token]",
+ Short: "Used to renew your universal auth access token",
+ DisableFlagsInUseLine: true,
+ Example: "infisical token renew <access-token>",
+ Args: cobra.ExactArgs(1),
+ Run: func(cmd *cobra.Command, args []string) {
+ // args[0] will be the <INSERT_TOKEN> from your command call
+ token := args[0]
+
+ if strings.HasPrefix(token, "st.") {
+ util.PrintErrorMessageAndExit("You are trying to renew a service token. You can only renew universal auth access tokens.")
+ }
+
+ renewedAccessToken, err := util.RenewUniversalAuthAccessToken(token)
+
+ if err != nil {
+ util.HandleError(err, "Unable to renew token")
+ }
+
+ boldGreen := color.New(color.FgGreen).Add(color.Bold)
+ time.Sleep(time.Second * 1)
+ boldGreen.Printf(">>>> Successfully renewed token!\n\n")
+ boldGreen.Printf("Renewed Access Token:\n%v", renewedAccessToken)
+
+ plainBold := color.New(color.Bold)
+ plainBold.Println("\n\nYou can use the new access token to authenticate through other commands in the CLI.")
+
+ },
+}
+
+func init() {
+ tokenCmd.AddCommand(tokenRenewCmd)
+
+ rootCmd.AddCommand(tokenCmd)
+}