@@ -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