connection

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfigRequireMasAuth = &Config{
	RequireAuth:    true,
	RequireMASAuth: true,
}

DefaultConfigRequireMasAuth is used when running commands which must authenticate with MAS-SSO

View Source
var DefaultConfigSkipMasAuth = &Config{
	RequireAuth:    true,
	RequireMASAuth: false,
}

DefaultConfigSkipMasAuth is used when running commands which do not require authenticatation with MAS-SSO

View Source
var DefaultScopes = []string{
	"openid",
}

Functions

func SplitKeycloakRealmURL

func SplitKeycloakRealmURL(u *url.URL) (issuer string, realm string, ok bool)

SplitKeycloakRealmURL splits a Keycloak auth URL to retrieve the base path and realm separately

Types

type AuthError

type AuthError struct {
	Err error
}

AuthError defines an Authentication error

func AuthErrorf

func AuthErrorf(format string, a ...interface{}) *AuthError

func (*AuthError) Error

func (e *AuthError) Error() string

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

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

func (b *Builder) DisableKeepAlives(flag bool) *Builder

DisableKeepAlives disables HTTP keep-alives with the server. This is unrelated to similarly named TCP keep-alives.

func (*Builder) WithAccessToken

func (b *Builder) WithAccessToken(accessToken string) *Builder

func (*Builder) WithAuthURL

func (b *Builder) WithAuthURL(authURL string) *Builder

func (*Builder) WithClientID

func (b *Builder) WithClientID(clientID string) *Builder

func (*Builder) WithConfig

func (b *Builder) WithConfig(cfgHandler *config.CfgHandler) *Builder

func (*Builder) WithConnectionConfig

func (b *Builder) WithConnectionConfig(cfg *Config) *Builder

WithConnectionConfig contains config for the connection instance

func (*Builder) WithInsecure

func (b *Builder) WithInsecure(insecure bool) *Builder

func (*Builder) WithLogger

func (b *Builder) WithLogger(logger logging.Logger) *Builder

func (*Builder) WithMASAccessToken

func (b *Builder) WithMASAccessToken(accessToken string) *Builder

func (*Builder) WithMASAuthURL

func (b *Builder) WithMASAuthURL(authURL string) *Builder

func (*Builder) WithMASRefreshToken

func (b *Builder) WithMASRefreshToken(refreshToken string) *Builder

func (*Builder) WithRefreshToken

func (b *Builder) WithRefreshToken(refreshToken string) *Builder

func (*Builder) WithScopes

func (b *Builder) WithScopes(scopes ...string) *Builder

func (*Builder) WithTransportWrapper

func (b *Builder) WithTransportWrapper(transportWrapper TransportWrapper) *Builder

func (*Builder) WithTrustedCAs

func (b *Builder) WithTrustedCAs(value *x509.CertPool) *Builder

func (*Builder) WithURL

func (b *Builder) WithURL(url string) *Builder

type Config

type Config struct {
	RequireAuth    bool
	RequireMASAuth bool
}

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) API

func (mock *ConnectionMock) API() *api.API

API calls APIFunc.

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.

Jump to

Keyboard shortcuts

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