helpers

package
Version: v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2022 License: UPL-1.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const BufferTime = 10

Assuming that the api call will take place within Buffer seconds from checking validity of token

View Source
const KubeConfigKeywordVerrazzano = "verrazzano"

To be used as nick name for Verrazzano related clusters,contexts,users,etc in kubeconfig

View Source
const (
	NothingFound = "no resources found"
)

Variables

This section is empty.

Functions

func Age

func Age(createTime v1.Time) string

Age takes a Time and returns the length of time from then to now in a compact format like 2d3h

func ConcatURLParams added in v1.1.0

func ConcatURLParams(urlParams map[string]string) string

Accepts url parameters in the form of map[string][string] Returns concatenated list of url parameters Return string of the form `code=xyz&status=abc`

func FormatStringSlice

func FormatStringSlice(in []string) string

FormatStringSlice formats a string slice as a comma separated list

func GenerateKeycloakAPIURL added in v1.1.0

func GenerateKeycloakAPIURL(codeChallenge string, redirectURI string, state string, verrazzanoAPIURL string) (string, error)

Generates the keycloak api url to login Return string of the form `https://keycloak.xyz.io:123/auth/realms/verrazzano-system/protocol/openid-connect/auth?redirect_uri=abc&state=xyz...`

func GenerateKeycloakTokenURL added in v1.1.0

func GenerateKeycloakTokenURL(verrazzanoAPIURL string) (string, error)

Gnerates and returns keycloak server api url to get the jwt token Return string of the form `https://keycloak.xyz.io:123/auth/realms/verrazzano-system/protocol/openid-connect/token

func GenerateRandomCodePair added in v1.1.0

func GenerateRandomCodePair() (string, string, error)

Generates a random code verifier and then produces a code challenge using it. Returns the produced code_verifier and code_challenge pair

func GenerateRandomState added in v1.1.0

func GenerateRandomState() (string, error)

Generates a random string which is used as the state

func GenerateRedirectURI added in v1.1.0

func GenerateRedirectURI(listener net.Listener) string

Generates redirect_uri using the given port number return string of the form `http://localhost:1234`

func GetCAData added in v1.1.0

func GetCAData(name string) ([]byte, error)

Returns the certificate authority data already present in kubeconfig

func GetClientID added in v1.1.0

func GetClientID() string

Returns the oidc client id

func GetCurrentContextFromKubeConfig added in v1.1.0

func GetCurrentContextFromKubeConfig() (string, error)

Returns the current context in kubeconfig

func GetKeycloakURL added in v1.1.0

func GetKeycloakURL(verrazzanoAPIURL string) (string, error)

Returns the keycloak base url

func GetVerrazzanoAPIURL added in v1.1.0

func GetVerrazzanoAPIURL(name string) (string, error)

Returns the Verrazzano api server url

func GetVerrazzanoRealm added in v1.1.0

func GetVerrazzanoRealm() string

Returns the realm name the oidc client is part of

func IsLoggedIn added in v1.1.0

func IsLoggedIn() (bool, error)

Helper function to find if the user is logged in

func IsLoggedOut added in v1.1.0

func IsLoggedOut() (bool, error)

Helper function to find if the user is logged out

func OpenURLInBrowser added in v1.1.0

func OpenURLInBrowser(url string) error

Non-blocking browser opener function

func PrintTable

func PrintTable(headings []string, data [][]string, w io.Writer) error

PrintTable will print the data in a well-formatted table with the headings at top

func RemoveAllAuthData added in v1.1.0

func RemoveAllAuthData() error

Helper function that removes all the user details from kubeconfig

func RemoveClusterFromKubeConfig added in v1.1.0

func RemoveClusterFromKubeConfig(name string) error

Removes a cluster with given name from kubeconfig

func RemoveContextFromKubeConfig added in v1.1.0

func RemoveContextFromKubeConfig(name string) error

Removes a context with given name from kubeconfig

func RemoveUserFromKubeConfig added in v1.1.0

func RemoveUserFromKubeConfig(name string) error

Removes a user with given name from kubeconfig

func ServerSideApply

func ServerSideApply(config *rest.Config, yaml string) error

func SetClusterInKubeConfig added in v1.1.0

func SetClusterInKubeConfig(name string, serverURL string, caData []byte) error

Adds a cluster to kubeconfig

func SetContextInKubeConfig added in v1.1.0

func SetContextInKubeConfig(name string, clusterName string, userName string) error

Adds a new context to kubeconfig

func SetCurrentContextInKubeConfig added in v1.1.0

func SetCurrentContextInKubeConfig(name string) error

Changes current cluster to given cluster in kubeconfig

func SetUserInKubeConfig added in v1.1.0

func SetUserInKubeConfig(name string, accessToken string, authDetails AuthDetails) error

Adds a user to kubeconfig

func WriteToKubeConfig added in v1.1.0

func WriteToKubeConfig(kubeConfig Config) error

Writes the given interface map to kubeconfig

Types

type AuthDetails added in v1.1.0

type AuthDetails struct {
	RefreshTokenExpTime int64
	AccessTokenExpTime  int64
	RefreshToken        string
}

Struct to store user's authentication data

func GetAuthDetails added in v1.1.0

func GetAuthDetails(name string) (AuthDetails, error)

Returns tokens and expiration times wrapped up in a struct

type Config added in v1.1.0

type Config struct {
	*clientcmdapi.Config `json:",inline"`
	KeycloakTokenInfos   []NamedKeycloakTokenInfo `json:"keycloakTokenInfo,omitempty"`
}

func ReadKubeConfig added in v1.1.0

func ReadKubeConfig() (Config, error)

Reads the kubeconfig into a interface map

type Kubernetes added in v0.17.0

type Kubernetes interface {
	GetKubeConfig() (*rest.Config, error)
	NewClustersClientSet() (clientset.Interface, error)
	NewProjectClientSet() (projectclientset.Interface, error)
	NewVerrazzanoClientSet() (verrazzanoclientset.Interface, error)
	NewClientSet() (kubernetes.Interface, error)
}

type NamedKeycloakTokenInfo added in v1.1.0

type NamedKeycloakTokenInfo struct {
	// Name is the nickname for this user
	Name string `json:"name"`
	// TokenInfo holds the token information
	TokenInfo TokenInfo `json:"tokenInfo"`
}

type PrintFlags added in v0.17.0

type PrintFlags struct {
	JSONYamlPrintFlags *genericclioptions.JSONYamlPrintFlags
	TemplateFlags      *genericclioptions.KubeTemplatePrintFlags

	OutputFormat *string
}

PrintFlags contains all the flags used for output options

func NewGetPrintFlags added in v0.17.0

func NewGetPrintFlags() *PrintFlags

NewGetPrintFlags returns a new PrintFlags struct for use

func (*PrintFlags) AddFlags added in v0.17.0

func (f *PrintFlags) AddFlags(cmd *cobra.Command)

AddFlags binds all the required flags for output to the cmd

func (*PrintFlags) AllowedFormats added in v0.17.0

func (f *PrintFlags) AllowedFormats() []string

AllowedFormats is a list of all the allowed formats for output options

func (*PrintFlags) ToPrinter added in v0.17.0

func (f *PrintFlags) ToPrinter() (printers.ResourcePrinter, error)

ToPrinter returns an appropriate printer based on the output format or returns an error if there is none

type TokenInfo added in v1.1.0

type TokenInfo struct {
	// Refresh token is a jwt token used to refresh the access token
	// +optional
	RefreshToken string `json:"refreshToken"`
	// Time until which access token will be alive
	// +optional
	AccessTokenExpTime int64 `json:"accessTokenExpTime"`
	// Time intil which refresh token will be alive
	// +optional
	RefreshTokenExpTime int64 `json:"refreshTokenExpTime"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL