Skip to content

Commit

Permalink
Refactor function to simplify logging & validation
Browse files Browse the repository at this point in the history
There are now distinct blocks of validation, logging, and initialisation.
  • Loading branch information
agrski committed Sep 13, 2023
1 parent 330b94a commit d5d03e8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions scheduler/pkg/kafka/config/oauth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,22 @@ func (c OAuthStoreOptions) String() string {
}

func NewOAuthStore(opts OAuthStoreOptions) (OAuthStore, error) {
logger := logrus.New().WithField("source", "OAuthStore")
logger.WithField("options", opts.String()).Info("creating new store")

secretName, ok := util.GetEnv(opts.Prefix, envSecretSuffix)
if !ok {
return nil, fmt.Errorf("OAuth mechanism is currently only supported on K8s")
}

logger.
WithField("secret", secretName).
WithField("prefix", opts.Prefix).
Info("creating store from secret")

namespace, ok := os.LookupEnv(envNamespace)
if !ok {
return nil, fmt.Errorf("Namespace env var %s not found and needed for OAuth secret", envNamespace)
}
logger.WithField("namespace", namespace).Info("determined namespace from env var")

logger := logrus.New().WithField("source", "OAuthStore")
logger.
WithField("namespace", namespace).
WithField("secret", secretName).
WithField("options", opts.String()).
Info("creating store from secret")

store, err := NewOAuthSecretHandler(secretName, opts.Clientset, namespace, opts.Prefix, logger)
if err != nil {
Expand Down

0 comments on commit d5d03e8

Please sign in to comment.