Documentation ¶
Index ¶
- Variables
- func SplitKeycloakRealmURL(u *url.URL) (issuer string, realm string, ok bool)
- type AuthError
- type Builder
- func (b *Builder) Build() (connection *KeycloakConnection, err error)
- func (b *Builder) BuildContext(ctx context.Context) (connection *KeycloakConnection, err error)
- func (b *Builder) DisableKeepAlives(flag bool) *Builder
- func (b *Builder) WithAccessToken(accessToken string) *Builder
- func (b *Builder) WithAuthURL(authURL string) *Builder
- func (b *Builder) WithClientID(clientID string) *Builder
- func (b *Builder) WithConfig(cfgHandler *config.CfgHandler) *Builder
- func (b *Builder) WithConnectionConfig(cfg *Config) *Builder
- func (b *Builder) WithInsecure(insecure bool) *Builder
- func (b *Builder) WithLogger(logger logging.Logger) *Builder
- func (b *Builder) WithMASAccessToken(accessToken string) *Builder
- func (b *Builder) WithMASAuthURL(authURL string) *Builder
- func (b *Builder) WithMASRefreshToken(refreshToken string) *Builder
- func (b *Builder) WithRefreshToken(refreshToken string) *Builder
- func (b *Builder) WithScopes(scopes ...string) *Builder
- func (b *Builder) WithTransportWrapper(transportWrapper TransportWrapper) *Builder
- func (b *Builder) WithTrustedCAs(value *x509.CertPool) *Builder
- func (b *Builder) WithURL(url string) *Builder
- type Config
- type Connection
- type ConnectionMock
- func (mock *ConnectionMock) API() *api.API
- func (mock *ConnectionMock) APICalls() []struct{}
- func (mock *ConnectionMock) Logout(ctx context.Context) error
- func (mock *ConnectionMock) LogoutCalls() []struct{ ... }
- func (mock *ConnectionMock) RefreshTokens(ctx context.Context) error
- func (mock *ConnectionMock) RefreshTokensCalls() []struct{ ... }
- type KeycloakConnection
- type MasAuthError
- type TransportWrapper
Constants ¶
This section is empty.
Variables ¶
var DefaultConfigRequireMasAuth = &Config{ RequireAuth: true, RequireMASAuth: true, }
DefaultConfigRequireMasAuth is used when running commands which must authenticate with MAS-SSO
var DefaultConfigSkipMasAuth = &Config{ RequireAuth: true, RequireMASAuth: false, }
DefaultConfigSkipMasAuth is used when running commands which do not require authenticatation with MAS-SSO
var DefaultScopes = []string{
"openid",
}
Functions ¶
Types ¶
type AuthError ¶
type AuthError struct {
Err error
}
AuthError defines an Authentication error
func AuthErrorf ¶
type Builder ¶
type Builder struct { AccessToken string RefreshToken string MasAccessToken string MasRefreshToken string CfgHandler *config.CfgHandler // contains filtered or unexported fields }
Builder contains the configuration and logic needed to connect to `api.openshift.com`. Don't create instances of this type directly, use the NewBulder function instead
func NewBuilder ¶
func NewBuilder() *Builder
NewBuilder create an builder that knows how to create connections with the default configuration.
func (*Builder) Build ¶
func (b *Builder) Build() (connection *KeycloakConnection, err error)
Build uses the configuration stored in the builder to create a new connection. The builder can be reused to create multiple connections with the same configuration. It returns a pointer to the connection, and an error if something fails when trying to create it.
This operation is potentially lengthy, as it may require network communications. Consider using a context and the BuildContext method.
func (*Builder) BuildContext ¶
func (b *Builder) BuildContext(ctx context.Context) (connection *KeycloakConnection, err error)
BuildContext uses the configuration stored in the builder to create a new connection. The builder can be reused to create multiple connections with the same configuration. It returns a pointer to the connection, and an error if something fails when trying to create it. nolint:funlen
func (*Builder) DisableKeepAlives ¶
DisableKeepAlives disables HTTP keep-alives with the server. This is unrelated to similarly named TCP keep-alives.
func (*Builder) WithAccessToken ¶
func (*Builder) WithAuthURL ¶
func (*Builder) WithClientID ¶
func (*Builder) WithConfig ¶
func (b *Builder) WithConfig(cfgHandler *config.CfgHandler) *Builder
func (*Builder) WithConnectionConfig ¶
WithConnectionConfig contains config for the connection instance
func (*Builder) WithInsecure ¶
func (*Builder) WithMASAccessToken ¶
func (*Builder) WithMASAuthURL ¶
func (*Builder) WithMASRefreshToken ¶
func (*Builder) WithRefreshToken ¶
func (*Builder) WithScopes ¶
func (*Builder) WithTransportWrapper ¶
func (b *Builder) WithTransportWrapper(transportWrapper TransportWrapper) *Builder
type Connection ¶
type Connection interface { // Method to refresh the OAuth tokens RefreshTokens(ctx context.Context) error // Method to perform a logout request to the authentication server Logout(ctx context.Context) error // Method to create the API clients API() *api.API }
Connection is an interface which defines methods for interacting with the control plane API and the authentication server
type ConnectionMock ¶
type ConnectionMock struct { // APIFunc mocks the API method. APIFunc func() *api.API // LogoutFunc mocks the Logout method. LogoutFunc func(ctx context.Context) error // RefreshTokensFunc mocks the RefreshTokens method. RefreshTokensFunc func(ctx context.Context) error // contains filtered or unexported fields }
ConnectionMock is a mock implementation of Connection.
func TestSomethingThatUsesConnection(t *testing.T) { // make and configure a mocked Connection mockedConnection := &ConnectionMock{ APIFunc: func() *api.API { panic("mock out the API method") }, LogoutFunc: func(ctx context.Context) error { panic("mock out the Logout method") }, RefreshTokensFunc: func(ctx context.Context) error { panic("mock out the RefreshTokens method") }, } // use mockedConnection in code that requires Connection // and then make assertions. }
func (*ConnectionMock) APICalls ¶
func (mock *ConnectionMock) APICalls() []struct{}
APICalls gets all the calls that were made to API. Check the length with:
len(mockedConnection.APICalls())
func (*ConnectionMock) Logout ¶
func (mock *ConnectionMock) Logout(ctx context.Context) error
Logout calls LogoutFunc.
func (*ConnectionMock) LogoutCalls ¶
func (mock *ConnectionMock) LogoutCalls() []struct { Ctx context.Context }
LogoutCalls gets all the calls that were made to Logout. Check the length with:
len(mockedConnection.LogoutCalls())
func (*ConnectionMock) RefreshTokens ¶
func (mock *ConnectionMock) RefreshTokens(ctx context.Context) error
RefreshTokens calls RefreshTokensFunc.
func (*ConnectionMock) RefreshTokensCalls ¶
func (mock *ConnectionMock) RefreshTokensCalls() []struct { Ctx context.Context }
RefreshTokensCalls gets all the calls that were made to RefreshTokens. Check the length with:
len(mockedConnection.RefreshTokensCalls())
type KeycloakConnection ¶
type KeycloakConnection struct { Token *token.Token MASToken *token.Token CfgHandler *config.CfgHandler // contains filtered or unexported fields }
KeycloakConnection contains the data needed to connect to the `api.openshift.com`. Don't create instances of this type directly, use the builder instead
func (*KeycloakConnection) API ¶
func (c *KeycloakConnection) API() *api.API
API Creates a new API type which is a single type for multiple APIs nolint:funlen
func (*KeycloakConnection) Logout ¶
func (c *KeycloakConnection) Logout(ctx context.Context) (err error)
Logout logs the user out from the authentication server Invalidating and removing the access and refresh tokens The user will have to log in again to access the API
func (*KeycloakConnection) RefreshTokens ¶
func (c *KeycloakConnection) RefreshTokens(ctx context.Context) (err error)
RefreshTokens will fetch a refreshed copy of the access token and refresh token from the authentication server The new tokens will have an increased expiry time and are persisted in the config and connection
type MasAuthError ¶
type MasAuthError struct {
Err error
}
func (*MasAuthError) Error ¶
func (e *MasAuthError) Error() string
func (*MasAuthError) Unwrap ¶
func (e *MasAuthError) Unwrap() error
type TransportWrapper ¶
type TransportWrapper func(http.RoundTripper) http.RoundTripper
TransportWrapper is a wrapper for a transport of type http.RoundTripper. Creating a transport wrapper, enables to preform actions and manipulations on the transport request and response.