@@ -17,7 +17,6 @@ package cmd
1717import (
1818 _ "embed"
1919 "fmt"
20- "io"
2120 stdlog "log"
2221 "os"
2322 "strings"
@@ -135,6 +134,13 @@ func getServerConfigFromEnv() (*auth_providers.Server, error) {
135134 apiPath , aOk := os .LookupEnv (auth_providers .EnvKeyfactorAPIPath )
136135 clientId , cOk := os .LookupEnv (auth_providers .EnvKeyfactorClientID )
137136 clientSecret , csOk := os .LookupEnv (auth_providers .EnvKeyfactorClientSecret )
137+ audience , _ := os .LookupEnv (auth_providers .EnvKeyfactorAuthAudience )
138+ scopesCSV , _ := os .LookupEnv (auth_providers .EnvKeyfactorAuthScopes )
139+ var scopes []string
140+ if scopesCSV != "" {
141+ scopes = strings .Split (scopesCSV , "," )
142+ }
143+
138144 tokenUrl , tOk := os .LookupEnv (auth_providers .EnvKeyfactorAuthTokenURL )
139145 skipVerify , svOk := os .LookupEnv (auth_providers .EnvKeyfactorSkipVerify )
140146 var skipVerifyBool bool
@@ -161,24 +167,44 @@ func getServerConfigFromEnv() (*auth_providers.Server, error) {
161167 }
162168
163169 if isBasicAuth {
164- log .Debug ().
165- Str ("username" , username ).
166- Str ("password" , hashSecretValue (password )).
167- Str ("domain" , domain ).
168- Str ("hostname" , hostname ).
170+
171+ log .Debug ().Str ("hostname" , hostname ).
169172 Str ("apiPath" , apiPath ).
170173 Bool ("skipVerify" , skipVerifyBool ).
171- Msg ("call: basicAuthNoParamsConfig.Authenticate() " )
174+ Msg ("setting up basic auth client base configuration " )
172175 basicAuthNoParamsConfig .WithCommandHostName (hostname ).
173176 WithCommandAPIPath (apiPath ).
174177 WithSkipVerify (skipVerifyBool )
175178
176- bErr := basicAuthNoParamsConfig .
179+ log .Debug ().
180+ Str ("username" , username ).
181+ Str ("password" , hashSecretValue (password )).
182+ Str ("domain" , domain ).
183+ Msg ("setting up basic auth configuration" )
184+ _ = basicAuthNoParamsConfig .
177185 WithUsername (username ).
178186 WithPassword (password ).
179- WithDomain (domain ).
180- Authenticate ()
181- log .Debug ().Msg ("complete: basicAuthNoParamsConfig.Authenticate()" )
187+ WithDomain (domain )
188+
189+ log .Debug ().
190+ Str ("username" , basicAuthNoParamsConfig .Username ).
191+ Str ("password" , hashSecretValue (password )).
192+ Str ("domain" , basicAuthNoParamsConfig .Domain ).
193+ Str ("hostname" , basicAuthNoParamsConfig .CommandHostName ).
194+ Str ("apiPath" , basicAuthNoParamsConfig .CommandAPIPath ).
195+ Bool ("skipVerify" , basicAuthNoParamsConfig .CommandAuthConfig .SkipVerify ).
196+ Msg (fmt .Sprintf ("%s basicAuthNoParamsConfig.Authenticate()" , DebugFuncCall ))
197+
198+ bErr := basicAuthNoParamsConfig .Authenticate ()
199+ log .Debug ().
200+ Str ("username" , basicAuthNoParamsConfig .Username ).
201+ Str ("password" , hashSecretValue (password )).
202+ Str ("domain" , basicAuthNoParamsConfig .Domain ).
203+ Str ("hostname" , basicAuthNoParamsConfig .CommandHostName ).
204+ Str ("apiPath" , basicAuthNoParamsConfig .CommandAPIPath ).
205+ Bool ("skipVerify" , basicAuthNoParamsConfig .CommandAuthConfig .SkipVerify ).
206+ Msg ("complete: basicAuthNoParamsConfig.Authenticate()" )
207+
182208 if bErr != nil {
183209 log .Error ().Err (bErr ).Msg ("unable to authenticate with provided credentials" )
184210 return nil , bErr
@@ -187,16 +213,36 @@ func getServerConfigFromEnv() (*auth_providers.Server, error) {
187213 return basicAuthNoParamsConfig .GetServerConfig (), nil
188214 } else if isOAuth {
189215 log .Debug ().
190- Str ("clientId" , clientId ).
191- Str ("clientSecret" , hashSecretValue (clientSecret )).
192- Str ("tokenUrl" , tokenUrl ).
193216 Str ("hostname" , hostname ).
194217 Str ("apiPath" , apiPath ).
195218 Bool ("skipVerify" , skipVerifyBool ).
196- Msg ("call: oAuthNoParamsConfig.Authenticate() " )
219+ Msg ("setting up oAuth client base configuration " )
197220 _ = oAuthNoParamsConfig .CommandAuthConfig .WithCommandHostName (hostname ).
198221 WithCommandAPIPath (apiPath ).
199222 WithSkipVerify (skipVerifyBool )
223+
224+ log .Debug ().
225+ Str ("clientId" , clientId ).
226+ Str ("clientSecret" , hashSecretValue (clientSecret )).
227+ Str ("tokenUrl" , tokenUrl ).
228+ Str ("audience" , audience ).
229+ Strs ("scopes" , scopes ).
230+ Msg ("setting up oAuth configuration" )
231+ _ = oAuthNoParamsConfig .WithClientId (clientId ).
232+ WithClientSecret (clientSecret ).
233+ WithTokenUrl (tokenUrl ).
234+ WithAudience (audience ).
235+ WithScopes (scopes )
236+
237+ log .Debug ().
238+ Str ("clientId" , oAuthNoParamsConfig .ClientID ).
239+ Str ("clientSecret" , hashSecretValue (oAuthNoParamsConfig .ClientSecret )).
240+ Str ("tokenUrl" , oAuthNoParamsConfig .TokenURL ).
241+ Str ("hostname" , oAuthNoParamsConfig .CommandHostName ).
242+ Str ("apiPath" , oAuthNoParamsConfig .CommandAPIPath ).
243+ Bool ("skipVerify" , oAuthNoParamsConfig .SkipVerify ).
244+ Str ("caCert" , oAuthNoParamsConfig .CommandCACert ).
245+ Msg (fmt .Sprintf ("%s oAuthNoParamsConfig.Authenticate()" , DebugFuncCall ))
200246 oErr := oAuthNoParamsConfig .Authenticate ()
201247 log .Debug ().Msg ("complete: oAuthNoParamsConfig.Authenticate()" )
202248 if oErr != nil {
@@ -738,7 +784,7 @@ var RootCmd = &cobra.Command{
738784// Execute adds all child commands to the root command and sets flags appropriately.
739785// This is called by main.main(). It only needs to happen once to the rootCmd.
740786func Execute () {
741- stdlog .SetOutput (io .Discard )
787+ // stdlog.SetOutput(io.Discard)
742788 err := RootCmd .Execute ()
743789 if err != nil {
744790 os .Exit (1 )
@@ -881,3 +927,9 @@ func init() {
881927
882928 RootCmd .AddCommand (makeDocsCmd )
883929}
930+
931+ func initStdLogger () {
932+ // Redirect standard library's log to zerolog
933+ stdlog .SetOutput (zerologWriter {})
934+ stdlog .SetFlags (0 ) // Remove timestamp from standard logger
935+ }
0 commit comments