Skip to content

Commit d0af8e3

Browse files
author
JojiiOfficial
committed
add base64 encoding
1 parent 1a784df commit d0af8e3

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

Command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func runCommand(parsed string, commandData *commands.CommandData) {
167167

168168
// Config view
169169
case configView.FullCommand():
170-
commands.ConfigView(commandData)
170+
commands.ConfigView(commandData, *configViewTokenBase)
171171

172172
// -- KeystoreCommands
173173
// Keystore create

commands/Config.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package commands
33
import (
44
"bufio"
55
"crypto/tls"
6+
"encoding/base64"
67
"encoding/json"
78
"errors"
89
"fmt"
@@ -81,11 +82,16 @@ func ConfigUse(cData *CommandData, target string, values []string) {
8182
}
8283

8384
// ConfigView view config
84-
func ConfigView(cData *CommandData) {
85+
func ConfigView(cData *CommandData, sessionBase64 bool) {
8586
if len(cData.Config.User.SessionToken) == 0 && cData.NoRedaction {
8687
s, err := cData.Config.GetToken()
8788
if err == nil {
88-
cData.Config.User.SessionToken = s
89+
if sessionBase64 {
90+
enc := base64.RawStdEncoding.EncodeToString([]byte(s))
91+
cData.Config.User.SessionToken = enc
92+
} else {
93+
cData.Config.User.SessionToken = s
94+
}
8995
}
9096
}
9197

@@ -168,6 +174,14 @@ func SetupClient(cData *CommandData, host, configFile string, ignoreCert, server
168174

169175
// Insert user directly if token and user is set
170176
if len(token) > 0 && len(username) > 0 {
177+
// Decode token
178+
dec, err := base64.RawStdEncoding.DecodeString(token)
179+
if err != nil {
180+
fmt.Println(err)
181+
return
182+
}
183+
184+
token = string(dec)
171185
cData.Config.InsertUser(username, token)
172186
cData.Config.Save()
173187
return

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ var (
106106
configUseTarget = configUse.Arg("target", "Use different namespace as default").HintOptions(commands.UseTargets...).Required().String()
107107
configUseTargetValue = configUse.Arg("value", "the value of the new target").HintOptions("default").Strings()
108108
// -- View
109-
configView = configCMD.Command("view", "View config")
109+
configView = configCMD.Command("view", "View config")
110+
configViewTokenBase = configView.Flag("base64", "Encode the sessiontoken as base64").Default("false").Bool()
110111

111112
//
112113
// ---------> File commands --------------------------------------

0 commit comments

Comments
 (0)