Skip to content

Add details for field.Required #9198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

sgallagher
Copy link
Contributor

Some fields are only required if other fields have certain values.
This patch adds some additional error messaging to inform the user
why these fields were necessary.

Fixes issue #7118

Signed-off-by: Stephen Gallagher [email protected]

Replaces #8269

@deads2k PTAL

}
}

if (len(certInfo.CertFile) > 0 && len(certInfo.KeyFile) == 0) || (len(certInfo.CertFile) == 0 && len(certInfo.KeyFile) > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this (len(certInfo.CertFile) == 0) != (len(certInfo.KeyFile) == 0) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damned boolean logic. Yes, this does reduce to that. I'll tweak it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean logic can be tricky, true or false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

False, due to the use of the phrase "can be".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong, the answer is true, since true or false always evaluates to true ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't reduce?

@sgallagher
Copy link
Contributor Author

@deads2k PTAL

}
if len(identity.User.Name) != 0 && len(identity.User.UID) == 0 {
allErrs = append(allErrs, field.Required(userPath.Child("uid"), ""))
allErrs = append(allErrs, field.Required(userPath.Child("uid"), "username is required when UID is provided"))
Copy link
Contributor

@liggitt liggitt Jun 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message doesn't make sense... they provided a username

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message doesn't make sense... they provided a username

still outstanding.

@sgallagher
Copy link
Contributor Author

@deads2k, @liggitt ping?

@@ -155,10 +155,10 @@ func ValidateIdentity(identity *api.Identity) field.ErrorList {
allErrs = append(allErrs, field.Invalid(userPath.Child("name"), identity.User.Name, msg))
}
if len(identity.User.Name) == 0 && len(identity.User.UID) != 0 {
allErrs = append(allErrs, field.Invalid(userPath.Child("uid"), identity.User.UID, "may not be set if user.name is empty"))
allErrs = append(allErrs, field.Invalid(userPath.Child("uid"), identity.User.UID, "username is required when UID is provided"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something went weird here. If username is required, why not field.Required(userPath.Child("username"),....) ?

@sgallagher sgallagher force-pushed the field-required branch 2 times, most recently from 72a9b84 to 810facb Compare June 20, 2016 17:43
@sgallagher
Copy link
Contributor Author

@deads2k Looks like I goofed and pushed an old branch by mistake. This should address your comments from this morning.

@@ -155,10 +155,10 @@ func ValidateIdentity(identity *api.Identity) field.ErrorList {
allErrs = append(allErrs, field.Invalid(userPath.Child("name"), identity.User.Name, msg))
}
if len(identity.User.Name) == 0 && len(identity.User.UID) != 0 {
allErrs = append(allErrs, field.Invalid(userPath.Child("uid"), identity.User.UID, "may not be set if user.name is empty"))
allErrs = append(allErrs, field.Invalid(userPath.Child("uid"), identity.User.UID, "username is required when username is provided"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phrasing this way is good, but you need to make it field.Required(userpath.Child("username")...) to match.

Some fields are only required if other fields have certain values.
This patch adds some additional error messaging to inform the user
why these fields were necessary.

Fixes issue openshift#7118

Signed-off-by: Stephen Gallagher <[email protected]>
@@ -155,10 +155,10 @@ func ValidateIdentity(identity *api.Identity) field.ErrorList {
allErrs = append(allErrs, field.Invalid(userPath.Child("name"), identity.User.Name, msg))
}
if len(identity.User.Name) == 0 && len(identity.User.UID) != 0 {
allErrs = append(allErrs, field.Invalid(userPath.Child("uid"), identity.User.UID, "may not be set if user.name is empty"))
allErrs = append(allErrs, field.Invalid(userPath.Child("username"), "username is required when uid is provided"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

field.Required?

@pweil-
Copy link

pweil- commented Sep 21, 2016

rebased and addressed the remaining feedback in #11034. Closing this in favor of the new PR.

@pweil- pweil- closed this Sep 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants