diff --git a/README.md b/README.md index e79ada0..48782c8 100644 --- a/README.md +++ b/README.md @@ -34,38 +34,104 @@ apps/ Espaço para app Spring Boot, agente AI e simulador BI - SQLcl, SQL*Plus ou outro cliente compatível. - Acesso a uma versão de Oracle AI Database compatível com Deep Data Security. -## Execução Em 7 Passos +## Execucao Em 7 Passos -1. Clone o repositório. -2. Copie o arquivo de exemplo: +1. Clone o repositorio. + +2. Copie o arquivo de exemplo. + + Linux/macOS: ```bash cp terraform/envs/demo/terraform.tfvars.example terraform/envs/demo/terraform.tfvars ``` -3. Edite `terraform/envs/demo/terraform.tfvars` com seus OCIDs e região. -4. Valide a infraestrutura: + Windows PowerShell: + + ```powershell + Copy-Item terraform\envs\demo\terraform.tfvars.example terraform\envs\demo\terraform.tfvars + ``` + +3. Edite `terraform/envs/demo/terraform.tfvars` com seus OCIDs, regiao e parametros do banco. + + Linux/macOS: + + ```bash + vi terraform/envs/demo/terraform.tfvars + ``` + + Windows PowerShell: + + ```powershell + notepad terraform\envs\demo\terraform.tfvars + ``` + +4. Valide a infraestrutura. + + Linux/macOS: + + ```bash + chmod +x scripts/*.sh + ./scripts/validate-terraform.sh + ``` + + Windows PowerShell: ```powershell powershell -ExecutionPolicy Bypass -File .\scripts\validate-terraform.ps1 ``` -5. Faça o deploy: +5. Faca o deploy. + + Linux/macOS: ```bash cd terraform/envs/demo terraform init terraform plan -out tfplan terraform apply tfplan + cd ../../.. ``` -6. Instale um cenário: + Windows PowerShell: + + ```powershell + Set-Location terraform\envs\demo + terraform init + terraform plan -out tfplan + terraform apply tfplan + Set-Location ..\..\.. + ``` + +6. Instale um cenario. + + Linux/macOS: + + ```bash + ./scripts/run-scenario.sh 01-ai-prompt-injection "" + ``` + + Windows PowerShell: ```powershell powershell -ExecutionPolicy Bypass -File .\scripts\run-scenario.ps1 -Scenario 01-ai-prompt-injection -ConnectString "" ``` -7. Execute os testes descritos no `README.md` do cenário. +7. Execute testes e reset quando necessario. + + Linux/macOS: + + ```bash + ./scripts/run-scenario.sh 05-legacy-app-ai-extension "" + ./scripts/reset-scenario.sh 05-legacy-app-ai-extension "" + ``` + + Windows PowerShell: + + ```powershell + powershell -ExecutionPolicy Bypass -File .\scripts\run-scenario.ps1 -Scenario 05-legacy-app-ai-extension -ConnectString "" + powershell -ExecutionPolicy Bypass -File .\scripts\reset-scenario.ps1 -Scenario 05-legacy-app-ai-extension -ConnectString "" + ``` ## Segurança Por Padrão diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh new file mode 100644 index 0000000..ba7ec7b --- /dev/null +++ b/scripts/bootstrap.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "Checking local tools..." + +for tool in git terraform; do + if command -v "$tool" >/dev/null 2>&1; then + echo "$tool found: $(command -v "$tool")" + else + echo "WARNING: $tool not found in PATH" >&2 + fi +done + +echo "Bootstrap check finished." + diff --git a/scripts/reset-scenario.sh b/scripts/reset-scenario.sh new file mode 100644 index 0000000..1932215 --- /dev/null +++ b/scripts/reset-scenario.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +usage() { + echo "Usage: $0 [sql_client]" >&2 +} + +if [[ $# -lt 2 ]]; then + usage + exit 1 +fi + +SCENARIO="$1" +CONNECT_STRING="$2" +SQL_CLIENT="${3:-sql}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" +RESET_SCRIPT="$REPO_ROOT/scenarios/$SCENARIO/sql/99_reset.sql" + +if [[ ! -f "$RESET_SCRIPT" ]]; then + echo "Reset script not found: $RESET_SCRIPT" >&2 + exit 1 +fi + +echo "Resetting scenario $SCENARIO" +"$SQL_CLIENT" "$CONNECT_STRING" "@$RESET_SCRIPT" + diff --git a/scripts/run-scenario.sh b/scripts/run-scenario.sh new file mode 100644 index 0000000..77f92a6 --- /dev/null +++ b/scripts/run-scenario.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -euo pipefail + +usage() { + echo "Usage: $0 [connect_string] [sql_client]" >&2 + echo "Example: $0 01-ai-prompt-injection 'admin/password@db_high' sql" >&2 +} + +if [[ $# -lt 1 ]]; then + usage + exit 1 +fi + +SCENARIO="$1" +CONNECT_STRING="${2:-}" +SQL_CLIENT="${3:-sql}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" +SQL_DIR="$REPO_ROOT/scenarios/$SCENARIO/sql" + +if [[ ! -d "$SQL_DIR" ]]; then + echo "Scenario SQL directory not found: $SQL_DIR" >&2 + exit 1 +fi + +mapfile -t SCRIPTS < <(find "$SQL_DIR" -maxdepth 1 -type f -name "*.sql" ! -name "99_reset.sql" | sort) + +echo "Scenario: $SCENARIO" +echo "Scripts to execute:" +for script in "${SCRIPTS[@]}"; do + echo " - $(basename "$script")" +done + +if [[ -z "$CONNECT_STRING" ]]; then + echo "WARNING: Connect string not provided. Review the SQL files above and execute them manually with SQLcl or SQL*Plus." >&2 + exit 0 +fi + +for script in "${SCRIPTS[@]}"; do + echo "Running $script" + "$SQL_CLIENT" "$CONNECT_STRING" "@$script" +done + diff --git a/scripts/validate-terraform.sh b/scripts/validate-terraform.sh new file mode 100644 index 0000000..2e57df7 --- /dev/null +++ b/scripts/validate-terraform.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail + +ENVIRONMENT="${1:-demo}" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" +TF_DIR="$REPO_ROOT/terraform/envs/$ENVIRONMENT" + +if [[ ! -d "$TF_DIR" ]]; then + echo "Terraform environment not found: $TF_DIR" >&2 + exit 1 +fi + +if ! command -v terraform >/dev/null 2>&1; then + echo "Terraform is not installed or not in PATH. Install Terraform 1.6+ and rerun this script." >&2 + exit 1 +fi + +cd "$TF_DIR" +terraform fmt -recursive -check +terraform init -backend=false +terraform validate +