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
f8ab6ddb
Commit
f8ab6ddb
authored
5 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Rudimentary hook receiver
parent
81070b5d
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
-0
83 additions, 0 deletions
hook.wsgi
with
83 additions
and
0 deletions
hook.wsgi
0 → 100644
+
83
−
0
View file @
f8ab6ddb
#!/usr/bin/python3
# A mini-app for accepting Zoom webhooks
import
configparser
import
json
import
psycopg2
import
traceback
### Configuration ###
config
=
configparser
.
ConfigParser
()
config
.
read
(
'
zoom.ini
'
)
### Database connection ###
db_connection
=
None
db
=
None
def
db_connect
():
global
db_connection
,
db
db_connection
=
psycopg2
.
connect
(
host
=
'
localhost
'
,
user
=
config
[
'
db
'
][
'
user
'
],
passwd
=
config
[
'
db
'
][
'
passwd
'
],
db
=
config
[
'
db
'
][
'
name
'
],
)
db
=
db_conn
.
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
:
# Reconnect if the connection died (timeout, server restart etc.)
db_connect
()
db
.
execute
(
query
,
args
)
### Application ###
class
HookApp
:
def
__init__
(
self
,
env
,
start_response
):
self
.
env
=
env
self
.
wsgi_start
=
start_response
def
log
(
self
,
msg
):
print
(
msg
,
file
=
self
.
env
[
'
wsgi.errors
'
],
flush
=
True
)
def
http_error
(
self
,
code
,
msg
,
extra_headers
=
[]):
self
.
wsgi_start
(
"
{} {}
"
.
format
(
code
,
msg
),
extra_headers
+
[
(
'
Content-Type
'
,
'
text/plain
'
)
])
return
[
"
{} {}
"
.
format
(
code
,
msg
)]
def
run
(
self
):
self
.
log
(
self
.
env
)
method
=
self
.
env
[
'
REQUEST_METHOD
'
]
if
method
!=
'
POST
'
:
return
self
.
http_error
(
405
,
'
Method not allowed
'
,
[(
'
Allow
'
,
'
POST
'
)])
# FIXME: Check authorization
self
.
log
(
'
Gotcha!
'
)
body
=
self
.
env
[
'
wsgi.input
'
].
read
()
js
=
json
.
loads
(
body
)
self
.
log
(
js
)
self
.
wsgi_start
(
"
204 No Content
"
,
[])
return
b
""
def
application
(
env
,
start_response
):
app
=
HookApp
(
env
,
start_response
)
try
:
return
app
.
run
()
except
Exception
as
exc
:
app
.
log
(
traceback
.
print_exception
(
etype
=
None
,
value
=
exc
,
tb
=
exc
.
__traceback__
))
return
app
.
http_error
(
500
,
"
Internal server error
"
)
# FIXME: Number of workers and access rights; reloading
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