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