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

Service Broker Create Service Instance Schema Validation #847

Merged
merged 9 commits into from
Jul 26, 2017

Conversation

ablease
Copy link

@ablease ablease commented Jul 11, 2017

As a Service Broker Author, when I register a plan with a create service instance schema, I get fast feedback when my schema is invalid.
#146276815, #146276747.

This PR follows from a previous PR.

Why

The Open Service Broker API is proposing allowing brokers to define JSON schema for their configuration parameters. This will allow tooling to validate parameters and UIs to auto generate forms.

What

This PR improves support for create instance schemas. Schemas are parsed during registration, and validated against the following criteria:

  1. Must conform to JSON schema Draft 04
  2. Must contain the following property "type": "object"
  3. Cannot be larger than 64kb
  4. Cannot contain external references
  5. Cannot contain file references

This PR address the 3 notes that were not implemented in the previous PR.

Notable things that are not in this PR but are addressed in future stories are:

  1. Update Service Instance Schema support.

Feedback appreciated!

  • I have viewed signed and have submitted the Contributor License Agreement

  • I have made this pull request to the master branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests on bosh lite

Samze and others added 9 commits July 11, 2017 12:13
[#145580731]

Signed-off-by: Alex Blease <[email protected]>
[#145580731]

Signed-off-by: Sam Gunaratne <[email protected]>
[#146276747]

Signed-off-by: Sam Gunaratne <[email protected]>
[#146276815]

Signed-off-by: Alex Blease <[email protected]>
[#146276747]

Signed-off-by: Luis Urraca <[email protected]>
[#146276747]

Signed-off-by: Luis Urraca <[email protected]>
@cfdreddbot
Copy link

Hey ablease!

Thanks for submitting this pull request! I'm here to inform the recipients of the pull request that you and the commit authors have already signed the CLA.

@cf-gitbot
Copy link

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/148656211

The labels on this github issue will be updated when the story is started.

@ljfranklin
Copy link
Contributor

Hey @ablease, we've prioritized this story and will take a look soon.

Copy link
Contributor

@aashah aashah left a comment

Choose a reason for hiding this comment

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

Disclaimer: We understand that the patterns we're requesting may not be consistent with some of the services code (such as CatalogPlan where we seem to have written another validation framework)...But we'd ideally like to modernize that part of the codebase as well eventually (PRs welcome).

We'd like to hear your thoughts on this before we merge.

@errors = VCAP::Services::ValidationErrors.new
validate_and_populate_create_instance(attrs)
validate_and_populate_create_instance(schema)
Copy link
Contributor

Choose a reason for hiding this comment

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

(This comment doesn't necessarily reflect changes form this specific PR, but the set of PRs)

We were surprised to see validations happening in the constructor. We are more familiar with the ActiveModel pattern of not explicitly implementing valid?, but rather including validate statements.

With this approach, we'd be able to convert the basic validations (data types, presence checks, length) with the validations provided by ActiveModel, and separate those from the content validations.

We're asking for this change to make the code consistent with recent V3 code where validations are important. Examples are in the messages/ folder

validate_schema(create_instance_path, create_instance_schema)
return unless errors.empty?

@create_instance = create_instance_schema
Copy link
Contributor

Choose a reason for hiding this comment

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

(This comment doesn't necessarily reflect changes form this specific PR, but the set of PRs)

We were also surprised to see the object being created conditionally through the validations. We'd prefer that the object's validity rely on valid?'s return value, rather than presence of an attribute.

end
end

def schema_validations
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is a prime example of being close to how ActiveModel validations are represented. See ActiveModel::Validations Custom Methods

@Samze
Copy link
Contributor

Samze commented Jul 26, 2017

Thanks for the feedback @aashah & @tcdowney. I agree that the lib/service validation code would benefit from being less custom.

Since submitting this we have added additional schema support which we are looking to raise as a PR in the next few days. This means that this branch and our head have diverged quite a lot.

To save us from having to modify this branch, merging, then fixing all the commits from our newer branch would you be willing to accept this PR and have us do the refactoring you suggest as part of our next PR Update Service Instance Schemas?

Let us know what you think.

Sam & @lurraca

@aashah
Copy link
Contributor

aashah commented Jul 26, 2017

Seems good to us! Feel free to close this PR.

@aashah
Copy link
Contributor

aashah commented Jul 26, 2017

Just kidding, let's just merge this PR right now. An upcoming PR can address some of the concerns above.

Whoever picks this up, feel free to just ignore the review (maybe don't dismiss it so it can stay as a reference)

@aashah aashah merged commit c9d1e5d into cloudfoundry:master Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants