Send a raw DynamoDB-format request to extenddb with SigV4 authentication.
(operation: str, body: dict)
| 31 | |
| 32 | ENDPOINT = os.environ.get("EXTENDDB_TEST_ENDPOINT", "http://localhost:8000").strip() |
| 33 | def extenddb_request(operation: str, body: dict) -> dict: |
| 34 | """Send a raw DynamoDB-format request to extenddb with SigV4 authentication.""" |
| 35 | body_bytes = json.dumps(body).encode("utf-8") |
| 36 | headers = { |
| 37 | "X-Amz-Target": f"DynamoDB_20120810.{operation}", |
| 38 | "Content-Type": "application/x-amz-json-1.0", |
| 39 | } |
| 40 | |
| 41 | # Sign the request with SigV4 using env var credentials. |
| 42 | access_key = os.environ.get("AWS_ACCESS_KEY_ID", "") |
| 43 | secret_key = os.environ.get("AWS_SECRET_ACCESS_KEY", "") |
| 44 | region = os.environ.get("AWS_DEFAULT_REGION", "us-east-1") |
| 45 | if access_key and secret_key: |
| 46 | creds = Credentials(access_key, secret_key) |
| 47 | aws_req = AWSRequest(method="POST", url=ENDPOINT, data=body_bytes, headers=headers) |
| 48 | SigV4Auth(creds, "dynamodb", region).add_auth(aws_req) |
| 49 | headers = dict(aws_req.headers) |
| 50 | |
| 51 | resp = requests.post( |
| 52 | ENDPOINT, |
| 53 | data=body_bytes, |
| 54 | headers=headers, |
| 55 | verify=not ENDPOINT.startswith("https://"), |
| 56 | ) |
| 57 | result = resp.json() |
| 58 | if resp.status_code >= 400: |
| 59 | error_type = result.get("__type", "Unknown") |
| 60 | error_msg = result.get("message", result.get("Message", "")) |
| 61 | raise RuntimeError(f"{error_type}: {error_msg} (HTTP {resp.status_code})") |
| 62 | return result |
| 63 | @pytest.fixture() |
| 64 | def unique_table_name(): |
| 65 | """Generate a unique table name.""" |
no test coverage detected