19
19
20
20
21
21
# WorkOS Setup
22
- workos .api_key = os .getenv ("WORKOS_API_KEY" )
23
- workos .client_id = os .getenv ("WORKOS_CLIENT_ID" )
24
- workos .base_api_url = "http://localhost:7000/" if DEBUG else workos .base_api_url
22
+ base_api_url = "http://localhost:7000/" if DEBUG else None
23
+ workos_client = workos .WorkOSClient (
24
+ api_key = os .getenv ("WORKOS_API_KEY" ),
25
+ client_id = os .getenv ("WORKOS_CLIENT_ID" ),
26
+ base_url = base_api_url ,
27
+ )
25
28
26
29
27
30
def to_pretty_json (value ):
@@ -34,7 +37,7 @@ def to_pretty_json(value):
34
37
@app .route ("/" , methods = ["POST" , "GET" ])
35
38
def index ():
36
39
try :
37
- link = workos . client .portal .generate_link (
40
+ link = workos_client .portal .generate_link (
38
41
organization_id = session ["organization_id" ], intent = "audit_logs"
39
42
)
40
43
today = datetime .today ()
@@ -50,7 +53,7 @@ def index():
50
53
except KeyError :
51
54
before = request .args .get ("before" )
52
55
after = request .args .get ("after" )
53
- organizations = workos . client .organizations .list_organizations (
56
+ organizations = workos_client .organizations .list_organizations (
54
57
before = before , after = after , limit = 5 , order = "desc"
55
58
)
56
59
before = organizations .list_metadata .before
@@ -68,10 +71,10 @@ def set_org():
68
71
organization_id = request .args .get ("id" ) or request .form ["organization_id" ]
69
72
70
73
session ["organization_id" ] = organization_id
71
- organization_set = workos . client .audit_logs .create_event (
72
- organization_id , user_organization_set
74
+ workos_client .audit_logs .create_event (
75
+ organization_id = organization_id , event = user_organization_set
73
76
)
74
- org = workos . client .organizations .get_organization (organization_id )
77
+ org = workos_client .organizations .get_organization (organization_id )
75
78
session ["organization_name" ] = org .name
76
79
return redirect ("/" )
77
80
@@ -110,7 +113,9 @@ def send_event():
110
113
},
111
114
}
112
115
)
113
- organization_set = workos .client .audit_logs .create_event (organization_id , event )
116
+ organization_set = workos_client .audit_logs .create_event (
117
+ organization_id = organization_id , event = event
118
+ )
114
119
return redirect ("/" )
115
120
116
121
@@ -149,7 +154,7 @@ def get_events():
149
154
150
155
try :
151
156
152
- create_export_response = workos . client .audit_logs .create_export (
157
+ create_export_response = workos_client .audit_logs .create_export (
153
158
organization_id = organization_id ,
154
159
range_start = request .form ["range-start" ],
155
160
range_end = request .form ["range-end" ],
@@ -165,7 +170,7 @@ def get_events():
165
170
return redirect ("/" )
166
171
if event_type == "access_csv" :
167
172
export_id = session ["export_id" ]
168
- fetch_export_response = workos . client .audit_logs .get_export (export_id )
173
+ fetch_export_response = workos_client .audit_logs .get_export (export_id )
169
174
if fetch_export_response .url is None :
170
175
return redirect ("/" )
171
176
@@ -178,7 +183,7 @@ def events():
178
183
if not intent == "audit_logs" :
179
184
return redirect ("/" )
180
185
181
- link = workos . client .portal .generate_link (
186
+ link = workos_client .portal .generate_link (
182
187
organization_id = session ["organization_id" ], intent = intent
183
188
)
184
189
0 commit comments