cli

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLI

type CLI struct {
	Genkey  GenKey  `kong:"cmd,help='Generate new keys.'"`
	Encrypt Encrypt `kong:"cmd,help='Generate a new encrypted token.'"`
	Sign    Sign    `kong:"cmd,help='Generate a new signed token.'"`
	Parse   Parse   `kong:"cmd,help='Parse and optionally validate a token.'"`

	Log struct {
		Level slog.Level `enum:"DEBUG,INFO,WARN,ERROR" default:"INFO" help:"Set the app logging level."`
	} `embed:"" prefix:"log-"`
	Version kong.VersionFlag `env:"-" help:"Output version and exit."`
	// contains filtered or unexported fields
}

CLI is the command line interface of PASETO.

func New

func New(appCtx *actx.Context, version string) (*CLI, error)

New initializes the command-line interface.

func (*CLI) Command

func (c *CLI) Command() string

Command returns the full path of the executed command.

func (*CLI) Execute

func (c *CLI) Execute(appCtx *actx.Context) error

Execute starts the command execution. Parse must be called before this method.

func (*CLI) ParseArgs

func (c *CLI) ParseArgs(args []string) error

ParseArgs parses the given command line arguments. This method must be called before Execute.

type ClaimsMapper

type ClaimsMapper struct {
	// contains filtered or unexported fields
}

ClaimsMapper parses token claims from CLI arguments and stdin.

func (ClaimsMapper) Decode

func (cm ClaimsMapper) Decode(kctx *kong.DecodeContext, target reflect.Value) error

Decode implements the kong.Mapper interface.

type ClaimsOption

type ClaimsOption struct {
	// contains filtered or unexported fields
}

ClaimsOption contains token claims passed via CLI arguments and stdin.

type Encrypt

type Encrypt struct {
	ProtocolVersion ProtocolVersionOption `default:"4" env:"PASETO_VERSION" short:"v" help:"Version of the PASETO protocol. Valid values: 2,3,4"`
	KeyFile         string                `required:"" short:"k" help:"Path to a symmetric key file to encrypt the token."`
	Expiration      time.Time             `` /* 197-byte string literal not displayed */
	Claims          ClaimsOption          `` /* 192-byte string literal not displayed */
}

Encrypt generates a new encrypted token.

func (*Encrypt) Run

func (c *Encrypt) Run(kctx *kong.Context, appCtx *actx.Context) error

Run the encrypt command.

type ExpirationMapper

type ExpirationMapper struct {
	// contains filtered or unexported fields
}

ExpirationMapper parses the token expiration duration or timestamp.

func (ExpirationMapper) Decode

func (em ExpirationMapper) Decode(kctx *kong.DecodeContext, target reflect.Value) error

Decode implements the kong.Mapper interface.

type GenKey

type GenKey struct {
	ProtocolVersion ProtocolVersionOption `default:"4" env:"PASETO_VERSION" short:"v" help:"Version of the PASETO protocol. Valid values: 2,3,4"`
	ProtocolPurpose paseto.Purpose        `` /* 169-byte string literal not displayed */
	OutFile         string                `env:"PASETO_KEY_OUT_FILE" short:"o" help:"Base file path to write the key(s) to; stdout will be used if not specified."`
	Encoding        xpaseto.KeyEncoding   `env:"PASETO_KEY_ENCODING" enum:"hex,pem" default:"hex" short:"e" help:"Encoding type. Valid values: ${enum}"`
}

GenKey generates new keys.

func (*GenKey) Run

func (c *GenKey) Run(appCtx *actx.Context) error

Run the genkey command.

type Parse

type Parse struct {
	KeyFile           string              `` /* 143-byte string literal not displayed */
	OutputFormat      xpaseto.TokenFormat `enum:"text,json" env:"PASETO_TOKEN_OUTPUT_FORMAT" default:"text" short:"o" help:"Token output format. Valid values: ${enum}"`
	Validate          bool                `default:"true" negatable:"" help:"Whether to validate the token."`
	TimeSkewTolerance time.Duration       `` /* 166-byte string literal not displayed */
	Token             string              `arg:"" help:"the token"`
}

Parse parses and optionally validates a token.

func (*Parse) Run

func (c *Parse) Run(appCtx *actx.Context) error

Run the parse command.

type ProtocolVersionOption

type ProtocolVersionOption paseto.Version

ProtocolVersionOption is a custom option that parses the protocol version.

func (*ProtocolVersionOption) UnmarshalText

func (o *ProtocolVersionOption) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*ProtocolVersionOption) Validate

func (o *ProtocolVersionOption) Validate() error

Validate implements kong's Validatable interface.

type Sign

type Sign struct {
	ProtocolVersion ProtocolVersionOption `default:"4" env:"PASETO_VERSION" short:"v" help:"Version of the PASETO protocol. Valid values: 2,3,4"`
	KeyFile         string                `required:"" short:"k" help:"Path to a private key file to sign the token."`
	Expiration      time.Time             `` /* 197-byte string literal not displayed */
	Claims          ClaimsOption          `` /* 192-byte string literal not displayed */
}

Sign generates a new signed token.

func (*Sign) Run

func (c *Sign) Run(kctx *kong.Context, appCtx *actx.Context) error

Run the sign command.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL