-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
42 lines (35 loc) · 1.13 KB
/
Copy pathrun.py
File metadata and controls
42 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
import argparse
import logging
from http.server import HTTPServer
from lib.oauth import oauth_config, OAuth2
from lib.webhook import webhook_config, Webhook
# LOGGING CONFIG
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(message)s')
# SUPPORTED SERVICES
OAUTH_SERVICE='oauth'
WEBHOOK_SERVICE='webhook'
# CLI ARG PARSER
cli_parser = argparse.ArgumentParser()
cli_parser.add_argument('-s', '--service')
arg = cli_parser.parse_args()
# APP INIT
if __name__ == "__main__":
if arg.service == OAUTH_SERVICE:
service = OAuth2
app_address = oauth_config.ADDRESS
app_port = oauth_config.PORT
elif arg.service == WEBHOOK_SERVICE:
service = Webhook
app_address = webhook_config.ADDRESS
app_port = webhook_config.PORT
address = (app_address, app_port)
http = HTTPServer(address, service)
logging.info(f'{service.__name__} service running at: {app_address}:{app_port}')
try:
http.serve_forever()
except KeyboardInterrupt:
logging.warning(f'{service.__name__} service aborted!!')
http.server_close()
sys.exit()