Ejemplo n.º 1
0
def list_groups(keycloak: KeycloakClient):
    try:
        return [
            group | {'_href': _group_href(group)}
            for group in keycloak.group_list()
        ]
    except KeycloakGetError as e:
        logger.exception(e)
        return problem_from_keycloak_error(e)
    except Exception as e:
        logger.exception(e)
        return problem(500, 'Unknown Error', str(e))
Ejemplo n.º 2
0
def delete_policy(keycloak: KeycloakClient, user, policy_id):
    """
    API endpoint to delete policy given policy id
    """
    policy = model.Policy.query.get(policy_id)
    if not policy:
        return problem(404, 'Not Found', 'Record Does Not Exist')

    try:
        groups = {group['name']: group for group in keycloak.group_list()}
        group_name = f'policy-{policy_id}-owners'
        group_id = groups[group_name]['id']
        keycloak.group_delete(group_id)
    except KeycloakGetError as e:
        logger.exception(e)
        return problem_from_keycloak_error(e)
    except Exception as e:
        logger.exception(e)
        return problem(500, 'Unknown Error',
                       f'Failed to delete owner group in Keycloak, {e}')

    db.session.delete(policy)
    db.session.commit()