@@ -324,15 +324,16 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
324
324
325
325
}
326
326
327
- // TLSPKMode controls how to authenticate to TLSPK / Jetstack Secure. Only one
328
- // TLSPKMode may be provided if using those backends .
329
- type TLSPKMode string
327
+ // OutputMode controls how the collected data is published.
328
+ // Only one OutputMode may be provided.
329
+ type OutputMode string
330
330
331
331
const (
332
- JetstackSecureOAuth TLSPKMode = "Jetstack Secure OAuth"
333
- JetstackSecureAPIToken TLSPKMode = "Jetstack Secure API Token"
334
- VenafiCloudKeypair TLSPKMode = "Venafi Cloud Key Pair Service Account"
335
- VenafiCloudVenafiConnection TLSPKMode = "Venafi Cloud VenafiConnection"
332
+ JetstackSecureOAuth OutputMode = "Jetstack Secure OAuth"
333
+ JetstackSecureAPIToken OutputMode = "Jetstack Secure API Token"
334
+ VenafiCloudKeypair OutputMode = "Venafi Cloud Key Pair Service Account"
335
+ VenafiCloudVenafiConnection OutputMode = "Venafi Cloud VenafiConnection"
336
+ LocalFile OutputMode = "Local File"
336
337
)
337
338
338
339
// The command-line flags and the config file are combined into this struct by
@@ -345,7 +346,7 @@ type CombinedConfig struct {
345
346
StrictMode bool
346
347
OneShot bool
347
348
348
- TLSPKMode TLSPKMode
349
+ OutputMode OutputMode
349
350
350
351
// Used by all TLSPK modes.
351
352
ClusterID string
@@ -389,7 +390,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
389
390
390
391
{
391
392
var (
392
- mode TLSPKMode
393
+ mode OutputMode
393
394
reason string
394
395
keysAndValues []any
395
396
)
@@ -419,18 +420,22 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
419
420
case ! flags .VenafiCloudMode && flags .CredentialsPath != "" :
420
421
mode = JetstackSecureOAuth
421
422
reason = "--credentials-file was specified without --venafi-cloud"
423
+ case flags .OutputPath != "" :
424
+ mode = LocalFile
425
+ reason = "--output-path was specified"
422
426
default :
423
- return CombinedConfig {}, nil , fmt .Errorf ("no TLSPK mode specified. " +
424
- "To enable one of the TLSPK modes, you can:\n " +
427
+ return CombinedConfig {}, nil , fmt .Errorf ("no output mode specified. " +
428
+ "To enable one of the output modes, you can:\n " +
425
429
" - Use (--venafi-cloud with --credentials-file) or (--client-id with --private-key-path) to use the " + string (VenafiCloudKeypair ) + " mode.\n " +
426
430
" - Use --venafi-connection for the " + string (VenafiCloudVenafiConnection ) + " mode.\n " +
427
431
" - Use --credentials-file alone if you want to use the " + string (JetstackSecureOAuth ) + " mode.\n " +
428
- " - Use --api-token if you want to use the " + string (JetstackSecureAPIToken ) + " mode." )
432
+ " - Use --api-token if you want to use the " + string (JetstackSecureAPIToken ) + " mode.\n " +
433
+ " - Use --output-path for " + string (LocalFile ) + " mode." )
429
434
}
430
435
431
436
keysAndValues = append (keysAndValues , "mode" , mode , "reason" , reason )
432
- log .V (logs .Debug ).Info ("Configured to push to Venafi " , keysAndValues ... )
433
- res .TLSPKMode = mode
437
+ log .V (logs .Debug ).Info ("Output mode selected " , keysAndValues ... )
438
+ res .OutputMode = mode
434
439
}
435
440
436
441
var errs error
@@ -459,7 +464,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
459
464
endpointPath = cfg .Endpoint .Path
460
465
case ! hasServerField && ! hasEndpointField :
461
466
server = "https://preflight.jetstack.io"
462
- if res .TLSPKMode == VenafiCloudKeypair {
467
+ if res .OutputMode == VenafiCloudKeypair {
463
468
// The VenafiCloudVenafiConnection mode doesn't need a server.
464
469
server = client .VenafiCloudProdURL
465
470
}
@@ -468,7 +473,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
468
473
if urlErr != nil || url .Hostname () == "" {
469
474
errs = multierror .Append (errs , fmt .Errorf ("server %q is not a valid URL" , server ))
470
475
}
471
- if res .TLSPKMode == VenafiCloudVenafiConnection && server != "" {
476
+ if res .OutputMode == VenafiCloudVenafiConnection && server != "" {
472
477
log .Info (fmt .Sprintf ("ignoring the server field specified in the config file. In %s mode, this field is not needed." , VenafiCloudVenafiConnection ))
473
478
server = ""
474
479
}
@@ -479,10 +484,10 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
479
484
// Validation of `venafi-cloud.upload_path`.
480
485
{
481
486
var uploadPath string
482
- switch res .TLSPKMode { // nolint:exhaustive
487
+ switch res .OutputMode { // nolint:exhaustive
483
488
case VenafiCloudKeypair :
484
489
if cfg .VenafiCloud == nil || cfg .VenafiCloud .UploadPath == "" {
485
- errs = multierror .Append (errs , fmt .Errorf ("the venafi-cloud.upload_path field is required when using the %s mode" , res .TLSPKMode ))
490
+ errs = multierror .Append (errs , fmt .Errorf ("the venafi-cloud.upload_path field is required when using the %s mode" , res .OutputMode ))
486
491
break // Skip to the end of the switch statement.
487
492
}
488
493
_ , urlErr := url .Parse (cfg .VenafiCloud .UploadPath )
@@ -499,7 +504,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
499
504
// change this value with the new --venafi-connection flag, and this
500
505
// field is simply ignored.
501
506
if cfg .VenafiCloud != nil && cfg .VenafiCloud .UploadPath != "" {
502
- log .Info (fmt .Sprintf (`ignoring the venafi-cloud.upload_path field in the config file. In %s mode, this field is not needed.` , res .TLSPKMode ))
507
+ log .Info (fmt .Sprintf (`ignoring the venafi-cloud.upload_path field in the config file. In %s mode, this field is not needed.` , res .OutputMode ))
503
508
}
504
509
uploadPath = ""
505
510
}
@@ -517,18 +522,18 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
517
522
// https://venafi.atlassian.net/browse/VC-35385 is done.
518
523
{
519
524
if cfg .VenafiCloud != nil && cfg .VenafiCloud .UploaderID != "" {
520
- log .Info (fmt .Sprintf (`ignoring the venafi-cloud.uploader_id field in the config file. This field is not needed in %s mode.` , res .TLSPKMode ))
525
+ log .Info (fmt .Sprintf (`ignoring the venafi-cloud.uploader_id field in the config file. This field is not needed in %s mode.` , res .OutputMode ))
521
526
}
522
527
}
523
528
524
529
// Validation of `cluster_id` and `organization_id`.
525
530
{
526
531
var clusterID string
527
532
var organizationID string // Only used by the old jetstack-secure mode.
528
- switch res .TLSPKMode { // nolint:exhaustive
533
+ switch res .OutputMode { // nolint:exhaustive
529
534
case VenafiCloudKeypair , VenafiCloudVenafiConnection :
530
535
if cfg .ClusterID == "" {
531
- errs = multierror .Append (errs , fmt .Errorf ("cluster_id is required in %s mode" , res .TLSPKMode ))
536
+ errs = multierror .Append (errs , fmt .Errorf ("cluster_id is required in %s mode" , res .OutputMode ))
532
537
}
533
538
clusterID = cfg .ClusterID
534
539
case JetstackSecureOAuth , JetstackSecureAPIToken :
@@ -592,7 +597,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
592
597
res .InstallNS = installNS
593
598
594
599
// Validation of --venafi-connection and --venafi-connection-namespace.
595
- if res .TLSPKMode == VenafiCloudVenafiConnection {
600
+ if res .OutputMode == VenafiCloudVenafiConnection {
596
601
res .VenConnName = flags .VenConnName
597
602
venConnNS := flags .VenConnNS
598
603
if flags .VenConnNS == "" {
@@ -639,12 +644,12 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
639
644
return CombinedConfig {}, nil , errs
640
645
}
641
646
642
- preflightClient , err := validateCredsAndCreateClient (log , flags .CredentialsPath , flags .ClientID , flags .PrivateKeyPath , flags .APIToken , res )
647
+ outputClient , err := validateCredsAndCreateClient (log , flags .CredentialsPath , flags .ClientID , flags .PrivateKeyPath , flags .APIToken , res )
643
648
if err != nil {
644
649
return CombinedConfig {}, nil , multierror .Prefix (err , "validating creds:" )
645
650
}
646
651
647
- return res , preflightClient , nil
652
+ return res , outputClient , nil
648
653
}
649
654
650
655
// Validation of --credentials-file/-k, --client-id, and --private-key-path,
@@ -656,9 +661,9 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
656
661
func validateCredsAndCreateClient (log logr.Logger , flagCredentialsPath , flagClientID , flagPrivateKeyPath , flagAPIToken string , cfg CombinedConfig ) (client.Client , error ) {
657
662
var errs error
658
663
659
- var preflightClient client.Client
664
+ var outputClient client.Client
660
665
metadata := & api.AgentMetadata {Version : version .PreflightVersion , ClusterID : cfg .ClusterID }
661
- switch cfg .TLSPKMode {
666
+ switch cfg .OutputMode {
662
667
case JetstackSecureOAuth :
663
668
// Note that there are no command line flags to configure the
664
669
// JetstackSecureOAuth mode.
@@ -674,7 +679,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
674
679
break // Don't continue with the client if credentials file invalid.
675
680
}
676
681
677
- preflightClient , err = client .NewOAuthClient (metadata , creds , cfg .Server )
682
+ outputClient , err = client .NewOAuthClient (metadata , creds , cfg .Server )
678
683
if err != nil {
679
684
errs = multierror .Append (errs , err )
680
685
}
@@ -726,7 +731,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
726
731
log .Info ("Loading upload_path from \" venafi-cloud\" configuration." )
727
732
728
733
var err error
729
- preflightClient , err = client .NewVenafiCloudClient (metadata , creds , cfg .Server , uploaderID , cfg .UploadPath )
734
+ outputClient , err = client .NewVenafiCloudClient (metadata , creds , cfg .Server , uploaderID , cfg .UploadPath )
730
735
if err != nil {
731
736
errs = multierror .Append (errs , err )
732
737
}
@@ -738,25 +743,27 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
738
743
break // Don't continue with the client if kubeconfig wasn't loaded.
739
744
}
740
745
741
- preflightClient , err = client .NewVenConnClient (restCfg , metadata , cfg .InstallNS , cfg .VenConnName , cfg .VenConnNS , nil )
746
+ outputClient , err = client .NewVenConnClient (restCfg , metadata , cfg .InstallNS , cfg .VenConnName , cfg .VenConnNS , nil )
742
747
if err != nil {
743
748
errs = multierror .Append (errs , err )
744
749
}
745
750
case JetstackSecureAPIToken :
746
751
var err error
747
- preflightClient , err = client .NewAPITokenClient (metadata , flagAPIToken , cfg .Server )
752
+ outputClient , err = client .NewAPITokenClient (metadata , flagAPIToken , cfg .Server )
748
753
if err != nil {
749
754
errs = multierror .Append (errs , err )
750
755
}
756
+ case LocalFile :
757
+ outputClient = client .NewFileClient (cfg .OutputPath )
751
758
default :
752
- panic (fmt .Errorf ("programmer mistake: auth mode not implemented: %s" , cfg .TLSPKMode ))
759
+ panic (fmt .Errorf ("programmer mistake: output mode not implemented: %s" , cfg .OutputMode ))
753
760
}
754
761
755
762
if errs != nil {
756
- return nil , fmt .Errorf ("failed loading config using the %s mode: %w" , cfg .TLSPKMode , errs )
763
+ return nil , fmt .Errorf ("failed loading config using the %s mode: %w" , cfg .OutputMode , errs )
757
764
}
758
765
759
- return preflightClient , nil
766
+ return outputClient , nil
760
767
}
761
768
762
769
// Same as ValidateAndCombineConfig but just for validating the data gatherers.
0 commit comments