@@ -294,9 +294,20 @@ func validateOIDC(oidc *v1.OIDC, fieldPath *field.Path) field.ErrorList {
294294
295295func validateAPIKey (apiKey * v1.APIKey , fieldPath * field.Path ) field.ErrorList {
296296 allErrs := field.ErrorList {}
297+
298+ if apiKey == nil {
299+ allErrs = append (allErrs , field .Required (fieldPath , "apiKey cannot be nil" ))
300+ return allErrs
301+ }
302+
303+ if apiKey .SuppliedIn == nil {
304+ allErrs = append (allErrs , field .Required (fieldPath .Child ("suppliedIn" ), "suppliedIn cannot be nil" ))
305+ return allErrs
306+ }
307+
297308 if apiKey .SuppliedIn .Query == nil && apiKey .SuppliedIn .Header == nil {
298309 msg := "at least one query or header name must be provided"
299- allErrs = append (allErrs , field .Required (fieldPath .Child ("SuppliedIn " ), msg ))
310+ allErrs = append (allErrs , field .Required (fieldPath .Child ("suppliedIn " ), msg ))
300311 }
301312
302313 if apiKey .SuppliedIn .Header != nil {
@@ -316,11 +327,11 @@ func validateAPIKey(apiKey *v1.APIKey, fieldPath *field.Path) field.ErrorList {
316327 }
317328
318329 if apiKey .ClientSecret == "" {
319- allErrs = append (allErrs , field .Required (fieldPath .Child ("clientSecret" ), "" ))
330+ allErrs = append (allErrs , field .Required (fieldPath .Child ("clientSecret" ), "clientSecret cannot be empty" ))
331+ } else {
332+ allErrs = append (allErrs , validateSecretName (apiKey .ClientSecret , fieldPath .Child ("clientSecret" ))... )
320333 }
321334
322- allErrs = append (allErrs , validateSecretName (apiKey .ClientSecret , fieldPath .Child ("clientSecret" ))... )
323-
324335 return allErrs
325336}
326337
0 commit comments