Sends a request to the CD Signer API.
(method: str, path: str, data: str | None = None)
| 123 | |
| 124 | |
| 125 | def cd_signer_request(method: str, path: str, data: str | None = None): |
| 126 | """ |
| 127 | Sends a request to the CD Signer API. |
| 128 | """ |
| 129 | SigV4Auth = import_module("botocore.auth").SigV4Auth |
| 130 | AWSRequest = import_module("botocore.awsrequest").AWSRequest |
| 131 | requests = import_module("requests") |
| 132 | |
| 133 | url = f"{SIGNING_API_BASE_URL}{path}" |
| 134 | headers = {"Content-Type": "application/json"} |
| 135 | request = AWSRequest(method=method, url=url, data=data, headers=headers) |
| 136 | SigV4Auth(get_creds(), "signer-builder-tools", CD_SIGNER_REGION).add_auth(request) |
| 137 | |
| 138 | for i in range(1, 8): |
| 139 | debug(f"Sending request {method} to {url} with data: {data}") |
| 140 | response = requests.request(method=method, url=url, headers=dict(request.headers), data=data) |
| 141 | info(f"CDSigner Request ({url}): {response.status_code}") |
| 142 | if response.status_code == 429: |
| 143 | warn(f"Too many requests, backing off for {2**i} seconds") |
| 144 | time.sleep(2**i) |
| 145 | continue |
| 146 | return response |
| 147 | |
| 148 | raise Exception(f"Failed to request {url}") |
| 149 | |
| 150 | |
| 151 | def cd_signer_create_request(manifest: Any) -> str: |
no test coverage detected