Beispiel #1
0
def TeamLeagues(id):
    conn.commit(
    )  # allows reload for testing otherwise database is not refreshed
    if request.method == 'GET':
        # get organizer
        cur.execute(
            "SELECT * FROM organizers WHERE id IN (SELECT organizer_id FROM organizers_teams WHERE team_id=%d)"
            % id)
        team = cur.fetchall()
        cur.execute("SELECT * FROM organizers WHERE id=%d" % id)
        league = cur.fetchall()
        resp = []
        if (league == []):
            resp = Response(json.dumps(resp), status=404)
            return resp
        else:
            for a in range(len(team)):
                obj = {}
                show_results(league_keys, obj, team, a, ['organizer_key'])
                resp.append(obj)
            return json.dumps(resp)
    elif request.method == 'DELETE':
        if check_auth('users', 'request_key', 'team_id',
                      str(id) + ' AND is_owner_team=1'):
            cur.execute('SELECT * FROM teams WHERE id=%d' % t_id)
            if (cur.fetchone() is None):
                return Response(status=404)
            else:
                cur.execute('DELETE FROM organizers_teams WHERE team_id=' +
                            str(t_id) + ' AND organizer_id=' + str(org_id))
                conn.commit()
                return Response(status=200)
        else:
            return Response(status=409)
Beispiel #2
0
def LeagueTeamsRequests(id):
    conn.commit(
    )  # allows reload for testing otherwise database is not refreshed
    if request.method == 'GET':
        # get organizer
        cur.execute(
            "SELECT * FROM teams WHERE id IN (SELECT team_id FROM organizers_teams WHERE organizer_id=%d AND request=1)"
            % id)
        team = cur.fetchall()
        cur.execute("SELECT * FROM organizers WHERE id=%d" % id)
        league = cur.fetchall()
        resp = []
        if (league == []):
            resp = Response(status=404)
            return resp
        else:
            for a in range(len(team)):
                obj = {}
                show_results(team_keys, obj, team, a, ['team_key'])
                resp.append(obj)
            return json.dumps(resp)
    elif request.method == 'POST':
        body = json.dumps(request.form)
        body = json.loads(body)
        if check_auth('users', 'request_key', 'team_id',
                      str(body['team_id']) + ' AND is_owner_team=1'):
            try:
                cur.execute('INSERT INTO organizers_teams ' + put_post(
                    organizer_team_keys, ['id', 'request'], body, 'POST'))
                conn.commit()
                return Response(status=200)
            except (mysql.connector.Error, KeyError) as err:
                return Response(status=404)
        else:
            return Response(status=409)
Beispiel #3
0
def Brackets(id):
    conn.commit(
    )  # allows reload for testing otherwise database is not refreshed
    if request.method == 'GET':
        # get all brackets
        resp = []
        cur.execute("SELECT * FROM brackets WHERE tournament_id=" + str(id) +
                    " ORDER BY place")
        brak = cur.fetchall()
        if brak == []:
            resp = Response(json.dumps(resp), status=404)
            return resp
        else:
            for a in range(len(brak)):
                obj = {}
                show_results(bracket_keys, obj, brak, a)
                obj['games_played'] = obj['games_won'] + obj[
                    'games_tied'] + obj['games_lost']
                resp.append(obj)
            return json.dumps(resp)
    elif request.method == 'POST':
        body = json.dumps(request.form)
        body = json.loads(body)
        body['tournament_id'] = str(id)
        cur.execute("SELECT type FROM tournaments WHERE id=" + str(id))
        tourn = cur.fetchone()
        if check_auth(
                'organizers', 'organizer_key', 'id',
                '(SELECT organizer_id FROM tournaments WHERE id=' + str(id) +
                ')'
        ) or check_auth(
                'users', 'request_key', 'id',
                '(SELECT owner_id FROM organizers WHERE id =(SELECT organizer_id FROM tournaments WHERE id='
                + str(id) + '))'):
            if tourn[0] == 1 or tourn[0] == 2:
                try:
                    cur.execute('INSERT INTO brackets ' +
                                put_post(bracket_keys, [
                                    'id', 'user_id', 'games_won', 'games_tied',
                                    'games_lost', 'score'
                                ], body, 'POST'))
                    conn.commit()
                    return Response(status=200)
                except (mysql.connector.Error, KeyError) as err:
                    return Response(status=404)
            else:
                try:
                    cur.execute('INSERT INTO brackets ' +
                                put_post(bracket_keys, [
                                    'id', 'team_id', 'games_won', 'games_tied',
                                    'games_lost', 'score'
                                ], body, 'POST'))
                    conn.commit()
                    return Response(status=200)
                except (mysql.connector.Error, KeyError) as err:
                    return Response(status=404)
        else:
            return Response(status=409)
Beispiel #4
0
def containers_list():
    client = connector.remote()
    if client['error']:
        response = Response({'success': False, 'payload': client['message']})
        return response.success()
    client = client['conn']
    #======================

    response = []
    containers = client.containers.all()
    for container in containers:
        IP_ADDR = "N/A"
        if container.status.lower() == "running":
            try:
                net_key = [key for key in container.state().network.keys() if key != 'lo'][0]#Exclude the LOOPBACK
                IP_ADDR = str(container.state().network[net_key]['addresses'][0]['address'])
            except:
                pass
        #OS-metadata

        if "image.distribution" in container.expanded_config.keys():
            IMAGE_OS = str(container.expanded_config["image.distribution"]).capitalize()
        else:
            IMAGE_OS = str(container.expanded_config["image.os"]).capitalize()
        
        if "image.release" in container.expanded_config.keys():
            IMAGE_REL = container.expanded_config["image.release"].capitalize()
        else:
            IMAGE_REL = str(container.expanded_config["image.version"])

        OS_METADATA = {"name" : IMAGE_OS,
                        "release" : IMAGE_REL,
                        "architecture" : str(container.expanded_config["image.architecture"])}


        response.append({'name': container.name,
            'ipaddress': IP_ADDR,
            'status': container.status,
            'created_at': container.created_at,
            'OS' : OS_METADATA
            })

    data = {'success': True, 'payload': response}
    response = Response(data)
    return response.success()
Beispiel #5
0
def TeamUsers(id):
    conn.commit(
    )  # allows reload for testing otherwise database is not refreshed
    if request.method == 'GET':
        # get organizer
        cur.execute("SELECT * FROM users WHERE team_id=" + str(id))
        usr = cur.fetchall()
        resp = []
        if (usr == []):
            resp = Response(json.dumps(resp), status=404)
            return resp
        else:
            for a in range(len(usr)):
                obj = {}
                show_results(user_keys, obj, usr, a,
                             ['password', 'request_key', 'team_id'])
                resp.append(obj)
            return json.dumps(resp)
Beispiel #6
0
def LeagueTournaments(id):
    conn.commit(
    )  # allows reload for testing otherwise database is not refreshed
    if request.method == 'GET':
        # get organizer
        cur.execute("SELECT * FROM tournaments WHERE organizer_id=%d" % id)
        trn = cur.fetchall()
        cur.execute("SELECT * FROM organizers WHERE id=%d" % id)
        league = cur.fetchall()
        resp = []
        if (league == []):
            resp = Response(status=404)
            return resp
        else:
            for a in range(len(trn)):
                obj = {}
                show_results(tournament_keys, obj, trn, a)
                money = str(obj['entry_fee'])[:-2] + "." + str(
                    obj['entry_fee']
                )[-2:]  #change entry fee from cent int to string decimal (used to display in json)
                obj['entry_fee'] = money
                resp.append(obj)
            return json.dumps(resp, default=str)