11package agent
22
33import (
4+ "crypto/x509"
45 "fmt"
56 "io"
67 "net/url"
@@ -10,9 +11,11 @@ import (
1011
1112 "github.com/go-logr/logr"
1213 "github.com/hashicorp/go-multierror"
14+ "github.com/jetstack/venafi-connection-lib/http_client"
1315 "github.com/spf13/cobra"
1416 "gopkg.in/yaml.v3"
1517 "k8s.io/client-go/rest"
18+ "k8s.io/client-go/transport"
1619
1720 "github.com/jetstack/preflight/api"
1821 "github.com/jetstack/preflight/pkg/client"
@@ -334,6 +337,7 @@ const (
334337 VenafiCloudKeypair OutputMode = "Venafi Cloud Key Pair Service Account"
335338 VenafiCloudVenafiConnection OutputMode = "Venafi Cloud VenafiConnection"
336339 LocalFile OutputMode = "Local File"
340+ MachineHub OutputMode = "MachineHub"
337341)
338342
339343// The command-line flags and the config file are combined into this struct by
@@ -420,6 +424,9 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
420424 case ! flags .VenafiCloudMode && flags .CredentialsPath != "" :
421425 mode = JetstackSecureOAuth
422426 reason = "--credentials-file was specified without --venafi-cloud"
427+ case flags .MachineHubMode :
428+ mode = MachineHub
429+ reason = "--machine-hub was specified"
423430 case flags .OutputPath != "" :
424431 mode = LocalFile
425432 reason = "--output-path was specified"
@@ -433,6 +440,7 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
433440 " - Use --venafi-connection for the " + string (VenafiCloudVenafiConnection ) + " mode.\n " +
434441 " - Use --credentials-file alone if you want to use the " + string (JetstackSecureOAuth ) + " mode.\n " +
435442 " - Use --api-token if you want to use the " + string (JetstackSecureAPIToken ) + " mode.\n " +
443+ " - Use --machine-hub if you want to use the " + string (MachineHub ) + " mode.\n " +
436444 " - Use --output-path or output-path in the config file for " + string (LocalFile ) + " mode." )
437445 }
438446
@@ -548,6 +556,13 @@ func ValidateAndCombineConfig(log logr.Logger, cfg Config, flags AgentCmdFlags)
548556 }
549557 organizationID = cfg .OrganizationID
550558 clusterID = cfg .ClusterID
559+ case MachineHub :
560+ if cfg .ClusterID != "" {
561+ log .Info (fmt .Sprintf (`Ignoring the cluster_id field in the config file. This field is not needed in %s mode.` , res .OutputMode ))
562+ }
563+ if cfg .OrganizationID != "" {
564+ log .Info (fmt .Sprintf (`Ignoring the organization_id field in the config file. This field is not needed in %s mode.` , res .OutputMode ))
565+ }
551566 }
552567 res .OrganizationID = organizationID
553568 res .ClusterID = clusterID
@@ -762,6 +777,17 @@ func validateCredsAndCreateClient(log logr.Logger, flagCredentialsPath, flagClie
762777 }
763778 case LocalFile :
764779 outputClient = client .NewFileClient (cfg .OutputPath )
780+ case MachineHub :
781+ var (
782+ err error
783+ rootCAs * x509.CertPool
784+ )
785+ httpClient := http_client .NewDefaultClient (version .UserAgent (), rootCAs )
786+ httpClient .Transport = transport .NewDebuggingRoundTripper (httpClient .Transport , transport .DebugByContext )
787+ outputClient , err = client .NewCyberArk (httpClient )
788+ if err != nil {
789+ errs = multierror .Append (errs , err )
790+ }
765791 default :
766792 panic (fmt .Errorf ("programmer mistake: output mode not implemented: %s" , cfg .OutputMode ))
767793 }
0 commit comments