예제 #1
0
    def finish_key_install(self, key_id, arguments):
        authorize_url = 'https://github.com/login/oauth/access_token'
        authorize_query = {
            'client_id': self.api_key,
            'client_secret': self.api_secret,
            'code': arguments['code']
        }
        authorize_headers = {'Accept': 'application/json'}
        token_obj = requests.post(authorize_url, data=authorize_query,
                                  headers=authorize_headers).json()
        token = token_obj['access_token']

        pub_key = orm.fetch_key(key_id)[2]

        list_repos_url = 'https://api.github.com/user/repos'
        list_repos_query = {
            'access_token': token
        }
        repos = requests.get(list_repos_url,
                             params=list_repos_query).json()

        return render_template('connectors/github/install_key.html',
                               access_token=token,
                               public_key=pub_key,
                               repos=repos
                               )
예제 #2
0
def show_raw_key(key_id):
    application.logger.info('Getting raw public key ' + key_id)
    key_obj = orm.fetch_key(key_id)
    if key_obj:
        return key_obj[2]
    else:
        application.logger.error('Key not found!')
        abort(404)
예제 #3
0
def expire_key(key_id):
    application.logger.info('Expiring key ' + key_id)
    if orm.fetch_key(key_id):
        orm.expire_key(key_id)
        return redirect('/')
    else:
        application.logger.error('Key not found!')
        abort(404)
예제 #4
0
def extend_key(key_id):
    application.logger.info('Extending key ' + key_id)
    if orm.fetch_key(key_id):
        orm.extend_key(key_id)
        return redirect(url_for('show_key', key_id=key_id))
    else:
        application.logger.error('Key not found!')
        abort(404)
예제 #5
0
def install_key(key_id, service):
    if service in config.SERVICE_CONNECTORS and orm.fetch_key(key_id):
        service_obj = config.SERVICE_CONNECTORS[service]
        return service_obj.start_key_install(key_id,
                                             url_for('finish_install_key',
                                                     key_id=key_id,
                                                     service=service,
                                                     _external=True))
    else:
        abort(404)
예제 #6
0
def show_key(key_id):
    application.logger.info('Getting public key ' + key_id)
    key_obj = orm.fetch_key(key_id)
    if key_obj:
        lifetime = key_obj[3] - datetime.datetime.now()
        rel_url = url_for('show_key', key_id=key_id)
        fq_url = urljoin(config.BASE_SHORTENER_URL, rel_url)
        return render_template('show_key.html',
                               key_id=key_id,
                               public_key=key_obj[2],
                               expires_in=str(lifetime).split('.')[0],
                               services=config.SERVICE_CONNECTORS
                               )
    else:
        application.logger.error('Key not found!')
        abort(404)
예제 #7
0
    def finish_key_install(self, key_id, arguments):
        authorize_url = 'https://github.com/login/oauth/access_token'
        authorize_query = {
            'client_id': self.api_key,
            'client_secret': self.api_secret,
            'code': arguments['code']
        }
        authorize_headers = {'Accept': 'application/json'}
        token_obj = requests.post(authorize_url,
                                  data=authorize_query,
                                  headers=authorize_headers).json()
        token = token_obj['access_token']

        pub_key = orm.fetch_key(key_id)[2]

        list_repos_url = 'https://api.github.com/user/repos'
        list_repos_query = {'access_token': token}
        repos = requests.get(list_repos_url, params=list_repos_query).json()

        return render_template('connectors/github/install_key.html',
                               access_token=token,
                               public_key=pub_key,
                               repos=repos)
예제 #8
0
def finish_install_key(key_id, service):
    if service in config.SERVICE_CONNECTORS and orm.fetch_key(key_id):
        service_obj = config.SERVICE_CONNECTORS[service]
        return service_obj.finish_key_install(key_id, request.args)
    else:
        abort(404)