コード例 #1
0
def get_access_token(user_name):
    user = User.query.filter_by(id=g.auth['sub']).first()
    if (user is None):
        raise DoesNotExistError(g.data['user'])
    for_user = User.query.filter_by(username=user_name).first()
    if (for_user is None):
        raise DoesNotExistError(g.data['user'])

    token = encode_access(user, for_user)
    return jsonify({
        'token': token.decode('utf-8')
    })
コード例 #2
0
def remove_member(group_name, member_email):
    group = Group.query.filter_by(user_id=g.auth['sub'],
                                  name=group_name).first()
    if group == None:
        raise DoesNotExistError(group_name)
    user = User.query.filter_by(email=member_email).first()
    if user == None:
        raise DoesNotExistError(member_email)
    try:
        group.members.remove(user)
        db.session.commit()
    except ValueError as e:
        raise DoesNotExistError(member_email)
    return ('', HTTPStatus.OK)
コード例 #3
0
def add_member(group_name, member_email):
    group = Group.query.filter_by(user_id=g.auth['sub'],
                                  name=group_name).first()
    if group == None:
        raise DoesNotExistError(group_name)
    user = User.query.filter_by(email=member_email).first()
    if user == None:
        raise DoesNotExistError(member_email)
    try:
        group.members.append(user)
        db.session.commit()
    except IntegrityError as e:
        raise AlreadyExistsError(member_email)
    return ('', HTTPStatus.OK)
コード例 #4
0
def remove_from_group(group_name, share_name):
    group = Group.query.filter_by(user_id=g.auth['sub'],
                                  name=group_name).first()
    if group == None:
        raise DoesNotExistError(group_name)
    share = Share.query.filter_by(user_id=g.auth['sub'],
                                  name=share_name).first()
    if share == None:
        raise DoesNotExistError(share_name)

    group.shares.remove(share)
    db.session.commit()

    print('Removing %s from %s' % (group_name, share_name))
    return ('', HTTPStatus.OK)
コード例 #5
0
def add_to_group(group_name, share_name):
    group = Group.query.filter_by(user_id=g.auth['sub'],
                                  name=group_name).first()
    if group == None:
        raise DoesNotExistError(group_name)
    share = Share.query.filter_by(user_id=g.auth['sub'],
                                  name=share_name).first()
    if share == None:
        raise DoesNotExistError(share_name)
    try:
        group.shares.append(share)
        db.session.commit()
    except IntegrityError as e:
        raise AlreadyExistsError(share_name)
    print('Adding %s to %s' % (group_name, share_name))
    return ('', HTTPStatus.OK)
コード例 #6
0
def remove_path(share_name, path_name):
    share = Share.query.filter_by(user_id=g.auth['sub'],
                                  name=share_name).first()
    if share == None:
        raise DoesNotExistError(share_name)
    Path.query.filter_by(share_id=share.id, name=path_name).delete()
    db.session.commit()
    return ('', HTTPStatus.OK)
コード例 #7
0
def enrollment_state(request):
    session_id = request.GET.get('session_id')
    try:
        enrollment_process = LearningProcess.objects.get(
            sample_sessions__session_id=session_id)
    except LearningProcess.DoesNotExist:
        raise DoesNotExistError("Learning process", session_id)

    state = enrollment_process.state_id
    return state
コード例 #8
0
def add_path(share_name, path_name):
    share = Share.query.filter_by(user_id=g.auth['sub'],
                                  name=share_name).first()
    if share == None:
        raise DoesNotExistError(share_name)
    try:
        path = Path(name=path_name, share_id=share.id, path=g.data['path'])
        db.session.add(path)
        db.session.commit()
    except IntegrityError as e:
        raise AlreadyExistsError(path_name)
    return ('', HTTPStatus.NO_CONTENT)
コード例 #9
0
ファイル: ecs.py プロジェクト: abunuwas/ecs_admin
 def _describe_services(self, cluster):
     #services = [service.split('/')[1] for service in list_services(cluster)]
     try:
         services = self.list_services(cluster=cluster)
         descriptions = self.ecs_client.describe_services(cluster=cluster,
                                                          services=services)
         return descriptions['services']
     except ClientError as e:
         if e.response['Error']['Code'] == 'ClusterNotFoundException':
             raise DoesNotExistError(
                 "Cluster {} does not exist. No services to describe.".
                 format(cluster))
コード例 #10
0
def list_shares():
    user = User.query.filter_by(id=g.auth['sub']).first()
    if (user is None):
        raise DoesNotExistError(g.data['user'])

    shares = []
    for group in user.in_groups:
        for share in group.shares:
            if not share in shares:
                shares.append(share)
    return jsonify({
        'shares': [out_aval_share(share) for share in shares]
    })
コード例 #11
0
def add(share_name):
    device = Device.query.filter_by(user_id=g.auth['sub'],
                                    name=g.data['device']).first()
    if device == None:
        raise DoesNotExistError(g.data['device'])
    try:
        share = Share(name=share_name,
                      user_id=g.auth['sub'],
                      device_id=device.id)
        db.session.add(share)
        db.session.commit()
    except IntegrityError as e:
        raise AlreadyExistsError(share_name)
    return ('', HTTPStatus.NO_CONTENT)
コード例 #12
0
def verification_state(request):
    session_id = request.GET.get('session_id')
    try:
        verification_process = VerificationProcess.objects.get(
            target_session__session_id=session_id)
    except VerificationProcess.DoesNotExist:
        raise DoesNotExistError("Verification process", session_id)

    state = verification_process.state_id
    if state == verification_process.VERIFIED:
        if verification_process.verification_result:
            state = 'verification_success'
            user = authenticate(username=request.GET.get('username'),
                                session_id=session_id,
                                verification_process=verification_process)
            if user is not None and user.is_active:
                logging.info("Logging user `%s` in.." % user.username)
                login(request, user)
        else:
            state = 'verification_failed'
    return state