-
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.
Merge pull request #803 from MatrixAI/feature-unix-rm
Implementing `secrets rm` RPC handler
- Loading branch information
Showing
10 changed files
with
350 additions
and
110 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 was deleted.
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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; | ||
// Create a record of secrets to be removed, grouped by vault names | ||
const vaultGroups: Record<string, string[]> = {}; | ||
input.secretNames.forEach(([vaultName, secretName]) => { | ||
if (vaultGroups[vaultName] == null) { | ||
vaultGroups[vaultName] = []; | ||
} | ||
vaultGroups[vaultName].push(secretName); | ||
}); | ||
await db.withTransactionF(async (tran) => { | ||
for (const [vaultName, secretNames] of Object.entries(vaultGroups)) { | ||
const vaultIdFromName = await vaultManager.getVaultId(vaultName, tran); | ||
const vaultId = vaultIdFromName ?? vaultsUtils.decodeVaultId(vaultName); | ||
if (vaultId == null) throw new vaultsErrors.ErrorVaultsVaultUndefined(); | ||
await vaultManager.withVaults( | ||
[vaultId], | ||
async (vault) => { | ||
await vaultOps.deleteSecret(vault, secretNames, { | ||
recursive: input.options?.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
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.