File tree 6 files changed +25
-20
lines changed
6 files changed +25
-20
lines changed Original file line number Diff line number Diff line change 1
1
import os
2
- from . settings import *
2
+
3
3
from .get_token import get_token
4
+ from .settings import *
4
5
5
6
# SECURITY WARNING: don't run with debug turned on in production!
6
7
DEBUG = True
37
38
'PASSWORD' : DBPASS ,
38
39
}
39
40
}
40
- get_token ()
41
+ get_token ()
Original file line number Diff line number Diff line change 1
1
import os
2
- from azure . identity import DefaultAzureCredential
2
+
3
3
import django .conf as conf
4
+ from azure .identity import DefaultAzureCredential
4
5
5
6
# This is for demo purposes. Consider using Django middleware to hook into req/resp processing.
6
7
7
8
def get_token ():
8
9
if 'RUNNING_IN_PRODUCTION' in os .environ or 'USE_REMOTE_POSTGRESQL' in os .environ :
9
- # Azure hosted PostgreSQL server, refresh token that becomes password.
10
+ # Azure hosted PostgreSQL server, refresh token that is used as the PostgreSQL password.
10
11
# Get token for Azure Database for PostgreSQL
11
12
azure_credential = DefaultAzureCredential ()
12
13
token = azure_credential .get_token ("https://ossrdbms-aad.database.windows.net/.default" )
13
14
conf .settings .DATABASES ['default' ]['PASSWORD' ] = token .token
14
15
else :
15
16
# Local PostgreSQL server, read password from environment variable.
16
17
conf .settings .DATABASES ['default' ]['PASSWORD' ] = os .environ ['DBPASS' ]
17
- return
18
+ return
Original file line number Diff line number Diff line change 1
1
import os
2
- from .settings import *
2
+ import secrets
3
+
3
4
from .get_token import get_token
5
+ from .settings import *
4
6
5
7
# Configure allowed host names that can be served and trusted origins for Azure Container Apps.
6
8
ALLOWED_HOSTS = ['.azurecontainerapps.io' ] if 'RUNNING_IN_PRODUCTION' in os .environ else []
11
13
# SECURITY WARNING: keep the secret key used in production secret!
12
14
# Use this py command to create secret
13
15
# python -c 'import secrets; print(secrets.token_hex())'
14
- SECRET_KEY = os .getenv ('AZURE_SECRET_KEY' )
16
+ SECRET_KEY = os .getenv ('AZURE_SECRET_KEY' ) or secrets . token_hex ()
15
17
16
18
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
17
19
25
27
'PASSWORD' : 'set with get_token()'
26
28
}
27
29
}
28
- get_token ()
30
+ get_token ()
Original file line number Diff line number Diff line change
1
+ import os
1
2
from pathlib import Path
2
- import os
3
3
4
4
# Build paths inside the project like this: BASE_DIR / 'subdir'.
5
5
BASE_DIR = Path (__file__ ).resolve ().parent .parent
Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ az acr build \
63
63
--image $IMAGE_NAME $CODE_LOCATION
64
64
echo " INFO:: Completed building image: $IMAGE_NAME ."
65
65
66
+ # Create a user-assigned managed identity named my-ua-managed-id to access database
67
+
68
+ az identity create \
69
+ --name my-ua-managed-id \
70
+ --resource-group $RESOURCE_GROUP
71
+ echo " INFO:: Created user-assigned managed identity named my-ua-managed-id in resource group: $RESOURCE_GROUP ."
72
+
66
73
# Create PostgreSQL database server.
67
74
68
75
az postgres flexible-server create \
@@ -94,13 +101,6 @@ az postgres flexible-server db create \
94
101
--database-name restaurants_reviews
95
102
echo " INFO:: Completed creating database restaurants_reviews on PostgreSQL server: $POSTGRESQL_NAME ."
96
103
97
- # Create a user-assigned managed identity named my-ua-managed-id to access database
98
-
99
- az identity create \
100
- --name my-ua-managed-id \
101
- --resource-group $RESOURCE_GROUP
102
- echo " INFO:: Created user-assigned managed identity named my-ua-managed-id in resource group: $RESOURCE_GROUP ."
103
-
104
104
# Add user assigned managed identity as role on server (requires rdbms-connect extension for token)
105
105
106
106
az postgres flexible-server execute \
Original file line number Diff line number Diff line change 1
- import uuid
2
1
import os
2
+ import uuid
3
+
4
+ from azureproject .get_token import get_token
5
+ from django .contrib import messages
6
+ from django .db .models import Avg , Count
3
7
from django .http import Http404 , HttpResponseRedirect
4
8
from django .shortcuts import render
5
- from django .db .models import Avg , Count
6
9
from django .urls import reverse
7
10
from django .utils import timezone
8
- from django .contrib import messages
9
11
from requests import RequestException , exceptions
10
- from azureproject .get_token import get_token
11
12
12
13
from restaurant_review .models import Restaurant , Review
13
14
You can’t perform that action at this time.
0 commit comments