Skip to content

Commit

Permalink
fix(verdaccio-google-cloud): catch missing Secret on first run (#247)
Browse files Browse the repository at this point in the history
in getSecret, if /Secret does not exist, we had an async
error uncaught. Catch it explicitly so that the Secret
will get created.
  • Loading branch information
donbowman authored and juanpicado committed Dec 28, 2019
1 parent 91acb12 commit 7742eea
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions plugins/google-cloud/src/data-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,26 @@ class GoogleCloudDatabase implements IPluginStorage<VerdaccioConfigGoogleStorage
const key: Key = this.helper.datastore.key(['Secret', 'secret']);
this.logger.debug('gcloud: [datastore getSecret] init');

return this.helper.datastore.get(key).then((data: object): string => {
this.logger.trace({ data }, 'gcloud: [datastore getSecret] response @{data}');
const entities = data[0];
if (!entities) {
// @ts-ignore
return null;
}
// "{\"secret\":\"181bc38698078f880564be1e4d7ec107ac8a3b344a924c6d86cea4a84a885ae0\"}"
return entities.secret;
});
return this.helper.datastore
.get(key)
.then((data: object): string => {
this.logger.trace({ data }, 'gcloud: [datastore getSecret] response @{data}');
const entities = data[0];
if (!entities) {
// @ts-ignore
return null;
}
// "{\"secret\":\"181bc38698078f880564be1e4d7ec107ac8a3b344a924c6d86cea4a84a885ae0\"}"
return entities.secret;
})
.catch(
(err: Error): Promise<string> => {
const error: VerdaccioError = getInternalError(err.message);

this.logger.warn({ error }, 'gcloud: [datastore getSecret] init error @{error}');
return Promise.reject(getServiceUnavailable('[getSecret] permissions error'));
}
);
}

public setSecret(secret: string): Promise<CommitResponse> {
Expand Down

0 comments on commit 7742eea

Please sign in to comment.