Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add proxy support for s3 storage #713

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading