Skip to content

Commit 026ccd2

Browse files
committed
Add local run to readme
1 parent b57880c commit 026ccd2

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The configuration is a JSON file with the following schema:
2828
OR
2929

3030
- `"type"`: `"random"`
31-
- `"kind"`: `"name"`, `"first_name"`, `"last_name"`, `"user_name"`, `"email"`, `"phone_number"`, etc. See the full list of [randomizer](https://faker.readthedocs.io/en/master/providers.html).
31+
- `"kind"`: `"name"`, `"first_name"`, `"last_name"`, `"user_name"`, `"email"`, `"phone_number"`, etc. See the full list of [random providers](https://faker.readthedocs.io/en/master/providers.html).
3232
- `"drop_constraints"`: list of table constraints to be dropped
3333
- `"drop_indexes"`: list of index to be dropped
3434

@@ -69,3 +69,15 @@ Example:
6969
]
7070
}
7171
```
72+
73+
# Running locally
74+
The tool is meant to be run inside the same network as the RDS subnet that contains the target cluster.
75+
76+
To run the tool locally (for debugging, etc), you need to:
77+
- Ensure that the temporary RDS cluster is accessible from localhost. See [port-forwarding with session manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-sessions-start.html#sessions-remote-port-forwarding).
78+
- Specify `--local` flag to set the RDS host target to localhost.
79+
80+
```bash
81+
poetry install
82+
poetry run sanitizer --flag
83+
```

src/sanitizer/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ def wrapper(*args, **kwargs):
2626

2727

2828
@click.command()
29+
@click.option("--local", is_flag=True, default=False, help="Run locally")
2930
@async_command
30-
async def main():
31+
async def main(local: bool):
3132
click.echo("#################### Finding latest snapshot ####################")
3233
snapshot = get_latest_snapshot(settings.rds_cluster_id)
3334
click.echo(f"Latest snapshot: {snapshot}")
@@ -49,7 +50,7 @@ async def main():
4950
click.echo("")
5051

5152
click.echo("#################### Sanitizing ####################")
52-
await sanitize(temp_cluster, ssm_param)
53+
await sanitize(temp_cluster, ssm_param, local)
5354
click.echo("")
5455

5556
click.echo("#################### Creating sanitized snapshot ####################")

src/sanitizer/sql.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ async def sanitize_table(table: Table, pool: AsyncConnectionPool) -> int:
5959
).rowcount
6060

6161

62-
async def sanitize(cluster: DBClusterTypeDef, ssm_param: str) -> None:
63-
cluster["Endpoint"] = "localhost"
62+
async def sanitize(cluster: DBClusterTypeDef, ssm_param: str, local: bool) -> None:
63+
if local:
64+
cluster["Endpoint"] = "localhost"
6465
conn_string = (
6566
f"postgresql://{cluster['MasterUsername']}:{get_password(ssm_param)}"
6667
f"@{cluster['Endpoint']}:{cluster['Port']}"

0 commit comments

Comments
 (0)