@@ -252,49 +252,51 @@ func (o *Options) addAuthFlags(fs *pflag.FlagSet) {
252
252
fs .StringVar (& o .selfhosted .Username ,
253
253
"selfhosted-username" , "" ,
254
254
fmt .Sprintf (
255
- "Username is authenticate with a selfhosted registry (%s_%s)." ,
256
- envPrefix , envSelfhostedUsername ,
255
+ "Username is authenticate with a selfhosted registry (%s_%s_% s)." ,
256
+ envPrefix , envSelfhostedPrefix , envSelfhostedUsername ,
257
257
))
258
258
fs .StringVar (& o .selfhosted .Password ,
259
259
"selfhosted-password" , "" ,
260
260
fmt .Sprintf (
261
- "Password is authenticate with a selfhosted registry (%s_%s)." ,
262
- envPrefix , envSelfhostedPassword ,
261
+ "Password is authenticate with a selfhosted registry (%s_%s_% s)." ,
262
+ envPrefix , envSelfhostedPrefix , envSelfhostedPassword ,
263
263
))
264
264
fs .StringVar (& o .selfhosted .Bearer ,
265
265
"selfhosted-token" , "" ,
266
266
fmt .Sprintf (
267
267
"Token to authenticate to a selfhosted registry. Cannot be used with " +
268
- "username/password (%s_%s)." ,
269
- envPrefix , envSelfhostedBearer ,
268
+ "username/password (%s_%s_% s)." ,
269
+ envPrefix , envSelfhostedPrefix , envSelfhostedBearer ,
270
270
))
271
271
fs .StringVar (& o .selfhosted .TokenPath ,
272
272
"selfhosted-token-path" , "" ,
273
273
fmt .Sprintf (
274
274
"Override the default selfhosted registry's token auth path. " +
275
- "(%s_%s)." ,
276
- envPrefix , envSelfhostedTokenPath ,
275
+ "(%s_%s_% s)." ,
276
+ envPrefix , envSelfhostedPrefix , envSelfhostedTokenPath ,
277
277
))
278
278
fs .StringVar (& o .selfhosted .Host ,
279
279
"selfhosted-registry-host" , "" ,
280
280
fmt .Sprintf (
281
- "Full host of the selfhosted registry. Include http[s] scheme (%s_%s)" ,
282
- envPrefix , envSelfhostedHost ,
281
+ "Full host of the selfhosted registry. Include http[s] scheme (%s_%s_% s)" ,
282
+ envPrefix , envSelfhostedPrefix , envSelfhostedHost ,
283
283
))
284
- fs .StringVar (& o .selfhosted .Host ,
284
+ fs .StringVar (& o .selfhosted .CAPath ,
285
285
"selfhosted-registry-ca-path" , "" ,
286
286
fmt .Sprintf (
287
- "Absolute path to a PEM encoded x509 certificate chain. (%s_%s)" ,
288
- envPrefix , envSelfhostedCAPath ,
287
+ "Absolute path to a PEM encoded x509 certificate chain. (%s_%s_% s)" ,
288
+ envPrefix , envSelfhostedPrefix , envSelfhostedCAPath ,
289
289
))
290
290
fs .BoolVarP (& o .selfhosted .Insecure ,
291
291
"selfhosted-insecure" , "" , false ,
292
292
fmt .Sprintf (
293
293
"Enable/Disable SSL Certificate Validation. WARNING: " +
294
- "THIS IS NOT RECOMMENDED AND IS INTENDED FOR DEBUGGING (%s_%s)" ,
295
- envPrefix , envSelfhostedInsecure ,
294
+ "THIS IS NOT RECOMMENDED AND IS INTENDED FOR DEBUGGING (%s_%s_% s)" ,
295
+ envPrefix , envSelfhostedPrefix , envSelfhostedInsecure ,
296
296
))
297
- ///
297
+ // if !validSelfHostedOpts(o) {
298
+ // panic(fmt.Errorf("invalid self hosted configuration"))
299
+ // }
298
300
}
299
301
300
302
func (o * Options ) complete () {
@@ -414,4 +416,26 @@ func (o *Options) assignSelfhosted(envs []string) {
414
416
if len (o .selfhosted .Host ) > 0 {
415
417
o .Client .Selfhosted [o .selfhosted .Host ] = & o .selfhosted
416
418
}
419
+ if ! validSelfHostedOpts (o ) {
420
+ panic (fmt .Errorf ("invalid self hosted configuration" ))
421
+ }
422
+ }
423
+
424
+ func validSelfHostedOpts (opts * Options ) bool {
425
+ // opts set using env vars
426
+ if opts .Client .Selfhosted != nil {
427
+ for _ , selfHostedOpts := range opts .Client .Selfhosted {
428
+ return isValidOption (selfHostedOpts .Host , "" )
429
+ }
430
+ }
431
+
432
+ // opts set using flags
433
+ if opts .selfhosted != (selfhosted.Options {}) {
434
+ return isValidOption (opts .selfhosted .Host , "" )
435
+ }
436
+ return true
437
+ }
438
+
439
+ func isValidOption (option , invalid string ) bool {
440
+ return option != invalid
417
441
}
0 commit comments