Skip to content

Commit bcd46c5

Browse files
@jotadevelopergriffithtp
authored andcommitted
feat: add file validation configuration
1 parent da6f19e commit bcd46c5

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

plugins/verdaccio-google-cloud/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ store:
2626
## google cloud recomend this file only for development
2727
## this field is not mandatory
2828
keyFilename: /path/project-01.json || env (GOOGLE_CLOUD_VERDACCIO_KEY)
29+
## default validation is, it can be overrided by
30+
## https://cloud.google.com/nodejs/docs/reference/storage/1.6.x/File.html#createWriteStream
31+
# validation: crc32c
2932
```
3033
Define `env` whether you want load the value from environment variables.
3134

plugins/verdaccio-google-cloud/src/storage.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { ConfigGoogleStorage } from '../types';
1313
export const noSuchFile: string = 'ENOENT';
1414
export const fileExist: string = 'EEXISTS';
1515
export const pkgFileName = 'package.json';
16+
export const defaultValidation = 'crc32c';
1617

1718
declare type StorageType = Package | void;
1819

@@ -91,7 +92,9 @@ class GoogleCloudStorageHandler implements ILocalPackageManager {
9192
this.logger.debug({ name: file.name }, 'gcloud: deleting @{name} from storage');
9293
try {
9394
file
94-
.delete()
95+
.delete({
96+
validation: this.config.validation || defaultValidation
97+
})
9598
.then(data => {
9699
const apiResponse = data[0];
97100
this.logger.debug({ name: file.name }, 'gcloud: @{name} was deleted successfully from storage');
@@ -111,16 +114,20 @@ class GoogleCloudStorageHandler implements ILocalPackageManager {
111114
// remove all files from storage
112115
const file = this._getBucket().file(`${this.name}`);
113116
this.logger.debug({ name: file.name }, 'gcloud: removing the package @{name} from storage');
114-
file.delete().then(
115-
() => {
116-
this.logger.debug({ name: file.name }, 'gcloud: package @{name} was deleted successfully from storage');
117-
callback(null);
118-
},
119-
err => {
120-
this.logger.error({ name: file.name, err: err.message }, 'gcloud: delete @{name} package has failed err: @{err}');
121-
callback(fSError(err.message, 500));
122-
}
123-
);
117+
file
118+
.delete({
119+
validation: this.config.validation || defaultValidation
120+
})
121+
.then(
122+
() => {
123+
this.logger.debug({ name: file.name }, 'gcloud: package @{name} was deleted successfully from storage');
124+
callback(null);
125+
},
126+
err => {
127+
this.logger.error({ name: file.name, err: err.message }, 'gcloud: delete @{name} package has failed err: @{err}');
128+
callback(fSError(err.message, 500));
129+
}
130+
);
124131
}
125132

126133
createPackage(name: string, metadata: Object, cb: Function): void {
@@ -159,7 +166,9 @@ class GoogleCloudStorageHandler implements ILocalPackageManager {
159166
return new Promise(async (resolve, reject) => {
160167
const file = this._buildFilePath(name, pkgFileName);
161168
try {
162-
await file.save(this._convertToString(metadata));
169+
await file.save(this._convertToString(metadata), {
170+
validation: this.config.validation || defaultValidation
171+
});
163172
resolve(null);
164173
} catch (err) {
165174
reject(fSError(err.message, 500));
@@ -224,7 +233,9 @@ class GoogleCloudStorageHandler implements ILocalPackageManager {
224233
} else {
225234
const file = this._getBucket().file(`${this.name}/${name}`);
226235
this.logger.info({ url: file.name }, 'gcloud: the @{url} is being uploaded to the storage');
227-
const fileStream = file.createWriteStream();
236+
const fileStream = file.createWriteStream({
237+
validation: this.config.validation || defaultValidation
238+
});
228239
uploadStream.done = () => {
229240
uploadStream.on('end', () => {
230241
fileStream.on('response', () => {

plugins/verdaccio-google-cloud/types/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export type ConfigGoogleStorage = {
88
// https://cloud.google.com/datastore/docs/reference/data/rest/v1/Key
99
kind: string,
1010
// for local development
11-
keyFilename?: string
11+
keyFilename?: string,
12+
// disable bucket validation
13+
validation?: boolean | string
1214
};
1315

1416
export type GoogleCloudOptions = {

0 commit comments

Comments
 (0)