cli: Make owner field optional for bearer token #1186

Merged
fyrchik merged 1 commit from aarifullin/frostfs-node:feat/cli_bearer into master 2024-06-19 17:24:00 +00:00

View file

@ -67,7 +67,6 @@ func init() {
_ = cobra.MarkFlagFilename(createCmd.Flags(), apeFlag) _ = cobra.MarkFlagFilename(createCmd.Flags(), apeFlag)
_ = cobra.MarkFlagRequired(createCmd.Flags(), commonflags.ExpireAt) _ = cobra.MarkFlagRequired(createCmd.Flags(), commonflags.ExpireAt)
_ = cobra.MarkFlagRequired(createCmd.Flags(), ownerFlag)
_ = cobra.MarkFlagRequired(createCmd.Flags(), outFlag) _ = cobra.MarkFlagRequired(createCmd.Flags(), outFlag)
} }
@ -108,16 +107,16 @@ func createToken(cmd *cobra.Command, _ []string) {
fmt.Errorf("expiration epoch is less than not-valid-before epoch: %d < %d", exp, nvb)) fmt.Errorf("expiration epoch is less than not-valid-before epoch: %d < %d", exp, nvb))
} }
ownerStr, _ := cmd.Flags().GetString(ownerFlag)
var ownerID user.ID
commonCmd.ExitOnErr(cmd, "can't parse recipient: %w", ownerID.DecodeString(ownerStr))
var b bearer.Token var b bearer.Token
b.SetExp(exp) b.SetExp(exp)
b.SetNbf(nvb) b.SetNbf(nvb)
b.SetIat(iat) b.SetIat(iat)
b.ForUser(ownerID)
if ownerStr, _ := cmd.Flags().GetString(ownerFlag); ownerStr != "" {
var ownerID user.ID
commonCmd.ExitOnErr(cmd, "can't parse recipient: %w", ownerID.DecodeString(ownerStr))
b.ForUser(ownerID)
}
impersonate, _ := cmd.Flags().GetBool(impersonateFlag) impersonate, _ := cmd.Flags().GetBool(impersonateFlag)
b.SetImpersonate(impersonate) b.SetImpersonate(impersonate)