Beispiel #1
0
def upgrade():
    # Query all orgs which are linked to BCOL.
    conn = op.get_bind()
    org_res = conn.execute(
        "select o.id, o.bcol_user_id from orgs o where bcol_user_id is not null and bcol_account_id is not null and status_code in ('ACTIVE', 'PENDING_STAFF_REVIEW');"
    )
    orgs = org_res.fetchall()
    print('starting migration for BCOL products')
    if len(orgs) > 0:
        token = RestService.get_service_account_token()
    for org_id in orgs:
        try:
            print('Getting bcol profile for ', org_id[0], org_id[1])
            bcol_response = RestService.get(
                endpoint=current_app.config.get('BCOL_API_URL') +
                f'/profiles/{org_id[1]}',
                token=token)
            print('BCOL Response', bcol_response.json())
            Product.create_subscription_from_bcol_profile(
                org_id[0],
                bcol_response.json().get('profileFlags'))
        except Exception as exc:
            print('Profile Error')
            print(exc)
            raise exc
    db.session.commit()
Beispiel #2
0
def build_cache(app):
    """Build cache."""
    cache.init_app(app)
    with app.app_context():
        cache.clear()
        if not app.config.get('TESTING', False):
            try:
                from auth_api.services.permissions import \
                    Permissions as PermissionService  # pylint: disable=import-outside-toplevel
                from auth_api.services.products import Product as ProductService
                PermissionService.build_all_permission_cache()
                ProductService.build_all_products_cache()
            except Exception as e:  # NOQA # pylint:disable=broad-except
                app.logger.error('Error on caching ')
                app.logger.error(e)
Beispiel #3
0
 def _is_product_based_auth(product_code):
     check_product_based_auth = False
     if product_code:
         product_type: str = ProductService.find_product_type_by_code(product_code)
         # TODO should we reject if the product code is unknown??
         if product_type == ProductTypeCodeEnum.PARTNER.value:  # PARTNERS needs product based auth
             check_product_based_auth = True
     return check_product_based_auth
Beispiel #4
0
    def _is_product_based_auth(product_code):

        check_product_based_auth = False
        if product_code:
            from auth_api.services.products import \
                Product as ProductService  # pylint:disable=cyclic-import, import-outside-toplevel
            product_type: str = ProductService.find_product_type_by_code(product_code)
            # TODO should we reject if the product code is unknown??
            if product_type == ProductTypeCodeEnum.PARTNER.value:  # PARTNERS needs product based auth
                check_product_based_auth = True
        return check_product_based_auth