Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mffzoom
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wizards
mffzoom
Commits
b0659b4f
Commit
b0659b4f
authored
5 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Hook: pre-reform
parent
afe971bc
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
hook.wsgi
+83
-10
83 additions, 10 deletions
hook.wsgi
with
83 additions
and
10 deletions
hook.wsgi
+
83
−
10
View file @
b0659b4f
...
...
@@ -4,7 +4,10 @@
import
configparser
import
json
import
psycopg2
import
psycopg2.extras
import
traceback
import
dateutil.parser
# import dateutil.tz
### Configuration ###
...
...
@@ -21,22 +24,31 @@ def db_connect():
db_connection
=
psycopg2
.
connect
(
host
=
'
localhost
'
,
user
=
config
[
'
db
'
][
'
user
'
],
passwd
=
config
[
'
db
'
][
'
passwd
'
],
db
=
config
[
'
db
'
][
'
name
'
],
passw
or
d
=
config
[
'
db
'
][
'
passwd
'
],
db
name
=
config
[
'
db
'
][
'
name
'
],
)
db
=
db_conn
.
cursor
(
cursor_factory
=
psycopg2
.
extras
.
NamedTupleCursor
)
db
=
db_conn
ection
.
cursor
(
cursor_factory
=
psycopg2
.
extras
.
NamedTupleCursor
)
def
db_query
(
query
,
args
=
()):
if
db
is
None
:
db_connect
()
try
:
db
.
execute
(
query
,
args
)
# FIXME: Adapt for Postgres!
except
MySQLdb
.
OperationalError
:
except
psycopg2
.
DatabaseError
:
# Reconnect if the connection died (timeout, server restart etc.)
db_connect
()
db
.
execute
(
query
,
args
)
### Utilities ###
# FIXME: Move to shared code?
def
parse_time
(
iso_time
,
tz_name
):
utc
=
dateutil
.
parser
.
isoparse
(
iso_time
)
# tz = dateutil.tz.gettz(tz_name)
# return utc.astimezone(tz)
return
utc
### Application ###
class
HookApp
:
...
...
@@ -54,21 +66,82 @@ class HookApp:
])
return
[
"
{} {}
"
.
format
(
code
,
msg
)]
def
run
(
self
):
self
.
log
(
self
.
env
)
def
create_meeting
(
self
,
js
):
payload
=
js
[
"
payload
"
]
object
=
payload
[
"
object
"
]
meeting_id
=
object
[
"
id
"
]
type
=
object
[
"
type
"
]
if
type
!=
2
and
type
!=
8
:
self
.
log
(
f
"
Meeting type
{
type
}
ignored
"
)
return
host_user_id
=
object
[
"
host_id
"
]
db_query
(
"
SELECT * FROM zoom_users WHERE user_id=%s
"
,
(
host_user_id
,))
user
=
db
.
fetchone
()
if
user
is
None
:
self
.
log
(
f
"
Meeting
{
meeting_id
}
: Host
{
host_user_id
}
not found in zoom_users
"
)
self
.
log
(
f
"
Meeting
{
meeting_id
}
: Planning
"
)
db_query
(
"""
INSERT INTO zoom_meetings
(meeting_id, uuid, host_id, topic, type, start_time, duration)
VALUES (%s, %s, %s, %s, %s, %s, %s)
"""
,
(
meeting_id
,
object
[
'
uuid
'
],
user
.
id
,
object
[
'
topic
'
],
object
[
'
type
'
],
parse_time
(
object
[
'
start_time
'
],
object
[
'
timezone
'
]),
object
[
'
duration
'
],
))
db_connection
.
commit
()
def
delete_meeting
(
self
,
js
):
payload
=
js
[
"
payload
"
]
object
=
payload
[
"
object
"
]
meeting_id
=
object
[
"
id
"
]
type
=
object
[
"
type
"
]
if
type
!=
2
and
type
!=
8
:
self
.
log
(
f
"
Meeting type
{
type
}
ignored
"
)
return
self
.
log
(
f
"
Meeting
{
meeting_id
}
: Deleting
"
)
db_query
(
"""
DELETE FROM zoom_meetings
WHERE meeting_id=%s AND start_time=%s AND duration=%s
"""
,
(
meeting_id
,
parse_time
(
object
[
'
start_time
'
],
object
[
'
timezone
'
]),
object
[
'
duration
'
],
))
db_connection
.
commit
()
def
run
(
self
):
method
=
self
.
env
[
'
REQUEST_METHOD
'
]
if
method
!=
'
POST
'
:
return
self
.
http_error
(
405
,
'
Method not allowed
'
,
[(
'
Allow
'
,
'
POST
'
)])
# FIXME: Check authorization
self
.
log
(
'
Gotcha!
'
)
if
self
.
env
.
get
(
'
HTTP_AUTHORIZATION
'
,
''
)
!=
config
[
'
hooks
'
][
'
verification_token
'
]:
self
.
log
(
'
Verification token does not match!
'
)
return
self
.
http_error
(
401
,
'
Authorization failed
'
)
body
=
self
.
env
[
'
wsgi.input
'
].
read
()
js
=
json
.
loads
(
body
)
self
.
log
(
js
)
event
=
js
[
"
event
"
]
# if event == "meeting.created":
# self.create_meeting(js)
# elif event == "meeting.deleted":
# self.delete_meeting(js)
# else:
# self.log(f"Unknown event: {event}")
self
.
wsgi_start
(
"
204 No Content
"
,
[])
return
b
""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment