mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 19:47:54 +00:00
command/generate-root: support returning json format on decode and generate otp (#7870)
This commit is contained in:
committed by
GitHub
parent
7dcb9d88a3
commit
c73a776ba2
@@ -242,7 +242,16 @@ func (c *OperatorGenerateRootCommand) Run(args []string) int {
|
|||||||
case c.flagGenerateOTP:
|
case c.flagGenerateOTP:
|
||||||
otp, code := c.generateOTP(client, kind)
|
otp, code := c.generateOTP(client, kind)
|
||||||
if code == 0 {
|
if code == 0 {
|
||||||
|
switch Format(c.UI) {
|
||||||
|
case "", "table":
|
||||||
return PrintRaw(c.UI, otp)
|
return PrintRaw(c.UI, otp)
|
||||||
|
default:
|
||||||
|
status := map[string]interface{}{
|
||||||
|
"otp": otp,
|
||||||
|
"otp_length": len(otp),
|
||||||
|
}
|
||||||
|
return OutputData(c.UI, status)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return code
|
return code
|
||||||
case c.flagDecode != "":
|
case c.flagDecode != "":
|
||||||
@@ -332,6 +341,7 @@ func (c *OperatorGenerateRootCommand) decode(client *api.Client, encoded, otp st
|
|||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var token string
|
||||||
switch status.OTPLength {
|
switch status.OTPLength {
|
||||||
case 0:
|
case 0:
|
||||||
// Backwards compat
|
// Backwards compat
|
||||||
@@ -341,13 +351,12 @@ func (c *OperatorGenerateRootCommand) decode(client *api.Client, encoded, otp st
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := uuid.FormatUUID(tokenBytes)
|
uuidToken, err := uuid.FormatUUID(tokenBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.UI.Error(fmt.Sprintf("Error formatting base64 token value: %s", err))
|
c.UI.Error(fmt.Sprintf("Error formatting base64 token value: %s", err))
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
token = strings.TrimSpace(uuidToken)
|
||||||
return PrintRaw(c.UI, strings.TrimSpace(token))
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
tokenBytes, err := base64.RawStdEncoding.DecodeString(encoded)
|
tokenBytes, err := base64.RawStdEncoding.DecodeString(encoded)
|
||||||
@@ -361,8 +370,17 @@ func (c *OperatorGenerateRootCommand) decode(client *api.Client, encoded, otp st
|
|||||||
c.UI.Error(errwrap.Wrapf("Error xoring token: {{err}}", err).Error())
|
c.UI.Error(errwrap.Wrapf("Error xoring token: {{err}}", err).Error())
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
token = string(tokenBytes)
|
||||||
|
}
|
||||||
|
|
||||||
return PrintRaw(c.UI, string(tokenBytes))
|
switch Format(c.UI) {
|
||||||
|
case "", "table":
|
||||||
|
return PrintRaw(c.UI, token)
|
||||||
|
default:
|
||||||
|
tokenJSON := map[string]interface{}{
|
||||||
|
"token": token,
|
||||||
|
}
|
||||||
|
return OutputData(c.UI, tokenJSON)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user