-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: removed undefined errors from vaultops
tests: added tests for VaultsSecretsWriteFile chore: updated secrets remove to properly operate on multiple paths chore: working on proper error wrapping for unexpected errors chore: added comments and cleaned up VaultOps chore: split vaultsSecretsGet and its tests chore: dealing with an edge case when error cannot be serialised chore: cleaned up files chore: added intelligent error message synthesis deps: updated version of @matrixai/rpc fix: handle attempt to remove vault root
- Loading branch information
1 parent
8c1cc9a
commit 35f08e2
Showing
18 changed files
with
1,368 additions
and
524 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { HandlerTypes } from '@matrixai/rpc'; | ||
import type VaultsSecretsCat from '../handlers/VaultsSecretsCat'; | ||
import { DuplexCaller } from '@matrixai/rpc'; | ||
|
||
type CallerTypes = HandlerTypes<VaultsSecretsCat>; | ||
|
||
const vaultsSecretsCat = new DuplexCaller< | ||
CallerTypes['input'], | ||
CallerTypes['output'] | ||
>(); | ||
|
||
export default vaultsSecretsCat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { DB } from '@matrixai/db'; | ||
import type { | ||
ClientRPCRequestParams, | ||
ClientRPCResponseResult, | ||
ContentOrErrorMessage, | ||
SecretIdentifierMessage, | ||
} from '../types'; | ||
import type VaultManager from '../../vaults/VaultManager'; | ||
import { DuplexHandler } from '@matrixai/rpc'; | ||
import * as vaultsUtils from '../../vaults/utils'; | ||
import * as vaultsErrors from '../../vaults/errors'; | ||
import * as vaultOps from '../../vaults/VaultOps'; | ||
|
||
// This method takes in multiple secret paths, and either returns the file | ||
// contents, or an `ErrorMessage` signifying the error. To read a single secret | ||
// instead, refer to `VaultsSecretsGet`. | ||
class VaultsSecretsCat extends DuplexHandler< | ||
{ | ||
db: DB; | ||
vaultManager: VaultManager; | ||
}, | ||
ClientRPCRequestParams<SecretIdentifierMessage>, | ||
ClientRPCResponseResult<ContentOrErrorMessage> | ||
> { | ||
public handle = async function* ( | ||
input: AsyncIterable<ClientRPCRequestParams<SecretIdentifierMessage>>, | ||
): AsyncGenerator<ClientRPCResponseResult<ContentOrErrorMessage>> { | ||
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } = | ||
this.container; | ||
yield* db.withTransactionG(async function* (tran): AsyncGenerator< | ||
ClientRPCResponseResult<ContentOrErrorMessage> | ||
> { | ||
// As we need to preserve the order of parameters, we need to loop over | ||
// them individually, as grouping them would make them go out of order. | ||
for await (const secretIdentiferMessage of input) { | ||
const { nameOrId, secretName } = secretIdentiferMessage; | ||
const vaultIdFromName = await vaultManager.getVaultId(nameOrId, tran); | ||
const vaultId = vaultIdFromName ?? vaultsUtils.decodeVaultId(nameOrId); | ||
if (vaultId == null) throw new vaultsErrors.ErrorVaultsVaultUndefined(); | ||
yield await vaultManager.withVaults( | ||
[vaultId], | ||
async (vault) => { | ||
try { | ||
const content = await vaultOps.getSecret(vault, secretName); | ||
return { | ||
type: 'success', | ||
success: true, | ||
secretContent: content.toString('binary'), | ||
}; | ||
} catch (e) { | ||
if ( | ||
e instanceof vaultsErrors.ErrorSecretsSecretUndefined || | ||
e instanceof vaultsErrors.ErrorSecretsIsDirectory | ||
) { | ||
return { | ||
type: 'error', | ||
code: e.cause.code, | ||
reason: secretName, | ||
}; | ||
} | ||
throw e; | ||
} | ||
}, | ||
tran, | ||
); | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
export default VaultsSecretsCat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.