Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
bf321d8
added modules
lseixas Mar 27, 2025
7876320
pytest markskip for modules that use dynamo
lseixas Mar 27, 2025
f1947c5
added manager
lseixas Apr 15, 2025
7642b42
added local minio image for testing bucket upload
lseixas Apr 15, 2025
0e87d4e
fixed environment client variables and local bucket endpoint url
lseixas Apr 15, 2025
9258818
added sender test
lseixas Apr 15, 2025
7200033
added s3manager
lseixas Apr 15, 2025
d961fa0
finished sender
lseixas Apr 15, 2025
cfaf80a
commented that sender test will not work with current mock dates
lseixas Apr 15, 2025
7b23ecd
feat: setup aws account id
tokujiTO May 6, 2025
fc84f2b
feat: fix env setup accountid to env
tokujiTO May 6, 2025
0d9509e
feat: add branch on push
tokujiTO May 6, 2025
aeae003
feat: fix s3 name to dev
tokujiTO May 6, 2025
b4ecd57
feat: get_all_users route made integrated with reservation_mss_user m…
JamizM May 16, 2025
fbffc2e
feat: added interface and function get_all_users
JamizM May 16, 2025
6fa3e85
fix: changing other routes for microservice integration to work
JamizM May 16, 2025
255c3f9
TODO on generate_report
JamizM May 16, 2025
4c64758
chore: add temporary macos files to .gitignore
VictorGasperi May 21, 2025
21a13c9
fix: defining get_all_users so load_booking_mock_to_dynamo can work
VictorGasperi May 21, 2025
b9ef6f8
feat: implement user_api_client Facade
VictorGasperi May 21, 2025
7c1872f
test: user_api_client tested
VictorGasperi May 21, 2025
5b3ead4
feat(report_aggregator): adds the user name on the excel file
VictorGasperi May 21, 2025
a72e1b6
feat(test_generate_report_transformer): update file opening logic for…
VictorGasperi May 21, 2025
d37e34c
feat(test_generate_report_transformer): update file opening logic for…
VictorGasperi May 21, 2025
acebfd4
chore: add requests package to requirements-dev.txt
VictorGasperi May 21, 2025
6cf72d2
feat(generate_report_aggregator): update user statistics key handling…
VictorGasperi May 21, 2025
36a0ce1
Merge branch 'dev' into user-on-generate-report
VictorGasperi May 23, 2025
bb057fd
Merge branch 'dev' into user-on-generate-report
VictorGasperi May 23, 2025
054fcd1
Revert "Merge branch 'dev' into user-on-generate-report"
VictorGasperi May 23, 2025
f4f37d1
Revert "Merge branch 'dev' into user-on-generate-report"
VictorGasperi May 23, 2025
6e25e19
fix: trying to resolve merge errors
VictorGasperi May 23, 2025
f0ceaf8
added 15 min intolerance in booking sheduling, added comments to code…
lseixas Jul 7, 2025
e437a64
added error message validation to tests
lseixas Jul 7, 2025
0c5cbc7
added 15 min and overlap intolerance to update_booking module, added …
lseixas Jul 7, 2025
7392794
Merge branch 'dev' into user-on-generate-report
lseixas Jul 7, 2025
167a3e3
fixed merge, removed get_all_users as it was unused
lseixas Jul 7, 2025
86c13e0
Merge pull request #20 from Maua-Dev/user-on-generate-report
lseixas Jul 7, 2025
255b5d9
updating import reference to newer cdk version
lseixas Jul 7, 2025
3a3d550
fix: generalizar o endpoint da api de user
VictorGasperi Jul 11, 2025
386532b
feat: adicionar variável USER_API_URL ao ambiente de implantação
VictorGasperi Jul 11, 2025
e3662dd
fix: generalizar o endpoint da api de user
VictorGasperi Jul 11, 2025
9377078
feat: adicionar variável USER_API_URL ao ambiente de implantação
VictorGasperi Jul 11, 2025
f9110b0
Merge branch 'dev' into fix/githubActions
tokujiTO Jul 11, 2025
3e10de3
Merge pull request #23 from Maua-Dev/fix/githubActions
tokujiTO Jul 11, 2025
a71db3b
feat: fix github action
tokujiTO Jul 11, 2025
a887da2
modified user api client location for global access, added new functi…
Jul 12, 2025
51e65a1
added graph authorizer
Jul 12, 2025
2ea43a2
added pytest marksip to unrunnable tests, moved user client folder test
lseixas Jul 12, 2025
9fb65b2
improved minio building, refactored s3 manager, made it a client, ref…
lseixas Jul 13, 2025
30d0ee8
added @ to markskip 🦧
lseixas Jul 13, 2025
bfa44cf
changed authorizer name, added new logic for validation in get-user r…
lseixas Jul 14, 2025
a387d0c
added role validation login
lseixas Jul 14, 2025
2b3004e
fixed tests
lseixas Jul 14, 2025
0296e58
bringing changes from auth to test in aws console
lseixas Jul 14, 2025
1c1b62b
feat: implementar lógica para receber informações do usuário e valida…
VictorGasperi Jul 16, 2025
1bd0e7e
added auth login to create court
lseixas Jul 18, 2025
fe7ad42
added auth logic to update_court, added forbidden action testing, add…
lseixas Jul 18, 2025
71505dd
added authorizer functions and token to court routes
lseixas Jul 18, 2025
a475f37
informative commit
lseixas Jul 18, 2025
7e24417
feat: adicionar lógica de validação de usuário na exclusão de reservas
VictorGasperi Jul 18, 2025
4940a53
refactor: remover comentários TODO sobre lógica de usuário e e-mail
VictorGasperi Jul 18, 2025
31ec0c6
Merge remote-tracking branch 'origin/auth' into email_notification
VictorGasperi Jul 18, 2025
b35a499
refactor: comentar método send_user_email no repositório de reservas
VictorGasperi Jul 18, 2025
edb1d2e
feat: adicionar lógica de validação de usuário na exclusão de reservas
VictorGasperi Jul 22, 2025
bf19bdd
feat: adicionar função para compor e-mail de delete booking para o us…
VictorGasperi Jul 22, 2025
6f88102
feat: implementar envio de e-mail para usuário ao cancelar reserva
VictorGasperi Jul 22, 2025
59699cc
feat: adicionar campo 'name' ao usuário nas classes de teste de exclu…
VictorGasperi Jul 22, 2025
37d684b
feat: adicionar permissões SES para a função de exclusão de reservas
VictorGasperi Jul 22, 2025
512835e
Merge branch 'dev' into email_notification
lseixas Jul 22, 2025
09c96d3
Merge pull request #25 from Maua-Dev/email_notification
lseixas Jul 22, 2025
2deac31
removed lambda_power_tools from authorizer
lseixas Jul 28, 2025
3c2db4a
readding variables to CD
lseixas Jul 29, 2025
e1018b6
added user api url to cd
lseixas Jul 29, 2025
f2dada5
reverting to old account for better debugging
lseixas Jul 30, 2025
7955a0a
shoving to sa-east-1
lseixas Jul 30, 2025
35f2064
uniquifying s3 bucket name as cant delete bucket in the new account
lseixas Jul 30, 2025
4458900
🦧
lseixas Jul 30, 2025
16977ab
added some commnets, added authorizer to create_booking
lseixas Jul 30, 2025
4de6655
fixing user endpoint
lseixas Jul 30, 2025
2d83898
adjusting create booking controller to fetch for the right parameter …
lseixas Jul 30, 2025
cccd31e
attempting to add more debug
lseixas Jul 30, 2025
cf914e2
fixing vent extraction
lseixas Jul 30, 2025
950bb3b
adding correct authorizer user catching, fixed tests
lseixas Jul 30, 2025
0db05ac
fixing get all booking module name in lambda_stack
lseixas Jul 30, 2025
792e4b1
fixing entire get-all-bookings module names
lseixas Jul 30, 2025
404c34a
fix: get_bookings de volta a vida
VictorGasperi Jul 30, 2025
9f1c3b3
Merge branch 'dev' into fix/get_bookings
VictorGasperi Jul 30, 2025
0dfadf8
attemp 1 reverting changes, merging old commit with todays dev
lseixas Aug 5, 2025
3b65671
pre-merge checkpoint
lseixas Aug 5, 2025
7e46589
fixing tests
lseixas Aug 5, 2025
4eee5da
Merge pull request #27 from Maua-Dev/fix/get_bookings
lseixas Aug 6, 2025
e99a1f5
removing unused imports
lseixas Aug 7, 2025
a7e8b21
refactoring adjust layer script to fetch new lambda dependencies
lseixas Aug 7, 2025
891dda2
adjusting relative import from new script
lseixas Aug 7, 2025
f5df94a
adjusting requirements name
lseixas Aug 7, 2025
60feb52
changing requirements directory
lseixas Aug 7, 2025
6795bc6
fixing urllib3 version as boto3 requires older one
lseixas Aug 7, 2025
385684a
fixing delete court
lseixas Aug 7, 2025
f0f1a13
attempting to fix none value somewhere in the dto
lseixas Aug 7, 2025
3b5095f
adding redundance to get all dynamo methods
lseixas Aug 7, 2025
e1a6623
added token authorizer to delete booking
lseixas Aug 7, 2025
2ce2d00
feat(update-booking): integrating user validation
VictorGasperi Aug 8, 2025
e7f3424
Merge pull request #28 from Maua-Dev/validate_update_booking
lseixas Aug 9, 2025
7a46254
adding dynamo permission to generate report
lseixas Aug 12, 2025
6ddbe44
updating to new account again
lseixas Aug 12, 2025
473c962
fixing region
lseixas Aug 12, 2025
70a1df4
fixing region again
lseixas Aug 12, 2025
2d630bb
updating aws region 🦧
lseixas Aug 12, 2025
d216abf
improved s3 upload method to debug tf is wrong
lseixas Aug 12, 2025
f98b595
passing the report bytes, not the object
lseixas Aug 12, 2025
f0886de
adding bucket name to environment variables at iac_stack
lseixas Aug 12, 2025
2c3602a
fix(update-booking): add user authorizer on lambda
VictorGasperi Aug 14, 2025
db3d674
added new module, added module to lambda stack, created new erros for…
lseixas Aug 27, 2025
2f47ad1
markskip to test that needs endpoint
lseixas Aug 27, 2025
77026e6
Merge pull request #30 from Maua-Dev/get-all-admin-bookings
lseixas Aug 27, 2025
86c4987
added authorizer to update_booking
lseixas Aug 27, 2025
d7ea9ff
dummy commit to update secret deploy
lseixas Aug 27, 2025
1db5825
removing unused secret
lseixas Aug 27, 2025
abc899d
Merge pull request #29 from Maua-Dev/auth_on_update_booking
VictorGasperi Aug 27, 2025
0e3d26d
chore: criando diretorio da rota
VictorGasperi Aug 28, 2025
d8b09fa
feat: usecase da rota feito
VictorGasperi Aug 28, 2025
692c386
chore: adicionando diretorio de testes da rota
VictorGasperi Aug 28, 2025
98cbe0d
fix: retirando user_id dos bookings retornados
VictorGasperi Aug 28, 2025
b567790
feat: viewmodel da rota
VictorGasperi Aug 28, 2025
b37a70a
feat: controller da rota
VictorGasperi Aug 28, 2025
d458619
feat: presenter da rota
VictorGasperi Aug 28, 2025
71a08a1
feat: integracao com o lambda
VictorGasperi Aug 28, 2025
46ddf33
Merge pull request #31 from Maua-Dev/route/get-all-bookings-grouped-b…
VictorGasperi Aug 28, 2025
ded1c68
fix: imports dando erro
VictorGasperi Aug 28, 2025
c49f285
Merge pull request #32 from Maua-Dev/fix/get_all_bookings_grouped_by_…
VictorGasperi Aug 28, 2025
6fa4238
removed user-id from all get routes
lseixas Aug 30, 2025
338037d
Merge pull request #33 from Maua-Dev/user-id-hidding
lseixas Aug 30, 2025
e6b4e9c
fixing homl name
lseixas Sep 6, 2025
34e0073
feat(entity): adicionando o parametro type em booking
VictorGasperi Sep 10, 2025
04d7246
feat(enum): TYPE
VictorGasperi Sep 10, 2025
17776eb
test(entity): implementa testes unitarios para a entidade
VictorGasperi Sep 10, 2025
40f4e92
fix(domain): adicionando um NA no sport e melhorando a criacao de um …
VictorGasperi Sep 11, 2025
e4a096d
test(entity): testes da entidade booking
VictorGasperi Sep 11, 2025
c07353c
test(repo): testes do mock do booking
VictorGasperi Sep 11, 2025
29495fe
test(repo): testes do repositorio mock
VictorGasperi Sep 11, 2025
ed24b50
feat(modules): adicionando novo campo nas rotas
VictorGasperi Sep 11, 2025
efc2b66
test(modules): testando novo campo na rota create_booking
VictorGasperi Sep 11, 2025
168e202
refat(booking): refatoramento geral:
VictorGasperi Sep 15, 2025
eb370ad
Merge pull request #34 from Maua-Dev/feat/booking
VictorGasperi Sep 15, 2025
44504e5
fix()get_all_bookigs): remove user_id from mock tests
VictorGasperi Sep 15, 2025
43de323
Merge pull request #35 from Maua-Dev/fix/get_all_bookings
VictorGasperi Sep 15, 2025
c67fd82
fix(DTO): tentando corrigir o DTO
VictorGasperi Sep 15, 2025
afe05aa
Merge pull request #36 from Maua-Dev/fix/DTO
VictorGasperi Sep 15, 2025
1f96c4c
fix(booking): corrigindo erros de viewmodel
VictorGasperi Sep 15, 2025
842ad38
Merge pull request #37 from Maua-Dev/fix/booking
VictorGasperi Sep 16, 2025
78a778a
fix: provavel problema no DTO
VictorGasperi Sep 16, 2025
ae377a3
fix(enums): adicionando o tipo UNDEFINED para bookings já existentes
VictorGasperi Sep 16, 2025
cf76b10
fix(create-booking): arrumando os testes do usecase
VictorGasperi Sep 16, 2025
30d27f6
Merge pull request #38 from Maua-Dev/fix/booking
VictorGasperi Sep 16, 2025
81e6371
fix(DTO): Retorna UNDEFINED caso o booking ja exista
VictorGasperi Sep 16, 2025
1321797
Merge pull request #39 from Maua-Dev/fix/DTO
VictorGasperi Sep 16, 2025
9af553a
fix(get-bookings): arrumando alguns pontos para ver se a rota funcion…
VictorGasperi Sep 17, 2025
592e25e
Merge pull request #40 from Maua-Dev/fix/get_bookings
VictorGasperi Sep 17, 2025
4b18502
fix(delete-booking): ajustando logica de envio de e-mail
VictorGasperi Oct 1, 2025
8718294
fixing bucket name, adding cfn distribution
lseixas Oct 4, 2025
2fee476
Merge pull request #41 from Maua-Dev/fix/email
VictorGasperi Oct 6, 2025
1093e54
fix(delete-booking): ajustando as variaveis de ambiente com o enderec…
VictorGasperi Oct 7, 2025
6ec9dd1
Merge pull request #42 from Maua-Dev/fix/email_env
VictorGasperi Oct 7, 2025
7cbf26d
fix(delete-booking): arrumando maneira de acesso as variaveis de ambi…
VictorGasperi Oct 7, 2025
866a40e
fix(delete_booking): tentando entender o problema
VictorGasperi Oct 7, 2025
acd6745
fix(delete-booking): tentando entender o problema
VictorGasperi Oct 7, 2025
0483290
feat(delete_booking): provavel erro na passagem da resposta do dynamo
VictorGasperi Oct 7, 2025
c2b46db
fix(compose-email): provavel erro no format
VictorGasperi Oct 7, 2025
7c99dd1
fix(generate-report): corrigindo possiveis problemas na geracao do re…
VictorGasperi Oct 9, 2025
cc4ac1d
fix(generate-report): adicionando prints para debuggar o problema
VictorGasperi Oct 9, 2025
9d60e42
Merge pull request #43 from Maua-Dev/fix/reports
VictorGasperi Oct 9, 2025
8e12cee
fix(generate-report): provavel erro na manipulacao da data
VictorGasperi Oct 9, 2025
8430ed8
fix(generate-report): court number inexistente no dicionario de estat…
VictorGasperi Oct 9, 2025
76d9943
fix(generate-report): erro de key nos esportes novos
VictorGasperi Oct 9, 2025
d1dde62
fix(generate-report): ajustando identacao das estatisticas de user
VictorGasperi Oct 9, 2025
74f1771
fix(generate-report): erro na validacao da existencia da key no dicio…
VictorGasperi Oct 9, 2025
9b4a500
fix(compose-email): ajuste no horário da reserva para GMT-03
VictorGasperi Oct 13, 2025
da6c9f9
Merge pull request #44 from Maua-Dev/fix/email-hour
VictorGasperi Oct 13, 2025
48ed817
fix(bucket-stack): alterando nome do bucket para ficar generico
VictorGasperi Oct 13, 2025
3b2bb9e
Merge pull request #45 from Maua-Dev/fix/bucket-stack
VictorGasperi Oct 13, 2025
f70b441
fix(compose-email): adicionando imagens ao e-mail de cancelamento
VictorGasperi Oct 16, 2025
bcbae3b
Merge pull request #46 from Maua-Dev/fix/email-images
VictorGasperi Oct 16, 2025
7b70133
fix(lambda-env): adicionando a url dos assets do e-mail
VictorGasperi Oct 16, 2025
c20715b
fix(compose-email): removendo alguns trechos do e-mail
VictorGasperi Oct 16, 2025
d4dc0f2
feat(sports-enum): adicionando esportes solicitados
VictorGasperi Oct 17, 2025
d0ced7c
fix(sports-enum): nao deu para alterar para tenis de mesa
VictorGasperi Oct 17, 2025
a5c1ba6
Merge pull request #47 from Maua-Dev/fix/sports
VictorGasperi Oct 17, 2025
35ace1a
fix(sport-enum): arrumando o esporte natacao
VictorGasperi Oct 17, 2025
b0f4a68
fix(generate-report): adicionando a quadra 0
VictorGasperi Oct 17, 2025
c3e276d
fix(lambda-stack): python 3.9 -> 13.3
VictorGasperi Oct 18, 2025
f2a12e7
fix(CD): mudanca de versao python para 13.3
VictorGasperi Oct 18, 2025
aa9cdbc
fix(python): 3.9 -> 3.13
VictorGasperi Oct 18, 2025
ad7935a
fix(lambda-stack): versao atual do lambda não tem o enum atualizado d…
VictorGasperi Oct 18, 2025
0a7f9ca
fix(lambda-stack): ajustando python layers
VictorGasperi Oct 18, 2025
47c2670
fix(generate-report): adicionando nome de usuario nas outras estatist…
VictorGasperi Oct 18, 2025
bd5b9e9
fix(delete-booking): alteracao no corpo do e-mail
veloy25 Oct 24, 2025
4a39659
Merge pull request #48 from Maua-Dev/fix_email
veloy25 Oct 24, 2025
60fe5f5
fix(compose-email): alterando corpo do email
VictorGasperi Oct 24, 2025
7af1cfb
fix(generate-report): ajustando horario das 18h para as 11:30h
VictorGasperi Nov 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 68 additions & 38 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: CD

on:
Expand All @@ -7,52 +6,83 @@ on:
- prod
- dev
- homolog
- fix/githubActions

workflow_dispatch:

jobs:
DeployToAWS:
environment:
name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v2
- name: Setup AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/GithubActionsRole
role-session-name: github-action

- name: Setting stage and stack name
run: |
echo "STAGE=${{ github.ref_name }}"
echo "STACK_NAME=ReservationStackScheduleANDCourts${{github.ref_name}}" >> $GITHUB_ENV

- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Installing Dependencies
run: |
npm install -g aws-cdk
cd iac
pip install -r requirements.txt

- name: DeployWithCDK
run: |
cd iac
cdk synth
cdk deploy --require-approval never

env:
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
STACK_NAME: ${{ env.STACK_NAME }}
GITHUB_REF_NAME: ${{ github.ref_name }}
GRAPH_MICROSOFT_ENDPOINT: ${{ secrets.GRAPH_MICROSOFT_ENDPOINT }}
- uses: actions/checkout@v2

- name: Set AWS Account ID
run: |
if [[ "${{ github.ref_name }}" == "dev" ]]; then
echo "AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID_DEV }}" >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "homolog" ]]; then
echo "AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID_HOML }}" >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "prod" ]]; then
echo "AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID_PROD }}" >> $GITHUB_ENV
else
echo "Invalid branch name!" && exit 1
fi

- name: Setup AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/GithubActionsRole
role-session-name: github-action

- name: Setting stage and stack name
run: |
echo "STAGE=${{ github.ref_name }}"
if [[ "${{ github.ref_name }}" == "prod" ]]; then
echo "STAGE=prod" >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "homolog" ]]; then
echo "STAGE=homolog" >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
echo "STAGE=dev" >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "fix/githubActions" ]]; then
echo "STAGE=dev" >> $GITHUB_ENV
else
echo "Invalid branch name!" && exit 1
fi
echo "STACK_NAME=ReservationStackScheduleANDCourts${{env.STAGE}}" >> $GITHUB_ENV

- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.13"

- name: Installing Dependencies
run: |
npm install -g aws-cdk
cd iac
pip install -r requirements.txt

- name: DeployWithCDK
run: |
cd iac
cdk synth
cdk deploy --require-approval never

env:
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ env.AWS_ACCOUNT_ID }}
STACK_NAME: ${{ env.STACK_NAME }}
GITHUB_REF_NAME: ${{ github.ref_name }}
MSS_NAME: ${{ github.event.repository.name }}
S3_ASSETS_CDN: ${{ vars.S3_ASSETS_CDN }}
AUTH_DEV_SYSTEM_USERPOOL_ARN_DEV: ${{ secrets.AUTH_DEV_SYSTEM_USERPOOL_ARN_DEV }}
FROM_EMAIL: ${{ vars.FROM_EMAIL }}
HIDDEN_COPY: ${{ vars.HIDDEN_COPY }}
REPLY_TO_EMAIL: ${{ vars.REPLY_TO_EMAIL }}
USER_API_URL: ${{ secrets.USER_API_URL }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ dmypy.json
/.idea/
iac/local/docker/dynamodb/shared-local-instance.db


# MACOS temp files
.DS_Store
88 changes: 54 additions & 34 deletions iac/adjust_layer_directory.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,57 @@
import os
import shutil
from pathlib import Path
import sys

IAC_DIRECTORY_NAME = "iac"
SOURCE_DIRECTORY_NAME = "src"
LAMBDA_LAYER_PREFIX = os.path.join("python", "src")


def adjust_layer_directory(shared_dir_name: str, destination: str):
# Get the root directory of the source directory
root_directory = Path(__file__).parent.parent
iac_directory = os.path.join(root_directory, IAC_DIRECTORY_NAME)

print(f"Root directory: {root_directory}")
print(f"Root direcotry files: {os.listdir(root_directory)}")
print(f"IaC directory: {iac_directory}")
print(f"IaC directory files: {os.listdir(iac_directory)}")


# Get the destination and source directory
destination_directory = os.path.join(root_directory, IAC_DIRECTORY_NAME, destination)
source_directory = os.path.join(root_directory, SOURCE_DIRECTORY_NAME, shared_dir_name)

# Delete the destination directory if it exists
if os.path.exists(destination_directory):
shutil.rmtree(destination_directory)

# Copy the source directory to the destination directory
shutil.copytree(source_directory, os.path.join(destination_directory, LAMBDA_LAYER_PREFIX, shared_dir_name))
print(
f"Copying files from {source_directory} to {os.path.join(destination_directory, LAMBDA_LAYER_PREFIX, shared_dir_name)}")


import subprocess
from pathlib import Path # Importe a biblioteca pathlib

# --- Configurações ---
BUILD_DIRECTORY = "build"
PYTHON_TOP_LEVEL_DIR = os.path.join(BUILD_DIRECTORY, "python")
REQUIREMENTS_FILE = "requirements-layer.txt"

# --- CONSTRUÇÃO CORRETA DO CAMINHO ---
# Pega o diretório do projeto (a raiz 'reservation_api') subindo um nível a partir do script atual.
PROJECT_ROOT = Path(__file__).parent.parent
# Agora, constrói o caminho para 'src/shared' a partir da raiz do projeto.
SHARED_CODE_SOURCE = os.path.join(PROJECT_ROOT, "src", "shared")


def adjust_layer_directory():
"""
Prepara um diretório 'build' para uma Lambda Layer do AWS CDK.

A função junta o código local compartilhado e as dependências externas (pip)
na estrutura de pastas que a Lambda espera (/python).
"""

# Garante que o build seja sempre limpo, removendo qualquer artefato antigo.
if os.path.exists(BUILD_DIRECTORY):
shutil.rmtree(BUILD_DIRECTORY)

# Cria a estrutura de pastas 'build/python/src/'.
# Isso é necessário para que os imports 'from src.shared...' funcionem na Lambda.
shared_code_intermediate_dir = os.path.join(PYTHON_TOP_LEVEL_DIR, "src")
os.makedirs(shared_code_intermediate_dir)

# Copia o código compartilhado (de 'src/shared') para dentro da estrutura da Layer.
# O resultado final será 'build/python/src/shared'.
print(f"Copiando código de: {SHARED_CODE_SOURCE}") # Adicionado para debug
shared_code_dest = os.path.join(shared_code_intermediate_dir, os.path.basename(SHARED_CODE_SOURCE))
shutil.copytree(SHARED_CODE_SOURCE, shared_code_dest)

# Se o arquivo de dependências existir, instala todas as bibliotecas.
# O arquivo de requirements também precisa ser lido a partir da raiz.
requirements_path = os.path.join(PROJECT_ROOT, REQUIREMENTS_FILE)
if os.path.exists(requirements_path):
# Instala os pacotes diretamente na pasta 'build/python'.
# Isso permite que a Lambda importe as bibliotecas de forma padrão (ex: import requests).
subprocess.check_call(
["pip", "install", "-r", requirements_path, "-t", PYTHON_TOP_LEVEL_DIR, "--no-cache-dir"]
)
else:
# Apenas um aviso caso o arquivo não seja encontrado.
print(f"Aviso: Arquivo '{requirements_path}' não encontrado. Nenhuma dependência externa será instalada.")


# Ponto de entrada do script.
if __name__ == '__main__':
adjust_layer_directory(shared_dir_name="shared", destination="copied_shared")
adjust_layer_directory()
2 changes: 1 addition & 1 deletion iac/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
print("Starting the CDK")

print("Adjusting the layer directory")
adjust_layer_directory(shared_dir_name="shared", destination="copied_shared")
adjust_layer_directory()
print("Finished adjusting the layer directory")


Expand Down
41 changes: 41 additions & 0 deletions iac/local/minio/docker-compose-minio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '3.8' # The top-level 'version' is obsolete but using a more modern one like 3.8 is fine

services:
minio:
image: minio/minio:latest
container_name: minio-reservation
# ✅ SET credentials for the MinIO server
environment:
MINIO_ROOT_USER: root # If you change any credentials, you have to match it in environments
MINIO_ROOT_PASSWORD: root1234
ports:
- "9000:9000"
- "9001:9001"
volumes:
- minio-data:/data
command: server /data --console-address :9001

create-bucket:
image: minio/mc:latest
depends_on:
- minio
entrypoint: >
/bin/sh -c "
# ✅ Make the script exit on any error
set -e;

# Wait for MinIO to be ready
# Use the more modern 'mc alias set' and provide the credentials
/usr/bin/mc alias set s3 http://minio:9000 root root1234;

# Create the bucket
/usr/bin/mc mb s3/bucket-test;

# Set the policy
/usr/bin/mc policy set public s3/bucket-test;

echo '✅ Bucket created successfully!';
"

volumes:
minio-data:
18 changes: 15 additions & 3 deletions iac/stacks/bucket_stack.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from aws_cdk import (
aws_s3 as s3,
aws_cloudfront as cloudfront,
aws_cloudfront_origins as origins,
aws_iam as iam,
RemovalPolicy,
Stack,
)
from constructs import Construct
import os
Expand All @@ -24,8 +25,19 @@ def __init__(self, scope: Construct, **kwargs) -> None:
stage = 'DEV'

self.bucket = s3.Bucket(
self, f"BACK_S3_REPORT_BUCKET_{stage}",
bucket_name=f"{self.stack_name}-report-bucket{stage}".lower(),
self, f"RESERVATION_BACK_S3_BUCKET_{stage}",
# TODO remover isso quando voltar pra conta nova ou tentar deletar o bucket criado la com power user
bucket_name=f"{self.stack_name}-bucket-{stage}".lower(),
versioned=True,
removal_policy=RemovalPolicy.DESTROY if not (stage == 'PROD') else RemovalPolicy.RETAIN,
block_public_access=s3.BlockPublicAccess.BLOCK_ALL
)

self.distribution = cloudfront.Distribution(
self, f"ReservationBucketDistribution{stage}",
default_behavior=cloudfront.BehaviorOptions(
origin=origins.S3Origin(self.bucket),
viewer_protocol_policy=cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
),
default_root_object=None # não obrigatório, mas evita erro se não tiver index.html
)
27 changes: 25 additions & 2 deletions iac/stacks/iac_stack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aws_cdk import (
Stack,
Stack, aws_iam
)
from constructs import Construct
from aws_cdk.aws_apigateway import RestApi, Cors
Expand Down Expand Up @@ -55,7 +55,11 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
"DYNAMO_PARTITION_KEY": "PK",
"DYNAMO_SORT_KEY": "SK",
"REGION": self.aws_region,
"GRAPH_MICROSOFT_ENDPOINT": os.getenv("GRAPH_MICROSOFT_ENDPOINT")
"USER_API_URL": os.environ.get("USER_API_URL"),
"S3_BUCKET_NAME": self.s3_bucket.bucket.bucket_name,
"FROM_EMAIL": os.environ.get("FROM_EMAIL"),
"HIDDEN_COPY": os.environ.get("HIDDEN_COPY"),
"S3_ASSETS_CDN": os.environ.get("S3_ASSETS_CDN")
}


Expand All @@ -69,4 +73,23 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
for function in self.lambda_stack.functions_that_need_s3_permissions:
self.s3_bucket.bucket.grant_read_write(function)

ses_admin_policy = aws_iam.PolicyStatement(
effect=aws_iam.Effect.ALLOW,
actions=[
"ses:*",
],
resources=[
"*"
]
)

functions_that_need_ses_permissions = [
self.lambda_stack.delete_booking
]

for f in functions_that_need_ses_permissions:
f.add_environment("HIDDEN_COPY", os.environ.get("HIDDEN_COPY"))
f.add_environment("FROM_EMAIL", os.environ.get("FROM_EMAIL"))
f.add_environment("REPLY_TO_EMAIL", os.environ.get("REPLY_TO_EMAIL"))
f.add_to_role_policy(ses_admin_policy)

Loading