Skip to content

Commit 10e844b

Browse files
committed
chore(passport): support init app config
1 parent bb10c92 commit 10e844b

5 files changed

Lines changed: 66 additions & 29 deletions

File tree

charts/passport/templates/_helpers.tpl

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,43 @@ rbac.authorization.k8s.io/v1
1616
env:
1717
- name: "TZ"
1818
value: {{ .Values.time_zone | default "UTC" | quote }}
19+
{{- if (.Values.initGrafanaKey) }}
20+
- name: "DRYCC_GRAFANA_DOMAIN"
21+
{{- if .Values.global.certManagerEnabled }}
22+
value: https://drycc-monitor-grafana.{{ .Values.global.platformDomain }}
23+
{{- else }}
24+
value: http://drycc-monitor-grafana.{{ .Values.global.platformDomain }}
25+
{{- end }}
26+
- name: DRYCC_PASSPORT_GRAFANA_KEY
27+
valueFrom:
28+
secretKeyRef:
29+
name: passport-creds
30+
key: drycc-passport-grafana-key
31+
- name: DRYCC_PASSPORT_GRAFANA_SECRET
32+
valueFrom:
33+
secretKeyRef:
34+
name: passport-creds
35+
key: drycc-passport-grafana-secret
36+
{{- end }}
37+
{{- if (.Values.initManagerKey) }}
38+
- name: "DRYCC_MONITOR_MANAGER_DOMAIN"
39+
{{- if .Values.global.certManagerEnabled }}
40+
value: https://drycc-manager.{{ .Values.global.platformDomain }}
41+
{{- else }}
42+
value: http://drycc-manager.{{ .Values.global.platformDomain }}
43+
{{- end }}
44+
- name: DRYCC_PASSPORT_MANAGER_KEY
45+
valueFrom:
46+
secretKeyRef:
47+
name: passport-creds
48+
key: drycc-passport-manager-key
49+
- name: DRYCC_PASSPORT_MANAGER_SECRET
50+
valueFrom:
51+
secretKeyRef:
52+
name: passport-creds
53+
key: drycc-passport-manager-secret
54+
{{- end }}
55+
{{- if (.Values.initControllerKey) }}
1956
- name: "DRYCC_CONTROLLER_DOMAIN"
2057
{{- if .Values.global.certManagerEnabled }}
2158
value: https://drycc.{{ .Values.global.platformDomain }}
@@ -37,6 +74,7 @@ env:
3774
secretKeyRef:
3875
name: passport-creds
3976
key: drycc-passport-controller-secret
77+
{{- end }}
4078
- name: WORKFLOW_NAMESPACE
4179
valueFrom:
4280
fieldRef:
@@ -47,26 +85,6 @@ env:
4785
value: {{ .Values.adminPassword | default "admin" | quote }}
4886
- name: ADMIN_EMAIL
4987
value: {{ .Values.adminEmail | default "admin@email.com" | quote }}
50-
{{- if eq .Values.global.grafanaLocation "on-cluster" }}
51-
- name: "DRYCC_MONITOR_GRAFANA_DOMAIN"
52-
{{- if .Values.global.certManagerEnabled }}
53-
value: https://drycc-monitor-grafana.{{ .Values.global.platformDomain }}
54-
{{- else }}
55-
value: http://drycc-monitor-grafana.{{ .Values.global.platformDomain }}
56-
{{- end }}
57-
- name: GRAFANA_ON_CLUSTER
58-
value: "true"
59-
- name: DRYCC_PASSPORT_GRAFANA_KEY
60-
valueFrom:
61-
secretKeyRef:
62-
name: passport-creds
63-
key: drycc-passport-grafana-key
64-
- name: DRYCC_PASSPORT_GRAFANA_SECRET
65-
valueFrom:
66-
secretKeyRef:
67-
name: passport-creds
68-
key: drycc-passport-grafana-secret
69-
{{- end }}
7088
{{- if (.Values.databaseUrl) }}
7189
- name: DRYCC_DATABASE_URL
7290
valueFrom:

charts/passport/templates/passport-secret-creds.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@ data:
1616
{{- end }}
1717
django-secret-key: {{ randAscii 64 | b64enc }}
1818
oidc-rsa-private-key: "{{genPrivateKey "rsa" | b64enc}}"
19+
{{- if (.Values.initGrafanaKey) }}
1920
drycc-passport-grafana-key: {{ randAlphaNum 40 | b64enc }}
2021
drycc-passport-grafana-secret: {{ randAlphaNum 64 | b64enc }}
22+
{{- end }}
23+
{{- if (.Values.initManagerKey) }}
24+
drycc-passport-manager-key: {{ randAlphaNum 40 | b64enc }}
25+
drycc-passport-manager-secret: {{ randAlphaNum 64 | b64enc }}
26+
{{- end }}
27+
{{- if (.Values.initControllerKey) }}
2128
drycc-passport-controller-key: {{ randAlphaNum 40 | b64enc }}
2229
drycc-passport-controller-secret: {{ randAlphaNum 64 | b64enc }}
30+
{{- end }}
2331
{{- end }}

charts/passport/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ adminUsername: "admin"
6666
adminPassword: "admin"
6767
adminEmail: "admin@email.com"
6868

69+
# The following configurations represent whether to initialize oauth2 application key
70+
initGrafanaKey: true
71+
initManagerKey: false
72+
initControllerKey: true
73+
6974
# Service
7075
service:
7176
# Provide any additional service annotations

rootfs/api/management/commands/create_oauth2_application.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ class Command(BaseCommand):
1010
"""Management command for create Oauth2 application"""
1111

1212
def handle(self, *args, **options):
13-
app_list = [{
14-
"name": "CONTROLLER",
15-
"redirect_uri": f"{os.environ.get('DRYCC_CONTROLLER_DOMAIN')}/v2/complete/drycc/" # noqa
16-
}]
17-
if os.environ.get('GRAFANA_ON_CLUSTER') == "true":
13+
app_list = []
14+
if os.environ.get('DRYCC_GRAFANA_DOMAIN'):
1815
app_list.append({
1916
"name": "GRAFANA",
20-
"redirect_uri": f"{os.environ.get('DRYCC_MONITOR_GRAFANA_DOMAIN')}/login/generic_oauth" # noqa
17+
"redirect_uri": f"{os.environ.get('DRYCC_GRAFANA_DOMAIN')}/login/generic_oauth" # noqa
18+
})
19+
if os.environ.get('DRYCC_MANAGER_DOMAIN'):
20+
app_list.append({
21+
"name": "MANAGER",
22+
"redirect_uri": f"{os.environ.get('DRYCC_MANAGER_DOMAIN')}/v1/complete/drycc/" # noqa
23+
})
24+
if os.environ.get('DRYCC_CONTROLLER_DOMAIN'):
25+
app_list.append({
26+
"name": "CONTROLLER",
27+
"redirect_uri": f"{os.environ.get('DRYCC_CONTROLLER_DOMAIN')}/v2/complete/drycc/" # noqa
2128
})
22-
2329
for app in app_list:
2430
client_id = os.environ.get(
2531
f'DRYCC_PASSPORT_{app["name"]}_KEY') if os.environ.get(
@@ -33,7 +39,7 @@ def handle(self, *args, **options):
3339
user = User.objects.filter(is_superuser=True).first()
3440
if not user:
3541
self.stdout.write("Cannot create because there is no superuser")
36-
application, updated = Application.objects.update_or_create(
42+
_, updated = Application.objects.update_or_create(
3743
name='Drycc ' + app["name"].title(),
3844
defaults={
3945
'client_id': client_id,

rootfs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Drycc passport requirements
2-
django==4.1
2+
django==4.1.2
33
pytz==2022.2.1
44
django-auth-ldap==3.0.0
55
django-cors-headers==3.7.0

0 commit comments

Comments
 (0)