コード例 #1
0
ファイル: token-manage.py プロジェクト: norcams/report-app
def action_list():
    with app.app_context():
        db.init_app(app)
        users = Tokens.query.all()
        user_list = list()
        for user in users:
            user_list.append([user.name, ', '.join(user.scope)])
        print(tabulate(user_list, headers=['Name', 'Scope']))
コード例 #2
0
ファイル: token-manage.py プロジェクト: norcams/report-app
def action_delete():
    with app.app_context():
        db.init_app(app)
        users = Tokens.query.filter_by(name=options.name).all()
        for u in users:
            db.session.delete(u)
        db.session.commit()
        print('delete all users with name {}'.format(options.name))
コード例 #3
0
ファイル: db-manage.py プロジェクト: norcams/report-app
def action_create():
    with app.app_context():
        if options.name == 'oauth':
            oauth.init_app(app)
            oauth.create_all()
            print('oauth tables created')
        if options.name == 'api':
            api.init_app(app)
            api.create_all()
            print('api tables created')
コード例 #4
0
ファイル: db-manage.py プロジェクト: norcams/report-app
def action_drop():
    with app.app_context():
        if options.name == 'oauth':
            oauth.init_app(app)
            oauth.drop_all()
            print('oauth tables dropped')
        if options.name == 'api':
            api.init_app(app)
            api.drop_all()
            print('api tables dropped')
コード例 #5
0
ファイル: token-manage.py プロジェクト: norcams/report-app
def action_create():
    with app.app_context():
        db.init_app(app)
        chars = string.ascii_letters + string.digits
        token = ''.join(random.choice(chars) for _ in range(32))
        token_hash = bcrypt.hashpw(token.encode('utf-8'), bcrypt.gensalt())
        scope = literal(','.join(options.scope))
        db.session.add(
            Tokens(token_hash=token_hash, name=options.name, scope=scope))
        db.session.commit()
        print('token: {} with scope {}'.format(token, ','.join(options.scope)))
コード例 #6
0
ファイル: app.py プロジェクト: norcams/report-app
# This will set the need env TOKENINFO_URL from production.cfg
token_url = app.app.config.get('TOKENINFO_URL')
if token_url:
    os.environ['TOKENINFO_URL'] = token_url

# requests will not use the default distro ca-bundle (with our own ca added)
os.environ['REQUESTS_CA_BUNDLE'] = '/etc/pki/tls/certs/ca-bundle.crt'

# Read the api.yaml file to configure the endpoints
app.add_api('api/api.yaml', strict_validation=True, validate_responses=False)
app.add_api('oauth/oauth2.yaml',
            strict_validation=True,
            validate_responses=True)

# Database setup - this will make import db work inside packages without more sql config
oauth_db.init_app(app.app)
api_db.init_app(app.app)


# Default landing page
@app.route("/")
def docs():
    output = "<h2>UH-IaaS report rest API server</h2>"
    output += '<ul><li><a href=/api/ui>report api docs</a></li>'
    output += '<li><a href=/oauth2/ui>oauth docs</a></li></ul>'
    return output


@app.route("/health")
def health():
    version = 'version.yaml'