Documentation ¶
Overview ¶
Package cmd defines a testable CLI-like interface in order for the true CLI binary to be simple.
Index ¶
- Variables
- func ComposeInitContext(ctx0 context.Context, cmps ...CommandComponent) (ctx context.Context, err error)
- func EndorseSet(ctx context.Context, setter func(ec *endorse.Context)) error
- func EndorseSetE(ctx context.Context, setter func(ec *endorse.Context) error) error
- func MakeApp(ctx context.Context, app *AppComponents) *cobra.Command
- func MustBeNonempty(name string, value *string) error
- type AppComponents
- type BootstrapCommand
- type CommandComponent
- type ComposedComponent
- type PartialComponent
- type RotateCommand
- type RunFn
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTimeAlreadySet is returned from a timeFlag parsing if the value has already been set. ErrTimeAlreadySet = errors.New("time flag has already been set") )
Functions ¶
func ComposeInitContext ¶
func ComposeInitContext(ctx0 context.Context, cmps ...CommandComponent) (ctx context.Context, err error)
ComposeInitContext returns the sequenced context initialization of all provided components' InitContext functions, or the first error encountered.
func EndorseSet ¶
EndorseSet calls the given setter function on the context's endorse.Context if it exists, or returns the missing context error.
func EndorseSetE ¶
EndorseSetE returns the setter's result given the context's endorse.Context if it exists, or returns the missing context error.
func MakeApp ¶
func MakeApp(ctx context.Context, app *AppComponents) *cobra.Command
MakeApp returns an initialized cobra root command for a CLI tool that includes all expected subcommands.
func MustBeNonempty ¶
MustBeNonempty returns an error if the given flag is empty.
Types ¶
type AppComponents ¶
type AppComponents struct { // Endorse abstracts any extra endorsement setup to do on top of the base before performing an // endorsement. Endorse CommandComponent // Global provides flags, validation, and context for every command. Its context must be // initialized explicitly. Global CommandComponent // SignatureRandom is the source of randomness used for certificate signature salting. SignatureRandom io.Reader // Bootstrap abstracts any extra setup to do on top of the base before performing key // bootstrapping. Bootstrap CommandComponent // Rotate abstracts any extra setup to do on top of the base before performing key rotation. Rotate CommandComponent // Wipeout abstracts any extra setup to do on top of the base before destroying all keys and // key certificates. Wipeout CommandComponent }
AppComponents contains implementations of application interfaces needed to instantiate the entire GCE TCB CLI tool.
type BootstrapCommand ¶
type BootstrapCommand struct{}
BootstrapCommand is the core bootstrap command component.
func (*BootstrapCommand) AddFlags ¶
func (b *BootstrapCommand) AddFlags(cmd *cobra.Command)
AddFlags adds any implementation-specific flags for this command component.
func (*BootstrapCommand) InitContext ¶
InitContext extends the given context with whatever else the component needs before execution.
func (*BootstrapCommand) PersistentPreRunE ¶
func (b *BootstrapCommand) PersistentPreRunE(cmd *cobra.Command, _ []string) error
PersistentPreRunE returns an error if the results of the parsed flags constitute an error.
type CommandComponent ¶
type CommandComponent interface { // InitContext extends the given context with whatever else the component needs before execution. // This is separate from PersistentPreRunE to allow all flag validation code to run before // performing these potentially expensive initialization actions. InitContext(ctx context.Context) (context.Context, error) // AddFlags adds any implementation-specific flags for this command component. AddFlags(cmd *cobra.Command) // PersistentPreRunE returns an error if the results of the parsed flags constitute an error. PersistentPreRunE(cmd *cobra.Command, args []string) error }
CommandComponent represents any setup that must happen before running a command.
func EndorseSetter ¶
func EndorseSetter(setter func(ec *endorse.Context)) CommandComponent
EndorseSetter returns a CommandComponent that runs the given initialization function with the context's endorse.Context if present.
func EndorseSetterE ¶
func EndorseSetterE(setter func(ec *endorse.Context) error) CommandComponent
EndorseSetterE returns a CommandComponent that whose InitContext returns the setter's result when given the context's endorse.Context. Returns the missing context error if not present.
type ComposedComponent ¶
type ComposedComponent struct {
Components []CommandComponent
}
ComposedComponent dispatches to the encapsulated components in sequence for each of their functions.
func Compose ¶
func Compose(cmps ...CommandComponent) *ComposedComponent
Compose returns a component that composes all the given components in the order given.
func (*ComposedComponent) AddFlags ¶
func (c *ComposedComponent) AddFlags(cmd *cobra.Command)
AddFlags adds any implementation-specific flags for the held command components.
func (*ComposedComponent) InitContext ¶
InitContext extends the given context with whatever else the held components need before execution.
func (*ComposedComponent) PersistentPreRunE ¶
func (c *ComposedComponent) PersistentPreRunE(cmd *cobra.Command, args []string) error
PersistentPreRunE returns an error if the results of the parsed flags constitute an error.
type PartialComponent ¶
type PartialComponent struct { // InitContext extends the given context with whatever else the component needs before execution. FInitContext func(ctx context.Context) (context.Context, error) // AddFlags adds any implementation-specific flags for this command component. FAddFlags func(cmd *cobra.Command) // PersistentPreRunE returns an error if the results of the parsed flags constitute an error. FPersistentPreRunE func(cmd *cobra.Command, args []string) error }
PartialComponent implements a CommandComponent with the provided functions. Missing fields have reasonable default behavior.
func (*PartialComponent) AddFlags ¶
func (p *PartialComponent) AddFlags(cmd *cobra.Command)
AddFlags adds any implementation-specific flags for this command component.
func (*PartialComponent) InitContext ¶
InitContext extends the given context with whatever else the component needs before execution.
func (*PartialComponent) PersistentPreRunE ¶
func (p *PartialComponent) PersistentPreRunE(cmd *cobra.Command, args []string) error
PersistentPreRunE returns an error if the results of the parsed flags constitute an error.
type RotateCommand ¶
type RotateCommand struct{}
RotateCommand provides the core CommandComponent for executing a key rotation. This must be defined in cmd instead of on top of rotate.SignerKeyContext since rotate cannot depend on cmd to do so.
func (*RotateCommand) AddFlags ¶
func (r *RotateCommand) AddFlags(cmd *cobra.Command)
AddFlags adds core flags for populating a rotate.SigningKeyContext.
func (*RotateCommand) InitContext ¶
InitContext extends the given context with whatever else the component needs before execution.
func (*RotateCommand) PersistentPreRunE ¶
func (r *RotateCommand) PersistentPreRunE(cmd *cobra.Command, _ []string) error
PersistentPreRunE returns an error if the results of the parsed flags constitute an error.
type RunFn ¶
RunFn is the type of a cobra error-returning runner function.
func ComposeRun ¶
func ComposeRun(cmp CommandComponent, run func(context.Context) error) RunFn
ComposeRun will return run called with a command's context that has been extended by cmp's InitContext if cmp is non-nil.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
The nonprod command provides a non-production CLI tool for endorsing an input UEFI binary and managing the keys to do so.
|
The nonprod command provides a non-production CLI tool for endorsing an input UEFI binary and managing the keys to do so. |
Package output provides operations for command implementations to write information of various kinds.
|
Package output provides operations for command implementations to write information of various kinds. |