Skip to content

Commit

Permalink
fix(cmd): Adds ttl flag to auth cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Nov 27, 2024
1 parent 4b92e00 commit 1ef412b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
15 changes: 1 addition & 14 deletions api/rpc/perms/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,7 @@ func (j *JWTPayload) MarshalBinary() (data []byte, err error) {
// NewTokenWithPerms generates and signs a new JWT token with the given secret
// and given permissions.
func NewTokenWithPerms(signer jwt.Signer, perms []auth.Permission) ([]byte, error) {
nonce := make([]byte, 32)
if _, err := rand.Read(nonce); err != nil {
return nil, err
}

p := &JWTPayload{
Allow: perms,
Nonce: nonce,
}
token, err := jwt.NewBuilder(signer).Build(p)
if err != nil {
return nil, err
}
return token.Bytes(), nil
return NewTokenWithTTL(signer, perms, 0)
}

// NewTokenWithTTL generates and signs a new JWT token with the given secret
Expand Down
9 changes: 8 additions & 1 deletion cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
nodemod "github.com/celestiaorg/celestia-node/nodebuilder/node"
)

var ttlFlagName = "ttl"

func AuthCmd(fsets ...*flag.FlagSet) *cobra.Command {
cmd := &cobra.Command{
Use: "auth [permission-level (e.g. read || write || admin)]",
Expand All @@ -35,7 +37,10 @@ func AuthCmd(fsets ...*flag.FlagSet) *cobra.Command {
return err
}

ttl, _ := cmd.Flags().GetDuration("ttl")
ttl, err := cmd.Flags().GetDuration(ttlFlagName)
if err != nil {
return err
}

ks, err := newKeystore(StorePath(cmd.Context()))
if err != nil {
Expand Down Expand Up @@ -65,6 +70,8 @@ func AuthCmd(fsets ...*flag.FlagSet) *cobra.Command {
for _, set := range fsets {
cmd.Flags().AddFlagSet(set)
}
cmd.Flags().Duration(ttlFlagName, 0, "Set a Time-to-live (TTL) for the token")

return cmd
}

Expand Down

0 comments on commit 1ef412b

Please sign in to comment.