Skip to content
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

pkg/asset/installconfig: Add input validation #350

Merged
merged 1 commit into from
Sep 27, 2018

Conversation

wking
Copy link
Member

@wking wking commented Sep 27, 2018

By switching to survey.Question which has room for a validator. I've also pushed the Required validator up into the per-property config, so we don't bake requiredness into UserProvided itself.

/assign @crawford

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 27, 2018
"us-east-1": "N. Virginia",
"us-east-2": "Ohio",
"us-west-1": "N. California",
"us-west-2": "Oregon",
Copy link
Member

Choose a reason for hiding this comment

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

This looks like something that could be a pain to keep up to date. How about a TODO or something to consider getting the list from an AWS API?

Copy link
Contributor

Choose a reason for hiding this comment

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

The installer doesn't require Internet access today. Reading this list from AWS would introduce that dependency.

Copy link
Member Author

Choose a reason for hiding this comment

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

How about a TODO or something to consider getting the list from an AWS API?

And also, AWS doesn't seem to provide an API for pulling the locations. Previous discussion starting here.

Copy link
Member

Choose a reason for hiding this comment

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

ok, thanks for the info and references

Options: validPlatforms,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
choice := ans.(string)
Copy link
Contributor

Choose a reason for hiding this comment

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

Put a check here? Just in case the dynamic type cast fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, this is correct. Programs should panic if there is a programmer error (vs an input error).

pkg/asset/installconfig/platform.go Show resolved Hide resolved
@@ -114,16 +147,26 @@ func (a *Platform) awsPlatform() (*asset.State, error) {

return assetStateForStringContents(
AWSPlatformType,
strings.Split(string(region.Contents[0].Data), " ")[0],
strings.SplitN(string(region.Contents[0].Data), " ", 2)[0],
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use a transformation (provided by Survey) instead of manipulating the user's choice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's use a transformation (provided by Survey) instead of manipulating the user's choice.

This sounded good, but turned out to be not a big win (I've done it in 362eda8 -> 5b3c205). It's nice to not have to muck with the response before we return it, but the validator fires before the tranform, so the validator needs to be able to handle both the short and long forms. I dunno why they didn't transform before validating...

pkg/asset/installconfig/platform.go Show resolved Hide resolved
@crawford
Copy link
Contributor

Looks good! Just a few questions/suggestions.

By switching to survey.Question which has room for a validator [1].
I've also pushed the Required validator up into the per-property
config, so we don't bake requiredness into UserProvided itself.

[1]: https://godoc.org/github.com/AlecAivazis/survey#Question
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
choice := regionTransform(ans).(string)
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 cast needed? regionTransform() returns a string.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this cast needed?

Yes.

regionTransform() returns a string.

No, regionTransform holds the result of TransformString, which is a Tranformer (and returns an interface{}). The string return is the function we're passing into TransformString as an argument, and we don't assign that function a name.

@crawford
Copy link
Contributor

/lgtm
/hold

Go ahead and cancel the hold if my last concern can be ignored.

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Sep 27, 2018
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: crawford, wking

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wking
Copy link
Member Author

wking commented Sep 27, 2018

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 27, 2018
@openshift-merge-robot openshift-merge-robot merged commit b8d7b01 into openshift:master Sep 27, 2018
@wking wking deleted the input-validation branch September 27, 2018 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants