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

Use YAML.load to load classes beyond the basic types #6596

Merged

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Jan 9, 2020

https://bugzilla.redhat.com/show_bug.cgi?id=1789153

Followup to ManageIQ/manageiq#19701

At the very least, we know MiqExpression objects are in the YAML but other
custom classes could be in the YAML so we need to use YAML.load to return to the
prior behavior.

https://bugzilla.redhat.com/show_bug.cgi?id=1789153

Followup to ManageIQ/manageiq#19701

At the very least, we know MiqExpression objects are in the YAML but other
custom classes could be in the YAML so we need to use YAML.load to return to the
prior behavior.
@jrafanie jrafanie force-pushed the fix_invalid_usage_of_yaml_safe_load branch from 7675a05 to 00cfceb Compare January 9, 2020 16:33
@jrafanie
Copy link
Member Author

jrafanie commented Jan 9, 2020

@himdel it's green now, thanks for the good 👀

@miq-bot
Copy link
Member

miq-bot commented Jan 9, 2020

Checked commit jrafanie@00cfceb with ruby 2.5.5, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 4 offenses detected

app/controllers/application_controller/miq_request_methods.rb

spec/controllers/application_controller/report_data_spec.rb

spec/support/report_helper.rb

@@ -168,7 +168,7 @@ def set_pre_prov_vars

unless %w[image_miq_request_new miq_template_miq_request_new].include?(params[:pressed])
path_to_report = ManageIQ::UI::Classic::Engine.root.join("product", "views", provisioning_report).to_s
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming all of these are controlled by us? That is, a user (via the UI/API) can't get their own files into this directory?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, those are ours manageiq-ui-classic/product/views, and provisioning_report will always return either ProvisionCloudTemplates.yaml or ProvisionInfraTemplates.yaml

@@ -168,7 +168,7 @@ def set_pre_prov_vars

unless %w[image_miq_request_new miq_template_miq_request_new].include?(params[:pressed])
path_to_report = ManageIQ::UI::Classic::Engine.root.join("product", "views", provisioning_report).to_s
@view = MiqReport.new(YAML.safe_load(File.open(path_to_report), [Symbol]))
@view = MiqReport.new(YAML.load(File.open(path_to_report)))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe not for this PR, but this opens a file handle and then never closes it. Perhaps instead use YAML.load_file or MiqReport.new(File.open(path_to_report) { |f| YAML.load(f) })

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, or File.read

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll do a followup PR

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll use File.read in case we want to enumerate the possible classes and change this back to safe_load since there is no YAML.safe_file_load.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense, thanks :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened a PR... note, I found other instances of the same pattern:
#6597

@himdel himdel self-assigned this Jan 9, 2020
@himdel himdel merged commit 7f0c10d into ManageIQ:master Jan 9, 2020
@himdel himdel added this to the Sprint 128 Ending Jan 20, 2020 milestone Jan 9, 2020
jrafanie added a commit to jrafanie/manageiq-ui-classic that referenced this pull request Jan 9, 2020
@jrafanie jrafanie deleted the fix_invalid_usage_of_yaml_safe_load branch January 9, 2020 20:20
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.

4 participants