Documentation ¶
Index ¶
- Constants
- Variables
- func HandleErr(err error)
- func WithSessionRetry(ctx *Context, cmd *cobra.Command, args []string, fn func(ctx *Context) error)
- type Context
- func (ctx *Context) GetCmd() *cobra.Command
- func (ctx *Context) GetInput() string
- func (ctx *Context) GetInputs() map[string]string
- func (ctx *Context) GetKey() (string, error)
- func (ctx *Context) GetMode() Mode
- func (ctx *Context) GetName() string
- func (ctx *Context) GetOpQuery() (*op.Query, error)
- func (ctx *Context) GetSessionToken() (string, error)
- func (ctx *Context) GetStdinDeadline() time.Duration
- func (ctx *Context) GetVaultName() (string, error)
- func (ctx *Context) ParseInput() (err error)
- func (ctx *Context) SetCmd(cmd *cobra.Command)
- func (ctx *Context) SetStdinDeadline(stdinDeadline time.Duration)
- func (ctx *Context) SetVaultName(vaultName string, shouldCreate bool) error
- func (ctx *Context) Signin() (string, error)
- type Flags
- type Mode
- type Runnable
Constants ¶
const ErrMsgClosedStdinAfterDeadline = "closed stdin after waiting"
const ErrMsgDockerServerUrlBadInputMultipleLines = "cannot parse url from multiple lines of input"
const ErrMsgDockerServerUrlBadInputZeroLines = "cannot parse url from zero lines of input"
const ErrMsgUnknownCommand = "unable to read inputs in the correct format without knowledge of the current command"
const ServiceName = "com.tlowerison.credential-1password"
const VaultKey = "vault"
Variables ¶
var PredefinedModes = []string{ string(DockerMode), string(GitMode), }
Functions ¶
func HandleErr ¶
func HandleErr(err error)
HandleErr does if nothing if the provided error is nil, otherwise it prints the provided err's message to stderr and exits.
func WithSessionRetry ¶
WithSessionRetry runs fn and if it receives an error which the op utils recognizes as an indication that a session token is missing or out of date, then it will request a new signin to generate a new session token and then run fn again with the new session token.
Types ¶
type Context ¶
func NewContext ¶
func (*Context) GetInput ¶
GetInput returns the private field input. input is the cached value of what is read from stdin.
func (*Context) GetInputs ¶
GetInputs is only required for testing, it duplicates all inputs in case of any bad usage in order to ensure that ctx.inputs is not mutated outside of this package.
func (*Context) GetKey ¶
GetKey returns the input key provided over stdin. This key will be used as the stored file's title. If it has already been computed, returns the cached value, otherwise, computes it based on whether the current mode is predefined or not. If predefined, the current mode is assumed to have its own method for processing stdin into a key. If not predefined, the current mode is returned as the key itself.
func (*Context) GetName ¶
GetName returns "$mode-credential-1password" if using a predefined mode, otherwise returns "credential-1password".
func (*Context) GetOpQuery ¶
GetOpQuery wraps an op.Context and the input key provided over stdin into an op.Query. This is a useful helper function as op.Query is embedded into most op structs.
func (*Context) GetSessionToken ¶
GetSessionToken retrieves the session token in context if present. If not, checks if the most recent session token date if it's still valid, and if it is, tries to return whatever is stored in the encrypted keystore. If there's nothing in the keystore or the token is out of date, it will request the user to sigin, store the newly created session token in the encrypted keystore as well as context, and return the session token.
func (*Context) GetStdinDeadline ¶
GetStdinDeadline returns the stdin timeout.
func (*Context) GetVaultName ¶
GetVaultName reads the configured vault name or returns the cached value if already read.
func (*Context) ParseInput ¶
ParseInput scans from stdin and splits each line by "=" to find key/value pairs. Any line which does not contain "=" is skipped over. Tries to store the inputs in the provided map, but if it's nil, will create a new map and fill that; returns the filled inputs map.
func (*Context) SetCmd ¶
SetCmd sets the private cmd field. cmd should be assigned by a prerun cobra command hook.
func (*Context) SetStdinDeadline ¶
SetStdinDeadline sets the private stdinDeadline field.
func (*Context) SetVaultName ¶
SetVaultName does: 1. checks whether the provided vault exists 2a. if so, sets the vault name and the vaultUUID in the encrypted keystore 2b. if not, and shouldCreate is false, fails 2c. if not, and shouldCreate is true, creates a new vault with the provided name, loop back to step 2a