#!/usr/bin/env bash
# Builds a throwaway git repo containing FAKE secrets, so you can practise scanning.
# Nothing here is a real credential. Never use real keys for this exercise.
set -e
rm -rf lab-repo && mkdir lab-repo && cd lab-repo && git init -q
git config user.email lab@example.com && git config user.name "Lab User"

cat > app.py << 'PY'
import boto3

# TODO: move this out before sharing
AWS_ACCESS_KEY_ID = "AKIAZ7LABFAKEKEY4TEST"
AWS_SECRET_ACCESS_KEY = "wJk3Lab9FakeSecretValueForTestingOnly0123456"

def list_reports():
    s3 = boto3.client("s3", aws_access_key_id=AWS_ACCESS_KEY_ID,
                      aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
    return s3.list_objects_v2(Bucket="example-lab-reports-bucket")
PY
git add -A && git commit -q -m "Add report lister (quick test)"

cat > .env << 'ENV'
DB_HOST=db.lab.example
DB_PASSWORD=Lab-Only-Fake-Pass-93412
API_TOKEN=lab_tok_fake_51HxxxxLABONLYxxxxxxxxxxxx
ENV
git add -A && git commit -q -m "Add env file"

cat > app.py << 'PY'
import boto3

def list_reports():
    s3 = boto3.client("s3")  # credentials now come from the environment/role
    return s3.list_objects_v2(Bucket="example-lab-reports-bucket")
PY
git rm -q --cached .env && rm .env && echo ".env" > .gitignore
git add -A && git commit -q -m "Remove hardcoded credentials"
git log --oneline
