aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/object-storage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-05-09 11:49:25 +0200
committerGitHub <noreply@github.com>2022-05-09 11:49:25 +0200
commitca3d5912e16b39697bdeeda35d10b44ed8f711aa (patch)
treeb7697f24d7587e6d031949e3925d9faff03e4537 /server/lib/object-storage
parent644014cc55fcf61e611f2031b125304da086c039 (diff)
downloadPeerTube-ca3d5912e16b39697bdeeda35d10b44ed8f711aa.tar.gz
PeerTube-ca3d5912e16b39697bdeeda35d10b44ed8f711aa.tar.zst
PeerTube-ca3d5912e16b39697bdeeda35d10b44ed8f711aa.zip
Add use proxy for s3 (#4973)
* Fix object storage to be accessible via proxy * fix lint * Use hpagent * Fix lint * Fix PR Co-authored-by: noellabo <noel.yoshiba@gmail.com>
Diffstat (limited to 'server/lib/object-storage')
-rw-r--r--server/lib/object-storage/shared/client.ts17
1 files changed, 16 insertions, 1 deletions
diff --git a/server/lib/object-storage/shared/client.ts b/server/lib/object-storage/shared/client.ts
index c9a614593..d5cb074df 100644
--- a/server/lib/object-storage/shared/client.ts
+++ b/server/lib/object-storage/shared/client.ts
@@ -1,8 +1,22 @@
1import { S3Client } from '@aws-sdk/client-s3' 1import { S3Client } from '@aws-sdk/client-s3'
2import { NodeHttpHandler } from '@aws-sdk/node-http-handler'
2import { logger } from '@server/helpers/logger' 3import { logger } from '@server/helpers/logger'
4import { isProxyEnabled } from '@server/helpers/proxy'
5import { getAgent } from '@server/helpers/requests'
3import { CONFIG } from '@server/initializers/config' 6import { CONFIG } from '@server/initializers/config'
4import { lTags } from './logger' 7import { lTags } from './logger'
5 8
9function getProxyRequestHandler () {
10 if (!isProxyEnabled()) return null
11
12 const { agent } = getAgent()
13
14 return new NodeHttpHandler({
15 httpAgent: agent.http,
16 httpsAgent: agent.https
17 })
18}
19
6let endpointParsed: URL 20let endpointParsed: URL
7function getEndpointParsed () { 21function getEndpointParsed () {
8 if (endpointParsed) return endpointParsed 22 if (endpointParsed) return endpointParsed
@@ -26,7 +40,8 @@ function getClient () {
26 accessKeyId: OBJECT_STORAGE.CREDENTIALS.ACCESS_KEY_ID, 40 accessKeyId: OBJECT_STORAGE.CREDENTIALS.ACCESS_KEY_ID,
27 secretAccessKey: OBJECT_STORAGE.CREDENTIALS.SECRET_ACCESS_KEY 41 secretAccessKey: OBJECT_STORAGE.CREDENTIALS.SECRET_ACCESS_KEY
28 } 42 }
29 : undefined 43 : undefined,
44 requestHandler: getProxyRequestHandler()
30 }) 45 })
31 46
32 logger.info('Initialized S3 client %s with region %s.', getEndpoint(), OBJECT_STORAGE.REGION, lTags()) 47 logger.info('Initialized S3 client %s with region %s.', getEndpoint(), OBJECT_STORAGE.REGION, lTags())