fix(driver): coerce OpenStack auth/config values to strings before Fog#239
Open
fix(driver): coerce OpenStack auth/config values to strings before Fog#239
Conversation
4805be1 to
fde979b
Compare
a3e2995 to
6280350
Compare
When clouds.yaml or .kitchen.yml provides scalar values such as
`identity_api_version: 3` (Integer) or numeric IDs, fog-openstack
crashes during authentication because `Fog::OpenStack::Auth::Token.build`
calls `=~` on the value:
NoMethodError: undefined method '=~' for an instance of Integer
Two layers of coercion are applied:
1. `Clouds` ingestion (clouds.rb): values mapped from clouds.yaml,
secure.yaml, and `OS_*` env vars are normalized to strings via
`STRING_CONFIG_KEYS`/`normalize_config_value` before being merged
into `config`.
2. Fog handoff (openstack.rb): `openstack_server` wraps every value
with `normalize_fog_setting`, which converts known string-typed
Fog auth/config keys (listed in `FOG_STRING_SETTINGS`) to strings
while preserving `nil` so that downstream "missing required
argument" validation still fires.
Additionally, `openstack_identity_api_version` requires special
handling. Fog::Service#coerce_options re-coerces any value where
`value.to_s.to_i.to_s == value.to_s` back to an Integer, undoing the
String coercion before Token.build sees it. The value is now
prefixed with "v" (e.g. `3` -> `"v3"`, `2`/`2.0` -> `"v2.0"`), which
prevents Fog's coercion round-trip while still satisfying
Token.build's `/(v)*2(\.0)*/i` regex check for v2 detection.
Regression specs added:
- spec/kitchen/driver/openstack/clouds_spec.rb verifies that
`translate_cloud_config` coerces non-string scalars for known
string keys.
- spec/kitchen/driver/openstack_spec.rb verifies that
`openstack_server` coerces numeric values for fog string settings
and that `identity_api_version` is v-prefixed so it survives
Fog::Service#coerce_options.
Signed-off-by: Lance Albertson <lance@osuosl.org>
6280350 to
fec1197
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
YAML parsing can return non-string scalars (for example
identity_api_version: 3 -> Integer). fog-openstack expects several
auth/config fields as strings and calls regex matching on
openstack_identity_api_version, which raised:
undefined method '=~' for an instance of Integer
during authentication.
Fix this in two layers so values from any source are normalized:
Normalize values when ingesting from clouds.yaml and OS_* env vars in
Kitchen::Driver::Openstack::Clouds, covering the keys mapped by
CLOUDS_YAML_AUTH_MAP and CLOUDS_YAML_TOP_MAP.
Normalize values at the final Fog handoff in Kitchen::Driver::Openstack
via FOG_STRING_SETTINGS and normalize_fog_setting, so values supplied
directly via .kitchen.yml (or any other source) are also coerced.
Nil values are preserved so Fog's required-argument validation still
fires as before.
Add regression tests:
openstack_domain_id, and openstack_identity_api_version.
Fog server definition.
Signed-off-by: Lance Albertson lance@osuosl.org
Description
Please describe what this change achieves
Issues Resolved
List any existing issues this PR resolves, or any Discourse or
StackOverflow discussions that are relevant
Type of Change
Our release process assumes you are using Conventional Commit messages.
The most important prefixes you should have in mind are:
_fix_: which represents bug fixes, and correlates to a SemVer patch._feat_: which represents a new feature, and correlates to a SemVer minor._feat!_:, orfix!:,refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a major version change.If you have not included a conventional commit message this can be fixed on merge.
Check List