Documentation ¶
Index ¶
- Constants
- Variables
- func ContainValue[V comparable](array []V, value V) bool
- func GetAuthRelyingParty(httpClient *http.Client, membershipURI string) (rp.RelyingParty, error)
- func GetBool(cmd *cobra.Command, flagName string) bool
- func GetCurrentProfileName(cmd *cobra.Command, config *Config) string
- func GetDateTime(cmd *cobra.Command, flagName string) (*time.Time, error)
- func GetHTTPClient(cmd *cobra.Command, defaultHeaders map[string][]string) *http.Client
- func GetInt(cmd *cobra.Command, flagName string) int
- func GetSelectedOrganization(cmd *cobra.Command) string
- func GetSelectedStackID(cmd *cobra.Command) string
- func GetString(cmd *cobra.Command, flagName string) string
- func GetStringSlice(cmd *cobra.Command, flagName string) []string
- func IsInvalidAuthentication(err error) bool
- func ListProfiles(cmd *cobra.Command, toComplete string) ([]string, error)
- func Map[SRC, DST any](srcs []SRC, mapper func(SRC) DST) []DST
- func MapKeys[K comparable, V any](m map[K]V) []K
- func MapMap[KEY comparable, VALUE, DST any](srcs map[KEY]VALUE, mapper func(KEY, VALUE) DST) []DST
- func NewCommand(use string, opts ...CommandOption) *cobra.Command
- func NewHTTPClient(debug bool, defaultHeaders map[string][]string) *http.Client
- func NewMembershipCommand(use string, opts ...CommandOption) *cobra.Command
- func NewStackCommand(use string, opts ...CommandOption) *cobra.Command
- func Prepend[V any](array []V, items ...V) []V
- func Ptr[T any](t T) *T
- func RetrieveOrganizationIDFromFlagOrProfile(cmd *cobra.Command, cfg *Config) (string, error)
- func WithRender[T any](cmd *cobra.Command, args []string, controller Controller[T], ...) error
- type CommandOption
- type CommandOptionFn
- func WithAliases(aliases ...string) CommandOptionFn
- func WithArgs(p cobra.PositionalArgs) CommandOptionFn
- func WithBoolFlag(name string, defaultValue bool, help string) CommandOptionFn
- func WithChildCommands(cmds ...*cobra.Command) CommandOptionFn
- func WithController[T any](c Controller[T]) CommandOptionFn
- func WithDeprecated(message string) CommandOptionFn
- func WithDeprecatedFlag(name, message string) CommandOptionFn
- func WithDescription(v string) CommandOptionFn
- func WithHidden() CommandOptionFn
- func WithHiddenFlag(name string) CommandOptionFn
- func WithIntFlag(name string, defaultValue int, help string) CommandOptionFn
- func WithPersistentBoolFlag(name string, defaultValue bool, help string) CommandOptionFn
- func WithPersistentBoolPFlag(name, short string, defaultValue bool, help string) CommandOptionFn
- func WithPersistentPreRunE(fn func(cmd *cobra.Command, args []string) error) CommandOptionFn
- func WithPersistentStringFlag(name, defaultValue, help string) CommandOptionFn
- func WithPersistentStringPFlag(name, short, defaultValue, help string) CommandOptionFn
- func WithPreRunE(fn func(cmd *cobra.Command, args []string) error) CommandOptionFn
- func WithRunE(fn func(cmd *cobra.Command, args []string) error) CommandOptionFn
- func WithShortDescription(v string) CommandOptionFn
- func WithSilenceError() CommandOptionFn
- func WithSilenceUsage() CommandOptionFn
- func WithStringArrayFlag(name string, defaultValue []string, help string) CommandOptionFn
- func WithStringFlag(name, defaultValue, help string) CommandOptionFn
- func WithStringSliceFlag(name string, defaultValue []string, help string) CommandOptionFn
- func WithValidArgs(validArgs ...string) CommandOptionFn
- func WithValidArgsFunction(...) CommandOptionFn
- type Config
- func (c *Config) DeleteProfile(s string) error
- func (c *Config) GetCurrentProfileName() string
- func (c *Config) GetProfile(name string) *Profile
- func (c *Config) GetProfileOrDefault(name, membershipURI string) *Profile
- func (c *Config) GetProfiles() map[string]*Profile
- func (c *Config) GetUniqueID() string
- func (c *Config) MarshalJSON() ([]byte, error)
- func (c *Config) Persist() error
- func (c *Config) SetCurrentProfile(name string, profile *Profile)
- func (c *Config) SetCurrentProfileName(s string)
- func (c *Config) SetProfile(name string, profile *Profile)
- func (c *Config) SetUniqueID(id string)
- func (c *Config) UnmarshalJSON(data []byte) error
- type ConfigManager
- type Controller
- type CurrentProfile
- type ErrInvalidAuthentication
- type ExportedData
- type Profile
- func (p *Profile) GetClaims() (jwt.MapClaims, error)
- func (p *Profile) GetDefaultOrganization() string
- func (p *Profile) GetMembershipURI() string
- func (p *Profile) GetToken(ctx context.Context, httpClient *http.Client) (*oauth2.Token, error)
- func (p *Profile) IsConnected() bool
- func (p *Profile) MarshalJSON() ([]byte, error)
- func (p *Profile) SetDefaultOrganization(o string)
- func (p *Profile) SetMembershipURI(v string)
- func (p *Profile) UnmarshalJSON(data []byte) error
- func (p *Profile) UpdateToken(token *oidc.AccessTokenResponse)
- type Renderable
- type RoundTripperFn
Constants ¶
const ( // MembershipURIFlag specifies the URI for membership MembershipURIFlag = "membership-uri" // FileFlag specifies the configuration file FileFlag = "config" // ProfileFlag specifies the profile to use ProfileFlag = "profile" // OutputFlag specifies the output format OutputFlag = "output" // DebugFlag specifies whether to run the command in debug mode DebugFlag = "debug" // TelemetryFlag specifies whether to enable telemetry TelemetryFlag = "telemetry" )
const AuthClient = "mdz"
AuthClient is the name of the OIDC client.
Variables ¶
var ( // ErrOrganizationNotSpecified indicates that no organization was specified when one was required. ErrOrganizationNotSpecified = errors.New("organization not specified") // ErrMultipleOrganizationsFound indicates that more than one organization was found when only one was expected, and no specific organization was specified. ErrMultipleOrganizationsFound = errors.New("found more than one organization and no organization specified") )
var ErrOpenningBrowser = errors.New("opening browser")
ErrOpenningBrowser is a struct that return an error when opening browser
Functions ¶
func ContainValue ¶
func ContainValue[V comparable](array []V, value V) bool
ContainValue func that valid if contains value
func GetAuthRelyingParty ¶
GetAuthRelyingParty returns a NewRelyingPartyOIDC that creates an (OIDC)
func GetCurrentProfileName ¶
GetCurrentProfileName retrieves the name of the current profile from the given cobra.Command and configuration. If the ProfileFlag is set, it returns the value of the ProfileFlag. Otherwise, it returns the current profile name from the configuration.
func GetDateTime ¶
GetDateTime retrieves the time value of the specified flag from the command.
func GetHTTPClient ¶
GetHTTPClient creates and returns a new HTTP client configured based on the provided cobra.Command flags and default headers. It utilizes the NewHTTPClient function, passing in the values of the InsecureTlsFlag and DebugFlag, along with any defaultHeaders specified. This allows for the creation of a customized http.Client instance tailored to the needs of the application, including support for insecure TLS connections and debugging capabilities.
func GetSelectedOrganization ¶
GetSelectedOrganization retrieves the selected organization from the command.
func GetSelectedStackID ¶
GetSelectedStackID retrieves the selected stack ID from the command.
func GetStringSlice ¶
GetStringSlice retrieves the string slice value of the specified flag from the command.
func IsInvalidAuthentication ¶
IsInvalidAuthentication checks if the provided error is an instance of ErrInvalidAuthentication.
func ListProfiles ¶
ListProfiles generates a list of profiles based on the toComplete string.
Parameters:
cmd: *cobra.Command - the command object toComplete: string - the string to complete
Return type:
[]string: list of profile strings error: any error that occurred
func Map ¶
func Map[SRC, DST any](srcs []SRC, mapper func(SRC) DST) []DST
Map func that appends slices
func MapKeys ¶
func MapKeys[K comparable, V any](m map[K]V) []K
MapKeys func that compare and appends slices
func MapMap ¶
func MapMap[KEY comparable, VALUE, DST any](srcs map[KEY]VALUE, mapper func(KEY, VALUE) DST) []DST
MapMap func that compare and appends slices
func NewCommand ¶
func NewCommand(use string, opts ...CommandOption) *cobra.Command
NewCommand creates a new cobra command with the specified use string and options.
Parameters: - use: a string representing the use of the command. - opts: variadic CommandOption options. Return type: - *cobra.Command: a pointer to the created cobra command.
func NewHTTPClient ¶
NewHTTPClient initializes and returns a new http.Client with customizable behavior. It allows for the configuration of TLS insecurity (skipping TLS verification), enabling a debug mode for additional logging, and setting default headers for all requests.
Parameters:
- insecureTLS: If true, the client will accept any TLS certificate presented by the server and any host name in that certificate. This is useful for testing with self-signed certificates.
- debug: If true, wraps the transport in a debugging layer that logs all requests and responses. This is helpful for development and troubleshooting.
- defaultHeaders: A map of header names to their values which will be added to every request made by this client. Useful for setting headers like `Authorization` or `User-Agent` that should be included in all requests.
Returns: - A pointer to an initialized http.Client configured as specified.
func NewMembershipCommand ¶
func NewMembershipCommand(use string, opts ...CommandOption) *cobra.Command
NewMembershipCommand is a helper function that returns a new membership command with the given options.
func NewStackCommand ¶
func NewStackCommand(use string, opts ...CommandOption) *cobra.Command
NewStackCommand is a helper function that returns a new stack command with the given options.
func Prepend ¶
func Prepend[V any](array []V, items ...V) []V
Prepend func that return two append items
func RetrieveOrganizationIDFromFlagOrProfile ¶
RetrieveOrganizationIDFromFlagOrProfile retrieves the organization ID from the command flag or profile.
func WithRender ¶
func WithRender[T any](cmd *cobra.Command, args []string, controller Controller[T], renderable Renderable) error
WithRender handles the rendering of the output based on the output flag.
Types ¶
type CommandOption ¶
type CommandOption interface {
// contains filtered or unexported methods
}
CommandOption is an interface for options that can be applied to a cobra.Command.
type CommandOptionFn ¶
CommandOptionFn is a function that applies a CommandOption to a cobra.Command.
func WithAliases ¶
func WithAliases(aliases ...string) CommandOptionFn
WithAliases is a helper function that returns a CommandOptionFn that applies aliases to a cobra.Command.
func WithArgs ¶
func WithArgs(p cobra.PositionalArgs) CommandOptionFn
WithArgs is a helper function that returns a CommandOptionFn that applies positional arguments to a cobra.Command.
func WithBoolFlag ¶
func WithBoolFlag(name string, defaultValue bool, help string) CommandOptionFn
WithBoolFlag is a helper function that returns a CommandOptionFn that applies a boolean flag to a cobra.Command.
func WithChildCommands ¶
func WithChildCommands(cmds ...*cobra.Command) CommandOptionFn
WithChildCommands is a helper function that returns a CommandOptionFn that applies child commands to a cobra.Command.
func WithController ¶
func WithController[T any](c Controller[T]) CommandOptionFn
WithController wraps a controller's Run method as a cobra command's RunE function.
func WithDeprecated ¶
func WithDeprecated(message string) CommandOptionFn
WithDeprecated is a helper function that returns a CommandOptionFn that applies a deprecated flag to a cobra.Command.
func WithDeprecatedFlag ¶
func WithDeprecatedFlag(name, message string) CommandOptionFn
WithDeprecatedFlag is a helper function that returns a CommandOptionFn that applies a deprecated flag to a cobra.Command.
func WithDescription ¶
func WithDescription(v string) CommandOptionFn
WithDescription is a helper function that returns a CommandOptionFn that applies a description to a cobra.Command.
func WithHidden ¶
func WithHidden() CommandOptionFn
WithHidden is a helper function that returns a CommandOptionFn that applies a hidden flag to a cobra.Command.
func WithHiddenFlag ¶
func WithHiddenFlag(name string) CommandOptionFn
WithHiddenFlag is a helper function that returns a CommandOptionFn that applies a hidden flag to a cobra.Command.
func WithIntFlag ¶
func WithIntFlag(name string, defaultValue int, help string) CommandOptionFn
WithIntFlag is a helper function that returns a CommandOptionFn that applies an integer flag to a cobra.Command.
func WithPersistentBoolFlag ¶
func WithPersistentBoolFlag(name string, defaultValue bool, help string) CommandOptionFn
WithPersistentBoolFlag is a helper function that returns a CommandOptionFn that applies a persistent boolean flag to a cobra.Command.
func WithPersistentBoolPFlag ¶
func WithPersistentBoolPFlag(name, short string, defaultValue bool, help string) CommandOptionFn
WithPersistentBoolPFlag is a helper function that returns a CommandOptionFn that applies a persistent boolean flag to a cobra.Command.
func WithPersistentPreRunE ¶
func WithPersistentPreRunE(fn func(cmd *cobra.Command, args []string) error) CommandOptionFn
WithPersistentPreRunE is a helper function that returns a CommandOptionFn that applies a persistent pre-run function to a cobra.Command.
func WithPersistentStringFlag ¶
func WithPersistentStringFlag(name, defaultValue, help string) CommandOptionFn
WithPersistentStringFlag is a helper function that returns a CommandOptionFn that applies a persistent string flag to a cobra.Command.
func WithPersistentStringPFlag ¶
func WithPersistentStringPFlag(name, short, defaultValue, help string) CommandOptionFn
WithPersistentStringPFlag is a helper function that returns a CommandOptionFn that applies a persistent string flag to a cobra.Command.
func WithPreRunE ¶
func WithPreRunE(fn func(cmd *cobra.Command, args []string) error) CommandOptionFn
WithPreRunE is a helper function that returns a CommandOptionFn that applies a pre-run function to a cobra.Command.
func WithRunE ¶
func WithRunE(fn func(cmd *cobra.Command, args []string) error) CommandOptionFn
WithRunE is a helper function that returns a CommandOptionFn that applies a run function to a cobra.Command.
func WithShortDescription ¶
func WithShortDescription(v string) CommandOptionFn
WithShortDescription is a helper function that returns a CommandOptionFn that applies a short description to a cobra.Command.
func WithSilenceError ¶
func WithSilenceError() CommandOptionFn
WithSilenceError is a helper function that returns a CommandOptionFn that applies silence error to a cobra.Command.
func WithSilenceUsage ¶
func WithSilenceUsage() CommandOptionFn
WithSilenceUsage is a helper function that returns a CommandOptionFn that applies silence usage to a cobra.Command.
func WithStringArrayFlag ¶
func WithStringArrayFlag(name string, defaultValue []string, help string) CommandOptionFn
WithStringArrayFlag is a helper function that returns a CommandOptionFn that applies a string array flag to a cobra.Command.
func WithStringFlag ¶
func WithStringFlag(name, defaultValue, help string) CommandOptionFn
WithStringFlag is a helper function that returns a CommandOptionFn that applies a string flag to a cobra.Command.
func WithStringSliceFlag ¶
func WithStringSliceFlag(name string, defaultValue []string, help string) CommandOptionFn
WithStringSliceFlag is a helper function that returns a CommandOptionFn that applies a string slice flag to a cobra.Command.
func WithValidArgs ¶
func WithValidArgs(validArgs ...string) CommandOptionFn
WithValidArgs is a helper function that returns a CommandOptionFn that applies valid arguments to a cobra.Command.
func WithValidArgsFunction ¶
func WithValidArgsFunction(fn func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)) CommandOptionFn
WithValidArgsFunction returns a CommandOptionFn that sets a custom validation function for command arguments.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config represents the configuration for the application. It encapsulates details such as the current profile in use, a unique identifier for the configuration, a map of profile names to Profile instances, and a reference to the ConfigManager responsible for managing this configuration.
func GetConfig ¶
GetConfig retrieves the configuration from the file system. It uses the ConfigManager to load the configuration from the file system.
func (*Config) DeleteProfile ¶
DeleteProfile removes a profile from the configuration by name. If the profile does not exist, it returns an error.
func (*Config) GetCurrentProfileName ¶
GetCurrentProfileName retrieves the name of the current profile from the configuration.
func (*Config) GetProfile ¶
GetProfile retrieves a profile by name from the configuration. If the profile does not exist, it returns nil.
func (*Config) GetProfileOrDefault ¶
GetProfileOrDefault retrieves a profile by name from the configuration. If the profile does not exist, it creates a new profile with the given membership URI and returns it.
func (*Config) GetProfiles ¶
GetProfiles retrieves the map of profile names to Profile instances from the configuration.
func (*Config) GetUniqueID ¶
GetUniqueID retrieves the unique identifier for the configuration.
func (*Config) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for Config. It converts the Config instance into a JSON-encoded byte slice.
func (*Config) Persist ¶
Persist saves the configuration to the file system. It uses the ConfigManager to update the configuration file with the current configuration.
func (*Config) SetCurrentProfile ¶
SetCurrentProfile sets the current profile to the given name and profile. It also updates the current profile name to the given name.
func (*Config) SetCurrentProfileName ¶
SetCurrentProfileName sets the name of the current profile to the given string.
func (*Config) SetProfile ¶
SetProfile sets the profile with the given name to the given profile.
func (*Config) SetUniqueID ¶
SetUniqueID sets the unique identifier for the configuration.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface for Config. It populates the Config instance with data from a JSON-encoded byte slice.
type ConfigManager ¶
type ConfigManager struct {
// contains filtered or unexported fields
}
ConfigManager is a struct that use a string configFilePath
func GetConfigManager ¶
func GetConfigManager(cmd *cobra.Command) *ConfigManager
GetConfigManager retrieves the ConfigManager instance associated with the given cobra.Command. It uses the FileFlag to determine the configuration file path and returns a new ConfigManager instance.
func NewConfigManager ¶
func NewConfigManager(configFilePath string) *ConfigManager
NewConfigManager is a func that return a struc of *ConfigManager
func (*ConfigManager) Load ¶
func (m *ConfigManager) Load() (*Config, error)
Load is a func that load a filepath and return a *Config of application
func (*ConfigManager) UpdateConfig ¶
func (m *ConfigManager) UpdateConfig(config *Config) error
UpdateConfig is a func that update a *Config of application
type Controller ¶
type Controller[T any] interface { GetStore() T Run(cmd *cobra.Command, args []string) (Renderable, error) }
Controller is a generic interface that defines the structure of a controller capable of handling commands. It requires two methods:
- GetStore, which returns a store of type T.
- Run, which takes a cobra.Command and a slice of strings (arguments), and returns a Renderable and an error. This method is responsible for executing the command's logic.
type ErrInvalidAuthentication ¶
type ErrInvalidAuthentication struct {
// contains filtered or unexported fields
}
ErrInvalidAuthentication is an error that occurs when the authentication token is invalid.
func (ErrInvalidAuthentication) Error ¶
func (e ErrInvalidAuthentication) Error() string
Error returns the error message for ErrInvalidAuthentication.
No parameters. Returns a string.
func (ErrInvalidAuthentication) Is ¶
func (e ErrInvalidAuthentication) Is(err error) bool
Is checks if the provided error is of type ErrInvalidAuthentication.
func (ErrInvalidAuthentication) Unwrap ¶
func (e ErrInvalidAuthentication) Unwrap() error
Unwrap returns the underlying error of ErrInvalidAuthentication.
No parameters. Returns an error.
type ExportedData ¶
type ExportedData struct {
Data any `json:"data"`
}
ExportedData represents a generic structure for data that can be exported. It contains a single field, Data, which can hold any type of value. The field is tagged with `json:"data"` to specify its JSON key when serialized.
type Profile ¶
type Profile struct {
// contains filtered or unexported fields
}
Profile represents a user profile.
func GetCurrentProfile ¶
GetCurrentProfile retrieves the current profile from the given cobra.Command and configuration. It returns the current profile from the configuration. If the current profile does not exist, it creates a new profile with the default membership URI and returns it.
func (*Profile) GetClaims ¶
GetClaims returns the jwt claims and an error.
No parameters. Returns jwt.MapClaims and error.
func (*Profile) GetDefaultOrganization ¶
GetDefaultOrganization returns the default organization for the Profile.
No parameters. Returns a string.
func (*Profile) GetMembershipURI ¶
GetMembershipURI returns the membership URI of the Profile.
No parameters. Returns a string.
func (*Profile) GetToken ¶
GetToken retrieves and refreshes the OAuth2 token if needed.
Parameters:
- ctx: the context for the HTTP request
- httpClient: the HTTP client to use for making HTTP requests
Returns:
- *oauth2.Token: the OAuth2 token retrieved or refreshed
- error: an error if any occurred during the token retrieval or refresh
func (*Profile) MarshalJSON ¶
MarshalJSON generates the JSON encoding for the Profile struct.
No parameters. Returns a byte slice and an error.
func (*Profile) SetDefaultOrganization ¶
SetDefaultOrganization sets the default organization
func (*Profile) SetMembershipURI ¶
SetMembershipURI sets the membership URI for the Profile.
Takes a string parameter.
func (*Profile) UnmarshalJSON ¶
UnmarshalJSON parses the JSON-encoded data and stores the result in the Profile struct.
It takes a byte slice data as a parameter. Returns an error.
func (*Profile) UpdateToken ¶
func (p *Profile) UpdateToken(token *oidc.AccessTokenResponse)
UpdateToken updates the token for the Profile.
token *oidc.AccessTokenResponse - The new access token to be set.
type Renderable ¶
Renderable defines an interface for objects that can render themselves. It requires implementing the Render method, which takes a cobra.Command and a slice of strings (arguments) and returns an error.
type RoundTripperFn ¶
RoundTripperFn is a function type that implements the http.RoundTripper interface. It allows any function with the appropriate signature to be used as an http.RoundTripper. This is useful for creating custom transport behaviors in an http.Client.