-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathset_smoketest_permissions.py
More file actions
executable file
·40 lines (31 loc) · 1.32 KB
/
set_smoketest_permissions.py
File metadata and controls
executable file
·40 lines (31 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
import json
import os
import fire
from aws_session_assume import get_boto_session
AWS_REGION = os.getenv("AWS_REGION", "eu-west-2")
def main(secret_env_name: str = "dev", bucket_env_name: str = "dev", env: str = "dev"):
boto_session = get_boto_session(env)
print("Getting smoke test parameters from AWS....") # noqa
smoke_test_params_name = f"nhsd-nrlf--{secret_env_name}--smoke-test-parameters"
secretsmanager = boto_session.client("secretsmanager", region_name=AWS_REGION)
smoke_test_params_value = secretsmanager.get_secret_value(
SecretId=smoke_test_params_name
)
print("Parsing parameters....") # noqa
smoke_test_params = json.loads(smoke_test_params_value["SecretString"])
nrlf_app_id = smoke_test_params["nrlf_app_id"]
ods_code = smoke_test_params["ods_code"]
print(f"Adding {ods_code} permissions to {nrlf_app_id} app in S3....") # noqa
bucket = f"nhsd-nrlf--{bucket_env_name}-authorization-store"
s3 = boto_session.client("s3")
s3.put_object(
Bucket=bucket,
Key=f"{nrlf_app_id}/{ods_code}.json",
Body=open(f"./tests/smoke/permissions/{ods_code}.json", "rb"),
ExpectedBucketOwner=boto_session.client("sts")
.get_caller_identity()
.get("Account"),
)
if __name__ == "__main__":
fire.Fire(main)