Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
AppElent committed Feb 17, 2023
1 parent 2cb4d20 commit 352bd12
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions django/api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.env
db.sqlite3
variables.txt

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
5 changes: 5 additions & 0 deletions django/api/api/modules/AzureAppConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ def load(self, endpoint, app, label):
key_vault_options = AzureAppConfigurationKeyVaultOptions(credential=credential)
self._config = load_provider(endpoint=endpoint, credential=credential, key_vault_options=key_vault_options, selects=selects, trimmed_key_prefixes=trimmed_key_prefixes)
keys = self._config.keys()
f = open("variables.txt", "w")
for key in keys:
print('Setting environment variable ' + key)
os.environ[key] = self._config[key]
f.write(key + '=' + self._config[key] + '\r\n')
f.close()
print('--- AzureAppConfiguration loaded successfully ---')
return self._config
# except Exception as e:
# print('!!!!! Azure App Configuration could not be loaded')
# print(e)
else:
return None

def get_config(self):
return self._config
Expand Down
13 changes: 8 additions & 5 deletions django/api/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
from .modules.AzureCosmosDb import AzureCosmosDb
from .modules.Firebase import Firebase
ENVIRONMENT_CONFIG = AzureAppConfiguration.load(os.getenv("AZURE_APP_CONFIGURATION_ENDPOINT"), "django-api", os.getenv("ENVIRONMENT") or "LOCAL")
AzureCosmosDb.load(ENVIRONMENT_CONFIG['cosmos-access-key'])
Firebase.load(ENVIRONMENT_CONFIG['firebase-creds'])
if ENVIRONMENT_CONFIG:
AzureCosmosDb.load(ENVIRONMENT_CONFIG.get('cosmos-access-key'))
Firebase.load(ENVIRONMENT_CONFIG.get('firebase-creds'))


#
Expand Down Expand Up @@ -66,7 +67,8 @@
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("SECRET_KEY", default=get_random_secret_key())
SECRET_KEY = get_random_secret_key() if not ENVIRONMENT_CONFIG else ENVIRONMENT_CONFIG.get('django-secret')
#os.getenv("SECRET_KEY", default=get_random_secret_key())

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False if ENVIRONMENT == "PRODUCTION" else True
Expand Down Expand Up @@ -165,14 +167,15 @@
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

if os.getenv("DATABASE_URL") or ENVIRONMENT_CONFIG.get('database-url'):
if os.getenv("DATABASE_URL") or ENVIRONMENT_CONFIG.get('database-server-url'):
# DATABASE_URL = os.getenv('postgresql-database-url') + '/django-api'
# os.environ['DATABASE_URL'] = DATABASE_URL
# DATABASES = {}
# DATABASES['default'] = dj_database_url.config(conn_max_age=600)
DATABASE_URL = ENVIRONMENT_CONFIG.get('database-server-url') + ENVIRONMENT_CONFIG.get('database-name')
DATABASES = {
'default': dj_database_url.config(
default=ENVIRONMENT_CONFIG.get('database-url'),
default=DATABASE_URL,
conn_max_age=600,
conn_health_checks=True,
)
Expand Down
3 changes: 2 additions & 1 deletion django/api/oauth/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class OauthConfig(AppConfig):
name = "oauth"

def ready(self):
AzureCosmosDb.load(settings.ENVIRONMENT_CONFIG['cosmos-access-key'])
if settings.ENVIRONMENT_CONFIG:
AzureCosmosDb.load(settings.ENVIRONMENT_CONFIG.get('cosmos-access-key'))

0 comments on commit 352bd12

Please sign in to comment.