@@ -355,19 +355,17 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
355
355
356
356
}
357
357
358
- // TLSPKMode controls how to authenticate to TLSPK / Jetstack Secure. Only one
359
- // TLSPKMode may be provided if using those backends .
360
- type TLSPKMode string
358
+ // OutputMode controls how the collected data is published.
359
+ // Only one OutputMode may be provided.
360
+ type OutputMode string
361
361
362
362
const (
363
- JetstackSecureOAuth TLSPKMode = "Jetstack Secure OAuth"
364
- JetstackSecureAPIToken TLSPKMode = "Jetstack Secure API Token"
365
- VenafiCloudKeypair TLSPKMode = "Venafi Cloud Key Pair Service Account"
366
- VenafiCloudVenafiConnection TLSPKMode = "Venafi Cloud VenafiConnection"
367
-
368
- // It is possible to push to both MachineHub and TLSPK. With this mode, the
369
- // agent will only push to MachineHub and not to TLSPK.
370
- Off TLSPKMode = "MachineHub only"
363
+ JetstackSecureOAuth OutputMode = "Jetstack Secure OAuth"
364
+ JetstackSecureAPIToken OutputMode = "Jetstack Secure API Token"
365
+ VenafiCloudKeypair OutputMode = "Venafi Cloud Key Pair Service Account"
366
+ VenafiCloudVenafiConnection OutputMode = "Venafi Cloud VenafiConnection"
367
+ MachineHub OutputMode = "MachineHub"
368
+ LocalFile OutputMode = "Local File"
371
369
)
372
370
373
371
// The command-line flags and the config file are combined into this struct by
@@ -380,7 +378,7 @@ type CombinedConfig struct {
380
378
StrictMode bool
381
379
OneShot bool
382
380
383
- TLSPKMode TLSPKMode
381
+ OutputMode OutputMode
384
382
385
383
// Used by all TLSPK modes.
386
384
ClusterID string
@@ -410,7 +408,6 @@ type CombinedConfig struct {
410
408
InputPath string
411
409
412
410
// MachineHub-related settings.
413
- MachineHubMode bool
414
411
MachineHubSubdomain string
415
412
MachineHubCredentialsSecretName string
416
413
}
@@ -431,8 +428,6 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
431
428
if err := cfg .MachineHub .Validate (); err != nil {
432
429
return CombinedConfig {}, nil , fmt .Errorf ("invalid MachineHub config provided: %w" , err )
433
430
}
434
-
435
- res .MachineHubMode = true
436
431
res .MachineHubSubdomain = cfg .MachineHub .Subdomain
437
432
res .MachineHubCredentialsSecretName = cfg .MachineHub .CredentialsSecretName
438
433
@@ -442,7 +437,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
442
437
443
438
{
444
439
var (
445
- mode TLSPKMode
440
+ mode OutputMode
446
441
reason string
447
442
keysAndValues []any
448
443
)
@@ -472,32 +467,32 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
472
467
case ! flags .VenafiCloudMode && flags .CredentialsPath != "" :
473
468
mode = JetstackSecureOAuth
474
469
reason = "--credentials-file was specified without --venafi-cloud"
470
+ case flags .MachineHubMode :
471
+ mode = MachineHub
472
+ reason = "--machine-hub was specified"
473
+ case flags .OutputPath != "" :
474
+ mode = LocalFile
475
+ reason = "--output-path was specified"
475
476
default :
476
- if ! flags .MachineHubMode {
477
- return CombinedConfig {}, nil , fmt .Errorf ("no TLSPK mode specified and MachineHub mode is disabled. You must either enable the MachineHub mode (using --machine-hub), or enable one of the TLSPK modes.\n " +
478
- "To enable one of the TLSPK modes, you can:\n " +
479
- " - Use (--venafi-cloud with --credentials-file) or (--client-id with --private-key-path) to use the " + string (VenafiCloudKeypair ) + " mode.\n " +
480
- " - Use --venafi-connection for the " + string (VenafiCloudVenafiConnection ) + " mode.\n " +
481
- " - Use --credentials-file alone if you want to use the " + string (JetstackSecureOAuth ) + " mode.\n " +
482
- " - Use --api-token if you want to use the " + string (JetstackSecureAPIToken ) + " mode.\n " +
483
- "Note that it is possible to use one of the TLSPK modes along with the MachineHub mode (--machine-hub)." )
484
- }
485
-
486
- mode = Off
477
+ return CombinedConfig {}, nil , fmt .Errorf ("no output mode specified.\n " +
478
+ "To enable one of the output modes, you can:\n " +
479
+ " - Use (--venafi-cloud with --credentials-file) or (--client-id with --private-key-path) to use the " + string (VenafiCloudKeypair ) + " mode.\n " +
480
+ " - Use --venafi-connection for the " + string (VenafiCloudVenafiConnection ) + " mode.\n " +
481
+ " - Use --credentials-file alone if you want to use the " + string (JetstackSecureOAuth ) + " mode.\n " +
482
+ " - Use --api-token if you want to use the " + string (JetstackSecureAPIToken ) + " mode.\n " +
483
+ " - Use --machine-hub for " + string (MachineHub ) + " mode.\n " +
484
+ " - Use --output-path for " + string (LocalFile ) + " mode." )
487
485
}
488
486
489
487
keysAndValues = append (keysAndValues , "mode" , mode , "reason" , reason )
490
- if mode != Off {
491
- log .V (logs .Debug ).Info ("Configured to push to Venafi" , keysAndValues ... )
492
- }
493
-
494
- res .TLSPKMode = mode
488
+ log .V (logs .Debug ).Info ("Output mode selected" , keysAndValues ... )
489
+ res .OutputMode = mode
495
490
}
496
491
497
492
var errs error
498
493
499
494
// Validation and defaulting of `server` and the deprecated `endpoint.path`.
500
- if res .TLSPKMode != Off {
495
+ if res .OutputMode != MachineHub {
501
496
// Only relevant if using TLSPK backends
502
497
hasEndpointField := cfg .Endpoint .Host != "" && cfg .Endpoint .Path != ""
503
498
hasServerField := cfg .Server != ""
@@ -520,7 +515,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
520
515
endpointPath = cfg .Endpoint .Path
521
516
case ! hasServerField && ! hasEndpointField :
522
517
server = "https://preflight.jetstack.io"
523
- if res .TLSPKMode == VenafiCloudKeypair {
518
+ if res .OutputMode == VenafiCloudKeypair {
524
519
// The VenafiCloudVenafiConnection mode doesn't need a server.
525
520
server = client .VenafiCloudProdURL
526
521
}
@@ -529,7 +524,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
529
524
if urlErr != nil || url .Hostname () == "" {
530
525
errs = multierror .Append (errs , fmt .Errorf ("server %q is not a valid URL" , server ))
531
526
}
532
- if res .TLSPKMode == VenafiCloudVenafiConnection && server != "" {
527
+ if res .OutputMode == VenafiCloudVenafiConnection && server != "" {
533
528
log .Info (fmt .Sprintf ("ignoring the server field specified in the config file. In %s mode, this field is not needed." , VenafiCloudVenafiConnection ))
534
529
server = ""
535
530
}
@@ -540,10 +535,10 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
540
535
// Validation of `venafi-cloud.upload_path`.
541
536
{
542
537
var uploadPath string
543
- switch res .TLSPKMode { // nolint:exhaustive
538
+ switch res .OutputMode { // nolint:exhaustive
544
539
case VenafiCloudKeypair :
545
540
if cfg .VenafiCloud == nil || cfg .VenafiCloud .UploadPath == "" {
546
- errs = multierror .Append (errs , fmt .Errorf ("the venafi-cloud.upload_path field is required when using the %s mode" , res .TLSPKMode ))
541
+ errs = multierror .Append (errs , fmt .Errorf ("the venafi-cloud.upload_path field is required when using the %s mode" , res .OutputMode ))
547
542
break // Skip to the end of the switch statement.
548
543
}
549
544
_ , urlErr := url .Parse (cfg .VenafiCloud .UploadPath )
@@ -560,7 +555,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
560
555
// change this value with the new --venafi-connection flag, and this
561
556
// field is simply ignored.
562
557
if cfg .VenafiCloud != nil && cfg .VenafiCloud .UploadPath != "" {
563
- 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 ))
558
+ 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 ))
564
559
}
565
560
uploadPath = ""
566
561
}
@@ -578,18 +573,18 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
578
573
// https://venafi.atlassian.net/browse/VC-35385 is done.
579
574
{
580
575
if cfg .VenafiCloud != nil && cfg .VenafiCloud .UploaderID != "" {
581
- 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 ))
576
+ 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 ))
582
577
}
583
578
}
584
579
585
580
// Validation of `cluster_id` and `organization_id`.
586
- if res .TLSPKMode != Off {
581
+ if res .OutputMode != MachineHub {
587
582
var clusterID string
588
583
var organizationID string // Only used by the old jetstack-secure mode.
589
- switch res .TLSPKMode { // nolint:exhaustive
584
+ switch res .OutputMode { // nolint:exhaustive
590
585
case VenafiCloudKeypair , VenafiCloudVenafiConnection :
591
586
if cfg .ClusterID == "" {
592
- errs = multierror .Append (errs , fmt .Errorf ("cluster_id is required in %s mode" , res .TLSPKMode ))
587
+ errs = multierror .Append (errs , fmt .Errorf ("cluster_id is required in %s mode" , res .OutputMode ))
593
588
}
594
589
clusterID = cfg .ClusterID
595
590
case JetstackSecureOAuth , JetstackSecureAPIToken :
@@ -651,7 +646,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
651
646
res .InstallNS = installNS
652
647
653
648
// Validation of --venafi-connection and --venafi-connection-namespace.
654
- if res .TLSPKMode == VenafiCloudVenafiConnection {
649
+ if res .OutputMode == VenafiCloudVenafiConnection {
655
650
res .VenConnName = flags .VenConnName
656
651
venConnNS := flags .VenConnNS
657
652
if flags .VenConnNS == "" {
@@ -717,7 +712,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
717
712
718
713
var preflightClient client.Client
719
714
metadata := & api.AgentMetadata {Version : version .PreflightVersion , ClusterID : cfg .ClusterID }
720
- switch cfg .TLSPKMode {
715
+ switch cfg .OutputMode {
721
716
case JetstackSecureOAuth :
722
717
// Note that there are no command line flags to configure the
723
718
// JetstackSecureOAuth mode.
@@ -807,14 +802,16 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
807
802
if err != nil {
808
803
errs = multierror .Append (errs , err )
809
804
}
810
- case Off :
805
+ case MachineHub :
806
+ // No client needed in this mode.
807
+ case LocalFile :
811
808
// No client needed in this mode.
812
809
default :
813
- panic (fmt .Errorf ("programmer mistake: auth mode not implemented: %s" , cfg .TLSPKMode ))
810
+ panic (fmt .Errorf ("programmer mistake: output mode not implemented: %s" , cfg .OutputMode ))
814
811
}
815
812
816
813
if errs != nil {
817
- return nil , fmt .Errorf ("failed loading config using the %s mode: %w" , cfg .TLSPKMode , errs )
814
+ return nil , fmt .Errorf ("failed loading config using the %s mode: %w" , cfg .OutputMode , errs )
818
815
}
819
816
820
817
return preflightClient , nil
0 commit comments