🌳
pt0/bktF/serverF/getS3CfgF.mts
6const parseS3Cfg = (cfg: Record<string, string> | undefined) => {
7 if (!cfg) return undefined
8 let {secretAccessKey, accessKeyId, endpoint, region} = cfg
9 accessKeyId ||= cfg.access_key_id
10 secretAccessKey ||= cfg.secret_access_key
11 if (!endpoint) endpoint = `https://s3.${region}.amazonaws.com`
12 return {...cfg, accessKeyId, secretAccessKey, endpoint}
15export const getOptS3Cfg = ({bucket_name}: {bucket_name: string}) => {
16 const cfg = getOptJsonSecret(secretForBkt(bucket_name) as any) as Record<string, string> | undefined
17 return parseS3Cfg(cfg)
20export const getS3Cfg = ({bucket_name, cluster_name}: {bucket_name: string, cluster_name?: string}) => {
21 const cfg = getReqJsonSecret(secretForBkt(bucket_name) as any) as Record<string, any>
23 let {secretAccessKey, accessKeyId, endpoint, region} = cfg
24 accessKeyId ||= cfg.access_key_id
25 secretAccessKey ||= cfg.secret_access_key
26 const clusterEndpoints: Record<string, string> | undefined = cfg.cluster_endpoints
27 if (cluster_name && clusterEndpoints?.[cluster_name]) {
28 endpoint = clusterEndpoints[cluster_name]
29 }
30 if (!endpoint) {
31 endpoint = `https://s3.${region}.amazonaws.com`
32 }
34 // Under runtests (testlocal), testS3EndpointCtx is set to the isolated test-server baseUrl.
35 // Rewrite self-served bucket endpoints (those on the app's own svcPortNo) to point at the test
36 // server, so signed-URL fetches hit it instead of a manual devserver on svcPortNo. Remote buckets
37 // (different port) and production (ctx unset) are unaffected.
38 const testEndpoint = testS3EndpointCtx.getStore()
39 if (testEndpoint && endpoint) {
40 const uri = new URL(endpoint)
41 if (uri.port === String(getAppCfg().svcPortNo)) {
42 uri.host = new URL(testEndpoint).host
43 endpoint = uri.toString()
44 }
45 }
47 return {...cfg, accessKeyId, secretAccessKey, endpoint}