@@ -263,49 +263,51 @@ func (o *Options) addAuthFlags(fs *pflag.FlagSet) {
263263 fs .StringVar (& o .selfhosted .Username ,
264264 "selfhosted-username" , "" ,
265265 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 ,
268268 ))
269269 fs .StringVar (& o .selfhosted .Password ,
270270 "selfhosted-password" , "" ,
271271 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 ,
274274 ))
275275 fs .StringVar (& o .selfhosted .Bearer ,
276276 "selfhosted-token" , "" ,
277277 fmt .Sprintf (
278278 "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 ,
281281 ))
282282 fs .StringVar (& o .selfhosted .TokenPath ,
283283 "selfhosted-token-path" , "" ,
284284 fmt .Sprintf (
285285 "Override the default selfhosted registry's token auth path. " +
286- "(%s_%s)." ,
287- envPrefix , envSelfhostedTokenPath ,
286+ "(%s_%s_% s)." ,
287+ envPrefix , envSelfhostedPrefix , envSelfhostedTokenPath ,
288288 ))
289289 fs .StringVar (& o .selfhosted .Host ,
290290 "selfhosted-registry-host" , "" ,
291291 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 ,
294294 ))
295- fs .StringVar (& o .selfhosted .Host ,
295+ fs .StringVar (& o .selfhosted .CAPath ,
296296 "selfhosted-registry-ca-path" , "" ,
297297 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 ,
300300 ))
301301 fs .BoolVarP (& o .selfhosted .Insecure ,
302302 "selfhosted-insecure" , "" , false ,
303303 fmt .Sprintf (
304304 "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 ,
307307 ))
308- ///
308+ // if !validSelfHostedOpts(o) {
309+ // panic(fmt.Errorf("invalid self hosted configuration"))
310+ // }
309311}
310312
311313func (o * Options ) complete () {
@@ -450,4 +452,26 @@ func (o *Options) assignSelfhosted(envs []string) {
450452 if len (o .selfhosted .Host ) > 0 {
451453 o .Client .Selfhosted [o .selfhosted .Host ] = & o .selfhosted
452454 }
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
453477}
0 commit comments