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

[go] parse environment variables #505

Merged
merged 3 commits into from
Jan 3, 2022
Merged

[go] parse environment variables #505

merged 3 commits into from
Jan 3, 2022

Conversation

lucasreed
Copy link
Contributor

Also changed in this PR:

  • make conversion from v1 to v2 schema a private function since everything should happen with the OpenV2 function.
  • changed all klog.Fatal() calls in the cmd package to red error output with exit code of 1 instead
  • reckoner convert command no longer calls the ConvertV1toV2 function and instead simply uses OpenV2 function.

Comment on lines +274 to +284
// Marshal back here just so we can populate the env vars without any yaml comments present
data, _ = yaml.Marshal(courseFile)
data, err = parseEnv(data)
if err != nil {
return nil, fmt.Errorf("failed to parse env variables: %v", err)
}
err = yaml.Unmarshal(data, courseFile)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal file after parsing env vars: %s", err.Error())
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason we are doing this unmarshal -> marshal -> unmarshal again is because if we parsed environment variables before the first unmarshal, it would also error out on any YAML comments that mention an environment variable. When we do the first unmarshal, all comments are stripped so we can marshal back to bytes, populate all the env vars and then unmarshal into our struct again.

Copy link
Member

Choose a reason for hiding this comment

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

That's actually really cool. That was fairly annoying in the python version at one point.

@sonarcloud
Copy link

sonarcloud bot commented Jan 3, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@lucasreed lucasreed merged commit 0acad4c into master Jan 3, 2022
@lucasreed lucasreed deleted the lr/parse_env_vars branch January 3, 2022 20:52
@lucasreed lucasreed linked an issue Jan 4, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Go Version] Parse environment variables in course
2 participants