* Resolves AWS credentials and the target bucket from the connector's * sourceConfig and the encrypted secret (delivered as accessToken). When an * `endpoint` is configured it is parsed/validated into an S3Endpoint so * the connector targets an S3-compatible store via path-style addressin
(accessToken: string, sourceConfig: Record<string, unknown>)
| 193 | * the connector targets an S3-compatible store via path-style addressing. |
| 194 | */ |
| 195 | function resolveContext(accessToken: string, sourceConfig: Record<string, unknown>): S3Context { |
| 196 | const accessKeyId = ((sourceConfig.accessKeyId as string) ?? '').trim() |
| 197 | const region = ((sourceConfig.region as string) ?? '').trim() |
| 198 | const bucket = ((sourceConfig.bucket as string) ?? '').trim() |
| 199 | const secretAccessKey = (accessToken ?? '').trim() |
| 200 | const rawEndpoint = ((sourceConfig.endpoint as string) ?? '').trim() |
| 201 | |
| 202 | if (!accessKeyId) throw new Error('Missing AWS Access Key ID') |
| 203 | if (!secretAccessKey) throw new Error('Missing AWS Secret Access Key') |
| 204 | if (!region) throw new Error('Missing AWS region') |
| 205 | if (!bucket) throw new Error('Missing S3 bucket name') |
| 206 | |
| 207 | const endpoint = rawEndpoint ? parseEndpoint(rawEndpoint) : undefined |
| 208 | |
| 209 | return { accessKeyId, secretAccessKey, region, bucket, endpoint } |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Returns the SigV4 canonical Host header for the request. For AWS this is the |