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

adding conversion for metadata that is string wrapped json #547

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
### Changes

### Fixes
- metadata sourced from file to the os env cannot be parsed if not compliant json, adding code to check for this

## v3.3.0 (2024-04-01)

Expand Down
10 changes: 7 additions & 3 deletions seedfarmer/mgmt/metadata_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ def _read_metadata_file(mms: ModuleMetadataSupport) -> Dict[str, Any]:
def _read_metadata_env_param(mms: ModuleMetadataSupport) -> Dict[str, Any]:
p = mms.metadata_file_name()
if p in os.environ:
env_data = os.getenv(p)
try:
env_data = os.getenv(p)
return cast(Dict[str, Any], json.loads(str(env_data)))
except Exception:
_logger.info("Cannot parse the file env metadata")
except ValueError:
# When echoing single quotes from env parameter, cannot convert to json.
# Poor man's fix
return cast(Dict[str, Any], json.loads(env_data.replace("'", '"'))) # type: ignore
except Exception as e:
_logger.info("Cannot parse the file env metadata %s due to %s", p, e)
return {}
else:
_logger.info("Cannot find existing metadata env param at %s, moving on", p)
Expand Down