-
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.
- Loading branch information
1 parent
8490111
commit 02e3049
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
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 VaultsSecretsRemove from '../handlers/VaultsSecretsRemove'; | ||
import { UnaryCaller } from '@matrixai/rpc'; | ||
|
||
type CallerTypes = HandlerTypes<VaultsSecretsRemove>; | ||
|
||
const vaultsSecretsRemove = new UnaryCaller< | ||
CallerTypes['input'], | ||
CallerTypes['output'] | ||
>(); | ||
|
||
export default vaultsSecretsRemove; |
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,51 @@ | ||
import type { DB } from '@matrixai/db'; | ||
import type { | ||
ClientRPCRequestParams, | ||
ClientRPCResponseResult, | ||
SuccessMessage, | ||
SecretRemoveMessage, | ||
} from '../types'; | ||
import type VaultManager from '../../vaults/VaultManager'; | ||
import { UnaryHandler } from '@matrixai/rpc'; | ||
import * as vaultsUtils from '../../vaults/utils'; | ||
import * as vaultsErrors from '../../vaults/errors'; | ||
import * as vaultOps from '../../vaults/VaultOps'; | ||
|
||
class VaultsSecretsRemove extends UnaryHandler< | ||
{ | ||
vaultManager: VaultManager; | ||
db: DB; | ||
}, | ||
ClientRPCRequestParams<SecretRemoveMessage>, | ||
ClientRPCResponseResult<SuccessMessage> | ||
> { | ||
public handle = async ( | ||
input: ClientRPCRequestParams<SecretRemoveMessage>, | ||
): Promise<ClientRPCResponseResult<SuccessMessage>> => { | ||
const { vaultManager, db } = this.container; | ||
await db.withTransactionF(async (tran) => { | ||
const vaultIdFromName = await vaultManager.getVaultId( | ||
input.nameOrId, | ||
tran, | ||
); | ||
const vaultId = | ||
vaultIdFromName ?? vaultsUtils.decodeVaultId(input.nameOrId); | ||
if (vaultId == null) throw new vaultsErrors.ErrorVaultsVaultUndefined(); | ||
await vaultManager.withVaults( | ||
[vaultId], | ||
async (vault) => { | ||
for (const secretName of input.secretNames) { | ||
await vaultOps.deleteSecret(vault, secretName, { | ||
recursive: input.recursive, | ||
}); | ||
} | ||
}, | ||
tran, | ||
); | ||
}); | ||
|
||
return { success: true }; | ||
}; | ||
} | ||
|
||
export default VaultsSecretsRemove; |
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