Documentation
¶
Overview ¶
Package cli contains utility for the cli
Package cli contains utility for the cli
Index ¶
- Constants
- Variables
- func ConcatenateAndWrap(input string, maxLen int) string
- func EnsureCredentials(cmd *cobra.Command, _ []string) error
- func ExitNicelyOnError(err error, userMsg string)
- func GRPCClientWrapRunE(...) func(cmd *cobra.Command, args []string) error
- func GetAppContext(ctx context.Context, v *viper.Viper) (context.Context, context.CancelFunc)
- func GetAppContextWithTimeoutDuration(ctx context.Context, v *viper.Viper, tout int) (context.Context, context.CancelFunc)
- func GetConfigDirPath() (string, error)
- func GetGrpcConnection(cfg clientconfig.GRPCClientConfig, issuerUrl string, realm string, ...) (*grpc.ClientConn, error)
- func GetNameAndOwnerFromRepository(repository string) (string, string)
- func GetRealmUrl(serverAddress string, opts []grpc.DialOption, issuerUrl string, realm string) (string, error)
- func GetRepositoryName(owner, name string) string
- func GetToken(serverAddress string, opts []grpc.DialOption, issuerUrl string, realm string, ...) (string, error)
- func GetTokenFromGitHub() (string, error)
- func GrpcForCommand(cmd *cobra.Command, v *viper.Viper) (*grpc.ClientConn, error)
- func IsYAMLFileAndNotATest(path string) bool
- func Login(ctx context.Context, cmd *cobra.Command, cfg *clientconfig.Config, ...) (*oidc.Tokens[*oidc.IDTokenClaims], error)
- func LoginAndSaveCreds(ctx context.Context, cmd *cobra.Command, clientConfig *clientconfig.Config) (string, error)
- func MessageAndError(msg string, err error) error
- func MultiSelect(choices []string) ([]string, error)
- func PrintYesNoPrompt(cmd *cobra.Command, promptMsg, confirmMsg, fallbackMsg string, defaultYes bool) bool
- func RemoveCredentials(serverAddress string) error
- func RenderMarkdown(payload string, opts ...glamour.TermRendererOption) string
- func RevokeOfflineToken(token string, issuerUrl string, realm string, clientId string) error
- func RevokeToken(token string, issuerUrl string, realm string, clientId string, ...) error
- func SaveCredentials(serverAddress string, tokens OpenIdCredentials) (string, error)
- func SetProviderConfig(ctx context.Context, provCli minderv1.ProvidersServiceClient, ...) error
- func ValidateRepositoryName(repository string) error
- func WidthFraction(fraction float64) glamour.TermRendererOption
- type ErrWrappedCLIError
- type JWTTokenCredentials
- type OpenIdCredentials
- type ProviderConfigUnion
Constants ¶
const GitHubActionsEndpoint = "ACTIONS_ID_TOKEN_REQUEST_URL"
GitHubActionsEndpoint is the environment variable GitHub uses to signal the endpoint for GitHub Actions OIDC token requests
const GitHubActionsTokenEnv = "ACTIONS_ID_TOKEN_REQUEST_TOKEN"
GitHubActionsTokenEnv is the environment variable GitHub uses to authenticate the calls to the GitHubActionsEndpoint
const MinderAuthTokenEnvVar = "MINDER_AUTH_TOKEN"
MinderAuthTokenEnvVar is the environment variable for the minder auth token
Variables ¶
var ( // PrimaryColor is the primary color for the cli. PrimaryColor = lipgloss.Color("#00BBBE") // SecondaryColor is the secondary color for the cli. SecondaryColor = lipgloss.Color("#59CFA8") // AccentColor is the accent color for the cli. AccentColor = lipgloss.Color("#3D34E0") // WhiteColor is the white color for the cli. WhiteColor = lipgloss.Color("#FFFFFF") // BlackColor is the black color for the cli. BlackColor = lipgloss.Color("#000000") )
Color Palette
var ( // DefaultBannerWidth is the default width for a banner DefaultBannerWidth = 80 // Header is the style to use for headers Header = lipgloss.NewStyle(). Bold(true). Foreground(PrimaryColor). PaddingTop(1). PaddingBottom(1). PaddingLeft(1). PaddingRight(1). MaxWidth(80) WarningBanner = lipgloss.NewStyle(). Bold(true). Background(BlackColor). Foreground(WhiteColor). BorderForeground(AccentColor). PaddingTop(2). PaddingBottom(2). PaddingLeft(4). PaddingRight(4). Width(DefaultBannerWidth) // SuccessBanner is the style to use for a success banner SuccessBanner = lipgloss.NewStyle(). Bold(true). Background(AccentColor). Foreground(WhiteColor). PaddingTop(1). PaddingBottom(1). PaddingLeft(4). PaddingRight(4). Width(DefaultBannerWidth) )
Banner styles
var (
CursorStyle = lipgloss.NewStyle().Foreground(SecondaryColor)
)
Common styles
var ErrGettingRefreshToken = errors.New("error refreshing credentials")
ErrGettingRefreshToken is an error for when we can't get a refresh token
Functions ¶
func ConcatenateAndWrap ¶
ConcatenateAndWrap takes a string and a maximum line length (maxLen), then outputs the string as a multiline string where each line does not exceed maxLen characters.
func EnsureCredentials ¶
EnsureCredentials is a PreRunE function to ensure that the user has valid credentials, opening a browser for login if needed.
func ExitNicelyOnError ¶
ExitNicelyOnError print a message and exit with the right code
func GRPCClientWrapRunE ¶
func GRPCClientWrapRunE( runEFunc func(ctx context.Context, cmd *cobra.Command, args []string, c *grpc.ClientConn) error, ) func(cmd *cobra.Command, args []string) error
GRPCClientWrapRunE is a wrapper for cobra commands that sets up the grpc client and context
func GetAppContext ¶
GetAppContext is a helper for getting the cmd app context
func GetAppContextWithTimeoutDuration ¶
func GetAppContextWithTimeoutDuration(ctx context.Context, v *viper.Viper, tout int) (context.Context, context.CancelFunc)
GetAppContextWithTimeoutDuration is a helper for getting the cmd app context with a custom timeout
func GetConfigDirPath ¶ added in v0.0.84
GetConfigDirPath returns the path to the config directory
func GetGrpcConnection ¶ added in v0.0.84
func GetGrpcConnection( cfg clientconfig.GRPCClientConfig, issuerUrl string, realm string, clientId string, opts ...grpc.DialOption) ( *grpc.ClientConn, error)
GetGrpcConnection is a helper for getting a testing connection for grpc
func GetNameAndOwnerFromRepository ¶
GetNameAndOwnerFromRepository returns the owner and name from a repository name in the format owner/name
func GetRealmUrl ¶ added in v0.0.86
func GetRealmUrl(serverAddress string, opts []grpc.DialOption, issuerUrl string, realm string) (string, error)
GetRealmUrl determines the authentication realm URL, preferring to fetch it from the server headers using the minder.v1.UserService.GetUser method (and extracting the realm from the "WWW-Authenticate" header), but falling back to static configuration if that fails.
func GetRepositoryName ¶
GetRepositoryName returns the repository name in the format owner/name
func GetToken ¶ added in v0.0.84
func GetToken(serverAddress string, opts []grpc.DialOption, issuerUrl string, realm string, clientId string) (string, error)
GetToken retrieves the access token from the credentials file and refreshes it if necessary
func GetTokenFromGitHub ¶ added in v0.1.0
GetTokenFromGitHub uses the GitHub $ACTIONS_ID_TOKEN_REQUEST_URL to fetch an OIDC token from GitHub which can be used to authenticate to Minder if the machine_accounts flag is enabled.
func GrpcForCommand ¶
GrpcForCommand is a helper for getting a testing connection from cobra flags
func IsYAMLFileAndNotATest ¶ added in v0.0.68
IsYAMLFileAndNotATest checks if a file is a YAML file and not a test file
func Login ¶
func Login( ctx context.Context, cmd *cobra.Command, cfg *clientconfig.Config, extraScopes []string, skipBroswer bool, ) (*oidc.Tokens[*oidc.IDTokenClaims], error)
Login is a helper function to handle the login process and return the access token
func LoginAndSaveCreds ¶
func LoginAndSaveCreds(ctx context.Context, cmd *cobra.Command, clientConfig *clientconfig.Config) (string, error)
LoginAndSaveCreds runs a login flow for the user, opening a browser if needed. If the credentials need to be refreshed, the new credentials will be saved for future use.
func MessageAndError ¶
MessageAndError prints a message and returns an error.
func MultiSelect ¶
MultiSelect implements the necessary logic to implement an interactive multi-select menu for the CLI.
Given a list of string as choices, returns those interactively selected by the user.
func PrintYesNoPrompt ¶
func PrintYesNoPrompt(cmd *cobra.Command, promptMsg, confirmMsg, fallbackMsg string, defaultYes bool) bool
PrintYesNoPrompt prints a yes/no prompt to the user and returns false if the user did not respond with yes or y
func RemoveCredentials ¶ added in v0.0.84
RemoveCredentials removes the local credentials file
func RenderMarkdown ¶
func RenderMarkdown(payload string, opts ...glamour.TermRendererOption) string
RenderMarkdown renders the given string as markdown.
func RevokeOfflineToken ¶ added in v0.0.84
RevokeOfflineToken revokes the given offline token using OAuth2.0's Token Revocation endpoint from RFC 7009.
func RevokeToken ¶ added in v0.0.84
func RevokeToken(token string, issuerUrl string, realm string, clientId string, tokenHint string) error
RevokeToken revokes the given token using OAuth2.0's Token Revocation endpoint from RFC 7009. The tokenHint is the type of token being revoked, such as "access_token" or "refresh_token". In the case of an offline token, the tokenHint should be "refresh_token".
func SaveCredentials ¶ added in v0.0.84
func SaveCredentials(serverAddress string, tokens OpenIdCredentials) (string, error)
SaveCredentials saves the credentials to a file
func SetProviderConfig ¶
func SetProviderConfig( ctx context.Context, provCli minderv1.ProvidersServiceClient, project, providerName string, serde *ProviderConfigUnion, ) error
SetProviderConfig sets the provider configuration in the minder service
func ValidateRepositoryName ¶
ValidateRepositoryName checks if a repository name is valid
func WidthFraction ¶ added in v0.1.0
func WidthFraction(fraction float64) glamour.TermRendererOption
WidthFraction sets the width of the markdown text to the fraction of the terminal width (0.0 to 1.0).
Types ¶
type ErrWrappedCLIError ¶
ErrWrappedCLIError is an error that wraps another error and provides a message used from within the CLI
func (*ErrWrappedCLIError) Error ¶
func (e *ErrWrappedCLIError) Error() string
type JWTTokenCredentials ¶ added in v0.0.84
type JWTTokenCredentials struct {
// contains filtered or unexported fields
}
JWTTokenCredentials is a helper struct for grpc
func (JWTTokenCredentials) GetRequestMetadata ¶ added in v0.0.84
func (jwt JWTTokenCredentials) GetRequestMetadata(_ context.Context, _ ...string) (map[string]string, error)
GetRequestMetadata implements the PerRPCCredentials interface.
func (JWTTokenCredentials) RequireTransportSecurity ¶ added in v0.0.84
func (JWTTokenCredentials) RequireTransportSecurity() bool
RequireTransportSecurity implements the PerRPCCredentials interface.
type OpenIdCredentials ¶ added in v0.0.84
type OpenIdCredentials struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` AccessTokenExpiresAt time.Time `json:"expiry"` }
OpenIdCredentials is a struct to hold the access and refresh tokens
func LoadCredentials ¶ added in v0.0.84
func LoadCredentials(serverAddress string) (OpenIdCredentials, error)
LoadCredentials loads the credentials from a file
func RefreshCredentials ¶ added in v0.0.84
func RefreshCredentials(serverAddress string, refreshToken string, realmUrl string, clientId string) (OpenIdCredentials, error)
RefreshCredentials uses a refresh token to get and save a new set of credentials
type ProviderConfigUnion ¶
type ProviderConfigUnion struct { *minderv1.ProviderConfig //nolint:lll GitHub *minderv1.GitHubProviderConfig `json:"github,omitempty" yaml:"github" mapstructure:"github" validate:"required"` //nolint:lll GitHubApp *minderv1.GitHubAppProviderConfig `json:"github_app,omitempty" yaml:"github_app" mapstructure:"github_app" validate:"required"` }
ProviderConfigUnion is a union type for the different provider configurations this is a temporary kludge until we can autogenerate the possible attributes
func GetProviderConfig ¶
func GetProviderConfig( ctx context.Context, provCli minderv1.ProvidersServiceClient, project, providerName string, ) (*ProviderConfigUnion, error)
GetProviderConfig retrieves the provider configuration from the minder service
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package table contains utilities for rendering tables
|
Package table contains utilities for rendering tables |
layouts
Package layouts defines the available table layouts
|
Package layouts defines the available table layouts |
Package types provides normalization types for CLI rendering.
|
Package types provides normalization types for CLI rendering. |
Package useragent contains utilities for setting up the CLI's user agent
|
Package useragent contains utilities for setting up the CLI's user agent |