Skip to content

Bug fix for loading hashmap inputs consistently - #5446

Merged
clintoncwolfe merged 5 commits into
masterfrom
nm/fix-input-hash-access
Apr 7, 2021
Merged

clintoncwolfe merged 5 commits into
masterfrom
nm/fix-input-hash-access

Conversation

@Nik08

@Nik08 Nik08 commented Mar 31, 2021 •

Copy link
Copy Markdown
Contributor

Signed-off-by: Nikita Mathur nikita.mathur@chef.io

Description

Issues:

  1. The inputs loaded from external file and metadata file were read in two different formats by InSpec, one hash with symbol keys and another hash with string as keys
  2. Hash inputs loaded using runner API and profile DSL also, returns success only in one of the formats.

Impact of solution:

This approach will solve reading inputs irrespective of their formats, which enables using hashes inside InSpec controls in any way preferred.

Related Issue

Fixes #4057

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New content (non-breaking change)
  • Breaking change (a content change which would break existing functionality or processes)

Checklist:

  • I have read the CONTRIBUTING document.

…adata file

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
@Nik08
Nik08 requested review from Vasu1105 and clintoncwolfe March 31, 2021 06:16
@Nik08
Nik08 requested a review from a team as a code owner March 31, 2021 06:16
@netlify

netlify Bot commented Mar 31, 2021 •

Copy link
Copy Markdown

@Nik08
Nik08 force-pushed the nm/fix-input-hash-access branch from c1664e9 to d0c17b3 Compare March 31, 2021 06:57
…sh type

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
@Nik08
Nik08 force-pushed the nm/fix-input-hash-access branch from d0c17b3 to a55b083 Compare March 31, 2021 07:05
@clintoncwolfe clintoncwolfe added Component: Inputs Parameter Input system (formerly attributes) Aspect: Correctness Is it actually right? Does it match a specification? labels Apr 2, 2021
@clintoncwolfe

Copy link
Copy Markdown
Contributor

@aaronlippold Does this approach - using HashWithIndifferentAccess - work for your use case?

Comment thread lib/inspec/input_registry.rb Outdated
data.inputs.each do |input_name, input_value|
evt = Inspec::Input::Event.new(
value: input_value,
value: input_value.is_a?(Hash) ? Thor::CoreExt::HashWithIndifferentAccess.new(input_value) : input_value,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For consistency, I wonder if we should make a similar change in bind_inputs_from_runner_api? Testing that would be difficult, however.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes for consistency that seems right. Let me look into the testing front for this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a method to handle this conversion input_value.is_a?(Hash) ? Thor::CoreExt::HashWithIndifferentAccess.new(input_value) : input_value so that we can just call that method wherever required and code will be maintainable ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes these checks could be re-used by having just a method :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@clintoncwolfe I observed this issue not only additionally happens for runner api input but also for other ways of input. Will try an alternate solution which could work for all the input types, rather than handling it in each method definition for different input types. Hope that would be a better solution.

@aaronlippold

Copy link
Copy Markdown
Collaborator

I'm not sure given that there isn't really a description of the change. Can you elaborate on what is being updated and remind me which use case we're talking about :-)

Nik08 added 2 commits April 5, 2021 14:41
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
@Nik08 Nik08 changed the title Bug fix for loading hashmap inputs consistently from external and metadata file Bug fix for loading hashmap inputs consistently Apr 5, 2021
@Nik08
Nik08 requested a review from clintoncwolfe April 7, 2021 09:07
@Nik08
Nik08 force-pushed the nm/fix-input-hash-access branch from 41c696c to 6cc4fc9 Compare April 7, 2021 09:13
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
@Nik08
Nik08 force-pushed the nm/fix-input-hash-access branch from 6cc4fc9 to 82e1267 Compare April 7, 2021 10:39

@clintoncwolfe clintoncwolfe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great testing - very good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Aspect: Correctness Is it actually right? Does it match a specification? Component: Inputs Parameter Input system (formerly attributes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hashes in inputs from inspec.yml and inputs file loaded differently

4 participants