misc: add plain support for user get token in CLI

This commit is contained in:
Sheen Capadngan
2025-07-02 04:45:53 +08:00
parent cce2a54265
commit 38c9242e5b
2 changed files with 46 additions and 13 deletions
+14 -2
View File
@@ -114,6 +114,11 @@ var userGetTokenCmd = &cobra.Command{
loggedInUserDetails = util.EstablishUserLoginSession()
}
plain, err := cmd.Flags().GetBool("plain")
if err != nil {
util.HandleError(err, "[infisical user get token]: Unable to get plain flag")
}
if err != nil {
util.HandleError(err, "[infisical user get token]: Unable to get logged in user token")
}
@@ -135,8 +140,12 @@ var userGetTokenCmd = &cobra.Command{
util.HandleError(err, "[infisical user get token]: Unable to parse token payload")
}
fmt.Println("Session ID:", tokenPayload.TokenVersionId)
fmt.Println("Token:", loggedInUserDetails.UserCredentials.JTWToken)
if plain {
fmt.Println(loggedInUserDetails.UserCredentials.JTWToken)
} else {
fmt.Println("Session ID:", tokenPayload.TokenVersionId)
fmt.Println("Token:", loggedInUserDetails.UserCredentials.JTWToken)
}
},
}
@@ -240,7 +249,10 @@ var domainCmd = &cobra.Command{
func init() {
updateCmd.AddCommand(domainCmd)
userCmd.AddCommand(updateCmd)
userGetTokenCmd.Flags().Bool("plain", false, "print token without formatting")
userGetCmd.AddCommand(userGetTokenCmd)
userCmd.AddCommand(userGetCmd)
userCmd.AddCommand(switchCmd)
rootCmd.AddCommand(userCmd)