@@ -232,7 +232,9 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
232232 false ,
233233 fmt .Sprintf ("Turns on the %s mode. The flag --credentials-file must also be passed." , JetstackSecureOAuth ),
234234 )
235- c .PersistentFlags ().MarkHidden ("venafi-cloud" )
235+ if err := c .PersistentFlags ().MarkHidden ("venafi-cloud" ); err != nil {
236+ panic (err )
237+ }
236238 c .PersistentFlags ().StringVarP (
237239 & cfg .ClientID ,
238240 "client-id" ,
@@ -247,7 +249,7 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
247249 "private-key-path" ,
248250 "" ,
249251 "" ,
250- fmt . Sprintf ( "To be used in conjunction with --client-id. The path to the private key file for the service account." ) ,
252+ "To be used in conjunction with --client-id. The path to the private key file for the service account." ,
251253 )
252254 c .PersistentFlags ().BoolVarP (
253255 & cfg .OneShot ,
@@ -334,7 +336,9 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
334336 false ,
335337 "Deprecated. No longer has an effect." ,
336338 )
337- c .PersistentFlags ().MarkDeprecated ("disable-compression" , "no longer has an effect" )
339+ if err := c .PersistentFlags ().MarkDeprecated ("disable-compression" , "no longer has an effect" ); err != nil {
340+ panic (err )
341+ }
338342
339343 // This is a hidden feature flag we use to build the "Machine Hub" feature
340344 // gradually without impacting customers. Once the feature is GA, we will
@@ -345,7 +349,9 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
345349 false ,
346350 "Enables the MachineHub mode. The agent will push data to CyberArk MachineHub." ,
347351 )
348- c .PersistentFlags ().MarkHidden ("machine-hub" )
352+ if err := c .PersistentFlags ().MarkHidden ("machine-hub" ); err != nil {
353+ panic (err )
354+ }
349355
350356}
351357
@@ -531,8 +537,8 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
531537 // Validation of `venafi-cloud.upload_path`.
532538 {
533539 var uploadPath string
534- switch {
535- case res . TLSPKMode == VenafiCloudKeypair :
540+ switch res . TLSPKMode { // nolint:exhaustive
541+ case VenafiCloudKeypair :
536542 if cfg .VenafiCloud == nil || cfg .VenafiCloud .UploadPath == "" {
537543 errs = multierror .Append (errs , fmt .Errorf ("the venafi-cloud.upload_path field is required when using the %s mode" , res .TLSPKMode ))
538544 break // Skip to the end of the switch statement.
@@ -544,7 +550,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
544550 }
545551
546552 uploadPath = cfg .VenafiCloud .UploadPath
547- case res . TLSPKMode == VenafiCloudVenafiConnection :
553+ case VenafiCloudVenafiConnection :
548554 // The venafi-cloud.upload_path was initially meant to let users
549555 // configure HTTP proxies, but it has never been used since HTTP
550556 // proxies don't rewrite paths. Thus, we've disabled the ability to
@@ -577,18 +583,18 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
577583 if res .TLSPKMode != Off {
578584 var clusterID string
579585 var organizationID string // Only used by the old jetstack-secure mode.
580- switch {
581- case res . TLSPKMode == VenafiCloudKeypair :
586+ switch res . TLSPKMode { // nolint:exhaustive
587+ case VenafiCloudKeypair :
582588 if cfg .ClusterID == "" {
583589 errs = multierror .Append (errs , fmt .Errorf ("cluster_id is required in %s mode" , res .TLSPKMode ))
584590 }
585591 clusterID = cfg .ClusterID
586- case res . TLSPKMode == VenafiCloudVenafiConnection :
592+ case VenafiCloudVenafiConnection :
587593 if cfg .ClusterID == "" {
588594 errs = multierror .Append (errs , fmt .Errorf ("cluster_id is required in %s mode" , res .TLSPKMode ))
589595 }
590596 clusterID = cfg .ClusterID
591- case res . TLSPKMode == JetstackSecureOAuth || res . TLSPKMode == JetstackSecureAPIToken :
597+ case JetstackSecureOAuth , JetstackSecureAPIToken :
592598 if cfg .OrganizationID == "" {
593599 errs = multierror .Append (errs , fmt .Errorf ("organization_id is required" ))
594600 }
@@ -637,7 +643,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
637643 }
638644
639645 // Validation of --install-namespace.
640- var installNS string = flags .InstallNS
646+ installNS : = flags .InstallNS
641647 if flags .InstallNS == "" {
642648 var err error
643649 installNS , err = getInClusterNamespace ()
@@ -650,7 +656,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
650656 // Validation of --venafi-connection and --venafi-connection-namespace.
651657 if res .TLSPKMode == VenafiCloudVenafiConnection {
652658 res .VenConnName = flags .VenConnName
653- var venConnNS string = flags .VenConnNS
659+ venConnNS : = flags .VenConnNS
654660 if flags .VenConnNS == "" {
655661 venConnNS = installNS
656662 }
@@ -714,8 +720,8 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
714720
715721 var preflightClient client.Client
716722 metadata := & api.AgentMetadata {Version : version .PreflightVersion , ClusterID : cfg .ClusterID }
717- switch {
718- case cfg . TLSPKMode == JetstackSecureOAuth :
723+ switch cfg . TLSPKMode {
724+ case JetstackSecureOAuth :
719725 // Note that there are no command line flags to configure the
720726 // JetstackSecureOAuth mode.
721727 credsBytes , err := readCredentialsFile (flagCredentialsPath )
@@ -734,7 +740,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
734740 if err != nil {
735741 errs = multierror .Append (errs , err )
736742 }
737- case cfg . TLSPKMode == VenafiCloudKeypair :
743+ case VenafiCloudKeypair :
738744 var creds client.Credentials
739745
740746 if flagClientID != "" && flagCredentialsPath != "" {
@@ -750,14 +756,15 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
750756 break
751757 }
752758
753- if flagClientID != "" && flagPrivateKeyPath != "" {
759+ switch {
760+ case flagClientID != "" && flagPrivateKeyPath != "" :
754761 // If --client-id and --private-key-path are passed, then
755762 // --credentials-file is ignored.
756763 creds = & client.VenafiSvcAccountCredentials {
757764 ClientID : flagClientID ,
758765 PrivateKeyFile : flagPrivateKeyPath ,
759766 }
760- } else if flagCredentialsPath != "" {
767+ case flagCredentialsPath != "" :
761768 credsBytes , err := readCredentialsFile (flagCredentialsPath )
762769 if err != nil {
763770 errs = multierror .Append (errs , multierror .Prefix (err , "credentials file:" ))
@@ -768,7 +775,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
768775 errs = multierror .Append (errs , multierror .Prefix (err , "credentials file:" ))
769776 break // Don't continue with the client since creds is invalid.
770777 }
771- } else {
778+ default :
772779 return nil , fmt .Errorf ("programmer mistake: --client-id and --private-key-path or --credentials-file must have been provided" )
773780 }
774781
@@ -777,7 +784,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
777784 if err != nil {
778785 errs = multierror .Append (errs , err )
779786 }
780- case cfg . TLSPKMode == VenafiCloudVenafiConnection :
787+ case VenafiCloudVenafiConnection :
781788 var restCfg * rest.Config
782789 restCfg , err := kubeconfig .LoadRESTConfig ("" )
783790 if err != nil {
@@ -789,13 +796,13 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
789796 if err != nil {
790797 errs = multierror .Append (errs , err )
791798 }
792- case cfg . TLSPKMode == JetstackSecureAPIToken :
799+ case JetstackSecureAPIToken :
793800 var err error
794801 preflightClient , err = client .NewAPITokenClient (metadata , flagAPIToken , cfg .Server )
795802 if err != nil {
796803 errs = multierror .Append (errs , err )
797804 }
798- case cfg . TLSPKMode == Off :
805+ case Off :
799806 // No client needed in this mode.
800807 default :
801808 panic (fmt .Errorf ("programmer mistake: auth mode not implemented: %s" , cfg .TLSPKMode ))
0 commit comments