Skip to content

Commit e9040e0

Browse files
committed
change the use of environment variables
1 parent de2d7b0 commit e9040e0

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

app/.env.example renamed to .env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ DB_PORT=5432
66
USERNAME="piccolo"
77
PASSWORD="piccolo123"
88
9-
ENCRIPTION_KEY="\xb7(\xa5\xa6\xa4&\xeb\x8eI\xfe_Y\x16\x12\xf4\xf4\xa8|\xc6#\xd1\x02\xa2s\x03]\xea\x12\xb9\xf1\xa2\xb3"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.11
1+
FROM python:3.11-slim
22

33
WORKDIR /code
44

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ git clone https://github.com/piccolo-orm/piccolo-admin-docker.git
1111
Creating an `.env` file.
1212

1313
```bash
14-
cd app
1514
cp .env.example .env && rm .env.example
16-
cd ..
1715
```
16+
1817
Creating a Docker image.
1918

2019
```bash
@@ -24,7 +23,7 @@ docker build -t piccolo_admin .
2423
Running a Docker image (use the `--network=host` flag for an existing database from the local machine).
2524

2625
```bash
27-
docker run -d --network=host --name admin_container piccolo_admin
26+
docker run --env-file .env -d --network=host --name admin_container piccolo_admin
2827
```
2928

3029
After site is running log in as admin user on [localhost:8000](http://localhost:8000/admin/) and use legacy database.

app/main.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22
import os
33

4-
from dotenv import find_dotenv, load_dotenv
54
from hypercorn import Config
65
from hypercorn.asyncio import serve
76
from piccolo.apps.user.tables import BaseUser
@@ -20,9 +19,6 @@
2019
DB = SQLiteEngine()
2120

2221

23-
load_dotenv(find_dotenv())
24-
25-
2622
class Sessions(SessionsBase, db=DB):
2723
pass
2824

@@ -75,6 +71,9 @@ async def main():
7571
for table_class in found_tables:
7672
table_class._meta._db = db
7773

74+
# create new encription key for MFA
75+
encryption_key = XChaCha20Provider.get_new_key()
76+
7877
app = create_admin(
7978
found_tables,
8079
auth_table=User,
@@ -83,9 +82,7 @@ async def main():
8382
mfa_providers=[
8483
AuthenticatorProvider(
8584
encryption_provider=XChaCha20Provider(
86-
encryption_key=os.environb[b"ENCRIPTION_KEY"]
87-
.decode("unicode-escape")
88-
.encode("latin-1")
85+
encryption_key=encryption_key,
8986
),
9087
secret_table=AuthenticatorSecret,
9188
),

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ aiosqlite
33
hypercorn
44
piccolo
55
piccolo-admin
6-
piccolo_api[authenticator,pynacl]
7-
python-dotenv
6+
piccolo_api[authenticator,pynacl]

0 commit comments

Comments
 (0)