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)
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)
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)
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)
def response(message, status_code): return utils.response({"message": message}, status_code)
def device(oid): devices = utils.response("device", oid, True).generate() return flask.jsonify(devices)
def counterMulti(oid, n): counter = utils.response("counter", oid, True) counter.getHistory(n) reply = counter.generate() return flask.jsonify(reply)
def counter(oid): counter = utils.response("counter", oid, True).generate() return flask.jsonify(counter)
def site(oid): site = utils.response("site", oid, True).generate() return flask.jsonify(site)
def siteAll(): site = utils.response("site", "all", False).generate() return flask.jsonify(site)
def connection(oid): cons = utils.response("connection", oid, True).generate() return flask.jsonify(cons)
def connectionAll(): cons = utils.response("connection", "all", False).generate() return flask.jsonify(cons)
def moveRight(): request_json = request.get_json() print("request json: ", request_json) return response('success', "moved right", 200)
def moveBackward(): request_json = request.get_json() print("request json: ", request_json) return response('success', "moved Backward", 200)
def deviceAll(): devices = utils.response("device", "all", False).generate() return flask.jsonify(devices)