@@ -232,7 +232,9 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
232
232
false ,
233
233
fmt .Sprintf ("Turns on the %s mode. The flag --credentials-file must also be passed." , JetstackSecureOAuth ),
234
234
)
235
- c .PersistentFlags ().MarkHidden ("venafi-cloud" )
235
+ if err := c .PersistentFlags ().MarkHidden ("venafi-cloud" ); err != nil {
236
+ panic (err )
237
+ }
236
238
c .PersistentFlags ().StringVarP (
237
239
& cfg .ClientID ,
238
240
"client-id" ,
@@ -247,7 +249,7 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
247
249
"private-key-path" ,
248
250
"" ,
249
251
"" ,
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." ,
251
253
)
252
254
c .PersistentFlags ().BoolVarP (
253
255
& cfg .OneShot ,
@@ -334,7 +336,9 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
334
336
false ,
335
337
"Deprecated. No longer has an effect." ,
336
338
)
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
+ }
338
342
339
343
// This is a hidden feature flag we use to build the "Machine Hub" feature
340
344
// gradually without impacting customers. Once the feature is GA, we will
@@ -345,7 +349,9 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
345
349
false ,
346
350
"Enables the MachineHub mode. The agent will push data to CyberArk MachineHub." ,
347
351
)
348
- c .PersistentFlags ().MarkHidden ("machine-hub" )
352
+ if err := c .PersistentFlags ().MarkHidden ("machine-hub" ); err != nil {
353
+ panic (err )
354
+ }
349
355
350
356
}
351
357
@@ -531,8 +537,8 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
531
537
// Validation of `venafi-cloud.upload_path`.
532
538
{
533
539
var uploadPath string
534
- switch {
535
- case res . TLSPKMode == VenafiCloudKeypair :
540
+ switch res . TLSPKMode { // nolint:exhaustive
541
+ case VenafiCloudKeypair :
536
542
if cfg .VenafiCloud == nil || cfg .VenafiCloud .UploadPath == "" {
537
543
errs = multierror .Append (errs , fmt .Errorf ("the venafi-cloud.upload_path field is required when using the %s mode" , res .TLSPKMode ))
538
544
break // Skip to the end of the switch statement.
@@ -544,7 +550,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
544
550
}
545
551
546
552
uploadPath = cfg .VenafiCloud .UploadPath
547
- case res . TLSPKMode == VenafiCloudVenafiConnection :
553
+ case VenafiCloudVenafiConnection :
548
554
// The venafi-cloud.upload_path was initially meant to let users
549
555
// configure HTTP proxies, but it has never been used since HTTP
550
556
// 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)
577
583
if res .TLSPKMode != Off {
578
584
var clusterID string
579
585
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 :
582
588
if cfg .ClusterID == "" {
583
589
errs = multierror .Append (errs , fmt .Errorf ("cluster_id is required in %s mode" , res .TLSPKMode ))
584
590
}
585
591
clusterID = cfg .ClusterID
586
- case res . TLSPKMode == VenafiCloudVenafiConnection :
592
+ case VenafiCloudVenafiConnection :
587
593
if cfg .ClusterID == "" {
588
594
errs = multierror .Append (errs , fmt .Errorf ("cluster_id is required in %s mode" , res .TLSPKMode ))
589
595
}
590
596
clusterID = cfg .ClusterID
591
- case res . TLSPKMode == JetstackSecureOAuth || res . TLSPKMode == JetstackSecureAPIToken :
597
+ case JetstackSecureOAuth , JetstackSecureAPIToken :
592
598
if cfg .OrganizationID == "" {
593
599
errs = multierror .Append (errs , fmt .Errorf ("organization_id is required" ))
594
600
}
@@ -637,7 +643,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
637
643
}
638
644
639
645
// Validation of --install-namespace.
640
- var installNS string = flags .InstallNS
646
+ installNS : = flags .InstallNS
641
647
if flags .InstallNS == "" {
642
648
var err error
643
649
installNS , err = getInClusterNamespace ()
@@ -650,7 +656,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
650
656
// Validation of --venafi-connection and --venafi-connection-namespace.
651
657
if res .TLSPKMode == VenafiCloudVenafiConnection {
652
658
res .VenConnName = flags .VenConnName
653
- var venConnNS string = flags .VenConnNS
659
+ venConnNS : = flags .VenConnNS
654
660
if flags .VenConnNS == "" {
655
661
venConnNS = installNS
656
662
}
@@ -714,8 +720,8 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
714
720
715
721
var preflightClient client.Client
716
722
metadata := & api.AgentMetadata {Version : version .PreflightVersion , ClusterID : cfg .ClusterID }
717
- switch {
718
- case cfg . TLSPKMode == JetstackSecureOAuth :
723
+ switch cfg . TLSPKMode {
724
+ case JetstackSecureOAuth :
719
725
// Note that there are no command line flags to configure the
720
726
// JetstackSecureOAuth mode.
721
727
credsBytes , err := readCredentialsFile (flagCredentialsPath )
@@ -734,7 +740,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
734
740
if err != nil {
735
741
errs = multierror .Append (errs , err )
736
742
}
737
- case cfg . TLSPKMode == VenafiCloudKeypair :
743
+ case VenafiCloudKeypair :
738
744
var creds client.Credentials
739
745
740
746
if flagClientID != "" && flagCredentialsPath != "" {
@@ -750,14 +756,15 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
750
756
break
751
757
}
752
758
753
- if flagClientID != "" && flagPrivateKeyPath != "" {
759
+ switch {
760
+ case flagClientID != "" && flagPrivateKeyPath != "" :
754
761
// If --client-id and --private-key-path are passed, then
755
762
// --credentials-file is ignored.
756
763
creds = & client.VenafiSvcAccountCredentials {
757
764
ClientID : flagClientID ,
758
765
PrivateKeyFile : flagPrivateKeyPath ,
759
766
}
760
- } else if flagCredentialsPath != "" {
767
+ case flagCredentialsPath != "" :
761
768
credsBytes , err := readCredentialsFile (flagCredentialsPath )
762
769
if err != nil {
763
770
errs = multierror .Append (errs , multierror .Prefix (err , "credentials file:" ))
@@ -768,7 +775,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
768
775
errs = multierror .Append (errs , multierror .Prefix (err , "credentials file:" ))
769
776
break // Don't continue with the client since creds is invalid.
770
777
}
771
- } else {
778
+ default :
772
779
return nil , fmt .Errorf ("programmer mistake: --client-id and --private-key-path or --credentials-file must have been provided" )
773
780
}
774
781
@@ -777,7 +784,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
777
784
if err != nil {
778
785
errs = multierror .Append (errs , err )
779
786
}
780
- case cfg . TLSPKMode == VenafiCloudVenafiConnection :
787
+ case VenafiCloudVenafiConnection :
781
788
var restCfg * rest.Config
782
789
restCfg , err := kubeconfig .LoadRESTConfig ("" )
783
790
if err != nil {
@@ -789,13 +796,13 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
789
796
if err != nil {
790
797
errs = multierror .Append (errs , err )
791
798
}
792
- case cfg . TLSPKMode == JetstackSecureAPIToken :
799
+ case JetstackSecureAPIToken :
793
800
var err error
794
801
preflightClient , err = client .NewAPITokenClient (metadata , flagAPIToken , cfg .Server )
795
802
if err != nil {
796
803
errs = multierror .Append (errs , err )
797
804
}
798
- case cfg . TLSPKMode == Off :
805
+ case Off :
799
806
// No client needed in this mode.
800
807
default :
801
808
panic (fmt .Errorf ("programmer mistake: auth mode not implemented: %s" , cfg .TLSPKMode ))
0 commit comments