@@ -42,6 +42,17 @@ const (
4242 nginxOneTelemetryEndpointHost = "agent.connect.nginx.com"
4343)
4444
45+ // UsageReportParams holds the parameters for building the usage report configuration for PLUS.
46+ type UsageReportParams struct {
47+ SecretName stringValidatingValue
48+ ClientSSLSecretName stringValidatingValue
49+ CASecretName stringValidatingValue
50+ Endpoint stringValidatingValue
51+ Resolver stringValidatingValue
52+ SkipVerify bool
53+ EnforceInitialReport bool
54+ }
55+
4556func createRootCommand () * cobra.Command {
4657 rootCmd := & cobra.Command {
4758 Use : "gateway" ,
@@ -149,25 +160,26 @@ func createControllerCommand() *cobra.Command {
149160 nginxDockerSecrets = stringSliceValidatingValue {
150161 validator : validateResourceName ,
151162 }
152- usageReportSkipVerify bool
153- usageReportSecretName = stringValidatingValue {
163+ )
164+
165+ usageReportParams := UsageReportParams {
166+ SecretName : stringValidatingValue {
154167 validator : validateResourceName ,
155168 value : "nplus-license" ,
156- }
157- usageReportEndpoint = stringValidatingValue {
169+ },
170+ Endpoint : stringValidatingValue {
158171 validator : validateEndpointOptionalPort ,
159- }
160- usageReportResolver = stringValidatingValue {
172+ },
173+ Resolver : stringValidatingValue {
161174 validator : validateEndpointOptionalPort ,
162- }
163- usageReportClientSSLSecretName = stringValidatingValue {
175+ },
176+ ClientSSLSecretName : stringValidatingValue {
164177 validator : validateResourceName ,
165- }
166- usageReportCASecretName = stringValidatingValue {
178+ },
179+ CASecretName : stringValidatingValue {
167180 validator : validateResourceName ,
168- }
169- usageReportEnforceInitialReport bool
170- )
181+ },
182+ }
171183
172184 cmd := & cobra.Command {
173185 Use : "controller" ,
@@ -213,21 +225,9 @@ func createControllerCommand() *cobra.Command {
213225 return fmt .Errorf ("error parsing telemetry endpoint insecure: %w" , err )
214226 }
215227
216- var usageReportConfig config.UsageReportConfig
217- if plus && usageReportSecretName .value == "" {
218- return errors .New ("usage-report-secret is required when using NGINX Plus" )
219- }
220-
221- if plus {
222- usageReportConfig = config.UsageReportConfig {
223- SecretName : usageReportSecretName .value ,
224- ClientSSLSecretName : usageReportClientSSLSecretName .value ,
225- CASecretName : usageReportCASecretName .value ,
226- Endpoint : usageReportEndpoint .value ,
227- Resolver : usageReportResolver .value ,
228- SkipVerify : usageReportSkipVerify ,
229- EnforceInitialReport : usageReportEnforceInitialReport ,
230- }
228+ usageReportConfig , urcErr := buildUsageReportConfig (plus , usageReportParams )
229+ if urcErr != nil {
230+ return urcErr
231231 }
232232
233233 flagKeys , flagValues := parseFlags (cmd .Flags ())
@@ -435,47 +435,54 @@ func createControllerCommand() *cobra.Command {
435435 )
436436
437437 cmd .Flags ().Var (
438- & usageReportSecretName ,
438+ & usageReportParams . SecretName ,
439439 usageReportSecretFlag ,
440440 "The name of the Secret containing the JWT for NGINX Plus usage reporting. Must exist in the same namespace " +
441441 "that the NGINX Gateway Fabric control plane is running in (default namespace: nginx-gateway)." ,
442442 )
443443
444444 cmd .Flags ().Var (
445- & usageReportEndpoint ,
445+ & usageReportParams . Endpoint ,
446446 usageReportEndpointFlag ,
447447 "The endpoint of the NGINX Plus usage reporting server." ,
448448 )
449449
450450 cmd .Flags ().Var (
451- & usageReportResolver ,
451+ & usageReportParams . Resolver ,
452452 usageReportResolverFlag ,
453453 "The nameserver used to resolve the NGINX Plus usage reporting endpoint. Used with NGINX Instance Manager." ,
454454 )
455455
456456 cmd .Flags ().BoolVar (
457- & usageReportSkipVerify ,
457+ & usageReportParams . SkipVerify ,
458458 usageReportSkipVerifyFlag ,
459459 false ,
460460 "Disable client verification of the NGINX Plus usage reporting server certificate." ,
461461 )
462462
463463 cmd .Flags ().Var (
464- & usageReportClientSSLSecretName ,
464+ & usageReportParams . ClientSSLSecretName ,
465465 usageReportClientSSLSecretFlag ,
466466 "The name of the Secret containing the client certificate and key for authenticating with NGINX Instance Manager. " +
467467 "Must exist in the same namespace that the NGINX Gateway Fabric control plane is running in " +
468468 "(default namespace: nginx-gateway)." ,
469469 )
470470
471471 cmd .Flags ().Var (
472- & usageReportCASecretName ,
472+ & usageReportParams . CASecretName ,
473473 usageReportCASecretFlag ,
474474 "The name of the Secret containing the NGINX Instance Manager CA certificate. " +
475475 "Must exist in the same namespace that the NGINX Gateway Fabric control plane is running in " +
476476 "(default namespace: nginx-gateway)." ,
477477 )
478478
479+ cmd .Flags ().BoolVar (
480+ & usageReportParams .EnforceInitialReport ,
481+ usageReportEnforceInitialReportFlag ,
482+ true ,
483+ "Enable enforcement of the initial NGINX Plus licensing report. If set to false, the initial report is not enforced." ,
484+ )
485+
479486 cmd .Flags ().BoolVar (
480487 & snippetsFilters ,
481488 snippetsFiltersFlag ,
@@ -491,16 +498,29 @@ func createControllerCommand() *cobra.Command {
491498 ` Only applicable in OpenShift.` ,
492499 )
493500
494- cmd .Flags ().BoolVar (
495- & usageReportEnforceInitialReport ,
496- usageReportEnforceInitialReportFlag ,
497- true ,
498- "Enable enforcement of the initial NGINX Plus licensing report. If set to false, the initial report is not enforced." ,
499- )
500-
501501 return cmd
502502}
503503
504+ func buildUsageReportConfig (plus bool , params UsageReportParams ) (config.UsageReportConfig , error ) {
505+ if plus && params .SecretName .value == "" {
506+ return config.UsageReportConfig {}, errors .New ("usage-report-secret is required when using NGINX Plus" )
507+ }
508+
509+ if plus {
510+ return config.UsageReportConfig {
511+ SecretName : params .SecretName .value ,
512+ ClientSSLSecretName : params .ClientSSLSecretName .value ,
513+ CASecretName : params .CASecretName .value ,
514+ Endpoint : params .Endpoint .value ,
515+ Resolver : params .Resolver .value ,
516+ SkipVerify : params .SkipVerify ,
517+ EnforceInitialReport : params .EnforceInitialReport ,
518+ }, nil
519+ }
520+
521+ return config.UsageReportConfig {}, nil
522+ }
523+
504524func createGenerateCertsCommand () * cobra.Command {
505525 // flag names
506526 const (
0 commit comments