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

Implemented secret handling #12

Merged
merged 2 commits into from
Mar 23, 2023
Merged

Implemented secret handling #12

merged 2 commits into from
Mar 23, 2023

Conversation

Radiergummi
Copy link
Contributor

As promised in #11, this PR adds support for secret files.

Many container orchestrators provide a way to inject secret configuration values into application securely by mounting read-only files into their file system; the application is expected to read those files upon starting up.
These changes modify configuration loading to:

  1. Try and read a configuration value from an environment variable FOO, if defined
  2. Try and read a file path from an environment variable FOO_PATH, if defined
  3. Try and read the file path from the variable, if it exists

If all three variants fail, and no default value is passed, a KeyError is raised. This should provide solid configuration handling and allow to specify all values as environment variables or secret files, with the environment always taking precedence - so existing installations are not affected.

@sonarcloud
Copy link

sonarcloud bot commented Mar 20, 2023

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
No Duplication information No Duplication information

access_token = load_env('ACCESS_TOKEN')
SCRAPE_INTERVAL = load_env('SCRAPE_INTERVAL', 30)
except KeyError as error:
print(str(error)[1:-1])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit obtuse, but Python will put quotes around the message of KeyError - so we strip the first and last character to have a proper error message printed to the console (foo instead of 'foo')

@wacken89
Copy link
Owner

Thank you for your valuable contribution. We truly appreciate your efforts, and we will make sure to merge your PR as soon as possible.

@wacken89 wacken89 merged commit 4b16073 into wacken89:master Mar 23, 2023
@Radiergummi
Copy link
Contributor Author

@wacken89 nice! Could you also do a new released soon? That would be great. Thank you for merging!

@wacken89
Copy link
Owner

Sure, I'm going to do it. I just need to update the readme on how to use files

@Radiergummi
Copy link
Contributor Author

@wacken89 Just added a new PR with the Readme update :)

@wacken89 wacken89 mentioned this pull request Mar 24, 2023
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.

2 participants