@@ -252,49 +252,51 @@ func (o *Options) addAuthFlags(fs *pflag.FlagSet) {
252252 fs .StringVar (& o .selfhosted .Username ,
253253 "selfhosted-username" , "" ,
254254 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 ,
257257 ))
258258 fs .StringVar (& o .selfhosted .Password ,
259259 "selfhosted-password" , "" ,
260260 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 ,
263263 ))
264264 fs .StringVar (& o .selfhosted .Bearer ,
265265 "selfhosted-token" , "" ,
266266 fmt .Sprintf (
267267 "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 ,
270270 ))
271271 fs .StringVar (& o .selfhosted .TokenPath ,
272272 "selfhosted-token-path" , "" ,
273273 fmt .Sprintf (
274274 "Override the default selfhosted registry's token auth path. " +
275- "(%s_%s)." ,
276- envPrefix , envSelfhostedTokenPath ,
275+ "(%s_%s_% s)." ,
276+ envPrefix , envSelfhostedPrefix , envSelfhostedTokenPath ,
277277 ))
278278 fs .StringVar (& o .selfhosted .Host ,
279279 "selfhosted-registry-host" , "" ,
280280 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 ,
283283 ))
284- fs .StringVar (& o .selfhosted .Host ,
284+ fs .StringVar (& o .selfhosted .CAPath ,
285285 "selfhosted-registry-ca-path" , "" ,
286286 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 ,
289289 ))
290290 fs .BoolVarP (& o .selfhosted .Insecure ,
291291 "selfhosted-insecure" , "" , false ,
292292 fmt .Sprintf (
293293 "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 ,
296296 ))
297- ///
297+ // if !validSelfHostedOpts(o) {
298+ // panic(fmt.Errorf("invalid self hosted configuration"))
299+ // }
298300}
299301
300302func (o * Options ) complete () {
@@ -414,4 +416,26 @@ func (o *Options) assignSelfhosted(envs []string) {
414416 if len (o .selfhosted .Host ) > 0 {
415417 o .Client .Selfhosted [o .selfhosted .Host ] = & o .selfhosted
416418 }
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
417441}
0 commit comments