Skip to content

Commit a648ffe

Browse files
committed
Update for new client
1 parent 1c1f24b commit a648ffe

File tree

1 file changed

+17
-12
lines changed
  • python-flask-audit-logs-example

1 file changed

+17
-12
lines changed

python-flask-audit-logs-example/app.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020

2121
# 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+
)
2528

2629

2730
def to_pretty_json(value):
@@ -34,7 +37,7 @@ def to_pretty_json(value):
3437
@app.route("/", methods=["POST", "GET"])
3538
def index():
3639
try:
37-
link = workos.client.portal.generate_link(
40+
link = workos_client.portal.generate_link(
3841
organization_id=session["organization_id"], intent="audit_logs"
3942
)
4043
today = datetime.today()
@@ -50,7 +53,7 @@ def index():
5053
except KeyError:
5154
before = request.args.get("before")
5255
after = request.args.get("after")
53-
organizations = workos.client.organizations.list_organizations(
56+
organizations = workos_client.organizations.list_organizations(
5457
before=before, after=after, limit=5, order="desc"
5558
)
5659
before = organizations.list_metadata.before
@@ -68,10 +71,10 @@ def set_org():
6871
organization_id = request.args.get("id") or request.form["organization_id"]
6972

7073
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
7376
)
74-
org = workos.client.organizations.get_organization(organization_id)
77+
org = workos_client.organizations.get_organization(organization_id)
7578
session["organization_name"] = org.name
7679
return redirect("/")
7780

@@ -110,7 +113,9 @@ def send_event():
110113
},
111114
}
112115
)
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+
)
114119
return redirect("/")
115120

116121

@@ -149,7 +154,7 @@ def get_events():
149154

150155
try:
151156

152-
create_export_response = workos.client.audit_logs.create_export(
157+
create_export_response = workos_client.audit_logs.create_export(
153158
organization_id=organization_id,
154159
range_start=request.form["range-start"],
155160
range_end=request.form["range-end"],
@@ -165,7 +170,7 @@ def get_events():
165170
return redirect("/")
166171
if event_type == "access_csv":
167172
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)
169174
if fetch_export_response.url is None:
170175
return redirect("/")
171176

@@ -178,7 +183,7 @@ def events():
178183
if not intent == "audit_logs":
179184
return redirect("/")
180185

181-
link = workos.client.portal.generate_link(
186+
link = workos_client.portal.generate_link(
182187
organization_id=session["organization_id"], intent=intent
183188
)
184189

0 commit comments

Comments
 (0)