-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add environment verification #16
Open
adamhb123
wants to merge
1
commit into
ComputerScienceHouse:master
Choose a base branch
from
adamhb123:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
|
||
from os import getenv | ||
from pprint import pprint | ||
import validators | ||
|
||
|
||
def get_app_envvar(app, var_name): | ||
return None if not var_name in app.config else app.config[var_name] | ||
|
||
|
||
def is_app_debugging(app): | ||
return get_app_envvar(app, 'DEBUG') or get_app_envvar(app, 'TESTING') | ||
|
||
|
||
def verify_environment(print_results=False): | ||
""" | ||
Verifies the various environment variables required for app operation. | ||
|
||
Improperly (un)set boolean values will default to False. | ||
""" | ||
def _as_bool(input): | ||
return True if type(input) == str and input.lower().strip() == 'true' else False | ||
# URL where game thumbnails are hosted | ||
IMAGE_URL = getenv('IMAGE_URL') | ||
# Set to whatever 'Stuff` database will be called | ||
MONGODB_DATABASE = getenv('MONGODB_DATABASE') | ||
# Set to anything, but keep it a secret | ||
SECRET_KEY = getenv('SECRET_KEY') | ||
# Set to `http` for CSH auth | ||
PREFERRED_URL_SCHEME = getenv('URL_SCHEME', 'http') | ||
# Set to localhost:5000 for use with CSH auth | ||
SERVER_NAME = getenv('SERVER_NAME', 'localhost:5000') | ||
|
||
''' OIDC ''' | ||
OIDC_CLIENT_ID = getenv('OIDC_CLIENT_ID') | ||
OIDC_CLIENT_SECRET = getenv('OIDC_CLIENT_SECRET') | ||
OIDC_ISSUER = getenv('OIDC_ISSUER') | ||
|
||
''' S3 ''' | ||
S3_BUCKET = getenv('S3_BUCKET') | ||
S3_KEY = getenv('S3_KEY') | ||
S3_SECRET = getenv('S3_SECRET') | ||
S3_ENDPOINT = getenv('S3_ENDPOINT') | ||
|
||
''' The below environment variables exist, but do not need to be set/modified ''' | ||
WTF_CSRF_ENABLED = _as_bool(getenv('WTF_CSRF_ENABLED', False)) | ||
comb_server_url = f'{PREFERRED_URL_SCHEME}://{SERVER_NAME}' | ||
tests = {'IMAGE_URL': validators.url(IMAGE_URL), | ||
'MONGODB_DATABASE': validators.truthy(MONGODB_DATABASE), | ||
'SECRET_KEY': validators.truthy(SECRET_KEY), | ||
'IMAGE_URL': validators.truthy(IMAGE_URL), | ||
'{PREFERRED_URL_SCHEME}://{SERVER_NAME}': | ||
True if validators.url(comb_server_url) | ||
else 'False (the combination of PREFERRED_URL_SCHEME and SERVER_NAME appears to be an invalid url...)', | ||
'OIDC_CLIENT_ID': validators.truthy(OIDC_CLIENT_ID), | ||
'OIDC_CLIENT_SECRET': validators.truthy(OIDC_CLIENT_SECRET), | ||
'OIDC_ISSUER': validators.truthy(OIDC_ISSUER), | ||
'S3_BUCKET': validators.truthy(S3_BUCKET), | ||
'S3_KEY': validators.truthy(S3_KEY), | ||
'S3_SECRET': validators.truthy(S3_SECRET), | ||
'S3_ENDPOINT': validators.truthy(S3_ENDPOINT)} | ||
if print_results: | ||
print('Environment verification results: ') | ||
pprint(tests) | ||
return tests | ||
|
||
|
||
if __name__ == '__main__': | ||
verify_environment(print_results=True) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from stuff import app as application | ||
|
||
if __name__ == '__main__': | ||
# For additional debugging info, set the env var: FLASK_DEBUG=True | ||
application.run() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we drop these random lines? Sorry