Skip to content

Commit 63b0217

Browse files
author
lijianguo
committed
chore(passport): create grafana oauth app
1 parent b52e156 commit 63b0217

4 files changed

Lines changed: 66 additions & 29 deletions

File tree

charts/passport/templates/_helpers.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ env:
3838
value: {{ .Values.admin_password | default "admin" | quote }}
3939
- name: ADMIN_EMAIL
4040
value: {{ .Values.admin_email | default "admin@email.com" | quote }}
41+
{{- if eq .Values.global.grafana_location "on-cluster" }}
42+
- name: "DRYCC_MONITOR_GRAFANA_DOMAIN"
43+
value: http://drycc-monitor-grafana.{{ .Values.global.platform_domain }}
44+
- name: GRAFANA_ON_CLUSTER
45+
value: "true"
46+
- name: SOCIAL_AUTH_DRYCC_GRAFANA_KEY
47+
valueFrom:
48+
secretKeyRef:
49+
name: passport-creds
50+
key: social-auth-drycc-grafana-key
51+
- name: SOCIAL_AUTH_DRYCC_GRAFANA_SECRET
52+
valueFrom:
53+
secretKeyRef:
54+
name: passport-creds
55+
key: social-auth-drycc-grafana-secret
56+
{{- end }}
4157
{{- if (.Values.database_url) }}
4258
- name: DRYCC_DATABASE_URL
4359
valueFrom:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ data:
1414
django-secret-key: {{ randAscii 64 | b64enc }}
1515
social-auth-drycc-controller-key: {{ randAlphaNum 40 | b64enc }}
1616
social-auth-drycc-controller-secret: {{ randAlphaNum 64 | b64enc }}
17+
{{- if eq .Values.global.grafana_location "on-cluster" }}
18+
social-auth-drycc-grafana-key: {{ randAlphaNum 40 | b64enc }}
19+
social-auth-drycc-grafana-secret: {{ randAlphaNum 64 | b64enc }}
20+
{{- end }}
1721
oidc-rsa-private-key: "{{genPrivateKey "rsa" | b64enc}}"
1822
{{- end }}

charts/passport/values.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ admin_password: "admin"
4444
admin_email: "admin@email.com"
4545

4646
global:
47+
# Set the location of Workflow's grafana instance
48+
#
49+
# Valid values are:
50+
# - on-cluster: Run Grafana within the Kubernetes cluster
51+
# - off-cluster: Grafana is running outside of the cluster
52+
grafana_location: "on-cluster"
53+
4754
# Admin email, used for each component to send email to administrator
4855
email: "drycc@drycc.cc"
4956
# Set the location of Workflow's PostgreSQL database

rootfs/api/management/commands/create_oauth2_application.py

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,42 @@ class Command(BaseCommand):
88
"""Management command for create Oauth2 application"""
99

1010
def handle(self, *args, **options):
11-
client_id = os.environ.get(
12-
'SOCIAL_AUTH_DRYCC_CONTROLLER_KEY') if os.environ.get(
13-
'SOCIAL_AUTH_DRYCC_CONTROLLER_KEY') else None
14-
client_secret = os.environ.get(
15-
'SOCIAL_AUTH_DRYCC_CONTROLLER_SECRET') if os.environ.get(
16-
'SOCIAL_AUTH_DRYCC_CONTROLLER_SECRET') else None
17-
controller_domain = os.environ.get('DRYCC_CONTROLLER_DOMAIN')
18-
if not all([client_id, client_secret, controller_domain]):
19-
self.stdout.write('client_id or client_secret non-existent')
20-
return
21-
user = User.objects.filter(is_superuser=True).first()
22-
if not user:
23-
self.stdout.write("Cannot create because there is no superuser")
24-
application, updated = Application.objects.update_or_create(
25-
name='Drycc Controller',
26-
defaults={
27-
'client_id': client_id,
28-
'client_secret': client_secret,
29-
'user': user,
30-
'redirect_uris': f'{controller_domain}/v2/complete/drycc/',
31-
'authorization_grant_type': 'authorization-code',
32-
'client_type': 'Public',
33-
'algorithm': 'RS256'
34-
}
35-
)
36-
if updated:
37-
self.stdout.write('Drycc controller app created')
38-
else:
39-
self.stdout.write("Drycc controller app updated")
11+
app_list = [{
12+
"name": "CONTROLLER",
13+
"redirect_uri": f"{os.environ.get('DRYCC_CONTROLLER_DOMAIN')}/v2/complete/drycc/" # noqa
14+
}]
15+
if os.environ.get('GRAFANA_ON_CLUSTER') == "true":
16+
app_list.append({
17+
"name": "GRAFANA",
18+
"redirect_uri": f"{os.environ.get('DRYCC_MONITOR_GRAFANA_DOMAIN')}/login/generic_oauth" # noqa
19+
})
20+
21+
for app in app_list:
22+
client_id = os.environ.get(
23+
f'SOCIAL_AUTH_DRYCC_{app["name"]}_KEY') if os.environ.get(
24+
f'SOCIAL_AUTH_DRYCC_{app["name"]}_KEY') else None
25+
client_secret = os.environ.get(
26+
f'SOCIAL_AUTH_DRYCC_{app["name"]}_SECRET') if os.environ.get(
27+
f'SOCIAL_AUTH_DRYCC_{app["name"]}_SECRET') else None
28+
if not all([client_id, client_secret]):
29+
self.stdout.write('client_id or client_secret non-existent')
30+
return
31+
user = User.objects.filter(is_superuser=True).first()
32+
if not user:
33+
self.stdout.write("Cannot create because there is no superuser")
34+
application, updated = Application.objects.update_or_create(
35+
name='Drycc ' + app["name"].title(),
36+
defaults={
37+
'client_id': client_id,
38+
'client_secret': client_secret,
39+
'user': user,
40+
'redirect_uris': app["redirect_uri"],
41+
'authorization_grant_type': 'authorization-code',
42+
'client_type': 'Public',
43+
'algorithm': 'RS256'
44+
}
45+
)
46+
if updated:
47+
self.stdout.write(f'Drycc {app["name"]} app created')
48+
else:
49+
self.stdout.write(f'Drycc {app["name"]} app updated')

0 commit comments

Comments
 (0)