# Path: isserviceup/config/config.py
# def s2l(x):
# def ensure_private_ssh_key():
# def get_status_description():
# DEBUG = config('DEBUG', cast=bool, default=False)
# FRONTEND_URL = config('FRONTEND_URL', default='http://localhost:8000/')
# REDIS_URL = config('REDIS_URL', default='redis://redis:devpassword@redis')
# MONGO_URL = config('MONGO_URL', default='mongodb://mongo/isserviceup')
# STATUS_UPDATE_INTERVAL = config('STATUS_UPDATE_INTERVAL', cast=int, default=30)
# SERVE_STATIC_FILES = config('SERVE_STATIC_FILES', cast=bool, default=True)
# SENTRY_DSN = config('SENTRY_DSN', default=None)
# CELERY_EAGER = config('CELERY_EAGER', cast=bool, default=False)
# CELERY_BROKER = config('CELERY_BROKER', default=REDIS_URL)
# CELERY_BACKEND = config('CELERY_BACKEND', default=REDIS_URL)
# GITHUB_CLIENT_ID = config('GITHUB_CLIENT_ID', default=None)
# GITHUB_CLIENT_SECRET = config('GITHUB_CLIENT_SECRET', default=None)
# SLACK_WEB_HOOK_URL = config('SLACK_WEB_HOOK_URL', default=None)
# NOTIFIERS = [
#     # Slack(SLACK_WEB_HOOK_URL)
# ]
# NOTIFY_ON_STARTUP = config('NOTIFY_ON_STARTUP', default=False, cast=bool)
# CACHET_NOTIFIER = config('CACHET_NOTIFIER', default=False, cast=bool)
# SERVICES = config('SERVICES', cast=s2l, default=None)
# PRIVATE_SSH_KEY = config('PRIVATE_SSH_KEY', default='')
#             PRIVATE_SSH_KEY = ''
# 
# Path: isserviceup/helpers/github.py
# def get_access_token(code):
# def get_user_info(access_token):
# 
# Path: isserviceup/storage/sessions.py
# SESSION_TTL = 60*60*24*30
# def get(sid):
# def create(data):
# def destroy(sid):
# 
# Path: isserviceup/storage/users.py
# def upsert_user(avatar_url, username, github_access_token):
#     return User.objects(username=username).upsert_one(set__avatar_url=avatar_url,
#                                                       set__github_access_token=github_access_token)


from flask import Blueprint
from flask import redirect
from flask import request
from isserviceup.config import config
from isserviceup.helpers import github
from isserviceup.storage import sessions
from isserviceup.storage.users import upsert_user


mod = Blueprint('auth', __name__)


@mod.route('/oauth_callback', methods=['GET'])
def oauth_callback():
    code = request.args['code']

    res = github.get_access_token(code)
    access_token = res.json()['access_token']


# Path: isserviceup/config/config.py
# def s2l(x):
# def ensure_private_ssh_key():
# def get_status_description():
# DEBUG = config('DEBUG', cast=bool, default=False)
# FRONTEND_URL = config('FRONTEND_URL', default='http://localhost:8000/')
# REDIS_URL = config('REDIS_URL', default='redis://redis:devpassword@redis')
# MONGO_URL = config('MONGO_URL', default='mongodb://mongo/isserviceup')
# STATUS_UPDATE_INTERVAL = config('STATUS_UPDATE_INTERVAL', cast=int, default=30)
# SERVE_STATIC_FILES = config('SERVE_STATIC_FILES', cast=bool, default=True)
# SENTRY_DSN = config('SENTRY_DSN', default=None)
# CELERY_EAGER = config('CELERY_EAGER', cast=bool, default=False)
# CELERY_BROKER = config('CELERY_BROKER', default=REDIS_URL)
# CELERY_BACKEND = config('CELERY_BACKEND', default=REDIS_URL)
# GITHUB_CLIENT_ID = config('GITHUB_CLIENT_ID', default=None)
# GITHUB_CLIENT_SECRET = config('GITHUB_CLIENT_SECRET', default=None)
# SLACK_WEB_HOOK_URL = config('SLACK_WEB_HOOK_URL', default=None)
# NOTIFIERS = [
#     # Slack(SLACK_WEB_HOOK_URL)
# ]
# NOTIFY_ON_STARTUP = config('NOTIFY_ON_STARTUP', default=False, cast=bool)
# CACHET_NOTIFIER = config('CACHET_NOTIFIER', default=False, cast=bool)
# SERVICES = config('SERVICES', cast=s2l, default=None)
# PRIVATE_SSH_KEY = config('PRIVATE_SSH_KEY', default='')
#             PRIVATE_SSH_KEY = ''
# 
# Path: isserviceup/helpers/github.py
# def get_access_token(code):
# def get_user_info(access_token):
# 
# Path: isserviceup/storage/sessions.py
# SESSION_TTL = 60*60*24*30
# def get(sid):
# def create(data):
# def destroy(sid):
# 
# Path: isserviceup/storage/users.py
# def upsert_user(avatar_url, username, github_access_token):
#     return User.objects(username=username).upsert_one(set__avatar_url=avatar_url,
#                                                       set__github_access_token=github_access_token)


# Path: isserviceup/api/auth.py
from flask import Blueprint
from flask import redirect
from flask import request
from isserviceup.config import config
from isserviceup.helpers import github
from isserviceup.storage import sessions
from isserviceup.storage.users import upsert_user



mod = Blueprint('auth', __name__)


@mod.route('/oauth_callback', methods=['GET'])
def oauth_callback():
    code = request.args['code']

    res = github.get_access_token(code)
    access_token = res.json()['access_token']


    res = github.get_user_info(access_token)