@@ -355,19 +355,18 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
355355
356356}
357357
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
361361
362362const (
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"
371370)
372371
373372// The command-line flags and the config file are combined into this struct by
@@ -380,7 +379,7 @@ type CombinedConfig struct {
380379 StrictMode bool
381380 OneShot bool
382381
383- TLSPKMode TLSPKMode
382+ OutputMode OutputMode
384383
385384 // Used by all TLSPK modes.
386385 ClusterID string
@@ -410,7 +409,6 @@ type CombinedConfig struct {
410409 InputPath string
411410
412411 // MachineHub-related settings.
413- MachineHubMode bool
414412 MachineHubSubdomain string
415413 MachineHubCredentialsSecretName string
416414}
@@ -431,8 +429,6 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
431429 if err := cfg .MachineHub .Validate (); err != nil {
432430 return CombinedConfig {}, nil , fmt .Errorf ("invalid MachineHub config provided: %w" , err )
433431 }
434-
435- res .MachineHubMode = true
436432 res .MachineHubSubdomain = cfg .MachineHub .Subdomain
437433 res .MachineHubCredentialsSecretName = cfg .MachineHub .CredentialsSecretName
438434
@@ -442,7 +438,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
442438
443439 {
444440 var (
445- mode TLSPKMode
441+ mode OutputMode
446442 reason string
447443 keysAndValues []any
448444 )
@@ -472,32 +468,32 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
472468 case ! flags .VenafiCloudMode && flags .CredentialsPath != "" :
473469 mode = JetstackSecureOAuth
474470 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"
475477 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." )
487486 }
488487
489488 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
495491 }
496492
497493 var errs error
498494
499495 // Validation and defaulting of `server` and the deprecated `endpoint.path`.
500- if res .TLSPKMode != Off {
496+ if res .OutputMode != MachineHub {
501497 // Only relevant if using TLSPK backends
502498 hasEndpointField := cfg .Endpoint .Host != "" && cfg .Endpoint .Path != ""
503499 hasServerField := cfg .Server != ""
@@ -520,7 +516,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
520516 endpointPath = cfg .Endpoint .Path
521517 case ! hasServerField && ! hasEndpointField :
522518 server = "https://preflight.jetstack.io"
523- if res .TLSPKMode == VenafiCloudKeypair {
519+ if res .OutputMode == VenafiCloudKeypair {
524520 // The VenafiCloudVenafiConnection mode doesn't need a server.
525521 server = client .VenafiCloudProdURL
526522 }
@@ -529,7 +525,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
529525 if urlErr != nil || url .Hostname () == "" {
530526 errs = multierror .Append (errs , fmt .Errorf ("server %q is not a valid URL" , server ))
531527 }
532- if res .TLSPKMode == VenafiCloudVenafiConnection && server != "" {
528+ if res .OutputMode == VenafiCloudVenafiConnection && server != "" {
533529 log .Info (fmt .Sprintf ("ignoring the server field specified in the config file. In %s mode, this field is not needed." , VenafiCloudVenafiConnection ))
534530 server = ""
535531 }
@@ -540,10 +536,10 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
540536 // Validation of `venafi-cloud.upload_path`.
541537 {
542538 var uploadPath string
543- switch res .TLSPKMode { // nolint:exhaustive
539+ switch res .OutputMode { // nolint:exhaustive
544540 case VenafiCloudKeypair :
545541 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 ))
547543 break // Skip to the end of the switch statement.
548544 }
549545 _ , urlErr := url .Parse (cfg .VenafiCloud .UploadPath )
@@ -560,7 +556,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
560556 // change this value with the new --venafi-connection flag, and this
561557 // field is simply ignored.
562558 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 ))
564560 }
565561 uploadPath = ""
566562 }
@@ -578,18 +574,18 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
578574 // https://venafi.atlassian.net/browse/VC-35385 is done.
579575 {
580576 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 ))
582578 }
583579 }
584580
585581 // Validation of `cluster_id` and `organization_id`.
586- if res .TLSPKMode != Off {
582+ if res .OutputMode != MachineHub {
587583 var clusterID string
588584 var organizationID string // Only used by the old jetstack-secure mode.
589- switch res .TLSPKMode { // nolint:exhaustive
585+ switch res .OutputMode { // nolint:exhaustive
590586 case VenafiCloudKeypair , VenafiCloudVenafiConnection :
591587 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 ))
593589 }
594590 clusterID = cfg .ClusterID
595591 case JetstackSecureOAuth , JetstackSecureAPIToken :
@@ -651,7 +647,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
651647 res .InstallNS = installNS
652648
653649 // Validation of --venafi-connection and --venafi-connection-namespace.
654- if res .TLSPKMode == VenafiCloudVenafiConnection {
650+ if res .OutputMode == VenafiCloudVenafiConnection {
655651 res .VenConnName = flags .VenConnName
656652 venConnNS := flags .VenConnNS
657653 if flags .VenConnNS == "" {
@@ -717,7 +713,7 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
717713
718714 var preflightClient client.Client
719715 metadata := & api.AgentMetadata {Version : version .PreflightVersion , ClusterID : cfg .ClusterID }
720- switch cfg .TLSPKMode {
716+ switch cfg .OutputMode {
721717 case JetstackSecureOAuth :
722718 // Note that there are no command line flags to configure the
723719 // JetstackSecureOAuth mode.
@@ -807,14 +803,16 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
807803 if err != nil {
808804 errs = multierror .Append (errs , err )
809805 }
810- case Off :
806+ case MachineHub :
807+ // No client needed in this mode.
808+ case LocalFile :
811809 // No client needed in this mode.
812810 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 ))
814812 }
815813
816814 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 )
818816 }
819817
820818 return preflightClient , nil
0 commit comments