@@ -3,11 +3,11 @@ package agent
33import (
44 "fmt"
55 "io"
6- "log"
76 "net/url"
87 "os"
98 "time"
109
10+ "github.com/go-logr/logr"
1111 "github.com/hashicorp/go-multierror"
1212 "github.com/pkg/errors"
1313 "github.com/spf13/cobra"
@@ -355,7 +355,8 @@ type CombinedConfig struct {
355355// The error returned may be a multierror.Error. Use multierror.Prefix(err,
356356// "context:") rather than fmt.Errorf("context: %w", err) when wrapping the
357357// error.
358- func ValidateAndCombineConfig (log * log.Logger , cfg Config , flags AgentCmdFlags ) (CombinedConfig , client.Client , error ) {
358+ func ValidateAndCombineConfig (log logr.Logger , cfg Config , flags AgentCmdFlags ) (CombinedConfig , client.Client , error ) {
359+
359360 res := CombinedConfig {}
360361 var errs error
361362
@@ -364,23 +365,23 @@ func ValidateAndCombineConfig(log *log.Logger, cfg Config, flags AgentCmdFlags)
364365 switch {
365366 case flags .VenafiCloudMode && flags .CredentialsPath != "" :
366367 mode = VenafiCloudKeypair
367- log .Printf ( "Using the %s auth mode since --venafi-cloud and --credentials-path were specified." , mode )
368+ log .Info ( fmt . Sprintf ( "Using the %s auth mode since --venafi-cloud and --credentials-path were specified." , mode ) )
368369 case flags .ClientID != "" && flags .PrivateKeyPath != "" :
369370 mode = VenafiCloudKeypair
370- log .Printf ( "Using the %s auth mode since --client-id and --private-key-path were specified." , mode )
371+ log .Info ( fmt . Sprintf ( "Using the %s auth mode since --client-id and --private-key-path were specified." , mode ) )
371372 case flags .ClientID != "" :
372373 return CombinedConfig {}, nil , fmt .Errorf ("if --client-id is specified, --private-key-path must also be specified" )
373374 case flags .PrivateKeyPath != "" :
374375 return CombinedConfig {}, nil , fmt .Errorf ("--private-key-path is specified, --client-id must also be specified" )
375376 case flags .VenConnName != "" :
376377 mode = VenafiCloudVenafiConnection
377- log .Printf ( "Using the %s auth mode since --venafi-connection was specified." , mode )
378+ log .Info ( fmt . Sprintf ( "Using the %s auth mode since --venafi-connection was specified." , mode ) )
378379 case flags .APIToken != "" :
379380 mode = JetstackSecureAPIToken
380- log .Printf ( "Using the %s auth mode since --api-token was specified." , mode )
381+ log .Info ( fmt . Sprintf ( "Using the %s auth mode since --api-token was specified." , mode ) )
381382 case ! flags .VenafiCloudMode && flags .CredentialsPath != "" :
382383 mode = JetstackSecureOAuth
383- log .Printf ( "Using the %s auth mode since --credentials-file was specified without --venafi-cloud." , mode )
384+ log .Info ( fmt . Sprintf ( "Using the %s auth mode since --credentials-file was specified without --venafi-cloud." , mode ) )
384385 default :
385386 return CombinedConfig {}, nil , fmt .Errorf ("no auth mode specified. You can use one of four auth modes:\n " +
386387 " - Use (--venafi-cloud with --credentials-file) or (--client-id with --private-key-path) to use the " + string (VenafiCloudKeypair ) + " mode.\n " +
@@ -403,10 +404,10 @@ func ValidateAndCombineConfig(log *log.Logger, cfg Config, flags AgentCmdFlags)
403404 case hasServerField && hasEndpointField :
404405 // The `server` field takes precedence over the deprecated
405406 // `endpoint` field.
406- log .Printf ("The `server` and `endpoint` fields are both set in the config; using the `server` field." )
407+ log .Info ("The `server` and `endpoint` fields are both set in the config; using the `server` field." )
407408 server = cfg .Server
408409 case ! hasServerField && hasEndpointField :
409- log .Printf ("Using deprecated Endpoint configuration. User Server instead." )
410+ log .Info ("Using deprecated Endpoint configuration. User Server instead." )
410411 if cfg .Endpoint .Protocol == "" && cfg .Server == "" {
411412 cfg .Endpoint .Protocol = "http"
412413 }
@@ -424,7 +425,7 @@ func ValidateAndCombineConfig(log *log.Logger, cfg Config, flags AgentCmdFlags)
424425 errs = multierror .Append (errs , fmt .Errorf ("server %q is not a valid URL" , server ))
425426 }
426427 if res .AuthMode == VenafiCloudVenafiConnection && server != "" {
427- log .Printf ( "ignoring the server field specified in the config file. In %s mode, this field is not needed." , VenafiCloudVenafiConnection )
428+ log .Info ( fmt . Sprintf ( "Ignoring the server field specified in the config file. In %s mode, this field is not needed." , VenafiCloudVenafiConnection ) )
428429 server = ""
429430 }
430431 res .Server = server
@@ -454,7 +455,7 @@ func ValidateAndCombineConfig(log *log.Logger, cfg Config, flags AgentCmdFlags)
454455 // change this value with the new --venafi-connection flag, and this
455456 // field is simply ignored.
456457 if cfg .VenafiCloud != nil && cfg .VenafiCloud .UploadPath != "" {
457- log .Printf ( `ignoring the venafi-cloud.upload_path field in the config file. In %s mode, this field is not needed.` , res .AuthMode )
458+ log .Info ( fmt . Sprintf ( `Ignoring the venafi-cloud.upload_path field in the config file. In %s mode, this field is not needed.` , res .AuthMode ) )
458459 }
459460 uploadPath = ""
460461 }
@@ -472,7 +473,7 @@ func ValidateAndCombineConfig(log *log.Logger, cfg Config, flags AgentCmdFlags)
472473 // https://venafi.atlassian.net/browse/VC-35385 is done.
473474 {
474475 if cfg .VenafiCloud != nil && cfg .VenafiCloud .UploaderID != "" {
475- log .Printf ( `ignoring the venafi-cloud.uploader_id field in the config file. This field is not needed in %s mode.` , res .AuthMode )
476+ log .Info ( fmt . Sprintf ( `Ignoring the venafi-cloud.uploader_id field in the config file. This field is not needed in %s mode.` , res .AuthMode ) )
476477 }
477478 }
478479
@@ -524,13 +525,13 @@ func ValidateAndCombineConfig(log *log.Logger, cfg Config, flags AgentCmdFlags)
524525 case flags .Period == 0 && cfg .Period == 0 :
525526 errs = multierror .Append (errs , fmt .Errorf ("period must be set using --period or -p, or using the 'period' field in the config file" ))
526527 case flags .Period == 0 && cfg .Period > 0 :
527- log .Printf ("Using period from config %s " , cfg .Period )
528+ log .Info ("Using period from config" , "period " , cfg .Period )
528529 period = cfg .Period
529530 case flags .Period > 0 && cfg .Period == 0 :
530531 period = flags .Period
531532 case flags .Period > 0 && cfg .Period > 0 :
532533 // The flag takes precedence.
533- log .Printf ("Both the 'period' field and --period are set. Using the value provided with --period." )
534+ log .Info ("Both the 'period' field and --period are set. Using the value provided with --period." )
534535 period = flags .Period
535536 }
536537 res .Period = period
@@ -599,7 +600,7 @@ func ValidateAndCombineConfig(log *log.Logger, cfg Config, flags AgentCmdFlags)
599600// The error returned may be a multierror.Error. Use multierror.Prefix(err,
600601// "context:") rather than fmt.Errorf("context: %w", err) when wrapping the
601602// error.
602- func validateCredsAndCreateClient (log * log .Logger , flagCredentialsPath , flagClientID , flagPrivateKeyPath , flagAPIToken string , cfg CombinedConfig ) (client.Client , error ) {
603+ func validateCredsAndCreateClient (log logr .Logger , flagCredentialsPath , flagClientID , flagPrivateKeyPath , flagAPIToken string , cfg CombinedConfig ) (client.Client , error ) {
603604 var errs error
604605
605606 var preflightClient client.Client
@@ -719,7 +720,7 @@ func ValidateDataGatherers(dataGatherers []DataGatherer) error {
719720
720721// The error returned may be a multierror.Error. Instead of adding context to
721722// the error with fmt.Errorf("%w", err), use multierror.Prefix(err, "context").
722- func createCredentialClient (log * log .Logger , credentials client.Credentials , cfg CombinedConfig , agentMetadata * api.AgentMetadata ) (client.Client , error ) {
723+ func createCredentialClient (log logr .Logger , credentials client.Credentials , cfg CombinedConfig , agentMetadata * api.AgentMetadata ) (client.Client , error ) {
723724 switch creds := credentials .(type ) {
724725 case * client.VenafiSvcAccountCredentials :
725726 // The uploader ID isn't actually used in the backend, let's use an
@@ -730,7 +731,7 @@ func createCredentialClient(log *log.Logger, credentials client.Credentials, cfg
730731 if cfg .AuthMode == VenafiCloudKeypair {
731732 // We don't do this for the VenafiCloudVenafiConnection mode because
732733 // the upload_path field is ignored in that mode.
733- log .Println ("Loading upload_path from \" venafi-cloud\" configuration." )
734+ log .Info ("Loading upload_path from \" venafi-cloud\" configuration." )
734735 uploadPath = cfg .UploadPath
735736 }
736737 return client .NewVenafiCloudClient (agentMetadata , creds , cfg .Server , uploaderID , uploadPath , cfg .DisableCompression )
0 commit comments