From bc356a932d9ed7963d777169e2e6ccabfff627b6 Mon Sep 17 00:00:00 2001 From: Emma Casolin Date: Wed, 4 May 2022 15:14:36 +1000 Subject: [PATCH] feat: added logger to service handlers All of the agent and client service handlers are now passed a shared logger that is used to log errors to stderr. #304 --- src/ErrorPolykey.ts | 18 +-- src/agent/service/index.ts | 55 ++++---- src/agent/service/nodesChainDataGet.ts | 10 +- .../service/nodesClosestLocalNodesGet.ts | 4 + src/agent/service/nodesCrossSignClaim.ts | 12 +- .../service/nodesHolePunchMessageSend.ts | 4 + src/agent/service/notificationsSend.ts | 4 + src/agent/service/vaultsGitInfoGet.ts | 116 ++++++++-------- src/agent/service/vaultsGitPackGet.ts | 128 +++++++++--------- src/agent/service/vaultsScan.ts | 4 + src/bin/nodes/CommandPing.ts | 3 +- src/claims/errors.ts | 8 +- src/client/service/agentLockAll.ts | 8 +- src/client/service/agentStatus.ts | 4 + src/client/service/agentStop.ts | 4 + src/client/service/agentUnlock.ts | 10 +- .../service/gestaltsActionsGetByIdentity.ts | 4 + .../service/gestaltsActionsGetByNode.ts | 4 + .../service/gestaltsActionsSetByIdentity.ts | 4 + .../service/gestaltsActionsSetByNode.ts | 4 + .../service/gestaltsActionsUnsetByIdentity.ts | 4 + .../service/gestaltsActionsUnsetByNode.ts | 4 + .../service/gestaltsDiscoveryByIdentity.ts | 4 + src/client/service/gestaltsDiscoveryByNode.ts | 4 + .../service/gestaltsGestaltGetByIdentity.ts | 4 + .../service/gestaltsGestaltGetByNode.ts | 4 + src/client/service/gestaltsGestaltList.ts | 4 + .../service/gestaltsGestaltTrustByIdentity.ts | 4 + .../service/gestaltsGestaltTrustByNode.ts | 4 + src/client/service/identitiesAuthenticate.ts | 8 +- .../service/identitiesAuthenticatedGet.ts | 8 +- src/client/service/identitiesClaim.ts | 8 +- .../service/identitiesInfoConnectedGet.ts | 8 +- src/client/service/identitiesInfoGet.ts | 8 +- src/client/service/identitiesProvidersList.ts | 8 +- src/client/service/identitiesTokenDelete.ts | 8 +- src/client/service/identitiesTokenGet.ts | 8 +- src/client/service/identitiesTokenPut.ts | 8 +- src/client/service/keysCertsChainGet.ts | 8 +- src/client/service/keysCertsGet.ts | 8 +- src/client/service/keysDecrypt.ts | 8 +- src/client/service/keysEncrypt.ts | 8 +- src/client/service/keysKeyPairRenew.ts | 8 +- src/client/service/keysKeyPairReset.ts | 8 +- src/client/service/keysKeyPairRoot.ts | 8 +- src/client/service/keysPasswordChange.ts | 8 +- src/client/service/keysSign.ts | 8 +- src/client/service/keysVerify.ts | 8 +- src/client/service/nodesAdd.ts | 8 +- src/client/service/nodesClaim.ts | 8 +- src/client/service/nodesFind.ts | 8 +- src/client/service/nodesPing.ts | 8 +- src/client/service/notificationsClear.ts | 8 +- src/client/service/notificationsRead.ts | 8 +- src/client/service/notificationsSend.ts | 8 +- src/client/service/vaultsClone.ts | 4 + src/client/service/vaultsCreate.ts | 8 +- src/client/service/vaultsDelete.ts | 8 +- src/client/service/vaultsList.ts | 8 +- src/client/service/vaultsLog.ts | 8 +- src/client/service/vaultsPermissionGet.ts | 8 +- src/client/service/vaultsPermissionSet.ts | 8 +- src/client/service/vaultsPermissionUnset.ts | 8 +- src/client/service/vaultsPull.ts | 4 + src/client/service/vaultsRename.ts | 8 +- src/client/service/vaultsScan.ts | 8 +- src/client/service/vaultsSecretsDelete.ts | 8 +- src/client/service/vaultsSecretsEdit.ts | 8 +- src/client/service/vaultsSecretsGet.ts | 8 +- src/client/service/vaultsSecretsList.ts | 8 +- src/client/service/vaultsSecretsMkdir.ts | 8 +- src/client/service/vaultsSecretsNew.ts | 8 +- src/client/service/vaultsSecretsNewDir.ts | 8 +- src/client/service/vaultsSecretsRename.ts | 8 +- src/client/service/vaultsSecretsStat.ts | 4 + src/client/service/vaultsVersion.ts | 8 +- src/gestalts/utils.ts | 2 +- src/grpc/GRPCClient.ts | 3 +- src/grpc/GRPCServer.ts | 3 +- src/grpc/utils/utils.ts | 53 ++++---- src/identities/errors.ts | 3 +- .../providers/github/GitHubProvider.ts | 3 +- src/network/utils.ts | 4 +- src/nodes/NodeConnection.ts | 4 +- src/notifications/errors.ts | 4 +- src/notifications/utils.ts | 4 +- src/status/Status.ts | 8 +- src/vaults/VaultInternal.ts | 8 +- .../agent/service/nodesCrossSignClaim.test.ts | 11 +- tests/agent/service/notificationsSend.test.ts | 1 + tests/client/GRPCClientClient.test.ts | 2 +- tests/client/service/agentLockAll.test.ts | 1 + tests/client/service/agentStatus.test.ts | 1 + tests/client/service/agentStop.test.ts | 1 + tests/client/service/agentUnlock.test.ts | 1 + ...staltsActionsSetUnsetGetByIdentity.test.ts | 3 + .../gestaltsActionsSetUnsetGetByNode.test.ts | 3 + .../gestaltsDiscoveryByIdentity.test.ts | 1 + .../service/gestaltsDiscoveryByNode.test.ts | 1 + .../gestaltsGestaltGetByIdentity.test.ts | 1 + .../service/gestaltsGestaltGetByNode.test.ts | 1 + .../service/gestaltsGestaltList.test.ts | 1 + .../gestaltsGestaltTrustByIdentity.test.ts | 1 + .../gestaltsGestaltTrustByNode.test.ts | 1 + .../service/identitiesAuthenticate.test.ts | 1 + .../identitiesAuthenticatedGet.test.ts | 1 + tests/client/service/identitiesClaim.test.ts | 1 + .../identitiesInfoConnectedGet.test.ts | 1 + .../client/service/identitiesInfoGet.test.ts | 1 + .../service/identitiesProvidersList.test.ts | 1 + .../identitiesTokenPutDeleteGet.test.ts | 3 + .../client/service/keysCertsChainGet.test.ts | 1 + tests/client/service/keysCertsGet.test.ts | 1 + .../client/service/keysEncryptDecrypt.test.ts | 2 + tests/client/service/keysKeyPairRenew.test.ts | 1 + tests/client/service/keysKeyPairReset.test.ts | 1 + tests/client/service/keysKeyPairRoot.test.ts | 1 + .../client/service/keysPasswordChange.test.ts | 1 + tests/client/service/keysSignVerify.test.ts | 2 + tests/client/service/nodesAdd.test.ts | 1 + tests/client/service/nodesClaim.test.ts | 1 + tests/client/service/nodesFind.test.ts | 3 +- tests/client/service/nodesPing.test.ts | 1 + .../client/service/notificationsClear.test.ts | 1 + .../client/service/notificationsRead.test.ts | 1 + .../client/service/notificationsSend.test.ts | 1 + tests/grpc/utils.test.ts | 16 ++- 127 files changed, 666 insertions(+), 316 deletions(-) diff --git a/src/ErrorPolykey.ts b/src/ErrorPolykey.ts index 3e418e757..deba43ef2 100644 --- a/src/ErrorPolykey.ts +++ b/src/ErrorPolykey.ts @@ -9,24 +9,24 @@ class ErrorPolykey extends AbstractError { _key: string = '', options: { description?: boolean; - message?: boolean, - exitCode?: boolean, + message?: boolean; + exitCode?: boolean; timestamp?: boolean; data?: boolean; cause?: boolean; stack?: boolean; - } = {} + } = {}, ): { type: string; data: { description?: string; message?: string; - exitCode?: number, - timestamp?: Date, + exitCode?: number; + timestamp?: Date; data?: POJO; - cause?: T, - stack?: string - } + cause?: T; + stack?: string; + }; } { options.description ??= true; options.message ??= true; @@ -54,7 +54,7 @@ class ErrorPolykey extends AbstractError { if (options.stack) data.stack = this.stack; return { type: this.name, - data + data, }; } } diff --git a/src/agent/service/index.ts b/src/agent/service/index.ts index aa96bfd2e..caa8c60ed 100644 --- a/src/agent/service/index.ts +++ b/src/agent/service/index.ts @@ -1,16 +1,15 @@ -import type { KeyManager } from '../../keys'; -import type { VaultManager } from '../../vaults'; -import type { - NodeGraph, - NodeManager, - NodeConnectionManager, -} from '../../nodes'; -import type { NotificationsManager } from '../../notifications'; -import type { Sigchain } from '../../sigchain'; -import type { ACL } from '../../acl'; -import type { GestaltGraph } from '../../gestalts'; +import type KeyManager from '../../keys/KeyManager'; +import type VaultManager from '../../vaults/VaultManager'; +import type NodeGraph from '../../nodes/NodeGraph'; +import type NodeManager from '../../nodes/NodeManager'; +import type NodeConnectionManager from '../../nodes/NodeConnectionManager'; +import type NotificationsManager from '../../notifications/NotificationsManager'; +import type Sigchain from '../../sigchain/Sigchain'; +import type ACL from '../../acl/ACL'; +import type GestaltGraph from '../../gestalts/GestaltGraph'; import type { IAgentServiceServer } from '../../proto/js/polykey/v1/agent_service_grpc_pb'; import type Proxy from '../../network/Proxy'; +import Logger from '@matrixai/logger'; import echo from './echo'; import nodesChainDataGet from './nodesChainDataGet'; import nodesClaimsGet from './nodesClaimsGet'; @@ -24,7 +23,11 @@ import vaultsScan from './vaultsScan'; import { AgentServiceService } from '../../proto/js/polykey/v1/agent_service_grpc_pb'; import * as agentUtils from '../utils'; -function createService(container: { +function createService({ + proxy, + logger = new Logger(createService.name), + ...containerRest +}: { keyManager: KeyManager; vaultManager: VaultManager; nodeConnectionManager: NodeConnectionManager; @@ -35,23 +38,25 @@ function createService(container: { acl: ACL; gestaltGraph: GestaltGraph; proxy: Proxy; + logger?: Logger; }): IAgentServiceServer { - const connectionInfoGet = agentUtils.connectionInfoGetter(container.proxy); - const container_ = { - ...container, + const connectionInfoGet = agentUtils.connectionInfoGetter(proxy); + const container = { + ...containerRest, + logger, connectionInfoGet: connectionInfoGet, }; const service: IAgentServiceServer = { - echo: echo(container_), - nodesChainDataGet: nodesChainDataGet(container_), - nodesClaimsGet: nodesClaimsGet(container_), - nodesClosestLocalNodesGet: nodesClosestLocalNodesGet(container_), - nodesCrossSignClaim: nodesCrossSignClaim(container_), - nodesHolePunchMessageSend: nodesHolePunchMessageSend(container_), - notificationsSend: notificationsSend(container_), - vaultsGitInfoGet: vaultsGitInfoGet(container_), - vaultsGitPackGet: vaultsGitPackGet(container_), - vaultsScan: vaultsScan(container_), + echo: echo(container), + nodesChainDataGet: nodesChainDataGet(container), + nodesClaimsGet: nodesClaimsGet(container), + nodesClosestLocalNodesGet: nodesClosestLocalNodesGet(container), + nodesCrossSignClaim: nodesCrossSignClaim(container), + nodesHolePunchMessageSend: nodesHolePunchMessageSend(container), + notificationsSend: notificationsSend(container), + vaultsGitInfoGet: vaultsGitInfoGet(container), + vaultsGitPackGet: vaultsGitPackGet(container), + vaultsScan: vaultsScan(container), }; return service; } diff --git a/src/agent/service/nodesChainDataGet.ts b/src/agent/service/nodesChainDataGet.ts index 2a03bdd7a..4301dff01 100644 --- a/src/agent/service/nodesChainDataGet.ts +++ b/src/agent/service/nodesChainDataGet.ts @@ -2,13 +2,20 @@ import type * as grpc from '@grpc/grpc-js'; import type { Sigchain } from '../../sigchain'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; import type { ClaimIdEncoded } from '../../claims/types'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; /** * Retrieves the ChainDataEncoded of this node. */ -function nodesChainDataGet({ sigchain }: { sigchain: Sigchain }) { +function nodesChainDataGet({ + sigchain, + logger, +}: { + sigchain: Sigchain; + logger: Logger; +}) { return async ( call: grpc.ServerUnaryCall, callback: grpc.sendUnaryData, @@ -38,6 +45,7 @@ function nodesChainDataGet({ sigchain }: { sigchain: Sigchain }) { return; } catch (e) { callback(grpcUtils.fromError(e, true)); + logger.error(e); return; } }; diff --git a/src/agent/service/nodesClosestLocalNodesGet.ts b/src/agent/service/nodesClosestLocalNodesGet.ts index 7e5739495..dc709195b 100644 --- a/src/agent/service/nodesClosestLocalNodesGet.ts +++ b/src/agent/service/nodesClosestLocalNodesGet.ts @@ -1,6 +1,7 @@ import type * as grpc from '@grpc/grpc-js'; import type { NodeConnectionManager } from '../../nodes'; import type { NodeId } from '../../nodes/types'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { utils as nodesUtils } from '../../nodes'; import { validateSync, utils as validationUtils } from '../../validation'; @@ -13,8 +14,10 @@ import * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; */ function nodesClosestLocalNodesGet({ nodeConnectionManager, + logger, }: { nodeConnectionManager: NodeConnectionManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -54,6 +57,7 @@ function nodesClosestLocalNodesGet({ return; } catch (e) { callback(grpcUtils.fromError(e, true)); + logger.error(e); return; } }; diff --git a/src/agent/service/nodesCrossSignClaim.ts b/src/agent/service/nodesCrossSignClaim.ts index 2606606ee..45af67a8d 100644 --- a/src/agent/service/nodesCrossSignClaim.ts +++ b/src/agent/service/nodesCrossSignClaim.ts @@ -5,6 +5,7 @@ import type { NodeId } from '../../nodes/types'; import type { Sigchain } from '../../sigchain'; import type { KeyManager } from '../../keys'; import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { utils as claimsUtils, errors as claimsErrors } from '../../claims'; import { utils as nodesUtils } from '../../nodes'; @@ -15,16 +16,16 @@ function nodesCrossSignClaim({ keyManager, nodeManager, sigchain, + logger, }: { keyManager: KeyManager; nodeManager: NodeManager; sigchain: Sigchain; + logger: Logger; }) { return async ( call: grpc.ServerDuplexStream, ) => { - // TODO: Move all "await genClaims.throw" to a final catch(). Wrap this - // entire thing in a try block. And re-throw whatever error is caught const genClaims = grpcUtils.generatorDuplex(call, true); try { await sigchain.transaction(async (sigchain) => { @@ -149,9 +150,7 @@ function nodesCrossSignClaim({ senderPublicKey, )); if (!verifiedDoubly) { - await genClaims.throw( - new claimsErrors.ErrorDoublySignedClaimVerificationFailed(), - ); + throw new claimsErrors.ErrorDoublySignedClaimVerificationFailed(); } // If verified, then we can safely add to our sigchain await sigchain.addExistingClaim(constructedDoublySignedClaim); @@ -161,8 +160,7 @@ function nodesCrossSignClaim({ }); } catch (e) { await genClaims.throw(e); - // TODO: Handle the exception on this server - throw e? - // throw e; + logger.error(e); return; } }; diff --git a/src/agent/service/nodesHolePunchMessageSend.ts b/src/agent/service/nodesHolePunchMessageSend.ts index 2196cceec..438af3775 100644 --- a/src/agent/service/nodesHolePunchMessageSend.ts +++ b/src/agent/service/nodesHolePunchMessageSend.ts @@ -3,6 +3,7 @@ import type { NodeManager, NodeConnectionManager } from '../../nodes'; import type KeyManager from '../../keys/KeyManager'; import type { NodeId } from '../../nodes/types'; import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; +import type Logger from '@matrixai/logger'; import * as networkUtils from '../../network/utils'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; @@ -13,10 +14,12 @@ function nodesHolePunchMessageSend({ keyManager, nodeManager, nodeConnectionManager, + logger, }: { keyManager: KeyManager; nodeManager: NodeManager; nodeConnectionManager: NodeConnectionManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -63,6 +66,7 @@ function nodesHolePunchMessageSend({ return; } catch (e) { callback(grpcUtils.fromError(e, true)); + logger.error(e); return; } }; diff --git a/src/agent/service/notificationsSend.ts b/src/agent/service/notificationsSend.ts index d942da04e..f11a18c95 100644 --- a/src/agent/service/notificationsSend.ts +++ b/src/agent/service/notificationsSend.ts @@ -1,14 +1,17 @@ import type * as grpc from '@grpc/grpc-js'; import type { NotificationsManager } from '../../notifications'; import type * as notificationsPB from '../../proto/js/polykey/v1/notifications/notifications_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { utils as notificationsUtils } from '../../notifications'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function notificationsSend({ notificationsManager, + logger, }: { notificationsManager: NotificationsManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall< @@ -26,6 +29,7 @@ function notificationsSend({ return; } catch (e) { callback(grpcUtils.fromError(e, true)); + logger.error(e); return; } }; diff --git a/src/agent/service/vaultsGitInfoGet.ts b/src/agent/service/vaultsGitInfoGet.ts index 1a043f92b..6f4ae9873 100644 --- a/src/agent/service/vaultsGitInfoGet.ts +++ b/src/agent/service/vaultsGitInfoGet.ts @@ -2,6 +2,7 @@ import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type ACL from '../../acl/ACL'; import type { ConnectionInfoGet } from '../../agent/types'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as grpcUtils from '../../grpc/utils'; import * as vaultsUtils from '../../vaults/utils'; @@ -14,80 +15,81 @@ import * as agentErrors from '../errors'; function vaultsGitInfoGet({ vaultManager, acl, + logger, connectionInfoGet, }: { vaultManager: VaultManager; acl: ACL; + logger: Logger; connectionInfoGet: ConnectionInfoGet; }) { return async ( call: grpc.ServerWritableStream, ): Promise => { const genWritable = grpcUtils.generatorWritable(call, true); - const request = call.request; - const vaultMessage = request.getVault(); - if (vaultMessage == null) { - await genWritable.throw({ code: grpc.status.NOT_FOUND }); - return; - } - let vaultName; - const vaultNameOrId = vaultMessage.getNameOrId(); - let vaultId = await vaultManager.getVaultId(vaultNameOrId as VaultName); - vaultName = vaultNameOrId; - if (vaultId == null) { - try { - vaultId = validationUtils.parseVaultId(vaultNameOrId); - vaultName = (await vaultManager.getVaultMeta(vaultId))?.vaultName; - } catch (err) { - await genWritable.throw(new vaultsErrors.ErrorVaultsVaultUndefined()); - return; + try { + const request = call.request; + const vaultMessage = request.getVault(); + if (vaultMessage == null) { + throw new vaultsErrors.ErrorVaultsVaultUndefined(); } - } - // Getting the NodeId from the ReverseProxy connection info - const connectionInfo = connectionInfoGet(call); - // If this is getting run the connection exists - // It SHOULD exist here - if (connectionInfo == null) { - throw new agentErrors.ErrorConnectionInfoMissing(); - } - const nodeId = connectionInfo.remoteNodeId; - const nodeIdEncoded = nodesUtils.encodeNodeId(nodeId); - const actionType = validationUtils.parseVaultAction(request.getAction()); - const permissions = await acl.getNodePerm(nodeId); - if (permissions == null) { - await genWritable.throw( - new vaultsErrors.ErrorVaultsPermissionDenied( + let vaultName; + const vaultNameOrId = vaultMessage.getNameOrId(); + let vaultId = await vaultManager.getVaultId(vaultNameOrId as VaultName); + vaultName = vaultNameOrId; + if (vaultId == null) { + try { + vaultId = validationUtils.parseVaultId(vaultNameOrId); + vaultName = (await vaultManager.getVaultMeta(vaultId))?.vaultName; + } catch (e) { + throw new vaultsErrors.ErrorVaultsVaultUndefined(e.message, { + cause: e, + }); + } + } + // Getting the NodeId from the ReverseProxy connection info + const connectionInfo = connectionInfoGet(call); + // If this is getting run the connection exists + // It SHOULD exist here + if (connectionInfo == null) { + throw new agentErrors.ErrorConnectionInfoMissing(); + } + const nodeId = connectionInfo.remoteNodeId; + const nodeIdEncoded = nodesUtils.encodeNodeId(nodeId); + const actionType = validationUtils.parseVaultAction(request.getAction()); + const permissions = await acl.getNodePerm(nodeId); + if (permissions == null) { + throw new vaultsErrors.ErrorVaultsPermissionDenied( `No permissions found for ${nodeIdEncoded}`, - ), - ); - return; - } - const vaultPerms = permissions.vaults[vaultId]; - if (vaultPerms?.[actionType] !== null) { - await genWritable.throw( - new vaultsErrors.ErrorVaultsPermissionDenied( + ); + } + const vaultPerms = permissions.vaults[vaultId]; + if (vaultPerms?.[actionType] !== null) { + throw new vaultsErrors.ErrorVaultsPermissionDenied( `${nodeIdEncoded} does not have permission to ${actionType} from vault ${vaultsUtils.encodeVaultId( vaultId, )}`, - ), - ); - return; - } - const meta = new grpc.Metadata(); - meta.set('vaultName', vaultName); - meta.set('vaultId', vaultsUtils.encodeVaultId(vaultId)); - genWritable.stream.sendMetadata(meta); - const response = new vaultsPB.PackChunk(); - const responseGen = vaultManager.handleInfoRequest(vaultId); - for await (const byte of responseGen) { - if (byte !== null) { - response.setChunk(byte); - await genWritable.next(response); - } else { - await genWritable.next(null); + ); + } + const meta = new grpc.Metadata(); + meta.set('vaultName', vaultName); + meta.set('vaultId', vaultsUtils.encodeVaultId(vaultId)); + genWritable.stream.sendMetadata(meta); + const response = new vaultsPB.PackChunk(); + const responseGen = vaultManager.handleInfoRequest(vaultId); + for await (const byte of responseGen) { + if (byte !== null) { + response.setChunk(byte); + await genWritable.next(response); + } else { + await genWritable.next(null); + } } + await genWritable.next(null); + } catch (e) { + await genWritable.throw(e); + logger.error(e); } - await genWritable.next(null); }; } diff --git a/src/agent/service/vaultsGitPackGet.ts b/src/agent/service/vaultsGitPackGet.ts index 8c0d9232f..e96398529 100644 --- a/src/agent/service/vaultsGitPackGet.ts +++ b/src/agent/service/vaultsGitPackGet.ts @@ -3,6 +3,7 @@ import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type { ConnectionInfoGet } from '../../agent/types'; import type ACL from '../../acl/ACL'; +import type Logger from '@matrixai/logger'; import * as nodesUtils from '../../nodes/utils'; import * as grpcErrors from '../../grpc/errors'; import * as grpcUtils from '../../grpc/utils'; @@ -15,86 +16,87 @@ import * as agentErrors from '../errors'; function vaultsGitPackGet({ vaultManager, acl, + logger, connectionInfoGet, }: { vaultManager: VaultManager; acl: ACL; + logger: Logger; connectionInfoGet: ConnectionInfoGet; }) { return async ( call: grpc.ServerDuplexStream, - ) => { + ): Promise => { const genDuplex = grpcUtils.generatorDuplex(call, true); - const clientBodyBuffers: Uint8Array[] = []; - const clientRequest = (await genDuplex.read()).value; - clientBodyBuffers.push(clientRequest!.getChunk_asU8()); - const body = Buffer.concat(clientBodyBuffers); - const meta = call.metadata; - // Getting the NodeId from the ReverseProxy connection info - const connectionInfo = connectionInfoGet(call); - // If this is getting run the connection exists - // It SHOULD exist here - if (connectionInfo == null) { - throw new agentErrors.ErrorConnectionInfoMissing(); - } - const nodeId = connectionInfo.remoteNodeId; - const nodeIdEncoded = nodesUtils.encodeNodeId(nodeId); - // Getting vaultId - const vaultNameOrId = meta.get('vaultNameOrId').pop()!.toString(); - if (vaultNameOrId == null) { - throw new grpcErrors.ErrorGRPC('vault-name not in metadata'); - } - let vaultId = await vaultManager.getVaultId(vaultNameOrId as VaultName); - vaultId = vaultId ?? vaultsUtils.decodeVaultId(vaultNameOrId); - if (vaultId == null) { - await genDuplex.throw( + try { + const clientBodyBuffers: Uint8Array[] = []; + const clientRequest = (await genDuplex.read()).value; + clientBodyBuffers.push(clientRequest!.getChunk_asU8()); + const body = Buffer.concat(clientBodyBuffers); + const meta = call.metadata; + // Getting the NodeId from the ReverseProxy connection info + const connectionInfo = connectionInfoGet(call); + // If this is getting run the connection exists + // It SHOULD exist here + if (connectionInfo == null) { + throw new agentErrors.ErrorConnectionInfoMissing(); + } + const nodeId = connectionInfo.remoteNodeId; + const nodeIdEncoded = nodesUtils.encodeNodeId(nodeId); + // Getting vaultId + const vaultNameOrId = meta.get('vaultNameOrId').pop()!.toString(); + if (vaultNameOrId == null) { + throw new grpcErrors.ErrorGRPC('vault-name not in metadata'); + } + let vaultId = await vaultManager.getVaultId(vaultNameOrId as VaultName); + vaultId = vaultId ?? vaultsUtils.decodeVaultId(vaultNameOrId); + if (vaultId == null) { // Throwing permission error to hide information about vaults existence - new vaultsErrors.ErrorVaultsPermissionDenied( + throw new vaultsErrors.ErrorVaultsPermissionDenied( `No permissions found for ${nodeIdEncoded}`, - ), + ); + } + // Checking permissions + const permissions = await acl.getNodePerm(nodeId); + const vaultPerms = permissions?.vaults[vaultId]; + const actionType = validationUtils.parseVaultAction( + meta.get('vaultAction').pop(), ); - return; - } - // Checking permissions - const permissions = await acl.getNodePerm(nodeId); - const vaultPerms = permissions?.vaults[vaultId]; - const actionType = validationUtils.parseVaultAction( - meta.get('vaultAction').pop(), - ); - if (vaultPerms?.[actionType] !== null) { - await genDuplex.throw( - new vaultsErrors.ErrorVaultsPermissionDenied( + if (vaultPerms?.[actionType] !== null) { + throw new vaultsErrors.ErrorVaultsPermissionDenied( `${nodeIdEncoded} does not have permission to ${actionType} from vault ${vaultsUtils.encodeVaultId( vaultId, )}`, - ), + ); + } + const response = new vaultsPB.PackChunk(); + const [sideBand, progressStream] = await vaultManager.handlePackRequest( + vaultId, + Buffer.from(body), ); - return; - } - const response = new vaultsPB.PackChunk(); - const [sideBand, progressStream] = await vaultManager.handlePackRequest( - vaultId, - Buffer.from(body), - ); - response.setChunk(Buffer.from('0008NAK\n')); - await genDuplex.write(response); - const responseBuffers: Uint8Array[] = []; - await new Promise((resolve, reject) => { - sideBand.on('data', async (data: Uint8Array) => { - responseBuffers.push(data); + response.setChunk(Buffer.from('0008NAK\n')); + await genDuplex.write(response); + const responseBuffers: Uint8Array[] = []; + await new Promise((resolve, reject) => { + sideBand.on('data', async (data: Uint8Array) => { + responseBuffers.push(data); + }); + sideBand.on('end', async () => { + response.setChunk(Buffer.concat(responseBuffers)); + await genDuplex.write(response); + resolve(); + }); + sideBand.on('error', (err) => { + reject(err); + }); + progressStream.write(Buffer.from('0014progress is at 50%\n')); + progressStream.end(); }); - sideBand.on('end', async () => { - response.setChunk(Buffer.concat(responseBuffers)); - await genDuplex.write(response); - resolve(); - }); - sideBand.on('error', (err) => { - reject(err); - }); - progressStream.write(Buffer.from('0014progress is at 50%\n')); - progressStream.end(); - }); - await genDuplex.next(null); + await genDuplex.next(null); + } catch (e) { + await genDuplex.throw(e); + logger.error(e); + } }; } diff --git a/src/agent/service/vaultsScan.ts b/src/agent/service/vaultsScan.ts index acdcfb0b1..bd7cb004b 100644 --- a/src/agent/service/vaultsScan.ts +++ b/src/agent/service/vaultsScan.ts @@ -2,6 +2,7 @@ import type * as grpc from '@grpc/grpc-js'; import type VaultManager from '../../vaults/VaultManager'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; import type { ConnectionInfoGet } from '../../agent/types'; +import type Logger from '@matrixai/logger'; import * as agentErrors from '../../agent/errors'; import * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; import * as vaultsUtils from '../../vaults/utils'; @@ -9,9 +10,11 @@ import * as grpcUtils from '../../grpc/utils'; function vaultsScan({ vaultManager, + logger, connectionInfoGet, }: { vaultManager: VaultManager; + logger: Logger; connectionInfoGet: ConnectionInfoGet; }) { return async ( @@ -42,6 +45,7 @@ function vaultsScan({ await genWritable.next(null); } catch (e) { await genWritable.throw(e); + logger.error(e); } }; } diff --git a/src/bin/nodes/CommandPing.ts b/src/bin/nodes/CommandPing.ts index 11913011a..3ff6049a1 100644 --- a/src/bin/nodes/CommandPing.ts +++ b/src/bin/nodes/CommandPing.ts @@ -59,7 +59,8 @@ class CommandPing extends CommandPolykey { error = new binErrors.ErrorNodePingFailed( `Failed to resolve node ID ${nodesUtils.encodeNodeId( nodeId, - )} to an address.`, { cause: err }, + )} to an address.`, + { cause: err }, ); } else { throw err; diff --git a/src/claims/errors.ts b/src/claims/errors.ts index 9685201f8..95b03c74a 100644 --- a/src/claims/errors.ts +++ b/src/claims/errors.ts @@ -85,16 +85,12 @@ class ErrorDoublySignedClaimNumSignatures extends ErrorSchemaValidate { exitCode = sysexits.CONFIG; } -class ErrorSinglySignedClaimValidationFailed< - T, -> extends ErrorSchemaValidate { +class ErrorSinglySignedClaimValidationFailed extends ErrorSchemaValidate { static description = 'Claim data does not match schema'; exitCode = sysexits.CONFIG; } -class ErrorDoublySignedClaimValidationFailed< - T, -> extends ErrorSchemaValidate { +class ErrorDoublySignedClaimValidationFailed extends ErrorSchemaValidate { static description = 'Claim data does not match schema'; exitCode = sysexits.CONFIG; } diff --git a/src/client/service/agentLockAll.ts b/src/client/service/agentLockAll.ts index dd80ebf62..6f7eaba76 100644 --- a/src/client/service/agentLockAll.ts +++ b/src/client/service/agentLockAll.ts @@ -1,15 +1,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { SessionManager } from '../../sessions'; +import type Logger from '@matrixai/logger'; import * as grpcUtils from '../../grpc/utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function agentLockAll({ - sessionManager, authenticate, + sessionManager, + logger, }: { - sessionManager: SessionManager; authenticate: Authenticate; + sessionManager: SessionManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -24,6 +27,7 @@ function agentLockAll({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/agentStatus.ts b/src/client/service/agentStatus.ts index e90042ebd..ecac4e1c1 100644 --- a/src/client/service/agentStatus.ts +++ b/src/client/service/agentStatus.ts @@ -4,6 +4,7 @@ import type KeyManager from '../../keys/KeyManager'; import type GRPCServer from '../../grpc/GRPCServer'; import type Proxy from '../../network/Proxy'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; +import type Logger from '@matrixai/logger'; import process from 'process'; import * as grpcUtils from '../../grpc/utils'; import * as nodesUtils from '../../nodes/utils'; @@ -15,12 +16,14 @@ function agentStatus({ grpcServerClient, grpcServerAgent, proxy, + logger, }: { authenticate: Authenticate; keyManager: KeyManager; grpcServerClient: GRPCServer; grpcServerAgent: GRPCServer; proxy: Proxy; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -46,6 +49,7 @@ function agentStatus({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/agentStop.ts b/src/client/service/agentStop.ts index 6f0c83bdc..f359036b8 100644 --- a/src/client/service/agentStop.ts +++ b/src/client/service/agentStop.ts @@ -1,6 +1,7 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type PolykeyAgent from '../../PolykeyAgent'; +import type Logger from '@matrixai/logger'; import { status, running } from '@matrixai/async-init'; import * as grpcUtils from '../../grpc/utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; @@ -8,9 +9,11 @@ import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function agentStop({ authenticate, pkAgent, + logger, }: { authenticate: Authenticate; pkAgent: PolykeyAgent; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -29,6 +32,7 @@ function agentStop({ callback(null, response); } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } // Stop is called after GRPC resources are cleared diff --git a/src/client/service/agentUnlock.ts b/src/client/service/agentUnlock.ts index a3ff33ddd..1814eb81a 100644 --- a/src/client/service/agentUnlock.ts +++ b/src/client/service/agentUnlock.ts @@ -1,9 +1,16 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; +import type Logger from '@matrixai/logger'; import * as grpcUtils from '../../grpc/utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; -function agentUnlock({ authenticate }: { authenticate: Authenticate }) { +function agentUnlock({ + authenticate, + logger, +}: { + authenticate: Authenticate; + logger: Logger; +}) { return async ( call: grpc.ServerUnaryCall, callback: grpc.sendUnaryData, @@ -16,6 +23,7 @@ function agentUnlock({ authenticate }: { authenticate: Authenticate }) { return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsActionsGetByIdentity.ts b/src/client/service/gestaltsActionsGetByIdentity.ts index c4df02f2c..3ec511381 100644 --- a/src/client/service/gestaltsActionsGetByIdentity.ts +++ b/src/client/service/gestaltsActionsGetByIdentity.ts @@ -3,6 +3,7 @@ import type { Authenticate } from '../types'; import type { GestaltGraph } from '../../gestalts'; import type { IdentityId, ProviderId } from '../../identities/types'; import type * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -11,9 +12,11 @@ import * as permissionsPB from '../../proto/js/polykey/v1/permissions/permission function gestaltsActionsGetByIdentity({ authenticate, gestaltGraph, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -55,6 +58,7 @@ function gestaltsActionsGetByIdentity({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsActionsGetByNode.ts b/src/client/service/gestaltsActionsGetByNode.ts index f4bcd4d5a..77b6c54fd 100644 --- a/src/client/service/gestaltsActionsGetByNode.ts +++ b/src/client/service/gestaltsActionsGetByNode.ts @@ -3,6 +3,7 @@ import type { Authenticate } from '../types'; import type { NodeId } from '../../nodes/types'; import type { GestaltGraph } from '../../gestalts'; import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -11,9 +12,11 @@ import * as permissionsPB from '../../proto/js/polykey/v1/permissions/permission function gestaltsActionsGetByNode({ authenticate, gestaltGraph, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -47,6 +50,7 @@ function gestaltsActionsGetByNode({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsActionsSetByIdentity.ts b/src/client/service/gestaltsActionsSetByIdentity.ts index 0a7637876..34140fec9 100644 --- a/src/client/service/gestaltsActionsSetByIdentity.ts +++ b/src/client/service/gestaltsActionsSetByIdentity.ts @@ -4,6 +4,7 @@ import type { GestaltGraph } from '../../gestalts'; import type { GestaltAction } from '../../gestalts/types'; import type { IdentityId, ProviderId } from '../../identities/types'; import type * as permissionsPB from '../../proto/js/polykey/v1/permissions/permissions_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -12,9 +13,11 @@ import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function gestaltsActionsSetByIdentity({ authenticate, gestaltGraph, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -56,6 +59,7 @@ function gestaltsActionsSetByIdentity({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsActionsSetByNode.ts b/src/client/service/gestaltsActionsSetByNode.ts index f7e2e22fc..0c801c350 100644 --- a/src/client/service/gestaltsActionsSetByNode.ts +++ b/src/client/service/gestaltsActionsSetByNode.ts @@ -4,6 +4,7 @@ import type { GestaltGraph } from '../../gestalts'; import type { GestaltAction } from '../../gestalts/types'; import type { NodeId } from '../../nodes/types'; import type * as permissionsPB from '../../proto/js/polykey/v1/permissions/permissions_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -12,9 +13,11 @@ import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function gestaltsActionsSetByNode({ authenticate, gestaltGraph, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -43,6 +46,7 @@ function gestaltsActionsSetByNode({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsActionsUnsetByIdentity.ts b/src/client/service/gestaltsActionsUnsetByIdentity.ts index a247babd8..9ab5ac61e 100644 --- a/src/client/service/gestaltsActionsUnsetByIdentity.ts +++ b/src/client/service/gestaltsActionsUnsetByIdentity.ts @@ -4,6 +4,7 @@ import type { GestaltGraph } from '../../gestalts'; import type { GestaltAction } from '../../gestalts/types'; import type { IdentityId, ProviderId } from '../../identities/types'; import type * as permissionsPB from '../../proto/js/polykey/v1/permissions/permissions_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -12,9 +13,11 @@ import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function gestaltsActionsUnsetByIdentity({ authenticate, gestaltGraph, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -56,6 +59,7 @@ function gestaltsActionsUnsetByIdentity({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsActionsUnsetByNode.ts b/src/client/service/gestaltsActionsUnsetByNode.ts index 0add07203..795f9c4fc 100644 --- a/src/client/service/gestaltsActionsUnsetByNode.ts +++ b/src/client/service/gestaltsActionsUnsetByNode.ts @@ -4,6 +4,7 @@ import type { GestaltGraph } from '../../gestalts'; import type { GestaltAction } from '../../gestalts/types'; import type { NodeId } from '../../nodes/types'; import type * as permissionsPB from '../../proto/js/polykey/v1/permissions/permissions_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -12,9 +13,11 @@ import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function gestaltsActionsUnsetByNode({ authenticate, gestaltGraph, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -43,6 +46,7 @@ function gestaltsActionsUnsetByNode({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsDiscoveryByIdentity.ts b/src/client/service/gestaltsDiscoveryByIdentity.ts index 4ebeae0ce..c8e515ab7 100644 --- a/src/client/service/gestaltsDiscoveryByIdentity.ts +++ b/src/client/service/gestaltsDiscoveryByIdentity.ts @@ -3,6 +3,7 @@ import type { Authenticate } from '../types'; import type { Discovery } from '../../discovery'; import type { IdentityId, ProviderId } from '../../identities/types'; import type * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; +import type Logger from '@matrixai/logger'; import { validateSync } from '../../validation'; import { matchSync } from '../../utils'; import * as grpcUtils from '../../grpc/utils'; @@ -12,9 +13,11 @@ import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function gestaltsDiscoveryByIdentity({ authenticate, discovery, + logger, }: { authenticate: Authenticate; discovery: Discovery; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -48,6 +51,7 @@ function gestaltsDiscoveryByIdentity({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsDiscoveryByNode.ts b/src/client/service/gestaltsDiscoveryByNode.ts index c8f900141..26e575c51 100644 --- a/src/client/service/gestaltsDiscoveryByNode.ts +++ b/src/client/service/gestaltsDiscoveryByNode.ts @@ -3,6 +3,7 @@ import type { Authenticate } from '../types'; import type { Discovery } from '../../discovery'; import type { NodeId } from '../../nodes/types'; import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; +import type Logger from '@matrixai/logger'; import { validateSync } from '../../validation'; import { matchSync } from '../../utils'; import * as grpcUtils from '../../grpc/utils'; @@ -12,9 +13,11 @@ import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function gestaltsDiscoveryByNode({ authenticate, discovery, + logger, }: { authenticate: Authenticate; discovery: Discovery; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -44,6 +47,7 @@ function gestaltsDiscoveryByNode({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsGestaltGetByIdentity.ts b/src/client/service/gestaltsGestaltGetByIdentity.ts index 357761c11..5f2257a82 100644 --- a/src/client/service/gestaltsGestaltGetByIdentity.ts +++ b/src/client/service/gestaltsGestaltGetByIdentity.ts @@ -3,6 +3,7 @@ import type { Authenticate } from '../types'; import type { GestaltGraph } from '../../gestalts'; import type { IdentityId, ProviderId } from '../../identities/types'; import type * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -11,9 +12,11 @@ import * as gestaltsPB from '../../proto/js/polykey/v1/gestalts/gestalts_pb'; function gestaltsGestaltGetByIdentity({ authenticate, gestaltGraph, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -53,6 +56,7 @@ function gestaltsGestaltGetByIdentity({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsGestaltGetByNode.ts b/src/client/service/gestaltsGestaltGetByNode.ts index 424ad0f65..a0ea6f03c 100644 --- a/src/client/service/gestaltsGestaltGetByNode.ts +++ b/src/client/service/gestaltsGestaltGetByNode.ts @@ -3,6 +3,7 @@ import type { Authenticate } from '../types'; import type { NodeId } from '../../nodes/types'; import type { GestaltGraph } from '../../gestalts'; import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -11,9 +12,11 @@ import * as gestaltsPB from '../../proto/js/polykey/v1/gestalts/gestalts_pb'; function gestaltsGestaltGetByNode({ authenticate, gestaltGraph, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -46,6 +49,7 @@ function gestaltsGestaltGetByNode({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsGestaltList.ts b/src/client/service/gestaltsGestaltList.ts index 6f3c1c9ea..305cd3b7d 100644 --- a/src/client/service/gestaltsGestaltList.ts +++ b/src/client/service/gestaltsGestaltList.ts @@ -3,15 +3,18 @@ import type { Authenticate } from '../types'; import type { GestaltGraph } from '../../gestalts'; import type { Gestalt } from '../../gestalts/types'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as gestaltsPB from '../../proto/js/polykey/v1/gestalts/gestalts_pb'; function gestaltsGestaltList({ authenticate, gestaltGraph, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream, @@ -31,6 +34,7 @@ function gestaltsGestaltList({ return; } catch (e) { await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsGestaltTrustByIdentity.ts b/src/client/service/gestaltsGestaltTrustByIdentity.ts index 754364f79..df7b60dc4 100644 --- a/src/client/service/gestaltsGestaltTrustByIdentity.ts +++ b/src/client/service/gestaltsGestaltTrustByIdentity.ts @@ -4,6 +4,7 @@ import type { GestaltGraph } from '../../gestalts'; import type { IdentityId, ProviderId } from '../../identities/types'; import type { Discovery } from '../../discovery'; import type * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; +import type Logger from '@matrixai/logger'; import { validateSync } from '../../validation'; import { matchSync } from '../../utils'; import * as grpcUtils from '../../grpc/utils'; @@ -14,10 +15,12 @@ function gestaltsGestaltTrustByIdentity({ authenticate, gestaltGraph, discovery, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; discovery: Discovery; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -70,6 +73,7 @@ function gestaltsGestaltTrustByIdentity({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/gestaltsGestaltTrustByNode.ts b/src/client/service/gestaltsGestaltTrustByNode.ts index b8f03fb87..8ebe7660b 100644 --- a/src/client/service/gestaltsGestaltTrustByNode.ts +++ b/src/client/service/gestaltsGestaltTrustByNode.ts @@ -4,6 +4,7 @@ import type { GestaltGraph } from '../../gestalts'; import type { Discovery } from '../../discovery'; import type { NodeId } from '../../nodes/types'; import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; +import type Logger from '@matrixai/logger'; import { validateSync } from '../../validation'; import { matchSync } from '../../utils'; import * as grpcUtils from '../../grpc/utils'; @@ -15,10 +16,12 @@ function gestaltsGestaltTrustByNode({ authenticate, gestaltGraph, discovery, + logger, }: { authenticate: Authenticate; gestaltGraph: GestaltGraph; discovery: Discovery; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -58,6 +61,7 @@ function gestaltsGestaltTrustByNode({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/identitiesAuthenticate.ts b/src/client/service/identitiesAuthenticate.ts index c80378790..e2e39162f 100644 --- a/src/client/service/identitiesAuthenticate.ts +++ b/src/client/service/identitiesAuthenticate.ts @@ -2,6 +2,7 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { IdentitiesManager } from '../../identities'; import type { ProviderId } from '../../identities/types'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { errors as identitiesErrors } from '../../identities'; import { validateSync, utils as validationUtils } from '../../validation'; @@ -9,11 +10,13 @@ import { matchSync, never } from '../../utils'; import * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; function identitiesAuthenticate({ - identitiesManager, authenticate, + identitiesManager, + logger, }: { - identitiesManager: IdentitiesManager; authenticate: Authenticate; + identitiesManager: IdentitiesManager; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream< @@ -70,6 +73,7 @@ function identitiesAuthenticate({ return; } catch (e) { await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/identitiesAuthenticatedGet.ts b/src/client/service/identitiesAuthenticatedGet.ts index fa2ca756f..d344c14a6 100644 --- a/src/client/service/identitiesAuthenticatedGet.ts +++ b/src/client/service/identitiesAuthenticatedGet.ts @@ -2,6 +2,7 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { IdentitiesManager } from '../../identities'; import type { ProviderId } from '../../identities/types'; +import type Logger from '@matrixai/logger'; import { validateSync } from '../../validation'; import { matchSync } from '../../utils'; import * as grpcUtils from '../../grpc/utils'; @@ -9,11 +10,13 @@ import * as validationUtils from '../../validation/utils'; import * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; function identitiesAuthenticatedGet({ - identitiesManager, authenticate, + identitiesManager, + logger, }: { - identitiesManager: IdentitiesManager; authenticate: Authenticate; + identitiesManager: IdentitiesManager; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream< @@ -60,6 +63,7 @@ function identitiesAuthenticatedGet({ return; } catch (e) { await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/identitiesClaim.ts b/src/client/service/identitiesClaim.ts index 0964ecf78..2367998df 100644 --- a/src/client/service/identitiesClaim.ts +++ b/src/client/service/identitiesClaim.ts @@ -4,6 +4,7 @@ import type KeyManager from '../../keys/KeyManager'; import type { Sigchain } from '../../sigchain'; import type { IdentitiesManager } from '../../identities'; import type { IdentityId, ProviderId } from '../../identities/types'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { utils as claimsUtils } from '../../claims'; import { utils as nodesUtils } from '../../nodes'; @@ -16,15 +17,17 @@ import * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_p * Augments the keynode with a new identity. */ function identitiesClaim({ + authenticate, identitiesManager, sigchain, keyManager, - authenticate, + logger, }: { + authenticate: Authenticate; identitiesManager: IdentitiesManager; sigchain: Sigchain; keyManager: KeyManager; - authenticate: Authenticate; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -80,6 +83,7 @@ function identitiesClaim({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/identitiesInfoConnectedGet.ts b/src/client/service/identitiesInfoConnectedGet.ts index 865616d06..f232e3a4d 100644 --- a/src/client/service/identitiesInfoConnectedGet.ts +++ b/src/client/service/identitiesInfoConnectedGet.ts @@ -6,6 +6,7 @@ import type { IdentityId, ProviderId, } from '../../identities/types'; +import type Logger from '@matrixai/logger'; import { validateSync } from '../../validation'; import { matchSync } from '../../utils'; import * as grpcUtils from '../../grpc/utils'; @@ -14,11 +15,13 @@ import * as identitiesErrors from '../../identities/errors'; import * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; function identitiesInfoConnectedGet({ - identitiesManager, authenticate, + identitiesManager, + logger, }: { - identitiesManager: IdentitiesManager; authenticate: Authenticate; + identitiesManager: IdentitiesManager; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream< @@ -116,6 +119,7 @@ function identitiesInfoConnectedGet({ return; } catch (e) { await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/identitiesInfoGet.ts b/src/client/service/identitiesInfoGet.ts index 400367140..31a8139c8 100644 --- a/src/client/service/identitiesInfoGet.ts +++ b/src/client/service/identitiesInfoGet.ts @@ -6,6 +6,7 @@ import type { IdentityId, ProviderId, } from '../../identities/types'; +import type Logger from '@matrixai/logger'; import { validateSync } from '../../validation'; import { matchSync } from '../../utils'; import * as grpcUtils from '../../grpc/utils'; @@ -15,11 +16,13 @@ import * as identitiesErrors from '../../identities/errors'; import * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; function identitiesInfoGet({ - identitiesManager, authenticate, + identitiesManager, + logger, }: { - identitiesManager: IdentitiesManager; authenticate: Authenticate; + identitiesManager: IdentitiesManager; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream< @@ -109,6 +112,7 @@ function identitiesInfoGet({ return; } catch (e) { await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/identitiesProvidersList.ts b/src/client/service/identitiesProvidersList.ts index a7ce51051..8fa533a9c 100644 --- a/src/client/service/identitiesProvidersList.ts +++ b/src/client/service/identitiesProvidersList.ts @@ -2,15 +2,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { IdentitiesManager } from '../../identities'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; function identitiesProvidersList({ - identitiesManager, authenticate, + identitiesManager, + logger, }: { - identitiesManager: IdentitiesManager; authenticate: Authenticate; + identitiesManager: IdentitiesManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -26,6 +29,7 @@ function identitiesProvidersList({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/identitiesTokenDelete.ts b/src/client/service/identitiesTokenDelete.ts index 835fee428..69bba5775 100644 --- a/src/client/service/identitiesTokenDelete.ts +++ b/src/client/service/identitiesTokenDelete.ts @@ -3,17 +3,20 @@ import type { Authenticate } from '../types'; import type { IdentitiesManager } from '../../identities'; import type { IdentityId, ProviderId } from '../../identities/types'; import type * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function identitiesTokenDelete({ - identitiesManager, authenticate, + identitiesManager, + logger, }: { - identitiesManager: IdentitiesManager; authenticate: Authenticate; + identitiesManager: IdentitiesManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -47,6 +50,7 @@ function identitiesTokenDelete({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/identitiesTokenGet.ts b/src/client/service/identitiesTokenGet.ts index 102ae3a07..cb7987156 100644 --- a/src/client/service/identitiesTokenGet.ts +++ b/src/client/service/identitiesTokenGet.ts @@ -2,17 +2,20 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { IdentitiesManager } from '../../identities'; import type { IdentityId, ProviderId } from '../../identities/types'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; import * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; function identitiesTokenGet({ - identitiesManager, authenticate, + identitiesManager, + logger, }: { - identitiesManager: IdentitiesManager; authenticate: Authenticate; + identitiesManager: IdentitiesManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -47,6 +50,7 @@ function identitiesTokenGet({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/identitiesTokenPut.ts b/src/client/service/identitiesTokenPut.ts index 1a371cb95..cb532d4c1 100644 --- a/src/client/service/identitiesTokenPut.ts +++ b/src/client/service/identitiesTokenPut.ts @@ -3,17 +3,20 @@ import type { Authenticate } from '../types'; import type { IdentitiesManager } from '../../identities'; import type { IdentityId, ProviderId, TokenData } from '../../identities/types'; import type * as identitiesPB from '../../proto/js/polykey/v1/identities/identities_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function identitiesTokenPut({ - identitiesManager, authenticate, + identitiesManager, + logger, }: { - identitiesManager: IdentitiesManager; authenticate: Authenticate; + identitiesManager: IdentitiesManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall< @@ -52,6 +55,7 @@ function identitiesTokenPut({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/keysCertsChainGet.ts b/src/client/service/keysCertsChainGet.ts index 792b86916..b62c85783 100644 --- a/src/client/service/keysCertsChainGet.ts +++ b/src/client/service/keysCertsChainGet.ts @@ -2,15 +2,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { KeyManager } from '../../keys'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as keysPB from '../../proto/js/polykey/v1/keys/keys_pb'; function keysCertsChainGet({ - keyManager, authenticate, + keyManager, + logger, }: { - keyManager: KeyManager; authenticate: Authenticate; + keyManager: KeyManager; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream, @@ -30,6 +33,7 @@ function keysCertsChainGet({ return; } catch (e) { await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/keysCertsGet.ts b/src/client/service/keysCertsGet.ts index 198a67884..6d63cfba8 100644 --- a/src/client/service/keysCertsGet.ts +++ b/src/client/service/keysCertsGet.ts @@ -2,15 +2,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { KeyManager } from '../../keys'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as keysPB from '../../proto/js/polykey/v1/keys/keys_pb'; function keysCertsGet({ - keyManager, authenticate, + keyManager, + logger, }: { - keyManager: KeyManager; authenticate: Authenticate; + keyManager: KeyManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -26,6 +29,7 @@ function keysCertsGet({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/keysDecrypt.ts b/src/client/service/keysDecrypt.ts index 0aa84d004..05e68e066 100644 --- a/src/client/service/keysDecrypt.ts +++ b/src/client/service/keysDecrypt.ts @@ -1,15 +1,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { KeyManager } from '../../keys'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as keysPB from '../../proto/js/polykey/v1/keys/keys_pb'; function keysDecrypt({ - keyManager, authenticate, + keyManager, + logger, }: { - keyManager: KeyManager; authenticate: Authenticate; + keyManager: KeyManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -27,6 +30,7 @@ function keysDecrypt({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/keysEncrypt.ts b/src/client/service/keysEncrypt.ts index 8c048e94c..2c84444fb 100644 --- a/src/client/service/keysEncrypt.ts +++ b/src/client/service/keysEncrypt.ts @@ -1,15 +1,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { KeyManager } from '../../keys'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as keysPB from '../../proto/js/polykey/v1/keys/keys_pb'; function keysEncrypt({ - keyManager, authenticate, + keyManager, + logger, }: { - keyManager: KeyManager; authenticate: Authenticate; + keyManager: KeyManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -27,6 +30,7 @@ function keysEncrypt({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/keysKeyPairRenew.ts b/src/client/service/keysKeyPairRenew.ts index ffcd9b5b4..c2d88acca 100644 --- a/src/client/service/keysKeyPairRenew.ts +++ b/src/client/service/keysKeyPairRenew.ts @@ -2,15 +2,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { KeyManager } from '../../keys'; import type * as keysPB from '../../proto/js/polykey/v1/keys/keys_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function keysKeyPairRenew({ - keyManager, authenticate, + keyManager, + logger, }: { - keyManager: KeyManager; authenticate: Authenticate; + keyManager: KeyManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -27,6 +30,7 @@ function keysKeyPairRenew({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/keysKeyPairReset.ts b/src/client/service/keysKeyPairReset.ts index a5fee6145..82e73277e 100644 --- a/src/client/service/keysKeyPairReset.ts +++ b/src/client/service/keysKeyPairReset.ts @@ -2,15 +2,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { KeyManager } from '../../keys'; import type * as keysPB from '../../proto/js/polykey/v1/keys/keys_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function keysKeyPairReset({ - keyManager, authenticate, + keyManager, + logger, }: { - keyManager: KeyManager; authenticate: Authenticate; + keyManager: KeyManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -27,6 +30,7 @@ function keysKeyPairReset({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/keysKeyPairRoot.ts b/src/client/service/keysKeyPairRoot.ts index 4a5858347..9f20b410b 100644 --- a/src/client/service/keysKeyPairRoot.ts +++ b/src/client/service/keysKeyPairRoot.ts @@ -2,15 +2,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { KeyManager } from '../../keys'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as keysPB from '../../proto/js/polykey/v1/keys/keys_pb'; function keysKeyPairRoot({ - keyManager, authenticate, + keyManager, + logger, }: { - keyManager: KeyManager; authenticate: Authenticate; + keyManager: KeyManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -27,6 +30,7 @@ function keysKeyPairRoot({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/keysPasswordChange.ts b/src/client/service/keysPasswordChange.ts index 2d5074abf..21ad66425 100644 --- a/src/client/service/keysPasswordChange.ts +++ b/src/client/service/keysPasswordChange.ts @@ -2,15 +2,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { KeyManager } from '../../keys'; import type * as sessionsPB from '../../proto/js/polykey/v1/sessions/sessions_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function keysPasswordChange({ - keyManager, authenticate, + keyManager, + logger, }: { - keyManager: KeyManager; authenticate: Authenticate; + keyManager: KeyManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -25,6 +28,7 @@ function keysPasswordChange({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/keysSign.ts b/src/client/service/keysSign.ts index 5f2eee691..14f722a0c 100644 --- a/src/client/service/keysSign.ts +++ b/src/client/service/keysSign.ts @@ -1,15 +1,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { KeyManager } from '../../keys'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as keysPB from '../../proto/js/polykey/v1/keys/keys_pb'; function keysSign({ - keyManager, authenticate, + keyManager, + logger, }: { - keyManager: KeyManager; authenticate: Authenticate; + keyManager: KeyManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -28,6 +31,7 @@ function keysSign({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/keysVerify.ts b/src/client/service/keysVerify.ts index 1090642c5..26918bc3d 100644 --- a/src/client/service/keysVerify.ts +++ b/src/client/service/keysVerify.ts @@ -2,15 +2,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { KeyManager } from '../../keys'; import type * as keysPB from '../../proto/js/polykey/v1/keys/keys_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function keysVerify({ - keyManager, authenticate, + keyManager, + logger, }: { - keyManager: KeyManager; authenticate: Authenticate; + keyManager: KeyManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -29,6 +32,7 @@ function keysVerify({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/nodesAdd.ts b/src/client/service/nodesAdd.ts index 57924cd5e..7cbfb739f 100644 --- a/src/client/service/nodesAdd.ts +++ b/src/client/service/nodesAdd.ts @@ -4,6 +4,7 @@ import type { NodeManager } from '../../nodes'; import type { NodeId, NodeAddress } from '../../nodes/types'; import type { Host, Hostname, Port } from '../../network/types'; import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -15,11 +16,13 @@ import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; * of the passed ID or host/port. */ function nodesAdd({ - nodeManager, authenticate, + nodeManager, + logger, }: { - nodeManager: NodeManager; authenticate: Authenticate; + nodeManager: NodeManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -60,6 +63,7 @@ function nodesAdd({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/nodesClaim.ts b/src/client/service/nodesClaim.ts index 280dedb24..b82731c05 100644 --- a/src/client/service/nodesClaim.ts +++ b/src/client/service/nodesClaim.ts @@ -4,6 +4,7 @@ import type { NodeManager } from '../../nodes'; import type { NodeId } from '../../nodes/types'; import type { NotificationsManager } from '../../notifications'; import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -15,13 +16,15 @@ import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; * other node and host node. */ function nodesClaim({ + authenticate, nodeManager, notificationsManager, - authenticate, + logger, }: { + authenticate: Authenticate; nodeManager: NodeManager; notificationsManager: NotificationsManager; - authenticate: Authenticate; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -65,6 +68,7 @@ function nodesClaim({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/nodesFind.ts b/src/client/service/nodesFind.ts index 7982fd9ad..b8cb887db 100644 --- a/src/client/service/nodesFind.ts +++ b/src/client/service/nodesFind.ts @@ -2,6 +2,7 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { NodeConnectionManager } from '../../nodes'; import type { NodeId } from '../../nodes/types'; +import type Logger from '@matrixai/logger'; import { utils as nodesUtils } from '../../nodes'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; @@ -14,11 +15,13 @@ import * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; * @throws ErrorNodeGraphNodeNotFound if node address cannot be found */ function nodesFind({ - nodeConnectionManager, authenticate, + nodeConnectionManager, + logger, }: { - nodeConnectionManager: NodeConnectionManager; authenticate: Authenticate; + nodeConnectionManager: NodeConnectionManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -53,6 +56,7 @@ function nodesFind({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/nodesPing.ts b/src/client/service/nodesPing.ts index 7dfd89939..2356f2072 100644 --- a/src/client/service/nodesPing.ts +++ b/src/client/service/nodesPing.ts @@ -3,6 +3,7 @@ import type { Authenticate } from '../types'; import type { NodeManager } from '../../nodes'; import type { NodeId } from '../../nodes/types'; import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { validateSync, utils as validationUtils } from '../../validation'; import { matchSync } from '../../utils'; @@ -12,11 +13,13 @@ import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; * Checks if a remote node is online. */ function nodesPing({ - nodeManager, authenticate, + nodeManager, + logger, }: { - nodeManager: NodeManager; authenticate: Authenticate; + nodeManager: NodeManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -47,6 +50,7 @@ function nodesPing({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/notificationsClear.ts b/src/client/service/notificationsClear.ts index 322f64cf6..7d2ba80cc 100644 --- a/src/client/service/notificationsClear.ts +++ b/src/client/service/notificationsClear.ts @@ -1,15 +1,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { NotificationsManager } from '../../notifications'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function notificationsClear({ - notificationsManager, authenticate, + notificationsManager, + logger, }: { - notificationsManager: NotificationsManager; authenticate: Authenticate; + notificationsManager: NotificationsManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -24,6 +27,7 @@ function notificationsClear({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/notificationsRead.ts b/src/client/service/notificationsRead.ts index e890ce6c0..f8bccc692 100644 --- a/src/client/service/notificationsRead.ts +++ b/src/client/service/notificationsRead.ts @@ -1,15 +1,18 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; import type { NotificationsManager } from '../../notifications'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import * as notificationsPB from '../../proto/js/polykey/v1/notifications/notifications_pb'; function notificationsRead({ - notificationsManager, authenticate, + notificationsManager, + logger, }: { - notificationsManager: NotificationsManager; authenticate: Authenticate; + notificationsManager: NotificationsManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -65,6 +68,7 @@ function notificationsRead({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/notificationsSend.ts b/src/client/service/notificationsSend.ts index ed3b26e05..c30512611 100644 --- a/src/client/service/notificationsSend.ts +++ b/src/client/service/notificationsSend.ts @@ -3,6 +3,7 @@ import type { Authenticate } from '../types'; import type { NotificationsManager } from '../../notifications'; import type { NodeId } from '../../nodes/types'; import type * as notificationsPB from '../../proto/js/polykey/v1/notifications/notifications_pb'; +import type Logger from '@matrixai/logger'; import { utils as grpcUtils } from '../../grpc'; import { utils as notificationsUtils } from '../../notifications'; import { validateSync, utils as validationUtils } from '../../validation'; @@ -10,11 +11,13 @@ import { matchSync } from '../../utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function notificationsSend({ - notificationsManager, authenticate, + notificationsManager, + logger, }: { - notificationsManager: NotificationsManager; authenticate: Authenticate; + notificationsManager: NotificationsManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -50,6 +53,7 @@ function notificationsSend({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsClone.ts b/src/client/service/vaultsClone.ts index a35d70e7f..75b6dcf56 100644 --- a/src/client/service/vaultsClone.ts +++ b/src/client/service/vaultsClone.ts @@ -1,6 +1,7 @@ import type { Authenticate } from '../types'; import type VaultManager from '../../vaults/VaultManager'; import type * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as grpcUtils from '../../grpc/utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; @@ -10,9 +11,11 @@ import * as vaultsUtils from '../../vaults/utils'; function vaultsClone({ authenticate, vaultManager, + logger, }: { authenticate: Authenticate; vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -46,6 +49,7 @@ function vaultsClone({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsCreate.ts b/src/client/service/vaultsCreate.ts index 363e4a200..74224733b 100644 --- a/src/client/service/vaultsCreate.ts +++ b/src/client/service/vaultsCreate.ts @@ -3,16 +3,19 @@ import type { VaultId, VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type * as grpc from '@grpc/grpc-js'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; +import type Logger from '@matrixai/logger'; import * as grpcUtils from '../../grpc/utils'; import * as vaultsUtils from '../../vaults/utils'; import * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; function vaultsCreate({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -31,6 +34,7 @@ function vaultsCreate({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsDelete.ts b/src/client/service/vaultsDelete.ts index d2f029c4a..0f7aa01e7 100644 --- a/src/client/service/vaultsDelete.ts +++ b/src/client/service/vaultsDelete.ts @@ -3,16 +3,19 @@ import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type * as grpc from '@grpc/grpc-js'; import type * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; +import type Logger from '@matrixai/logger'; import * as grpcUtils from '../../grpc/utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; import * as validationUtils from '../../validation/utils'; function vaultsDelete({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -32,6 +35,7 @@ function vaultsDelete({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsList.ts b/src/client/service/vaultsList.ts index c35f51eea..794c44909 100644 --- a/src/client/service/vaultsList.ts +++ b/src/client/service/vaultsList.ts @@ -2,16 +2,19 @@ import type { Authenticate } from '../types'; import type VaultManager from '../../vaults/VaultManager'; import type * as grpc from '@grpc/grpc-js'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; +import type Logger from '@matrixai/logger'; import * as grpcUtils from '../../grpc/utils'; import * as vaultsUtils from '../../vaults/utils'; import * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; function vaultsList({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream, @@ -34,6 +37,7 @@ function vaultsList({ return; } catch (e) { await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsLog.ts b/src/client/service/vaultsLog.ts index 02b35a6f8..6d720e825 100644 --- a/src/client/service/vaultsLog.ts +++ b/src/client/service/vaultsLog.ts @@ -1,6 +1,7 @@ import type { Authenticate } from '../types'; import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb'; import * as grpcUtils from '../../grpc/utils'; @@ -8,11 +9,13 @@ import * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; import * as validationUtils from '../../validation/utils'; function vaultsLog({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream, @@ -52,6 +55,7 @@ function vaultsLog({ return; } catch (e) { await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsPermissionGet.ts b/src/client/service/vaultsPermissionGet.ts index bb2b24dc1..8dd0866c3 100644 --- a/src/client/service/vaultsPermissionGet.ts +++ b/src/client/service/vaultsPermissionGet.ts @@ -5,6 +5,7 @@ import type * as grpc from '@grpc/grpc-js'; import type { VaultActions } from '../../vaults/types'; import type ACL from '../../acl/ACL'; import type { NodeId, NodeIdEncoded } from 'nodes/types'; +import type Logger from '@matrixai/logger'; import { IdInternal } from '@matrixai/id'; import * as grpcUtils from '../../grpc/utils'; import * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; @@ -16,10 +17,12 @@ function vaultsPermissionGet({ authenticate, vaultManager, acl, + logger, }: { authenticate: Authenticate; vaultManager: VaultManager; acl: ACL; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream, @@ -57,8 +60,9 @@ function vaultsPermissionGet({ } await genWritable.next(null); return; - } catch (err) { - await genWritable.throw(err); + } catch (e) { + await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsPermissionSet.ts b/src/client/service/vaultsPermissionSet.ts index 6b4768ee8..f19ec7da3 100644 --- a/src/client/service/vaultsPermissionSet.ts +++ b/src/client/service/vaultsPermissionSet.ts @@ -6,6 +6,7 @@ import type ACL from '../../acl/ACL'; import type NotificationsManager from '../../notifications/NotificationsManager'; import type { VaultActions } from '../../vaults/types'; import type * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as vaultsUtils from '../../vaults/utils'; import * as vaultsErrors from '../../vaults/errors'; @@ -14,17 +15,19 @@ import * as grpcUtils from '../../grpc/utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function vaultsPermissionSet({ - vaultManager, authenticate, + vaultManager, gestaltGraph, acl, notificationsManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; gestaltGraph: GestaltGraph; acl: ACL; notificationsManager: NotificationsManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -74,6 +77,7 @@ function vaultsPermissionSet({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsPermissionUnset.ts b/src/client/service/vaultsPermissionUnset.ts index d16d81d98..cd9c0ee9e 100644 --- a/src/client/service/vaultsPermissionUnset.ts +++ b/src/client/service/vaultsPermissionUnset.ts @@ -4,6 +4,7 @@ import type VaultManager from '../../vaults/VaultManager'; import type GestaltGraph from '../../gestalts/GestaltGraph'; import type ACL from '../../acl/ACL'; import type * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as vaultsErrors from '../../vaults/errors'; import * as validationUtils from '../../validation/utils'; @@ -11,15 +12,17 @@ import * as grpcUtils from '../../grpc/utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function vaultsPermissionUnset({ - vaultManager, authenticate, + vaultManager, gestaltGraph, acl, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; gestaltGraph: GestaltGraph; acl: ACL; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -73,6 +76,7 @@ function vaultsPermissionUnset({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsPull.ts b/src/client/service/vaultsPull.ts index 8c18e1a29..821e3179a 100644 --- a/src/client/service/vaultsPull.ts +++ b/src/client/service/vaultsPull.ts @@ -2,6 +2,7 @@ import type { Authenticate } from '../types'; import type VaultManager from '../../vaults/VaultManager'; import type { VaultName } from '../../vaults/types'; import type * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as grpcUtils from '../../grpc/utils'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; @@ -11,9 +12,11 @@ import * as vaultsUtils from '../../vaults/utils'; function vaultsPull({ authenticate, vaultManager, + logger, }: { authenticate: Authenticate; vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -58,6 +61,7 @@ function vaultsPull({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsRename.ts b/src/client/service/vaultsRename.ts index 506162989..27276c1aa 100644 --- a/src/client/service/vaultsRename.ts +++ b/src/client/service/vaultsRename.ts @@ -1,6 +1,7 @@ import type { Authenticate } from '../types'; import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; @@ -8,11 +9,13 @@ import * as vaultsUtils from '../../vaults/utils'; import * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; function vaultsRename({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -37,6 +40,7 @@ function vaultsRename({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsScan.ts b/src/client/service/vaultsScan.ts index 0ed5ebbbe..f0392dba5 100644 --- a/src/client/service/vaultsScan.ts +++ b/src/client/service/vaultsScan.ts @@ -3,6 +3,7 @@ import type { NodeId } from '../../nodes/types'; import type * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; import type * as grpc from '@grpc/grpc-js'; import type VaultManager from '../../vaults/VaultManager'; +import type Logger from '@matrixai/logger'; import * as grpcUtils from '../../grpc/utils'; import { validateSync } from '../../validation'; import * as validationUtils from '../../validation/utils'; @@ -10,11 +11,13 @@ import { matchSync } from '../../utils'; import * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; function vaultsScan({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream, @@ -53,6 +56,7 @@ function vaultsScan({ return; } catch (e) { await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsSecretsDelete.ts b/src/client/service/vaultsSecretsDelete.ts index 07a56a92d..6332c1442 100644 --- a/src/client/service/vaultsSecretsDelete.ts +++ b/src/client/service/vaultsSecretsDelete.ts @@ -2,6 +2,7 @@ import type { Authenticate } from '../types'; import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type * as secretsPB from '../../proto/js/polykey/v1/secrets/secrets_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; @@ -9,11 +10,13 @@ import * as vaultOps from '../../vaults/VaultOps'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function vaultsSecretsDelete({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -40,6 +43,7 @@ function vaultsSecretsDelete({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsSecretsEdit.ts b/src/client/service/vaultsSecretsEdit.ts index 8f45362b2..d502d9808 100644 --- a/src/client/service/vaultsSecretsEdit.ts +++ b/src/client/service/vaultsSecretsEdit.ts @@ -2,6 +2,7 @@ import type { Authenticate } from '../types'; import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type * as secretsPB from '../../proto/js/polykey/v1/secrets/secrets_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; @@ -9,11 +10,13 @@ import * as vaultOps from '../../vaults/VaultOps'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function vaultsSecretsEdit({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -46,6 +49,7 @@ function vaultsSecretsEdit({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsSecretsGet.ts b/src/client/service/vaultsSecretsGet.ts index fa836e1b0..bd3c3a330 100644 --- a/src/client/service/vaultsSecretsGet.ts +++ b/src/client/service/vaultsSecretsGet.ts @@ -2,6 +2,7 @@ import type { Authenticate } from '../types'; import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; @@ -9,11 +10,13 @@ import * as vaultOps from '../../vaults/VaultOps'; import * as secretsPB from '../../proto/js/polykey/v1/secrets/secrets_pb'; function vaultsSecretsGet({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -43,6 +46,7 @@ function vaultsSecretsGet({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsSecretsList.ts b/src/client/service/vaultsSecretsList.ts index db71fc128..c9732edbf 100644 --- a/src/client/service/vaultsSecretsList.ts +++ b/src/client/service/vaultsSecretsList.ts @@ -3,17 +3,20 @@ import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type * as grpc from '@grpc/grpc-js'; import type * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; +import type Logger from '@matrixai/logger'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; import * as vaultOps from '../../vaults/VaultOps'; import * as secretsPB from '../../proto/js/polykey/v1/secrets/secrets_pb'; function vaultsSecretsList({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerWritableStream, @@ -42,6 +45,7 @@ function vaultsSecretsList({ return; } catch (e) { await genWritable.throw(e); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsSecretsMkdir.ts b/src/client/service/vaultsSecretsMkdir.ts index fca32d4f9..3753571c7 100644 --- a/src/client/service/vaultsSecretsMkdir.ts +++ b/src/client/service/vaultsSecretsMkdir.ts @@ -2,6 +2,7 @@ import type { Authenticate } from '../types'; import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; @@ -9,11 +10,13 @@ import * as vaultOps from '../../vaults/VaultOps'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function vaultsSecretsMkdir({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -42,6 +45,7 @@ function vaultsSecretsMkdir({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsSecretsNew.ts b/src/client/service/vaultsSecretsNew.ts index 3c22baa7a..b264631f9 100644 --- a/src/client/service/vaultsSecretsNew.ts +++ b/src/client/service/vaultsSecretsNew.ts @@ -2,6 +2,7 @@ import type { Authenticate } from '../types'; import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type * as secretsPB from '../../proto/js/polykey/v1/secrets/secrets_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; @@ -9,11 +10,13 @@ import * as vaultOps from '../../vaults/VaultOps'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function vaultsSecretsNew({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -41,6 +44,7 @@ function vaultsSecretsNew({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsSecretsNewDir.ts b/src/client/service/vaultsSecretsNewDir.ts index 31a075e01..36fd2b3af 100644 --- a/src/client/service/vaultsSecretsNewDir.ts +++ b/src/client/service/vaultsSecretsNewDir.ts @@ -3,6 +3,7 @@ import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type { FileSystem } from '../../types'; import type * as secretsPB from '../../proto/js/polykey/v1/secrets/secrets_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; @@ -10,13 +11,15 @@ import * as vaultOps from '../../vaults/VaultOps'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function vaultsSecretsNewDir({ - vaultManager, authenticate, + vaultManager, fs, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; fs: FileSystem; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -43,6 +46,7 @@ function vaultsSecretsNewDir({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsSecretsRename.ts b/src/client/service/vaultsSecretsRename.ts index 7de527519..ceeb7160e 100644 --- a/src/client/service/vaultsSecretsRename.ts +++ b/src/client/service/vaultsSecretsRename.ts @@ -2,6 +2,7 @@ import type { Authenticate } from '../types'; import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; import type * as secretsPB from '../../proto/js/polykey/v1/secrets/secrets_pb'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; @@ -9,11 +10,13 @@ import * as vaultOps from '../../vaults/VaultOps'; import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; function vaultsSecretsRename({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -46,6 +49,7 @@ function vaultsSecretsRename({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsSecretsStat.ts b/src/client/service/vaultsSecretsStat.ts index e657d4009..ab03c57e4 100644 --- a/src/client/service/vaultsSecretsStat.ts +++ b/src/client/service/vaultsSecretsStat.ts @@ -1,6 +1,7 @@ import type VaultManager from '../../vaults/VaultManager'; import type { VaultName } from '../../vaults/types'; import type { Authenticate } from '../types'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; @@ -10,9 +11,11 @@ import * as secretsPB from '../../proto/js/polykey/v1/secrets/secrets_pb'; function vaultsSecretsStat({ authenticate, vaultManager, + logger, }: { authenticate: Authenticate; vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -39,6 +42,7 @@ function vaultsSecretsStat({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/client/service/vaultsVersion.ts b/src/client/service/vaultsVersion.ts index 4338966da..fcb32a2fe 100644 --- a/src/client/service/vaultsVersion.ts +++ b/src/client/service/vaultsVersion.ts @@ -1,17 +1,20 @@ import type { Authenticate } from '../types'; import type { VaultName } from '../../vaults/types'; import type VaultManager from '../../vaults/VaultManager'; +import type Logger from '@matrixai/logger'; import * as grpc from '@grpc/grpc-js'; import * as validationUtils from '../../validation/utils'; import * as grpcUtils from '../../grpc/utils'; import * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb'; function vaultsVersion({ - vaultManager, authenticate, + vaultManager, + logger, }: { - vaultManager: VaultManager; authenticate: Authenticate; + vaultManager: VaultManager; + logger: Logger; }) { return async ( call: grpc.ServerUnaryCall, @@ -52,6 +55,7 @@ function vaultsVersion({ return; } catch (e) { callback(grpcUtils.fromError(e)); + logger.error(e); return; } }; diff --git a/src/gestalts/utils.ts b/src/gestalts/utils.ts index 1f1df121f..2bba234e6 100644 --- a/src/gestalts/utils.ts +++ b/src/gestalts/utils.ts @@ -11,7 +11,7 @@ import type { NodeId } from '../nodes/types'; import type { IdentityId, ProviderId } from '../identities/types'; import canonicalize from 'canonicalize'; import { gestaltActions } from './types'; -import { utils as nodesUtils } from '../nodes'; +import * as nodesUtils from '../nodes/utils'; /** * Construct GestaltKey from GestaltId diff --git a/src/grpc/GRPCClient.ts b/src/grpc/GRPCClient.ts index b705e9aa5..22a7c65e5 100644 --- a/src/grpc/GRPCClient.ts +++ b/src/grpc/GRPCClient.ts @@ -151,7 +151,8 @@ abstract class GRPCClient { `Failed GRPC server certificate verification connecting to ${address}`, ); const e_ = new grpcErrors.ErrorGRPCClientVerification( - `${e.name}: ${e.message}`,{ + `${e.name}: ${e.message}`, + { data: e.data, cause: e, }, diff --git a/src/grpc/GRPCServer.ts b/src/grpc/GRPCServer.ts index 2c7edf11b..b7a0ac84c 100644 --- a/src/grpc/GRPCServer.ts +++ b/src/grpc/GRPCServer.ts @@ -100,7 +100,8 @@ class GRPCServer { `Failed GRPC client certificate verification connecting from ${address}`, ); const e_ = new grpcErrors.ErrorGRPCServerVerification( - `${e.name}: ${e.message}`, { + `${e.name}: ${e.message}`, + { data: e.data, cause: e, }, diff --git a/src/grpc/utils/utils.ts b/src/grpc/utils/utils.ts index b75a6d21e..7db50484c 100644 --- a/src/grpc/utils/utils.ts +++ b/src/grpc/utils/utils.ts @@ -162,7 +162,10 @@ function getServerSession(call: ServerSurfaceCall): Http2Session { * If sending to an agent (rather than a client), set sensitive to true to * prevent sensitive information from being sent over the network */ -function fromError(error: Error, sensitive: boolean = false): ServerStatusResponse { +function fromError( + error: Error, + sensitive: boolean = false, +): ServerStatusResponse { const metadata = new grpc.Metadata(); if (sensitive) { metadata.set('error', JSON.stringify(error, sensitiveReplacer)); @@ -188,10 +191,7 @@ function toError(e: ServiceError): errors.ErrorPolykey { // check if the error code matches a known grpc status // @ts-ignore grpc.status[key] is in fact a string if (isNaN(parseInt(key)) && e.code === grpc.status[key]) { - if ( - key === 'UNKNOWN' && - errorData != null - ) { + if (key === 'UNKNOWN' && errorData != null) { const error: Error = JSON.parse(errorData, reviver); return new errors.ErrorPolykeyRemote(error.message, { cause: error }); } else { @@ -214,7 +214,7 @@ function toError(e: ServiceError): errors.ErrorPolykey { * Polykey errors are handled by their inbuilt `toJSON` method , so this only * serialises other errors */ - function replacer(key: string, value: any): any { +function replacer(key: string, value: any): any { if (value instanceof AbstractError) { // Include the standard properties from an AbstractError return { @@ -226,8 +226,8 @@ function toError(e: ServiceError): errors.ErrorPolykey { data: value.data, cause: value.cause, stack: value.stack, - } - } + }, + }; } else if (value instanceof Error) { // If it's some other type of error then only serialise the message and // stack (and the type of the error) @@ -236,8 +236,8 @@ function toError(e: ServiceError): errors.ErrorPolykey { data: { message: value.message, stack: value.stack, - } - } + }, + }; } else { // If it's not an error then just leave as is return value; @@ -262,13 +262,13 @@ function sensitiveReplacer(key: string, value: any) { * Allows these errors to be reconstructed from GRPC metadata */ const otherErrors = { - 'Error': Error, - 'EvalError': EvalError, - 'RangeError': RangeError, - 'ReferenceError': ReferenceError, - 'SyntaxError': SyntaxError, - 'TypeError': TypeError, - 'URIError': URIError + Error: Error, + EvalError: EvalError, + RangeError: RangeError, + ReferenceError: ReferenceError, + SyntaxError: SyntaxError, + TypeError: TypeError, + URIError: URIError, }; /** @@ -280,17 +280,18 @@ const otherErrors = { */ function reviver(key: string, value: any): any { // If the value is an error then reconstruct it - if (typeof value === 'object' && typeof value.type === 'string' && typeof value.data === 'object') { + if ( + typeof value === 'object' && + typeof value.type === 'string' && + typeof value.data === 'object' + ) { const message = value.data.message ?? ''; if (value.type in errors) { - const error = new errors[value.type]( - message, - { - timestamp: value.data.timestamp, - data: value.data.data, - cause: value.data.cause, - }, - ); + const error = new errors[value.type](message, { + timestamp: value.data.timestamp, + data: value.data.data, + cause: value.data.cause, + }); error.exitCode = value.data.exitCode; if (value.data.stack) { error.stack = value.data.stack; diff --git a/src/identities/errors.ts b/src/identities/errors.ts index dece95ffc..40ade2ceb 100644 --- a/src/identities/errors.ts +++ b/src/identities/errors.ts @@ -33,7 +33,8 @@ class ErrorProviderAuthentication extends ErrorIdentities { } class ErrorProviderUnauthenticated extends ErrorIdentities { - static description = 'Provider has not been authenticated or access token is expired or invalid'; + static description = + 'Provider has not been authenticated or access token is expired or invalid'; exitCode = sysexits.NOPERM; } diff --git a/src/identities/providers/github/GitHubProvider.ts b/src/identities/providers/github/GitHubProvider.ts index 122122931..8fd0a79fe 100644 --- a/src/identities/providers/github/GitHubProvider.ts +++ b/src/identities/providers/github/GitHubProvider.ts @@ -120,7 +120,8 @@ class GitHubProvider extends Provider { data = await response.json(); } catch (e) { throw new identitiesErrors.ErrorProviderAuthentication( - 'Provider access token response is not valid JSON', { cause: e }, + 'Provider access token response is not valid JSON', + { cause: e }, ); } if (data.error) { diff --git a/src/network/utils.ts b/src/network/utils.ts index f97f71ef9..1df7faa7f 100644 --- a/src/network/utils.ts +++ b/src/network/utils.ts @@ -101,7 +101,9 @@ async function resolveHost(host: Host | Hostname): Promise { // Resolve the hostname and get the IPv4 address resolvedHost = await lookup(host, 4); } catch (e) { - throw new networkErrors.ErrorHostnameResolutionFailed(e.message, { cause: e }); + throw new networkErrors.ErrorHostnameResolutionFailed(e.message, { + cause: e, + }); } // Returns an array of [ resolved address, family (4 or 6) ] return resolvedHost[0] as Host; diff --git a/src/nodes/NodeConnection.ts b/src/nodes/NodeConnection.ts index d81ac9721..f79272413 100644 --- a/src/nodes/NodeConnection.ts +++ b/src/nodes/NodeConnection.ts @@ -135,7 +135,9 @@ class NodeConnection { await nodeConnection.destroy(); // If the connection times out, re-throw this with a higher level nodes exception if (e instanceof grpcErrors.ErrorGRPCClientTimeout) { - throw new nodesErrors.ErrorNodeConnectionTimeout(e.message, { cause: e }); + throw new nodesErrors.ErrorNodeConnectionTimeout(e.message, { + cause: e, + }); } throw e; } diff --git a/src/notifications/errors.ts b/src/notifications/errors.ts index 3a9ca102f..028862e50 100644 --- a/src/notifications/errors.ts +++ b/src/notifications/errors.ts @@ -47,9 +47,7 @@ class ErrorNotificationsGeneralInvalid extends ErrorSchemaValidate { exitCode = sysexits.USAGE; } -class ErrorNotificationsGestaltInviteInvalid< - T, -> extends ErrorSchemaValidate { +class ErrorNotificationsGestaltInviteInvalid extends ErrorSchemaValidate { static description = 'Invalid notification data'; exitCode = sysexits.USAGE; } diff --git a/src/notifications/utils.ts b/src/notifications/utils.ts index 0f55a6620..a31b0ad59 100644 --- a/src/notifications/utils.ts +++ b/src/notifications/utils.ts @@ -78,7 +78,9 @@ async function verifyAndDecodeNotif(notifJWT: string): Promise { throw err; } else { // Error came from jose - throw new notificationsErrors.ErrorNotificationsParse(err.message, { cause: err }); + throw new notificationsErrors.ErrorNotificationsParse(err.message, { + cause: err, + }); } } } diff --git a/src/status/Status.ts b/src/status/Status.ts index fbee3edce..01647736c 100644 --- a/src/status/Status.ts +++ b/src/status/Status.ts @@ -145,7 +145,9 @@ class Status { try { statusInfo = JSON.parse(statusData, this.statusReviver); } catch (e) { - throw new statusErrors.ErrorStatusParse('JSON parsing failed', {cause: e}); + throw new statusErrors.ErrorStatusParse('JSON parsing failed', { + cause: e, + }); } if (!statusUtils.statusValidate(statusInfo)) { throw new statusErrors.ErrorStatusParse( @@ -246,7 +248,9 @@ class Status { try { statusInfo = JSON.parse(statusData, this.statusReviver); } catch (e) { - throw new statusErrors.ErrorStatusParse('JSON parsing failed', { cause: e }); + throw new statusErrors.ErrorStatusParse('JSON parsing failed', { + cause: e, + }); } if (!statusUtils.statusValidate(statusInfo)) { throw new statusErrors.ErrorStatusParse( diff --git a/src/vaults/VaultInternal.ts b/src/vaults/VaultInternal.ts index c7f60829b..34597b034 100644 --- a/src/vaults/VaultInternal.ts +++ b/src/vaults/VaultInternal.ts @@ -376,7 +376,9 @@ class VaultInternal { e instanceof git.Errors.NotFoundError || e instanceof git.Errors.CommitNotFetchedError ) { - throw new vaultsErrors.ErrorVaultReferenceMissing(e.message, { cause: e }); + throw new vaultsErrors.ErrorVaultReferenceMissing(e.message, { + cause: e, + }); } throw e; } @@ -551,7 +553,9 @@ class VaultInternal { if (err instanceof git.Errors.SmartHttpError && error) { throw error; } else if (err instanceof git.Errors.MergeNotSupportedError) { - throw new vaultsErrors.ErrorVaultsMergeConflict(err.message, { cause: err }); + throw new vaultsErrors.ErrorVaultsMergeConflict(err.message, { + cause: err, + }); } throw err; } diff --git a/tests/agent/service/nodesCrossSignClaim.test.ts b/tests/agent/service/nodesCrossSignClaim.test.ts index 0c3a1da7a..5b3f6c53e 100644 --- a/tests/agent/service/nodesCrossSignClaim.test.ts +++ b/tests/agent/service/nodesCrossSignClaim.test.ts @@ -5,6 +5,7 @@ import fs from 'fs'; import path from 'path'; import os from 'os'; import Logger, { LogLevel, StreamHandler } from '@matrixai/logger'; +import { ErrorPolykeyRemote } from '@/errors'; import PolykeyAgent from '@/PolykeyAgent'; import GRPCServer from '@/grpc/GRPCServer'; import GRPCClientAgent from '@/agent/GRPCClientAgent'; @@ -14,7 +15,6 @@ import * as nodesPB from '@/proto/js/polykey/v1/nodes/nodes_pb'; import * as keysUtils from '@/keys/utils'; import * as nodesUtils from '@/nodes/utils'; import * as claimsUtils from '@/claims/utils'; -import * as claimsErrors from '@/claims/errors'; import * as testNodesUtils from '../../nodes/utils'; import * as testUtils from '../../utils'; @@ -78,6 +78,7 @@ describe('nodesCrossSignClaim', () => { keyManager: pkAgent.keyManager, nodeManager: pkAgent.nodeManager, sigchain: pkAgent.sigchain, + logger, }), }; grpcServer = new GRPCServer({ logger }); @@ -204,9 +205,7 @@ describe('nodesCrossSignClaim', () => { // 2. X <- sends its intermediary signed claim <- Y const crossSignMessageUndefinedSingly = new nodesPB.CrossSign(); await genClaims.write(crossSignMessageUndefinedSingly); - await expect(() => genClaims.read()).rejects.toThrow( - claimsErrors.ErrorUndefinedSinglySignedClaim, - ); + await expect(() => genClaims.read()).rejects.toThrow(ErrorPolykeyRemote); expect(genClaims.stream.destroyed).toBe(true); // Check sigchain's lock is released expect(pkAgent.sigchain.locked).toBe(false); @@ -226,9 +225,7 @@ describe('nodesCrossSignClaim', () => { intermediaryNoSignature, ); await genClaims.write(crossSignMessageUndefinedSinglySignature); - await expect(() => genClaims.read()).rejects.toThrow( - claimsErrors.ErrorUndefinedSignature, - ); + await expect(() => genClaims.read()).rejects.toThrow(ErrorPolykeyRemote); expect(genClaims.stream.destroyed).toBe(true); // Check sigchain's lock is released expect(pkAgent.sigchain.locked).toBe(false); diff --git a/tests/agent/service/notificationsSend.test.ts b/tests/agent/service/notificationsSend.test.ts index a0eb81ffa..3732b407e 100644 --- a/tests/agent/service/notificationsSend.test.ts +++ b/tests/agent/service/notificationsSend.test.ts @@ -137,6 +137,7 @@ describe('notificationsSend', () => { const agentService = { notificationsSend: notificationsSend({ notificationsManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/GRPCClientClient.test.ts b/tests/client/GRPCClientClient.test.ts index a6ce3f3bb..bb083f816 100644 --- a/tests/client/GRPCClientClient.test.ts +++ b/tests/client/GRPCClientClient.test.ts @@ -1,6 +1,6 @@ +import type * as grpc from '@grpc/grpc-js'; import type { Host, Port } from '@/network/types'; import type { NodeId } from '@/nodes/types'; -import type * as grpc from '@grpc/grpc-js'; import os from 'os'; import path from 'path'; import fs from 'fs'; diff --git a/tests/client/service/agentLockAll.test.ts b/tests/client/service/agentLockAll.test.ts index 21a533dd6..4ae0d6665 100644 --- a/tests/client/service/agentLockAll.test.ts +++ b/tests/client/service/agentLockAll.test.ts @@ -75,6 +75,7 @@ describe('agentLockall', () => { agentLockAll: agentLockAll({ authenticate, sessionManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/agentStatus.test.ts b/tests/client/service/agentStatus.test.ts index 04c68aa2e..cb26d32d2 100644 --- a/tests/client/service/agentStatus.test.ts +++ b/tests/client/service/agentStatus.test.ts @@ -83,6 +83,7 @@ describe('agentStatus', () => { grpcServerClient, grpcServerAgent, proxy, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/agentStop.test.ts b/tests/client/service/agentStop.test.ts index 6a5e00dd4..a799729cb 100644 --- a/tests/client/service/agentStop.test.ts +++ b/tests/client/service/agentStop.test.ts @@ -59,6 +59,7 @@ describe('agentStop', () => { agentStop: agentStop({ authenticate, pkAgent: pkAgent as unknown as PolykeyAgent, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/agentUnlock.test.ts b/tests/client/service/agentUnlock.test.ts index 4ca05aba0..4a64076ad 100644 --- a/tests/client/service/agentUnlock.test.ts +++ b/tests/client/service/agentUnlock.test.ts @@ -22,6 +22,7 @@ describe('agentUnlock', () => { const clientService = { agentUnlock: agentUnlock({ authenticate, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/gestaltsActionsSetUnsetGetByIdentity.test.ts b/tests/client/service/gestaltsActionsSetUnsetGetByIdentity.test.ts index 4ea77f742..09dfaae3b 100644 --- a/tests/client/service/gestaltsActionsSetUnsetGetByIdentity.test.ts +++ b/tests/client/service/gestaltsActionsSetUnsetGetByIdentity.test.ts @@ -72,14 +72,17 @@ describe('gestaltsActionsByIdentity', () => { gestaltsActionsSetByIdentity: gestaltsActionsSetByIdentity({ authenticate, gestaltGraph, + logger, }), gestaltsActionsGetByIdentity: gestaltsActionsGetByIdentity({ authenticate, gestaltGraph, + logger, }), gestaltsActionsUnsetByIdentity: gestaltsActionsUnsetByIdentity({ authenticate, gestaltGraph, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/gestaltsActionsSetUnsetGetByNode.test.ts b/tests/client/service/gestaltsActionsSetUnsetGetByNode.test.ts index 5eb2e40bf..cfec8dfda 100644 --- a/tests/client/service/gestaltsActionsSetUnsetGetByNode.test.ts +++ b/tests/client/service/gestaltsActionsSetUnsetGetByNode.test.ts @@ -66,14 +66,17 @@ describe('gestaltsActionsByNode', () => { gestaltsActionsSetByNode: gestaltsActionsSetByNode({ authenticate, gestaltGraph, + logger, }), gestaltsActionsGetByNode: gestaltsActionsGetByNode({ authenticate, gestaltGraph, + logger, }), gestaltsActionsUnsetByNode: gestaltsActionsUnsetByNode({ authenticate, gestaltGraph, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/gestaltsDiscoveryByIdentity.test.ts b/tests/client/service/gestaltsDiscoveryByIdentity.test.ts index a987f6aad..2c314711b 100644 --- a/tests/client/service/gestaltsDiscoveryByIdentity.test.ts +++ b/tests/client/service/gestaltsDiscoveryByIdentity.test.ts @@ -155,6 +155,7 @@ describe('gestaltsDiscoveryByIdentity', () => { gestaltsDiscoveryByIdentity: gestaltsDiscoveryByIdentity({ authenticate, discovery, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/gestaltsDiscoveryByNode.test.ts b/tests/client/service/gestaltsDiscoveryByNode.test.ts index d03fe307a..7071428e6 100644 --- a/tests/client/service/gestaltsDiscoveryByNode.test.ts +++ b/tests/client/service/gestaltsDiscoveryByNode.test.ts @@ -155,6 +155,7 @@ describe('gestaltsDiscoveryByNode', () => { gestaltsDiscoveryByNode: gestaltsDiscoveryByNode({ authenticate, discovery, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/gestaltsGestaltGetByIdentity.test.ts b/tests/client/service/gestaltsGestaltGetByIdentity.test.ts index a8aa0b5bf..cddc5af3f 100644 --- a/tests/client/service/gestaltsGestaltGetByIdentity.test.ts +++ b/tests/client/service/gestaltsGestaltGetByIdentity.test.ts @@ -89,6 +89,7 @@ describe('gestaltsGestaltGetByIdentity', () => { gestaltsGestaltGetByIdentity: gestaltsGestaltGetByIdentity({ authenticate, gestaltGraph, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/gestaltsGestaltGetByNode.test.ts b/tests/client/service/gestaltsGestaltGetByNode.test.ts index ebff5bf7d..2a5848203 100644 --- a/tests/client/service/gestaltsGestaltGetByNode.test.ts +++ b/tests/client/service/gestaltsGestaltGetByNode.test.ts @@ -86,6 +86,7 @@ describe('gestaltsGestaltGetByNode', () => { gestaltsGestaltGetByNode: gestaltsGestaltGetByNode({ authenticate, gestaltGraph, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/gestaltsGestaltList.test.ts b/tests/client/service/gestaltsGestaltList.test.ts index 6b714e073..c724124d7 100644 --- a/tests/client/service/gestaltsGestaltList.test.ts +++ b/tests/client/service/gestaltsGestaltList.test.ts @@ -92,6 +92,7 @@ describe('gestaltsGestaltList', () => { gestaltsGestaltList: gestaltsGestaltList({ authenticate, gestaltGraph, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/gestaltsGestaltTrustByIdentity.test.ts b/tests/client/service/gestaltsGestaltTrustByIdentity.test.ts index 8bd0a749e..74ecff0e3 100644 --- a/tests/client/service/gestaltsGestaltTrustByIdentity.test.ts +++ b/tests/client/service/gestaltsGestaltTrustByIdentity.test.ts @@ -227,6 +227,7 @@ describe('gestaltsGestaltTrustByIdentity', () => { authenticate, gestaltGraph, discovery, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/gestaltsGestaltTrustByNode.test.ts b/tests/client/service/gestaltsGestaltTrustByNode.test.ts index ccc7c827d..7cb297e67 100644 --- a/tests/client/service/gestaltsGestaltTrustByNode.test.ts +++ b/tests/client/service/gestaltsGestaltTrustByNode.test.ts @@ -225,6 +225,7 @@ describe('gestaltsGestaltTrustByNode', () => { authenticate, gestaltGraph, discovery, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/identitiesAuthenticate.test.ts b/tests/client/service/identitiesAuthenticate.test.ts index fb3c2a9ff..73bce737e 100644 --- a/tests/client/service/identitiesAuthenticate.test.ts +++ b/tests/client/service/identitiesAuthenticate.test.ts @@ -56,6 +56,7 @@ describe('identitiesAuthenticate', () => { identitiesAuthenticate: identitiesAuthenticate({ authenticate, identitiesManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/identitiesAuthenticatedGet.test.ts b/tests/client/service/identitiesAuthenticatedGet.test.ts index 8233589d5..1dacdddbc 100644 --- a/tests/client/service/identitiesAuthenticatedGet.test.ts +++ b/tests/client/service/identitiesAuthenticatedGet.test.ts @@ -48,6 +48,7 @@ describe('identitiesAuthenticatedGet', () => { identitiesAuthenticatedGet: identitiesAuthenticatedGet({ authenticate, identitiesManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/identitiesClaim.test.ts b/tests/client/service/identitiesClaim.test.ts index b040a7b0a..6259afaea 100644 --- a/tests/client/service/identitiesClaim.test.ts +++ b/tests/client/service/identitiesClaim.test.ts @@ -148,6 +148,7 @@ describe('identitiesClaim', () => { identitiesManager, sigchain, keyManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/identitiesInfoConnectedGet.test.ts b/tests/client/service/identitiesInfoConnectedGet.test.ts index 0dce4a1bb..300567584 100644 --- a/tests/client/service/identitiesInfoConnectedGet.test.ts +++ b/tests/client/service/identitiesInfoConnectedGet.test.ts @@ -52,6 +52,7 @@ describe('identitiesInfoConnectedGet', () => { identitiesInfoConnectedGet: identitiesInfoConnectedGet({ authenticate, identitiesManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/identitiesInfoGet.test.ts b/tests/client/service/identitiesInfoGet.test.ts index 41bc2a1e0..68b9df655 100644 --- a/tests/client/service/identitiesInfoGet.test.ts +++ b/tests/client/service/identitiesInfoGet.test.ts @@ -51,6 +51,7 @@ describe('identitiesInfoGet', () => { identitiesInfoGet: identitiesInfoGet({ authenticate, identitiesManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/identitiesProvidersList.test.ts b/tests/client/service/identitiesProvidersList.test.ts index 071703386..e75ffd477 100644 --- a/tests/client/service/identitiesProvidersList.test.ts +++ b/tests/client/service/identitiesProvidersList.test.ts @@ -60,6 +60,7 @@ describe('identitiesProvidersList', () => { identitiesProvidersList: identitiesProvidersList({ authenticate, identitiesManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/identitiesTokenPutDeleteGet.test.ts b/tests/client/service/identitiesTokenPutDeleteGet.test.ts index 6fca93e68..f26eb192b 100644 --- a/tests/client/service/identitiesTokenPutDeleteGet.test.ts +++ b/tests/client/service/identitiesTokenPutDeleteGet.test.ts @@ -56,14 +56,17 @@ describe('identitiesTokenPutDeleteGet', () => { identitiesTokenPut: identitiesTokenPut({ authenticate, identitiesManager, + logger, }), identitiesTokenGet: identitiesTokenGet({ authenticate, identitiesManager, + logger, }), identitiesTokenDelete: identitiesTokenDelete({ authenticate, identitiesManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/keysCertsChainGet.test.ts b/tests/client/service/keysCertsChainGet.test.ts index f0b97a681..48b734c95 100644 --- a/tests/client/service/keysCertsChainGet.test.ts +++ b/tests/client/service/keysCertsChainGet.test.ts @@ -61,6 +61,7 @@ describe('keysCertsChainGet', () => { keysCertsChainGet: keysCertsChainGet({ authenticate, keyManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/keysCertsGet.test.ts b/tests/client/service/keysCertsGet.test.ts index ad2fb28ba..d3bd83e09 100644 --- a/tests/client/service/keysCertsGet.test.ts +++ b/tests/client/service/keysCertsGet.test.ts @@ -60,6 +60,7 @@ describe('keysCertsGet', () => { keysCertsGet: keysCertsGet({ authenticate, keyManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/keysEncryptDecrypt.test.ts b/tests/client/service/keysEncryptDecrypt.test.ts index 0c2a1259a..a6421649f 100644 --- a/tests/client/service/keysEncryptDecrypt.test.ts +++ b/tests/client/service/keysEncryptDecrypt.test.ts @@ -55,10 +55,12 @@ describe('keysEncryptDecrypt', () => { keysEncrypt: keysEncrypt({ authenticate, keyManager, + logger, }), keysDecrypt: keysDecrypt({ authenticate, keyManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/keysKeyPairRenew.test.ts b/tests/client/service/keysKeyPairRenew.test.ts index 714055cf0..550f793dd 100644 --- a/tests/client/service/keysKeyPairRenew.test.ts +++ b/tests/client/service/keysKeyPairRenew.test.ts @@ -74,6 +74,7 @@ describe('keysKeyPairRenew', () => { keysKeyPairRenew: keysKeyPairRenew({ authenticate, keyManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/keysKeyPairReset.test.ts b/tests/client/service/keysKeyPairReset.test.ts index 155d6071e..754d80075 100644 --- a/tests/client/service/keysKeyPairReset.test.ts +++ b/tests/client/service/keysKeyPairReset.test.ts @@ -74,6 +74,7 @@ describe('keysKeyPairReset', () => { keysKeyPairReset: keysKeyPairReset({ authenticate, keyManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/keysKeyPairRoot.test.ts b/tests/client/service/keysKeyPairRoot.test.ts index 19330b0cc..e5d5f2629 100644 --- a/tests/client/service/keysKeyPairRoot.test.ts +++ b/tests/client/service/keysKeyPairRoot.test.ts @@ -56,6 +56,7 @@ describe('keysKeyPairRoot', () => { keysKeyPairRoot: keysKeyPairRoot({ authenticate, keyManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/keysPasswordChange.test.ts b/tests/client/service/keysPasswordChange.test.ts index 8f22e95e2..7814ec86a 100644 --- a/tests/client/service/keysPasswordChange.test.ts +++ b/tests/client/service/keysPasswordChange.test.ts @@ -62,6 +62,7 @@ describe('keysPasswordChange', () => { keysPasswordChange: keysPasswordChange({ authenticate, keyManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/keysSignVerify.test.ts b/tests/client/service/keysSignVerify.test.ts index 34cf424fd..c420d7ed6 100644 --- a/tests/client/service/keysSignVerify.test.ts +++ b/tests/client/service/keysSignVerify.test.ts @@ -56,10 +56,12 @@ describe('keysSignVerify', () => { keysSign: keysSign({ authenticate, keyManager, + logger, }), keysVerify: keysVerify({ authenticate, keyManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/nodesAdd.test.ts b/tests/client/service/nodesAdd.test.ts index 1cd51eb05..168e64a34 100644 --- a/tests/client/service/nodesAdd.test.ts +++ b/tests/client/service/nodesAdd.test.ts @@ -116,6 +116,7 @@ describe('nodesAdd', () => { nodesAdd: nodesAdd({ authenticate, nodeManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/nodesClaim.test.ts b/tests/client/service/nodesClaim.test.ts index 07d41e500..2686ce3ed 100644 --- a/tests/client/service/nodesClaim.test.ts +++ b/tests/client/service/nodesClaim.test.ts @@ -159,6 +159,7 @@ describe('nodesClaim', () => { authenticate, nodeManager, notificationsManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/nodesFind.test.ts b/tests/client/service/nodesFind.test.ts index 1197638f5..0297bccbd 100644 --- a/tests/client/service/nodesFind.test.ts +++ b/tests/client/service/nodesFind.test.ts @@ -110,8 +110,9 @@ describe('nodesFind', () => { await nodeConnectionManager.start(); const clientService = { nodesFind: nodesFind({ - nodeConnectionManager, authenticate, + nodeConnectionManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/nodesPing.test.ts b/tests/client/service/nodesPing.test.ts index 0bfcabc97..43dddcba1 100644 --- a/tests/client/service/nodesPing.test.ts +++ b/tests/client/service/nodesPing.test.ts @@ -121,6 +121,7 @@ describe('nodesPing', () => { nodesPing: nodesPing({ authenticate, nodeManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/notificationsClear.test.ts b/tests/client/service/notificationsClear.test.ts index 2fab2e233..62cc7ce63 100644 --- a/tests/client/service/notificationsClear.test.ts +++ b/tests/client/service/notificationsClear.test.ts @@ -135,6 +135,7 @@ describe('notificationsClear', () => { notificationsClear: notificationsClear({ authenticate, notificationsManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/notificationsRead.test.ts b/tests/client/service/notificationsRead.test.ts index 1b77af1a3..393943f5e 100644 --- a/tests/client/service/notificationsRead.test.ts +++ b/tests/client/service/notificationsRead.test.ts @@ -209,6 +209,7 @@ describe('notificationsRead', () => { notificationsRead: notificationsRead({ authenticate, notificationsManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/client/service/notificationsSend.test.ts b/tests/client/service/notificationsSend.test.ts index 01764d368..7709f7b47 100644 --- a/tests/client/service/notificationsSend.test.ts +++ b/tests/client/service/notificationsSend.test.ts @@ -144,6 +144,7 @@ describe('notificationsSend', () => { notificationsSend: notificationsSend({ authenticate, notificationsManager, + logger, }), }; grpcServer = new GRPCServer({ logger }); diff --git a/tests/grpc/utils.test.ts b/tests/grpc/utils.test.ts index b2390e2fa..496f6553b 100644 --- a/tests/grpc/utils.test.ts +++ b/tests/grpc/utils.test.ts @@ -105,7 +105,9 @@ describe('GRPC utils', () => { const messageTo = new utilsPB.EchoMessage(); messageTo.setChallenge(challenge); const stream = serverStream(messageTo); - await expect(() => stream.next()).rejects.toThrow(errors.ErrorPolykeyRemote); + await expect(() => stream.next()).rejects.toThrow( + errors.ErrorPolykeyRemote, + ); // The generator will have ended // the internal stream will be automatically destroyed const result = await stream.next(); @@ -276,7 +278,9 @@ describe('GRPC utils', () => { const messageTo = new utilsPB.EchoMessage(); messageTo.setChallenge('error'); await genDuplex.write(messageTo); - await expect(() => genDuplex.read()).rejects.toThrow(errors.ErrorPolykeyRemote); + await expect(() => genDuplex.read()).rejects.toThrow( + errors.ErrorPolykeyRemote, + ); expect(genDuplex.stream.destroyed).toBe(true); expect(genDuplex.stream.getPeer()).toBe(`127.0.0.1:${port}`); }); @@ -316,7 +320,7 @@ describe('GRPC utils', () => { message: '', code: 2, details: '', - metadata: serialised + metadata: serialised, }); expect(deserialisedError).toBeInstanceOf(errors.ErrorPolykeyRemote); expect(deserialisedError.message).toBe('test error'); @@ -341,7 +345,7 @@ describe('GRPC utils', () => { message: '', code: 2, details: '', - metadata: serialised + metadata: serialised, }); expect(deserialisedError).toBeInstanceOf(errors.ErrorPolykeyRemote); expect(deserialisedError.message).toBe('test error'); @@ -360,7 +364,7 @@ describe('GRPC utils', () => { message: '', code: 2, details: '', - metadata: serialised + metadata: serialised, }); expect(deserialisedError).toBeInstanceOf(errors.ErrorPolykeyRemote); expect(deserialisedError.message).toBe(''); @@ -397,7 +401,7 @@ describe('GRPC utils', () => { message: '', code: 2, details: '', - metadata: serialised + metadata: serialised, }); expect(deserialisedError).toBeInstanceOf(errors.ErrorPolykeyRemote); expect(deserialisedError.message).toBe('test error');