Documentation ¶
Index ¶
- Variables
- func AddFlag(path, name, short, description string, defaultValue interface{})
- func BuildHelpConfigCommand(appName string) *cobra.Command
- func BuildHelpInputCommand() *cobra.Command
- func BuildSecretsCommands() (cmd *cobra.Command)
- func BuildSettingsCommands() (configCommand *cobra.Command)
- func DeepAssign(target, source map[string]interface{})
- func GetBody(mediaType string, args []string) (string, error)
- func GetMatchValue(ctx *context.Context, selector string, reqParams map[string]interface{}, ...) (interface{}, error)
- func HandleAfter(path string, params *viper.Viper, resp *gentleman.Response, data interface{}) interface{}
- func HandleBefore(path string, params *viper.Viper, r *gentleman.Request)
- func Init(config *Config)
- func InitConfiguration(envPrefix, settingsFilePath, secretsFilePath string, globalFlags []GlobalFlag) (err error)
- func LogMiddleware(useColor bool)
- func Markdown(content string) string
- func Match(test string, expected json.RawMessage, actual interface{}) (bool, error)
- func RegisterAfter(path string, handler AfterHandlerFunc)
- func RegisterBefore(path string, handler BeforeHandlerFunc)
- func SetCustomFlags(cmd *cobra.Command)
- func UnmarshalRequest(ctx *context.Context, s interface{}) error
- func UnmarshalResponse(resp *gentleman.Response, s interface{}) error
- func UseAuth(typeName string, handler AuthHandler)
- func UserAgentMiddleware(appName string)
- type AfterHandlerFunc
- type Applications
- type AuthHandler
- type AuthServer
- type BeforeHandlerFunc
- type CLI
- type ClientConfiguration
- type Config
- type ConsoleWriter
- type Credentials
- type DefaultFormatter
- type GlobalFlag
- type GlobalFlagDefaults
- type Profile
- type ResponseFormatter
- type Secrets
- type Settings
- type TokenPayload
- type VerbosityType
Constants ¶
This section is empty.
Variables ¶
var AuthHandlers = make(map[string]AuthHandler)
AuthHandlers is the map of registered auth type names to handlers
var Client *gentleman.Client
Client makes HTTP requests and parses the responses.
var (
ErrCannotUnmarshal = errors.New("Unable to unmarshal response")
)
HTTP Client Errors
var PreRun func(cmd *cobra.Command, args []string) error
PreRun is a function that will run after flags are parsed but before the command handler has been called.
var Root *cobra.Command
Root command (entrypoint) of the CLI.
var Stderr io.Writer = os.Stderr
Stderr is a cross-platform, color-safe writer if colors are enabled, otherwise it defaults to `os.Stderr`.
var Stdout io.Writer = os.Stdout
Stdout is a cross-platform, color-safe writer if colors are enabled, otherwise it defaults to `os.Stdout`.
Functions ¶
func AddFlag ¶
func AddFlag(path, name, short, description string, defaultValue interface{})
AddFlag registers a new custom flag for the command path. Use the `RegisterBefore` and `RegisterAfter` functions to register a handler that can check the value of this flag.
func BuildHelpConfigCommand ¶ added in v0.0.8
func BuildHelpInputCommand ¶ added in v0.0.8
func BuildSecretsCommands ¶ added in v0.0.6
BuildSecretsCommands sets up basic commands and the credentials file so that new auth handlers can be registered. This MUST be called only after auth handlers have been set up through UseAuth.
func BuildSettingsCommands ¶ added in v0.0.6
func DeepAssign ¶
func DeepAssign(target, source map[string]interface{})
DeepAssign recursively merges a source map into the target.
func GetBody ¶
GetBody returns the request body if one was passed either as shorthand arguments or via stdin.
func GetMatchValue ¶
func GetMatchValue(ctx *context.Context, selector string, reqParams map[string]interface{}, decoded interface{}) (interface{}, error)
GetMatchValue returns a value for the given selector query.
func HandleAfter ¶
func HandleAfter(path string, params *viper.Viper, resp *gentleman.Response, data interface{}) interface{}
HandleAfter runs any regeistered post-request handlers for the given command.
func HandleBefore ¶
HandleBefore runs any registered pre-request handlers for the given command.
func InitConfiguration ¶ added in v0.0.5
func InitConfiguration(envPrefix, settingsFilePath, secretsFilePath string, globalFlags []GlobalFlag) (err error)
func LogMiddleware ¶
func LogMiddleware(useColor bool)
LogMiddleware adds verbose log info to HTTP requests.
func Match ¶
func Match(test string, expected json.RawMessage, actual interface{}) (bool, error)
Match returns `true` if the expected value of the match type is found in the given response data.
func RegisterAfter ¶
func RegisterAfter(path string, handler AfterHandlerFunc)
RegisterAfter registers a post-request handler for the given command path. The handler may modify the unmarshalled response.
func RegisterBefore ¶
func RegisterBefore(path string, handler BeforeHandlerFunc)
RegisterBefore registers a pre-request handler for the given command path. The handler may modify the request before it gets sent over the wire.
func SetCustomFlags ¶
SetCustomFlags sets up the command with additional registered flags.
func UnmarshalRequest ¶
UnmarshalRequest body into a given structure `s`. Supports both JSON and YAML depending on the request's content-type header.
func UnmarshalResponse ¶
func UnmarshalResponse(resp *gentleman.Response, s interface{}) error
UnmarshalResponse into a given structure `s`. Supports both JSON and YAML depending on the response's content-type header.
func UseAuth ¶
func UseAuth(typeName string, handler AuthHandler)
UseAuth registers a new auth handler for a given type name. For backward- compatibility, the auth type name can be a blank string. It is recommended to always pass a value for the type name.
func UserAgentMiddleware ¶
func UserAgentMiddleware(appName string)
UserAgentMiddleware sets the user-agent header on requests.
Types ¶
type AfterHandlerFunc ¶
AfterHandlerFunc is a function that runs after a request has been sent and the response is unmarshalled. It may modify the response. It must return the response data regardless of whether it was modified.
type Applications ¶ added in v0.0.5
type Applications struct {
CLI CLI `mapstructure:"cli"`
}
type AuthHandler ¶
type AuthHandler interface { ExecuteFlow(log *zerolog.Logger) (*oauth2.Token, error) // ProfileKeys returns the key names for fields to store in the profileName. ProfileKeys() []string // OnRequest gets run before the request goes out on the wire. OnRequest(log *zerolog.Logger, request *http.Request) error }
AuthHandler describes a handler that can be called on a request to inject auth information and is agnostic to the type of auth.
type AuthServer ¶ added in v0.0.5
type BeforeHandlerFunc ¶
BeforeHandlerFunc is a function that runs before a command sends a request over the wire. It may modify the request.
type CLI ¶ added in v0.0.5
type CLI struct { Verbosity VerbosityType `mapstructure:"verbosity"` OutputFormat string `mapstructure:"output_format"` Query string `mapstructure:"query"` Raw bool `mapstructure:"raw"` }
func (CLI) ZeroLogLevel ¶ added in v0.0.5
type ClientConfiguration ¶ added in v0.0.5
type ClientConfiguration struct { ProfileName string `mapstructure:"profile_name"` Secrets Secrets `mapstructure:"secrets"` Settings Settings `mapstructure:"settings"` // contains filtered or unexported fields }
var RunConfig ClientConfiguration
func LoadConfiguration ¶ added in v0.0.5
func LoadConfiguration(envPrefix, settingsFilePath, secretsFilePath string, globalFlags []GlobalFlag) (config ClientConfiguration, err error)
LoadConfiguration loads secret and settings files. It will additional override those persisted values with (1) environment variables and (2) flag values (in order of increasing precedence).
func (ClientConfiguration) GetAuthServer ¶ added in v0.0.5
func (cc ClientConfiguration) GetAuthServer() AuthServer
func (ClientConfiguration) GetCredentials ¶ added in v0.0.5
func (cc ClientConfiguration) GetCredentials() Credentials
func (ClientConfiguration) GetProfile ¶ added in v0.0.5
func (cc ClientConfiguration) GetProfile() Profile
func (*ClientConfiguration) UpdateCredentialsToken ¶ added in v0.0.5
func (cc *ClientConfiguration) UpdateCredentialsToken(credentialsName string, token *oauth2.Token) error
type ConsoleWriter ¶
ConsoleWriter reads a JSON object per write operation and outputs an optionally colored human readable version on the Out writer. This has been modified from the ConsoleWriter that ships with zerolog.
type Credentials ¶ added in v0.0.5
type Credentials struct {
TokenPayload TokenPayload `mapstructure:"token_payload"`
}
type DefaultFormatter ¶
type DefaultFormatter struct {
// contains filtered or unexported fields
}
DefaultFormatter can apply JMESPath queries and can output prettyfied JSON and YAML output. If Stdout is a TTY, then colorized output is provided. The default formatter uses the `query` and `output-format` configuration values to perform JMESPath queries and set JSON (default) or YAML output.
func NewDefaultFormatter ¶
func NewDefaultFormatter(tty bool) *DefaultFormatter
NewDefaultFormatter creates a new formatted with autodetected TTY capabilities.
func (*DefaultFormatter) Format ¶
func (f *DefaultFormatter) Format(data interface{}) error
Format will filter, prettify, colorize and output the data.
type GlobalFlag ¶ added in v0.0.5
func MakeAndParseGlobalFlags ¶ added in v0.0.5
func MakeAndParseGlobalFlags(defaults GlobalFlagDefaults) (globalFlags []GlobalFlag, flagSet *pflag.FlagSet, err error)
type GlobalFlagDefaults ¶ added in v0.0.5
type GlobalFlagDefaults struct { ProfileName string AuthServerName string CredentialsName string ApiURL string OutputFormat string Verbosity string Raw bool }
func NewGlobalFlagDefaults ¶ added in v0.0.5
func NewGlobalFlagDefaults(apiURL string) GlobalFlagDefaults
type Profile ¶ added in v0.0.5
type Profile struct { ApiURL string `mapstructure:"api_url"` AuthServerName string `mapstructure:"auth_server_name"` CredentialsName string `mapstructure:"credentials_name"` Applications `mapstructure:"applications"` }
type ResponseFormatter ¶
type ResponseFormatter interface {
Format(interface{}) error
}
ResponseFormatter will filter, prettify, and print out the results of a call.
var Formatter ResponseFormatter
Formatter is the currently configured response output formatter.
type Secrets ¶ added in v0.0.5
type Secrets struct {
Credentials map[string]Credentials `mapstructure:"credentials"`
}
type Settings ¶ added in v0.0.5
type Settings struct { DefaultProfileName string `mapstructure:"default_profile_name"` Profiles map[string]Profile `mapstructure:"profiles"` AuthServers map[string]AuthServer `mapstructure:"auth_servers"` // contains filtered or unexported fields }
type TokenPayload ¶ added in v0.0.5
type TokenPayload struct { ExpiresIn int `mapstructure:"expires_in"` RefreshToken string `mapstructure:"refresh_token"` AccessToken string `mapstructure:"access_token"` IDToken string `mapstructure:"id_token"` Scope string `mapstructure:"scope"` TokenType string `mapstructure:"token_type"` }
func (TokenPayload) ClientID ¶ added in v0.0.5
func (tp TokenPayload) ClientID() string
func (TokenPayload) ExpiresAt ¶ added in v0.0.5
func (tp TokenPayload) ExpiresAt() (time.Time, error)
func (TokenPayload) Issuer ¶ added in v0.0.5
func (tp TokenPayload) Issuer() string
func (TokenPayload) ToMap ¶ added in v0.0.5
func (tp TokenPayload) ToMap() map[string]interface{}
type VerbosityType ¶ added in v0.0.5
type VerbosityType string
const VerbosityTypeDebug VerbosityType = "debug"
const VerbosityTypeError VerbosityType = "error"
const VerbosityTypeFatal VerbosityType = "fatal"
const VerbosityTypeInfo VerbosityType = "info"
const VerbosityTypePanic VerbosityType = "panic"
const VerbosityTypeWarn VerbosityType = "warn"