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}) => { 17 return parseS3Cfg(cfg) 20export const getS3Cfg = ({bucket_name, cluster_name}: {bucket_name: string, cluster_name?: string}) => { 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] 31 endpoint = `https://s3.${region}.amazonaws.com` 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) 42 uri.host = new URL(testEndpoint).host 43 endpoint = uri.toString() 47 return {...cfg, accessKeyId, secretAccessKey, endpoint}