diff --git a/.changeset/fuzzy-rice-cover.md b/.changeset/fuzzy-rice-cover.md new file mode 100644 index 00000000..b0f4748d --- /dev/null +++ b/.changeset/fuzzy-rice-cover.md @@ -0,0 +1,5 @@ +--- +'verdaccio-aws-s3-storage': minor +--- + +feat: add proxy support for s3 storage diff --git a/plugins/aws-s3-storage/README.md b/plugins/aws-s3-storage/README.md index 543b31b2..d00e4d4f 100644 --- a/plugins/aws-s3-storage/README.md +++ b/plugins/aws-s3-storage/README.md @@ -58,6 +58,7 @@ store: accessKeyId: your-access-key-id # optional, aws accessKeyId for private S3 bucket secretAccessKey: your-secret-access-key # optional, aws secretAccessKey for private S3 bucket sessionToken: your-session-token # optional, aws sessionToken for private S3 bucket + proxy: your-proxy # optional, HTTP or HTTPS proxies if you can't connect to internet directly ``` The configured values can either be the actual value or the name of an environment variable that contains the value for the following options: @@ -69,6 +70,7 @@ The configured values can either be the actual value or the name of an environme - `accessKeyId` - `secretAccessKey` - `sessionToken` +- `proxy` > If an environment variable is not set then it is assumed the value is the literal value given. For example, if `S3_BUCKET` is not set, then this will use a bucket named exactly "S3_BUCKET". @@ -82,6 +84,7 @@ store: accessKeyId: S3_ACCESS_KEY_ID secretAccessKey: S3_SECRET_ACCESS_KEY sessionToken: S3_SESSION_TOKEN + proxy: HTTPS_PROXY ``` Additional properties can be defined for packages. The `storage` location corresponds to the folder in the S3 bucket. diff --git a/plugins/aws-s3-storage/conf/config.yaml b/plugins/aws-s3-storage/conf/config.yaml index 98645dc2..6362bc26 100644 --- a/plugins/aws-s3-storage/conf/config.yaml +++ b/plugins/aws-s3-storage/conf/config.yaml @@ -9,6 +9,7 @@ store: accessKeyId: foobar secretAccessKey: 1234567e s3ForcePathStyle: true + proxy: http://localhost:8080 uplinks: npmjs: diff --git a/plugins/aws-s3-storage/src/config.ts b/plugins/aws-s3-storage/src/config.ts index 4bd931e2..551085be 100644 --- a/plugins/aws-s3-storage/src/config.ts +++ b/plugins/aws-s3-storage/src/config.ts @@ -10,4 +10,5 @@ export interface S3Config extends Config { accessKeyId?: string; secretAccessKey?: string; sessionToken?: string; + proxy?: string; } diff --git a/plugins/aws-s3-storage/src/index.ts b/plugins/aws-s3-storage/src/index.ts index 051eac63..a697314a 100644 --- a/plugins/aws-s3-storage/src/index.ts +++ b/plugins/aws-s3-storage/src/index.ts @@ -42,6 +42,7 @@ export default class S3Database implements IPluginStorage { this.config.accessKeyId = setConfigValue(this.config.accessKeyId); this.config.secretAccessKey = setConfigValue(this.config.secretAccessKey); this.config.sessionToken = setConfigValue(this.config.sessionToken); + this.config.proxy = setConfigValue(this.config.proxy); const configKeyPrefix = this.config.keyPrefix; this._localData = null; @@ -59,6 +60,9 @@ export default class S3Database implements IPluginStorage { accessKeyId: this.config.accessKeyId, secretAccessKey: this.config.secretAccessKey, sessionToken: this.config.sessionToken, + httpOptions: { + proxy: this.config.proxy, + }, }); } diff --git a/plugins/aws-s3-storage/src/s3PackageManager.ts b/plugins/aws-s3-storage/src/s3PackageManager.ts index 24d51615..9baa4668 100644 --- a/plugins/aws-s3-storage/src/s3PackageManager.ts +++ b/plugins/aws-s3-storage/src/s3PackageManager.ts @@ -38,6 +38,7 @@ export default class S3PackageManager implements ILocalPackageManager { secretAccessKey, sessionToken, tarballACL, + proxy, } = config; this.tarballACL = tarballACL || 'private'; @@ -48,6 +49,9 @@ export default class S3PackageManager implements ILocalPackageManager { accessKeyId, secretAccessKey, sessionToken, + httpOptions: { + proxy, + }, }); this.logger.trace( { packageName }, @@ -75,6 +79,10 @@ export default class S3PackageManager implements ILocalPackageManager { { sessionToken }, 's3: [S3PackageManager constructor] sessionToken @{sessionToken}' ); + this.logger.trace( + { proxy }, + 's3: [S3PackageManager constructor] proxy @{proxy}' + ); const packageAccess = this.config.getMatchedPackagesSpec(packageName); if (packageAccess) {