Beispiel #1
0
        public override Task <GetApprovalRequestsResponse> GetApprovalRequests(GetApprovalRequestsRequests request, ServerCallContext context)
        {
            var validatorId = context.GetHttpContext().User.GetClaimOrDefault(Claims.KeyKeeperId);
            var tenantId    = context.GetHttpContext().User.GetTenantIdOrDefault();
            var apiKeyId    = context.GetHttpContext().User.GetClaimOrDefault(Claims.ApiKeyId);

            if (string.IsNullOrEmpty(tenantId))
            {
                return(Task.FromResult(new GetApprovalRequestsResponse
                {
                    Error = new ValidatorApiError
                    {
                        Code = ValidatorApiError.Types.ErrorCodes.Unknown,
                        Message = "Tenant Id required"
                    }
                }));
            }

            var validatorLinkEntity = _validatorLinkReader.Get(
                ValidatorLinkEntity.GeneratePartitionKey(tenantId),
                ValidatorLinkEntity.GenerateRowKey(apiKeyId));

            if (validatorLinkEntity == null)
            {
                return(Task.FromResult(new GetApprovalRequestsResponse
                {
                    Error = new ValidatorApiError
                    {
                        Code = ValidatorApiError.Types.ErrorCodes.ExpiredApiKey,
                        Message = "API key is expired or deleted",
                        Data = apiKeyId
                    }
                }));
            }

            var res = new GetApprovalRequestsResponse();

            var requests = _approvalRequestReader.Get(ApprovalRequestMyNoSqlEntity.GeneratePartitionKey(validatorId))
                           .Where(r => r.IsOpen && r.TenantId == tenantId);

            //todo: add filter by tenant from API key, need to add tenant into api key

            foreach (var entity in requests)
            {
                var item = new GetApprovalRequestsResponse.Types.ApprovalRequest()
                {
                    TransferSigningRequestId = entity.TransferSigningRequestId,
                    Status = GetApprovalRequestsResponse.Types.ApprovalRequest.Types.RequestStatus.Open,
                    TransactionDetailsEncBase64 = entity.MessageEnc,
                    SecretEncBase64             = entity.SecretEnc,
                    IvNonce = entity.IvNonce
                };
                res.Payload.Add(item);
            }

            _logger.LogInformation("Return {Count} ApprovalRequests to ValidatorId='{ValidatorId}'", res.Payload.Count, validatorId);

            return(Task.FromResult(res));
        }
Beispiel #2
0
        public override async Task <ResolveApprovalRequestsResponse> ResolveApprovalRequests(ResolveApprovalRequestsRequest request, ServerCallContext context)
        {
            var validatorId = context.GetHttpContext().User.GetClaimOrDefault(Claims.KeyKeeperId);
            var tenantId    = context.GetHttpContext().User.GetTenantIdOrDefault();
            var apiKeyId    = context.GetHttpContext().User.GetClaimOrDefault(Claims.ApiKeyId);

            var validatorLinkEntity = _validatorLinkReader.Get(
                ValidatorLinkEntity.GeneratePartitionKey(tenantId),
                ValidatorLinkEntity.GenerateRowKey(apiKeyId));

            if (validatorLinkEntity == null)
            {
                return(new ResolveApprovalRequestsResponse
                {
                    Error = new ValidatorApiError
                    {
                        Code = ValidatorApiError.Types.ErrorCodes.ExpiredApiKey,
                        Message = "API key is expired or deleted",
                        Data = apiKeyId
                    }
                });
            }

            Console.WriteLine($"===============================");
            Console.WriteLine("Receive ResolveApprovalRequests:");
            Console.WriteLine($"{DateTime.UtcNow:s}");
            Console.WriteLine($"validatorId: {validatorId}");
            Console.WriteLine($"DeviceInfo: {request.DeviceInfo}");
            Console.WriteLine($"TransferSigningRequestId: {request.TransferSigningRequestId}");
            Console.WriteLine($"Signature: {request.Signature}");
            Console.WriteLine($"ResolutionDocumentEncBase64: {request.ResolutionDocumentEncBase64}");
            Console.WriteLine($"-------------------------------");


            var approvalRequest = _approvalRequestReader.Get(
                ApprovalRequestMyNoSqlEntity.GeneratePartitionKey(validatorId),
                ApprovalRequestMyNoSqlEntity.GenerateRowKey(request.TransferSigningRequestId));

            if (approvalRequest == null || !approvalRequest.IsOpen)
            {
                _logger.LogInformation("ResolveApprovalRequests skip because active request not found. TransferSigningRequestId={TransferSigningRequestId}; ValidatorId={ValidatorId}", request.TransferSigningRequestId, validatorId);
                return(new ResolveApprovalRequestsResponse());
            }

            approvalRequest.ResolutionDocumentEncBase64 = request.ResolutionDocumentEncBase64;
            approvalRequest.ResolutionSignature         = request.Signature;
            approvalRequest.IsOpen = false;

            await _approvalRequestWriter.InsertOrReplaceAsync(approvalRequest);

            _logger.LogInformation("ResolveApprovalRequests processed. TransferSigningRequestId={TransferSigningRequestId}; ValidatorId={ValidatorId}", request.TransferSigningRequestId, validatorId);

            return(new ResolveApprovalRequestsResponse());
        }
Beispiel #3
0
        public override async Task <AcknowledgeResultResponse> AcknowledgeResult(AcknowledgeResultRequest request, ServerCallContext context)
        {
            var vaultId = context.GetVaultId();

            var item = _dataReader.Get(ApprovalRequestMyNoSqlEntity.GeneratePartitionKey(request.ValidatorId),
                                       ApprovalRequestMyNoSqlEntity.GenerateRowKey(request.TransferSigningRequestId));

            if (item != null && item.VaultId == vaultId)
            {
                await _dataWriter.DeleteAsync(ApprovalRequestMyNoSqlEntity.GeneratePartitionKey(request.ValidatorId),
                                              ApprovalRequestMyNoSqlEntity.GenerateRowKey(request.TransferSigningRequestId));

                _logger.LogInformation("Acknowledge ApprovalResults. TransferSigningRequestId={TransferSigningRequestId}; TenantId={TenantId}; VaultId={VaultId}; ValidatorId={ValidatorId}", item.TransferSigningRequestId, item.TenantId, item.VaultId, item.ValidatorId);
            }

            return(new AcknowledgeResultResponse());
        }