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

(PDK-470) Validation of task metadata. #301

Merged
merged 11 commits into from
Oct 4, 2017
Merged

Conversation

bmjen
Copy link
Contributor

@bmjen bmjen commented Sep 26, 2017

I've refactored the task metadata validation to validate against a json-schema per recommendation/request from @garethr .

This PR also includes functionality to extend the MetadataSyntax validator to validate the tasks JSON as well.

@bmjen bmjen changed the title (PDK-470) Validation of task metadata. {WIP}(PDK-470) Validation of task metadata. Sep 26, 2017
@bmjen
Copy link
Contributor Author

bmjen commented Sep 26, 2017

I still need to fix-up the remaining spec tests as well as update the Acceptance tests to reflect the new changes to the info/debug output strings.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 92.08% when pulling 540aa39 on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@@ -0,0 +1,65 @@
module PDK
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to have the schema as a separate file instead of embedded? That way other tools can consume it

Copy link
Contributor

Choose a reason for hiding this comment

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

Also means the schema file itself can be validated

Copy link
Contributor

Choose a reason for hiding this comment

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

There's been some discussion on tech-discuss and I've proposed hosting a JSON Schema for task (and module) metadata on the Forge. I've got a PR for that with just a placeholder so we could move this schema into that PR:

https://github.com/puppetlabs/puppet-forge-api/pull/371

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively we could publish at http://schemastore.org/json/

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Because two sources of truth is rarely a good thing. Pick one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then I'll easily pick the one we have direct control over.

Seems like the best approach would be to host it ourselves and just add it to the schemastore catalog.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

@@ -45,7 +45,7 @@ def self.parse_targets(options)
skipped << target if target_list.flatten.empty?
target_list
elsif File.file?(target)
if target.eql? pattern
if Array(pattern).flatten.include? target
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to call flatten after Array() unless pattern is going to be a multidimensional array (Array([1, 2, 3]) => [1, 2, 3])

module PDK
module Validate
module TaskMetadataSchema
SCHEMA = '{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please point here to the canonical version of this schema, so that there can be no doubt about which copy is the primary.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.9%) to 91.519% when pulling 7882d58 on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.9%) to 91.519% when pulling f418f51 on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

raise PDK::CLI::FatalError, _('Unable to download Task Metadata Schema file. Please check internet connectivity and retry this action.')
end
end
JSON.parse(schema)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider rescuing JSON parse error here (and logging a nicer error message) in case the schema is corrupted somehow

@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'tty-spinner', '0.5.0'
spec.add_runtime_dependency 'tty-prompt', '0.13.1'
spec.add_runtime_dependency 'json_pure', '~> 2.1.0'
spec.add_runtime_dependency 'json-schema', '2.8.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 there a ticket or PR for adding this to the vanagon repo?

Copy link
Contributor

Choose a reason for hiding this comment

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

(and it's runtime dependencies)

@scotje
Copy link
Contributor

scotje commented Oct 3, 2017

Left a couple small comments but overall looking good @bmjen !

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.01%) to 91.372% when pulling 0675dd8 on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.009%) to 91.377% when pulling 7d194cf on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.009%) to 91.377% when pulling c305f72 on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 92.658% when pulling 2b713f4 on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 92.658% when pulling 3abecd2 on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@bmjen bmjen changed the title {WIP}(PDK-470) Validation of task metadata. (PDK-470) Validation of task metadata. Oct 4, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 92.658% when pulling d01313c on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 92.769% when pulling 2b7ab62 on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 92.769% when pulling e8ceeaa on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 92.769% when pulling 3fd7d81 on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

rescue OpenSSL::SSL::SSLError => e
ssl_failures += 1

unless ssl_failures < 2 && Gem.win_platform? && PDK::Util.gem_install?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this mean that on a Windows system with a package install getting SSL errors, we'll retry forever?

Copy link
Contributor

@scotje scotje Oct 4, 2017

Choose a reason for hiding this comment

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

See ssl_failures variable. Although we might need to do an explicit "begin" context instead of rescuing the whole method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, I see the counter. I misread the conditional itself.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.9%) to 92.472% when pulling 317a28c on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.9%) to 92.472% when pulling 854f31a on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.06%) to 92.324% when pulling b772c9b on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.06%) to 92.324% when pulling 7d6e35f on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.06%) to 92.324% when pulling 7d6e35f on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.06%) to 92.324% when pulling 5a8fc84 on bmjen:pdk-470 into e205ea5 on puppetlabs:tasks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.06%) to 92.328% when pulling dc28a9d on bmjen:pdk-470 into d324544 on puppetlabs:tasks.

@bmjen bmjen merged commit 166de73 into puppetlabs:tasks Oct 4, 2017
@bmjen bmjen added the feature label Oct 5, 2017
@bmjen bmjen deleted the pdk-470 branch November 14, 2017 21:12
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.

6 participants