Skip to content

Commit

Permalink
chore: rename some properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Enda Phelan committed Mar 11, 2021
1 parent 6c5fd44 commit 122f256
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/factory/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func New(cliVersion string) *Factory {
return nil, err
}

builder.WithOpts(connectionCfg)
builder.WithConnectionConfig(connectionCfg)

conn, err = builder.Build()
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions pkg/connection/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Builder struct {
config config.IConfig
logger logging.Logger
transportWrapper TransportWrapper
connectionOpts *Config
connectionConfig *Config
}

// TransportWrapper is a wrapper for a transport of type http.RoundTripper.
Expand Down Expand Up @@ -126,8 +126,9 @@ func (b *Builder) WithConfig(cfg config.IConfig) *Builder {
return b
}

func (b *Builder) WithOpts(cfg *Config) *Builder {
b.connectionOpts = cfg
// WithConnectionConfig contains config for the connection instance
func (b *Builder) WithConnectionConfig(cfg *Config) *Builder {
b.connectionConfig = cfg
return b
}

Expand All @@ -151,11 +152,11 @@ func (b *Builder) BuildContext(ctx context.Context) (connection *KeycloakConnect
return nil, AuthErrorf("Missing client ID")
}

if b.connectionOpts.RequireAuth && b.accessToken == "" && b.refreshToken == "" {
if b.connectionConfig.RequireAuth && b.accessToken == "" && b.refreshToken == "" {
return nil, &AuthError{notLoggedInError()}
}

if b.connectionOpts.RequireMASAuth && b.masAccessToken == "" && b.masRefreshToken == "" {
if b.connectionConfig.RequireMASAuth && b.masAccessToken == "" && b.masRefreshToken == "" {
return nil, &MasAuthError{notLoggedInMASError()}
}

Expand Down Expand Up @@ -278,7 +279,7 @@ func (b *Builder) BuildContext(ctx context.Context) (connection *KeycloakConnect
masRealm: masKcRealm,
logger: b.logger,
Config: b.config,
connectionOpts: b.connectionOpts,
connectionConfig: b.connectionConfig,
}

return connection, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/connection/keycloak_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type KeycloakConnection struct {
masRealm string
logger logging.Logger
Config config.IConfig
connectionOpts *Config
connectionConfig *Config
}

// RefreshTokens will fetch a refreshed copy of the access token and refresh token from the authentication server
Expand All @@ -73,7 +73,7 @@ func (c *KeycloakConnection) RefreshTokens(ctx context.Context) (err error) {

// track if we need to update the config with new token values
var cfgChanged bool
if c.connectionOpts.RequireAuth {
if c.connectionConfig.RequireAuth {
// nolint:govet
refreshedTk, err := c.keycloakClient.RefreshToken(ctx, c.Token.RefreshToken, c.clientID, "", c.defaultRealm)
if err != nil {
Expand All @@ -92,7 +92,7 @@ func (c *KeycloakConnection) RefreshTokens(ctx context.Context) (err error) {
}
}

if c.connectionOpts.RequireMASAuth {
if c.connectionConfig.RequireMASAuth {
// nolint:govet
refreshedMasTk, err := c.masKeycloakClient.RefreshToken(ctx, c.MASToken.RefreshToken, c.clientID, "", c.masRealm)
if err != nil {
Expand Down

0 comments on commit 122f256

Please sign in to comment.