Skip to content

Commit

Permalink
feat: add proxy support for s3 storage (#713)
Browse files Browse the repository at this point in the history
* add proxy for s3 storage

* changeset

* Revert "changeset"

This reverts commit 29e0c82.

* add changeset

---------

Co-authored-by: Dewen Kong <dewen@fb.com>
Co-authored-by: Cloud User <cloud-user@ip-10-0-1-159.us-west-2.compute.internal>
Co-authored-by: Cloud User <cloud-user@ip-10-0-2-89.us-west-2.compute.internal>
  • Loading branch information
4 people committed May 3, 2024
1 parent abcf94e commit cf14be6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-rice-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'verdaccio-aws-s3-storage': minor
---

feat: add proxy support for s3 storage
3 changes: 3 additions & 0 deletions plugins/aws-s3-storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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".
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions plugins/aws-s3-storage/conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ store:
accessKeyId: foobar
secretAccessKey: 1234567e
s3ForcePathStyle: true
proxy: http://localhost:8080

uplinks:
npmjs:
Expand Down
1 change: 1 addition & 0 deletions plugins/aws-s3-storage/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface S3Config extends Config {
accessKeyId?: string;
secretAccessKey?: string;
sessionToken?: string;
proxy?: string;
}
4 changes: 4 additions & 0 deletions plugins/aws-s3-storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class S3Database implements IPluginStorage<S3Config> {
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;
Expand All @@ -59,6 +60,9 @@ export default class S3Database implements IPluginStorage<S3Config> {
accessKeyId: this.config.accessKeyId,
secretAccessKey: this.config.secretAccessKey,
sessionToken: this.config.sessionToken,
httpOptions: {
proxy: this.config.proxy,
},
});
}

Expand Down
8 changes: 8 additions & 0 deletions plugins/aws-s3-storage/src/s3PackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class S3PackageManager implements ILocalPackageManager {
secretAccessKey,
sessionToken,
tarballACL,
proxy,
} = config;
this.tarballACL = tarballACL || 'private';

Expand All @@ -48,6 +49,9 @@ export default class S3PackageManager implements ILocalPackageManager {
accessKeyId,
secretAccessKey,
sessionToken,
httpOptions: {
proxy,
},
});
this.logger.trace(
{ packageName },
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit cf14be6

Please sign in to comment.