diff options
author | Chocobozzz <me@florianbigard.com> | 2022-05-09 11:49:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-09 11:49:25 +0200 |
commit | ca3d5912e16b39697bdeeda35d10b44ed8f711aa (patch) | |
tree | b7697f24d7587e6d031949e3925d9faff03e4537 /server/lib/object-storage | |
parent | 644014cc55fcf61e611f2031b125304da086c039 (diff) | |
download | PeerTube-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.ts | 17 |
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 @@ | |||
1 | import { S3Client } from '@aws-sdk/client-s3' | 1 | import { S3Client } from '@aws-sdk/client-s3' |
2 | import { NodeHttpHandler } from '@aws-sdk/node-http-handler' | ||
2 | import { logger } from '@server/helpers/logger' | 3 | import { logger } from '@server/helpers/logger' |
4 | import { isProxyEnabled } from '@server/helpers/proxy' | ||
5 | import { getAgent } from '@server/helpers/requests' | ||
3 | import { CONFIG } from '@server/initializers/config' | 6 | import { CONFIG } from '@server/initializers/config' |
4 | import { lTags } from './logger' | 7 | import { lTags } from './logger' |
5 | 8 | ||
9 | function 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 | |||
6 | let endpointParsed: URL | 20 | let endpointParsed: URL |
7 | function getEndpointParsed () { | 21 | function 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()) |