def lambda_handler(event, context):

    client = event['pathParameters']['id']

    #connecting to redis
    conn = daoredis.connection(ssmutils.get_parameter_store('REDIS_HOST'))

    #get client
    resp = daoredis.get_all(conn, "client:" + client)

    if resp:
        return utils.response(resp, 200)
    else:
        return utils.response({"message": "Not Found"}, 404)
def lambda_handler(event, context):

    #get id client pathParameter
    client_id = event['pathParameters']['id']

    #get client and queue information by this client_id
    conn_mysql = connection()
    resp = get_user_queue(conn_mysql, client_id)

    #if do not exists, so not found
    if not resp:
        return utils.response({"message": "Not Found"}, 404)
    else:
        return utils.response(resp, 200)
Example #3
0
def lambda_handler(event, context):

    customer_id = ''

    #verify if token is in header
    if not 'Authorization' in event['headers'] or not event['headers'][
            'Authorization']:
        return response('Token invalido', 400)

    #decode token
    try:
        token = event['headers']['Authorization'].split()
        if not (token[0].lower() == 'bearer' and token[1]):
            raise Exception('Unauthorized')

        token_decoded = utils.jwt_decode(
            token[1], ssmutils.get_parameter_store('TOKEN_KEY'))
        customer_id = token_decoded['inf']['email']

    except Exception as e:
        print(e)
        raise Exception('Unauthorized')

    #get customer
    customer = get_pre_customer(customer_id)
    if not customer:
        return response('Usuario invalido', 400)

    #remove password
    customer.pop('password', None)

    return utils.response(customer, 200)
Example #4
0
def lambda_handler(event, context):

    queue = event['pathParameters']['id']

    #verify if this list belongs to this user
    token = get_token_from_headers(event['headers'])
    token_decoded = utils.jwt_decode(token,
                                     ssmutils.get_parameter_store('TOKEN_KEY'))
    conn = connection()
    if not verify_user_queue(conn, token_decoded['inf']['uuid'], queue):
        conn.close()
        return response('Fila invalida!', 400)

    #connecting to redis
    conn = daoredis.connection(ssmutils.get_parameter_store('REDIS_HOST'))

    #get clients from queue
    clients = daoredis.get_all_queue(conn, queue)

    #transform string position into integer position, after sort by position
    if clients:
        list = []
        for client in clients:
            client["pos"] = int(client["pos"])
            list.append(client)
        list.sort(key=operator.itemgetter("pos"))
        clients = list

    return utils.response(clients, 200)
def lambda_handler(event, context):

    if 'username' not in event['headers'] or not event['headers']['username']:
        return response('Unauthorized', 401)

    if 'password' not in event['headers'] or not event['headers']['password']:
        return response('Unauthorized', 401)

    username = event['headers']['username']
    password = event['headers']['password']

    #get from dynamodb: custmer
    customer = get_customer(username)
    if not customer:
        print('user doesnot exists precustomer neither customer')
        return response('Unauthorized', 401)
    else:
        #if user exists, but password wrong
        if customer['password'] != utils.encode_password(password):
            return response('Unauthorized', 401)
        else:
            #generate token
            token_expiration = 3600 * 24  #one day expiration
            token = str(
                utils.jwt_encode(
                    {
                        'email': customer['email'],
                        'uuid': customer['UUID']
                    }, ssmutils.get_parameter_store('TOKEN_KEY'),
                    token_expiration), "utf-8")

            #print login
            log = {
                'login-auth': {
                    'time': str(datetime.now()),
                    'user': username
                }
            }
            print(log)

            #auth ok
            return utils.response(
                {
                    "token": token,
                    "exp": int((time())) + token_expiration,
                    "type": "Bearer"
                }, 200)
def lambda_handler(event, context):

    #get customer (user_id) from token
    token = get_token_from_headers(event['headers'])
    token_decoded = utils.jwt_decode(token,
                                     ssmutils.get_parameter_store('TOKEN_KEY'))
    user_id = token_decoded['inf']['uuid']

    #set queue_id if exists, to bring an especific queue
    queue_id = False
    if event['pathParameters'] != None and 'id' in event['pathParameters']:
        queue_id = event['pathParameters']['id']
        print('queue_id: ' + queue_id)

    #get queues
    conn_mysql = connection()
    queues = get_user_queue(conn_mysql, user_id, queue_id)

    #if the request is trying to get an especific queue, but the query not find, so its 404 (not found)
    if not queues and queue_id:
        return response('Not Found', 404)
    else:
        return utils.response(queues, 200)
Example #7
0
def moveLeft():
    # USE JSON FOR SIMPLICITY
    request_json = request.get_json()
    print("request json: ", request_json)
    # socketio.emit("move", request_json["message"])  # emit to the robot socket
    return response('success', "moved left", 200)
Example #8
0
def response(message, status_code):
    return utils.response({"message": message}, status_code)
Example #9
0
def device(oid):
    devices = utils.response("device", oid, True).generate()
    return flask.jsonify(devices)
Example #10
0
def counterMulti(oid, n):
    counter = utils.response("counter", oid, True)
    counter.getHistory(n)
    reply = counter.generate()
    return flask.jsonify(reply)
Example #11
0
def counter(oid):
    counter = utils.response("counter", oid, True).generate()
    return flask.jsonify(counter)
Example #12
0
def site(oid):
    site = utils.response("site", oid, True).generate()
    return flask.jsonify(site)
Example #13
0
def siteAll():
    site = utils.response("site", "all", False).generate()
    return flask.jsonify(site)
Example #14
0
def connection(oid):
    cons = utils.response("connection", oid, True).generate()
    return flask.jsonify(cons)
Example #15
0
def connectionAll():
    cons = utils.response("connection", "all", False).generate()
    return flask.jsonify(cons)
Example #16
0
def moveRight():
    request_json = request.get_json()
    print("request json: ", request_json)
    return response('success', "moved right", 200)
Example #17
0
def moveBackward():
    request_json = request.get_json()
    print("request json: ", request_json)
    return response('success', "moved Backward", 200)
Example #18
0
def deviceAll():
    devices = utils.response("device", "all", False).generate()
    return flask.jsonify(devices)