Skip to content

Commit 948baa2

Browse files
author
lijianguo
committed
chore(passport): modify boot shell
1 parent 6af4568 commit 948baa2

5 files changed

Lines changed: 23 additions & 10 deletions

File tree

charts/passport/templates/_helpers.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ env:
3232
valueFrom:
3333
fieldRef:
3434
fieldPath: metadata.namespace
35+
- name: ADMIN_USERNAME
36+
value: {{ .Values.admin_username | default "admin" | quote }}
37+
- name: ADMIN_PASSWORD
38+
value: {{ .Values.admin_password | default "admin" | quote }}
39+
- name: ADMIN_EMAIN
40+
value: {{ .Values.admin_email | default "admin@email.com" | quote }}
3541
{{- if (.Values.database_url) }}
3642
- name: DRYCC_DATABASE_URL
3743
valueFrom:

charts/passport/templates/passport-ingress.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ spec:
3030
tls:
3131
- secretName: drycc-passport-certificate-auto
3232
hosts:
33-
- drycc.{{ .Values.global.platform_domain }}
33+
- drycc-passport.{{ .Values.global.platform_domain }}
3434
{{- end }}
3535
{{- end }}

rootfs/api/management/commands/create_oauth2_application.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import base64
32
from django.contrib.auth.models import User
43
from django.core.management.base import BaseCommand
54
from oauth2_provider.models import Application
@@ -9,17 +8,19 @@ class Command(BaseCommand):
98
"""Management command for create Oauth2 application"""
109

1110
def handle(self, *args, **options):
12-
client_id = base64.b64decode(os.environ.get(
13-
'SOCIAL_AUTH_DRYCC_CONTROLLER_KEY')) if os.environ.get(
11+
client_id = os.environ.get(
12+
'SOCIAL_AUTH_DRYCC_CONTROLLER_KEY') if os.environ.get(
1413
'SOCIAL_AUTH_DRYCC_CONTROLLER_KEY') else None
15-
client_secret = base64.b64decode(os.environ.get(
16-
'SOCIAL_AUTH_DRYCC_CONTROLLER_SECRET')) if os.environ.get(
14+
client_secret = os.environ.get(
15+
'SOCIAL_AUTH_DRYCC_CONTROLLER_SECRET') if os.environ.get(
1716
'SOCIAL_AUTH_DRYCC_CONTROLLER_SECRET') else None
1817
controller_domain = os.environ.get('DRYCC_CONTROLLER_DOMAIN')
1918
if not all([client_id, client_secret, controller_domain]):
2019
self.stdout.write('client_id or client_secret non-existent')
2120
return
22-
user = User.objects.get(username='admin')
21+
user = User.objects.filter(is_superuser=True).first()
22+
if not user:
23+
self.stdout.write("Cannot create because there is no superuser")
2324
application, created = Application.objects.get_or_create(
2425
client_id=client_id,
2526
client_secret=client_secret,

rootfs/api/management/commands/createadminuser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ def handle(self, *args, **options):
1919

2020
if password and not username:
2121
raise CommandError("--username is required if specifying --password")
22-
22+
user = self.UserModel._default_manager.db_manager(database).\
23+
get(username=username)
24+
if user:
25+
self.stdout.write('That username is already created')
26+
return
2327
super(Command, self).handle(*args, **options)
2428

2529
if password:

rootfs/bin/boot

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ echo "Database Migrations:"
2828
python /app/manage.py migrate --noinput
2929

3030
echo ""
31-
echo "Create administrator"
32-
python /app/manage.py createadminuser --username "${ADMIN_USERNAME}" --password "${ADMIN_PASSWORD}" --noinput --email "${ADMIN_EMAIL}"
31+
if [ "${ADMIN_USERNAME}" ] && [ "${ADMIN_PASSWORD}" ] && [ "${ADMIN_EMAIL}" ]; then
32+
echo "Create administrator"
33+
python /app/manage.py createadminuser --username "${ADMIN_USERNAME}" --password "${ADMIN_PASSWORD}" --noinput --email "${ADMIN_EMAIL}"
34+
fi
3335

3436
echo ""
3537
echo "Create application for drycc controller "

0 commit comments

Comments
 (0)