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): client = event['pathParameters']['id'] #verify if this client belongs from this customer (user) token = get_token_from_headers(event['headers']) token_decoded = utils.jwt_decode(token, ssmutils.get_parameter_store('TOKEN_KEY')) conn_mysql = connection() if not verify_client_customer(conn_mysql, token_decoded['inf']['uuid'], client): conn_mysql.close() return response('Cliente invalido!', 400) #connecting to redis conn = daoredis.connection(ssmutils.get_parameter_store('REDIS_HOST')) #remove client from queue clients = daoredis.remove_client(conn, client) #add date_out in mysql update_client(conn_mysql, client) conn_mysql.close() return response('ok!', 200)
def lambda_handler(event, context): payload = json.loads(event['body']) if 'token' not in payload or not payload['token']: return response('Token invalido', 400) token = payload['token'] #verify token try: result = utils.jwt_decode(token, ssmutils.get_parameter_store('TOKEN_KEY')) except Exception as e: #token expired/invalid print(e) return response('Token invalido', 400) else: customer = get_pre_customer(result['inf']['uuid']) if not customer: return response('Token invalido', 400) customer = customer['precustomer'] print(customer) #add to customer save_customer(customer, result['inf']['uuid']) #remove from pre-customer delete_pre_customer(result['inf']['uuid']) return response('Conta validada', 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): client = json.loads(event['body']) token = get_token_from_headers(event['headers']) #validate payload #validate name if 'name' not in client or not client['name']: return response('Digite o nome!', 400) #validate maximum qtd caracteres in name if (len(client['name']) > int(os.environ['MAXIMUM_QTD_NAME'])): return response('Nome nao pode conter mais que '+os.environ['MAXIMUM_QTD_NAME']+' caracteres!', 400) #verify if email and telephone are not null together if 'email' not in client and 'telephone' not in client: return response('Digite e-mail ou telephone!', 400) if 'email' in client: if not valid_email(client['email']): return response('E-mail invalido!', 400) if 'telephone' in client: if (len(client['telephone']) != int(os.environ['MAXIMUM_QTD_TEL'])): return response('Telefone invalido!', 400) #validate queue belong to user token_decoded = utils.jwt_decode(token, ssmutils.get_parameter_store('TOKEN_KEY')) conn_mysql = connection() if not verify_user_queue(conn_mysql, token_decoded['inf']['uuid'], client['queue']): conn_mysql.close() return response('Fila invalida!', 400) #generate an uuid for queue client client['id_queue_client'] = str(uuid.uuid1()) #set date time in client['date_in'] = str(datetime.now()) #write data into mysql save_client(conn_mysql, client) conn_mysql.close() #add new client in cache position client = { 'id_client':client['id_queue_client'], 'name':client['name'], 'date':client['date_in'], 'id_queue':client['queue'] } conn = daoredis.connection(ssmutils.get_parameter_store('REDIS_HOST')) daoredis.add_client(conn, client) return response('ok!', 200)
def lambda_handler(event, context): #get body and token (Bearer) queue = json.loads(event['body']) token = get_token_from_headers(event['headers']) #validate name if 'name' not in queue or not queue['name']: return response('Digite o nome da fila!', 400) #validate maximum qtd caracteres in name if (len(queue['name']) > int(os.environ['MAXIMUM_QTD_NAME'])): return response( 'Nome nao pode conter mais que ' + os.environ['MAXIMUM_QTD_NAME'] + ' caracteres!', 400) #validate maximum qtd caracteres in text and end queue if (len(queue['text_queue']) > int(os.environ['MAXIMUM_QTD_TEXT'])): return response( 'Texto da fila nao pode conter mais que ' + os.environ['MAXIMUM_QTD_TEXT'] + ' caracteres!', 400) if (len(queue['end_queue']) > int(os.environ['MAXIMUM_QTD_TEXT'])): return response( 'Texto de chamada nao pode conter mais que ' + os.environ['MAXIMUM_QTD_TEXT'] + ' caracteres!', 400) #decode jwt and id_user token_decoded = utils.jwt_decode(token, ssmutils.get_parameter_store('TOKEN_KEY')) #setting variables id_queue = id = str(uuid.uuid1()) name = queue['name'] text_queue = queue['text_queue'] end_queue = queue['end_queue'] id_user = token_decoded['inf']['uuid'] #connection conn = connection() sql = "INSERT INTO queue(id_queue, name, text_queue, end_queue, date_register, id_user) VALUES ('" + id_queue + "', '" + name + "', '" + text_queue + "', '" + end_queue + "', NOW(),'" + id_user + "')" mysqlutils.execute(conn, sql) conn.close() return response('ok', 200)
def lambda_handler(event, context): if not 'authorizationToken' in event or not event['authorizationToken']: return 'Unauthorized' try: token = event['authorizationToken'].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')) policy = generate_policy(token_decoded['inf']['uuid'], 'Allow', event['methodArn']) return policy except Exception as e: print(e) raise Exception('Unauthorized')
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)