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

Allows option policy factory variable inputs #2956

Merged
merged 4 commits into from
Sep 21, 2023

Conversation

jvanderhoof
Copy link
Contributor

@jvanderhoof jvanderhoof commented Sep 19, 2023

Desired Outcome

This PR fixes a small bug where optional variables which are not present in the request body cause an error to occur when attempting to save the factory variables.

Implemented Changes

Describe how the desired outcome above has been achieved with this PR. In
particular, consider:

  • Policy Factory now attempts to save variables at the intersection of those defined in the factory and those present in the request body.

Connected Issue/Story

N/A

Definition of Done

At least 1 todo must be completed in the sections below for the PR to be
merged.

Changelog

  • The CHANGELOG has been updated, or
  • This PR does not include user-facing changes and doesn't require a
    CHANGELOG update

Test coverage

  • This PR includes new unit and integration tests to go with the code
    changes, or
  • The changes in this PR do not require tests

Documentation

  • Docs (e.g. READMEs) were updated in this PR
  • A follow-up issue to update official docs has been filed here: [insert issue ID]
  • This PR does not require updating any documentation

Behavior

  • This PR changes product behavior and has been reviewed by a PO, or
  • These changes are part of a larger initiative that will be reviewed later, or
  • No behavior was changed with this PR

Security

  • Security architect has reviewed the changes in this PR,
  • These changes are part of a larger initiative with a separate security review, or
  • There are no security aspects to these changes

@jvanderhoof jvanderhoof force-pushed the allow-option-factory-inputs branch from 7e8c22f to a875f74 Compare September 19, 2023 15:13
@jvanderhoof jvanderhoof marked this pull request as ready for review September 19, 2023 15:36
@jvanderhoof jvanderhoof requested a review from a team as a code owner September 19, 2023 15:36
@jvanderhoof jvanderhoof force-pushed the allow-option-factory-inputs branch from a875f74 to e9dc20a Compare September 19, 2023 16:23
@@ -12,9 +12,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [1.20.0] - 2023-08-16

### Fixed
- Allow Factories with optional variables to save without error
Copy link

Choose a reason for hiding this comment

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

Lists should be surrounded by blank lines

john-odonnell
john-odonnell previously approved these changes Sep 20, 2023
Comment on lines 173 to 174
(schema_variables.keys & factory_variables.keys).each do |schema_variable|
next unless factory_variables.key?(schema_variable)
Copy link
Contributor

@john-odonnell john-odonnell Sep 20, 2023

Choose a reason for hiding this comment

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

nit: shouldn't have to check that schema_variable gets a positive response from factory_variables.key? because it's baked into the parent array (schema_variables.keys & factory_variables.keys).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. This was left over after I realized finding the intersection of keys was much more effective.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: These tests now ensure that omitted optional vars don't get in the way of a factory request - should we include a case to ensure an included optional var is picked up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. This bug made me realize the edge cases not covered despite "100%" branch coverage 😞.

This commit fixes an issue where an error was raised if an optional factory value was not present
in the request body.
The previous implementation was causing errors to fill up the logs because
Runit couldn't find a key file (which had been deleted).
Copy link
Contributor

@john-odonnell john-odonnell left a comment

Choose a reason for hiding this comment

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

LGTM!

@jvanderhoof
Copy link
Contributor Author

@adamouamani

variable_id = @uri.encode_www_form_component("#{variable_path}/#{factory_variable}")
# Only set secrets defined in the policy and present in factory payload
(schema_variables.keys & factory_variables.keys).each do |schema_variable|

Copy link

Choose a reason for hiding this comment

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

Extra empty line detected at block body beginning.

@codeclimate
Copy link

codeclimate bot commented Sep 21, 2023

Code Climate has analyzed commit 9603717 and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 2
Complexity 1

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 88.4% (-0.1% change).

View more on Code Climate.

@jvanderhoof jvanderhoof merged commit 7d7691c into master Sep 21, 2023
@jvanderhoof jvanderhoof deleted the allow-option-factory-inputs branch September 21, 2023 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants