@@ -263,49 +263,51 @@ func (o *Options) addAuthFlags(fs *pflag.FlagSet) {
263
263
fs .StringVar (& o .selfhosted .Username ,
264
264
"selfhosted-username" , "" ,
265
265
fmt .Sprintf (
266
- "Username is authenticate with a selfhosted registry (%s_%s)." ,
267
- envPrefix , envSelfhostedUsername ,
266
+ "Username is authenticate with a selfhosted registry (%s_%s_% s)." ,
267
+ envPrefix , envSelfhostedPrefix , envSelfhostedUsername ,
268
268
))
269
269
fs .StringVar (& o .selfhosted .Password ,
270
270
"selfhosted-password" , "" ,
271
271
fmt .Sprintf (
272
- "Password is authenticate with a selfhosted registry (%s_%s)." ,
273
- envPrefix , envSelfhostedPassword ,
272
+ "Password is authenticate with a selfhosted registry (%s_%s_% s)." ,
273
+ envPrefix , envSelfhostedPrefix , envSelfhostedPassword ,
274
274
))
275
275
fs .StringVar (& o .selfhosted .Bearer ,
276
276
"selfhosted-token" , "" ,
277
277
fmt .Sprintf (
278
278
"Token to authenticate to a selfhosted registry. Cannot be used with " +
279
- "username/password (%s_%s)." ,
280
- envPrefix , envSelfhostedBearer ,
279
+ "username/password (%s_%s_% s)." ,
280
+ envPrefix , envSelfhostedPrefix , envSelfhostedBearer ,
281
281
))
282
282
fs .StringVar (& o .selfhosted .TokenPath ,
283
283
"selfhosted-token-path" , "" ,
284
284
fmt .Sprintf (
285
285
"Override the default selfhosted registry's token auth path. " +
286
- "(%s_%s)." ,
287
- envPrefix , envSelfhostedTokenPath ,
286
+ "(%s_%s_% s)." ,
287
+ envPrefix , envSelfhostedPrefix , envSelfhostedTokenPath ,
288
288
))
289
289
fs .StringVar (& o .selfhosted .Host ,
290
290
"selfhosted-registry-host" , "" ,
291
291
fmt .Sprintf (
292
- "Full host of the selfhosted registry. Include http[s] scheme (%s_%s)" ,
293
- envPrefix , envSelfhostedHost ,
292
+ "Full host of the selfhosted registry. Include http[s] scheme (%s_%s_% s)" ,
293
+ envPrefix , envSelfhostedPrefix , envSelfhostedHost ,
294
294
))
295
- fs .StringVar (& o .selfhosted .Host ,
295
+ fs .StringVar (& o .selfhosted .CAPath ,
296
296
"selfhosted-registry-ca-path" , "" ,
297
297
fmt .Sprintf (
298
- "Absolute path to a PEM encoded x509 certificate chain. (%s_%s)" ,
299
- envPrefix , envSelfhostedCAPath ,
298
+ "Absolute path to a PEM encoded x509 certificate chain. (%s_%s_% s)" ,
299
+ envPrefix , envSelfhostedPrefix , envSelfhostedCAPath ,
300
300
))
301
301
fs .BoolVarP (& o .selfhosted .Insecure ,
302
302
"selfhosted-insecure" , "" , false ,
303
303
fmt .Sprintf (
304
304
"Enable/Disable SSL Certificate Validation. WARNING: " +
305
- "THIS IS NOT RECOMMENDED AND IS INTENDED FOR DEBUGGING (%s_%s)" ,
306
- envPrefix , envSelfhostedInsecure ,
305
+ "THIS IS NOT RECOMMENDED AND IS INTENDED FOR DEBUGGING (%s_%s_% s)" ,
306
+ envPrefix , envSelfhostedPrefix , envSelfhostedInsecure ,
307
307
))
308
- ///
308
+ // if !validSelfHostedOpts(o) {
309
+ // panic(fmt.Errorf("invalid self hosted configuration"))
310
+ // }
309
311
}
310
312
311
313
func (o * Options ) complete () {
@@ -450,4 +452,26 @@ func (o *Options) assignSelfhosted(envs []string) {
450
452
if len (o .selfhosted .Host ) > 0 {
451
453
o .Client .Selfhosted [o .selfhosted .Host ] = & o .selfhosted
452
454
}
455
+ if ! validSelfHostedOpts (o ) {
456
+ panic (fmt .Errorf ("invalid self hosted configuration" ))
457
+ }
458
+ }
459
+
460
+ func validSelfHostedOpts (opts * Options ) bool {
461
+ // opts set using env vars
462
+ if opts .Client .Selfhosted != nil {
463
+ for _ , selfHostedOpts := range opts .Client .Selfhosted {
464
+ return isValidOption (selfHostedOpts .Host , "" )
465
+ }
466
+ }
467
+
468
+ // opts set using flags
469
+ if opts .selfhosted != (selfhosted.Options {}) {
470
+ return isValidOption (opts .selfhosted .Host , "" )
471
+ }
472
+ return true
473
+ }
474
+
475
+ func isValidOption (option , invalid string ) bool {
476
+ return option != invalid
453
477
}
0 commit comments