Skip to content

Commit

Permalink
fix: vault context for file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
wkolod committed May 25, 2023
1 parent 2be87d7 commit 667d8ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class NodeService<T = NodeLike> extends Service {
}

protected async setVaultContextFromNodeId(nodeId: string, type: NodeType, vaultId?: string) {
const object = await this.api.getNode<NodeLike>(nodeId, type, this.vaultId);
const object = await this.api.getNode<NodeLike>(nodeId, type, vaultId);
this.setVaultId(object.vaultId);
this.setIsPublic(object.__public__);
await this.setMembershipKeys(object);
Expand Down
14 changes: 9 additions & 5 deletions src/core/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ class StackService extends NodeService<Stack> {
...options
}
await this.setVaultContext(vaultId);
this.setVaultContextForFile();
this.setActionRef(actionRefs.STACK_CREATE);
this.setFunction(functions.NODE_CREATE);
this.setTags(createOptions.tags);

createOptions.cacheOnly = this.vault.cacheOnly;

const state = {
name: await this.processWriteString(name ? name : file.name),
versions: [await this.uploadNewFileVersion(file, createOptions)],
Expand All @@ -44,6 +47,7 @@ class StackService extends NodeService<Stack> {
*/
public async import(vaultId: string, fileTxId: string, options: NodeCreateOptions = this.defaultCreateOptions): Promise<StackCreateResult> {
await this.setVaultContext(vaultId);
this.setVaultContextForFile();
this.setActionRef(actionRefs.STACK_CREATE);
this.setFunction(functions.NODE_CREATE);

Expand Down Expand Up @@ -72,8 +76,11 @@ class StackService extends NodeService<Stack> {
*/
public async uploadRevision(stackId: string, file: FileLike, options: FileUploadOptions = {}): Promise<StackUpdateResult> {
await this.setVaultContextFromNodeId(stackId, this.objectType);
this.setVaultContextForFile();
this.setActionRef(actionRefs.STACK_UPLOAD_REVISION);

options.cacheOnly = this.object.__cacheOnly__;

const state = {
versions: [await this.uploadNewFileVersion(file, options)]
};
Expand All @@ -91,6 +98,7 @@ class StackService extends NodeService<Stack> {
const stack = new Stack(await this.api.getNode<Stack>(stackId, objectType.STACK, this.vaultId), null);
const version = stack.getVersion(index);
await this.setVaultContext(stack.vaultId);
this.setVaultContextForFile();
const { fileData, metadata } = await this.api.downloadFile(version.getUri(StorageType.S3), { public: this.isPublic });
const data = await this.processReadRaw(fileData, metadata);
const name = await this.processReadString(version.name);
Expand All @@ -110,9 +118,6 @@ class StackService extends NodeService<Stack> {
}

private async uploadNewFileVersion(file: FileLike, options: FileUploadOptions): Promise<FileVersion> {
if (this.object.__cacheOnly__) {
options.cacheOnly = true
}
const {
resourceTx,
resourceUrl,
Expand All @@ -133,8 +138,7 @@ class StackService extends NodeService<Stack> {
return version;
}

protected async setVaultContext(vaultId: string): Promise<void> {
await super.setVaultContext(vaultId);
protected setVaultContextForFile(): void {
this.fileService.setKeys(this.keys);
this.fileService.setRawDataEncryptionPublicKey(this.dataEncrypter.publicKey);
this.fileService.setVaultId(this.vaultId);
Expand Down

0 comments on commit 667d8ca

Please sign in to comment.