Skip to content

Commit

Permalink
Merge pull request #547 from dgraeber/fix/metadata-parse
Browse files Browse the repository at this point in the history
adding conversion for metadata that is string wrapped json
  • Loading branch information
dgraeber authored Apr 8, 2024
2 parents 701d37e + 4469b62 commit 0c30cac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit 0c30cac

Please sign in to comment.