Skip to content

Commit 637b0ea

Browse files
committed
fix(client): Add logging for client base configuration parameters.
1 parent 047455e commit 637b0ea

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

client.go

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func newClient(config *keyfactorConfig, b *keyfactorBackend) (*keyfactorClient,
3333
}
3434

3535
hostname := config.KeyfactorUrl
36+
b.Logger().Debug(fmt.Sprintf("using hostname %s", hostname))
3637

3738
isBasicAuth := config.Username != "" && config.Password != ""
3839
isOAuth := (config.ClientId != "" && config.ClientSecret != "" && config.TokenUrl != "") || config.AccessToken != ""
@@ -48,20 +49,44 @@ func newClient(config *keyfactorConfig, b *keyfactorBackend) (*keyfactorClient,
4849
basicAuthConfig := &auth_providers.CommandAuthConfigBasic{}
4950

5051
if isBasicAuth {
51-
b.Logger().Debug(fmt.Sprintf("using basic auth with username %s, domain %s and password (hidden)", config.Username, config.Domain))
52+
b.Logger().Debug(
53+
fmt.Sprintf(
54+
"using basic auth with username %s, domain %s and password (hidden)",
55+
config.Username,
56+
config.Domain,
57+
),
58+
)
59+
b.Logger().With(
60+
"url", hostname,
61+
"api_path", config.CommandAPIPath,
62+
"skip_verify", config.SkipTLSVerify,
63+
"ca_cert", config.CommandCertPath,
64+
).Debug("setting base Command configuration")
5265

5366
basicAuthConfig.WithCommandHostName(hostname).
5467
WithCommandAPIPath(config.CommandAPIPath).
5568
WithSkipVerify(config.SkipTLSVerify).
5669
WithCommandCACert(config.CommandCertPath)
70+
71+
b.Logger().With(
72+
"username",
73+
config.Username,
74+
"domain",
75+
config.Domain,
76+
"password",
77+
"(hidden)",
78+
).Debug("setting basic auth credentials")
5779
bErr := basicAuthConfig.
5880
WithUsername(config.Username).
5981
WithPassword(config.Password).
6082
WithDomain(config.Domain).
6183
Authenticate()
6284

6385
if bErr != nil {
64-
errMsg := fmt.Sprintf("[ERROR] unable to authenticate with provided basic auth credentials: %s", bErr.Error())
86+
errMsg := fmt.Sprintf(
87+
"[ERROR] unable to authenticate with provided basic auth credentials: %s",
88+
bErr.Error(),
89+
)
6590
b.Logger().Error(errMsg)
6691
return nil, bErr
6792
} else {
@@ -77,12 +102,24 @@ func newClient(config *keyfactorConfig, b *keyfactorBackend) (*keyfactorClient,
77102
}
78103

79104
} else if isOAuth {
80-
b.Logger().Debug(fmt.Sprintf("using oAuth authentication with client_id: %s, token_url %s and client_secret: (hidden)", config.ClientId, config.TokenUrl))
105+
b.Logger().With(
106+
"url", hostname,
107+
"api_path", config.CommandAPIPath,
108+
"skip_verify", config.SkipTLSVerify,
109+
"ca_cert", config.CommandCertPath,
110+
).Debug("setting base Command configuration")
81111
_ = oAuthConfig.WithCommandHostName(hostname).
82112
WithCommandAPIPath(config.CommandAPIPath).
83113
WithSkipVerify(config.SkipTLSVerify).
84114
WithCommandCACert(config.CommandCertPath)
85115

116+
b.Logger().Debug(
117+
fmt.Sprintf(
118+
"using oAuth authentication with client_id: %s, token_url %s and client_secret: (hidden)",
119+
config.ClientId,
120+
config.TokenUrl,
121+
),
122+
)
86123
oErr := oAuthConfig.
87124
WithClientId(config.ClientId).
88125
WithClientSecret(config.ClientSecret).

0 commit comments

Comments
 (0)