From 8d2a25210471fd8fca49ad3826a2bbe3a9543173 Mon Sep 17 00:00:00 2001 From: alanmmolina Date: Fri, 27 Sep 2024 17:23:23 -0300 Subject: [PATCH] atualizando remetente e corrigindo erro na lambda --- source/lambda/auth/main.py | 4 ++-- terraform/variables.tf | 2 +- tests/email.sh | 18 ++++++++++++++++++ tests/login.sh | 31 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 tests/email.sh create mode 100644 tests/login.sh diff --git a/source/lambda/auth/main.py b/source/lambda/auth/main.py index 97f1e80..0717b5e 100644 --- a/source/lambda/auth/main.py +++ b/source/lambda/auth/main.py @@ -41,10 +41,10 @@ def lambda_handler(event, context): except client.exceptions.NotAuthorizedException: return { "statusCode": 401, - "body": json.dumps({"message": "Credenciais inválidas", "response": str(response)}), + "body": json.dumps({"message": "Credenciais inválidas"}), } except Exception as error: return { "statusCode": 400, - "body": json.dumps({"message": str(error), "response": str(response)}), + "body": json.dumps({"message": str(error)}), } diff --git a/terraform/variables.tf b/terraform/variables.tf index be49887..52d3401 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -1,6 +1,6 @@ variable "email" { description = "E-mail do grupo" - default = "postech-5soat-grupo-25@googlegroups.com" + default = "postech-5soat-grupo-25@grr.la" } # AWS Cognito diff --git a/tests/email.sh b/tests/email.sh new file mode 100644 index 0000000..f2169ea --- /dev/null +++ b/tests/email.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +API_GATEWAY_ID="..." +SES_REGION="us-east-1" +FROM_EMAIL="..." +TO_EMAIL="..." # E-mail do médico a ser enviado +NOME_MEDICO="Dr. João" # Nome do médico +NOME_PACIENTE="Alan" # Nome do paciente +DATA="2024-09-30" # Data da consulta +HORARIO="14:00" # Horário da consulta + +# Chamando o endpoint /email +echo "Enviando o e-mail de confirmação..." +response=$(curl -X POST https://$API_GATEWAY_ID.execute-api.us-east-1.amazonaws.com/prod/email \ + -H "Content-Type: application/json" \ + -d "{\"email_medico\": \"$TO_EMAIL\", \"nome_medico\": \"$NOME_MEDICO\", \"nome_paciente\": \"$NOME_PACIENTE\", \"data\": \"$DATA\", \"horario\": \"$HORARIO\"}") + +echo "Resposta da API: $response" \ No newline at end of file diff --git a/tests/login.sh b/tests/login.sh new file mode 100644 index 0000000..980519b --- /dev/null +++ b/tests/login.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +API_GATEWAY_ID="..." +USER_POOL_ID="..." +USERNAME="..." +PASSWORD="..." + +# Cria o usuário com uma senha temporária +echo "Criando o usuário..." +aws cognito-idp admin-create-user \ + --user-pool-id $USER_POOL_ID \ + --username $USERNAME \ + --user-attributes Name=email,Value=$USERNAME \ + --temporary-password $PASSWORD \ + --message-action SUPPRESS > /dev/null 2>&1 + +# Altera a senha para uma permanente +echo "Alterando a senha para uma permanente..." +aws cognito-idp admin-set-user-password \ + --user-pool-id $USER_POOL_ID \ + --username $USERNAME \ + --password $PASSWORD \ + --permanent > /dev/null 2>&1 + +echo "Usuário criado e senha alterada com sucesso!" + +# Faz login usando o API Gateway +echo "Realizando o login..." +curl -X POST https://$API_GATEWAY_ID.execute-api.us-east-1.amazonaws.com/prod/login \ + -H "Content-Type: application/json" \ + -d "{\"email\": \"$USERNAME\", \"password\": \"$PASSWORD\"}"