Exemple #1
0
        public async stt::Task SignBlobResourceNamesAsync()
        {
            moq::Mock <IAMCredentials.IAMCredentialsClient> mockGrpcClient = new moq::Mock <IAMCredentials.IAMCredentialsClient>(moq::MockBehavior.Strict);
            SignBlobRequest request = new SignBlobRequest
            {
                ServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
                Delegates          =
                {
                    "delegates331d18f6",
                },
                Payload = proto::ByteString.CopyFromUtf8("payloadf43c1c32"),
            };
            SignBlobResponse expectedResponse = new SignBlobResponse
            {
                KeyId      = "key_id2691f630",
                SignedBlob = proto::ByteString.CopyFromUtf8("signed_blob0afddec9"),
            };

            mockGrpcClient.Setup(x => x.SignBlobAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <SignBlobResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            IAMCredentialsClient client = new IAMCredentialsClientImpl(mockGrpcClient.Object, null);
            SignBlobResponse     responseCallSettings = await client.SignBlobAsync(request.ServiceAccountName, request.Delegates, request.Payload, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            SignBlobResponse responseCancellationToken = await client.SignBlobAsync(request.ServiceAccountName, request.Delegates, request.Payload, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Exemple #2
0
        public void SignBlobResourceNames()
        {
            moq::Mock <IAMCredentials.IAMCredentialsClient> mockGrpcClient = new moq::Mock <IAMCredentials.IAMCredentialsClient>(moq::MockBehavior.Strict);
            SignBlobRequest request = new SignBlobRequest
            {
                ServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
                Delegates          =
                {
                    "delegates331d18f6",
                },
                Payload = proto::ByteString.CopyFromUtf8("payloadf43c1c32"),
            };
            SignBlobResponse expectedResponse = new SignBlobResponse
            {
                KeyId      = "key_id2691f630",
                SignedBlob = proto::ByteString.CopyFromUtf8("signed_blob0afddec9"),
            };

            mockGrpcClient.Setup(x => x.SignBlob(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            IAMCredentialsClient client   = new IAMCredentialsClientImpl(mockGrpcClient.Object, null);
            SignBlobResponse     response = client.SignBlob(request.ServiceAccountName, request.Delegates, request.Payload);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
            private ProjectsResource.ServiceAccountsResource.SignBlobRequest CreateRequest(byte[] data)
            {
                SignBlobRequest body = new SignBlobRequest {
                    BytesToSign = Convert.ToBase64String(data)
                };
                string account = $"projects/-/serviceAccounts/{Id}";

                ProjectsResource.ServiceAccountsResource.SignBlobRequest request =
                    _iamService.Projects.ServiceAccounts.SignBlob(body, account);
                return(request);
            }
Exemple #4
0
 /// <summary>Snippet for SignBlob</summary>
 public void SignBlobRequestObject()
 {
     // Snippet: SignBlob(SignBlobRequest, CallSettings)
     // Create client
     IAMCredentialsClient iAMCredentialsClient = IAMCredentialsClient.Create();
     // Initialize request argument(s)
     SignBlobRequest request = new SignBlobRequest
     {
         ServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
         Delegates          = { "", },
         Payload            = ByteString.Empty,
     };
     // Make the request
     SignBlobResponse response = iAMCredentialsClient.SignBlob(request);
     // End snippet
 }
Exemple #5
0
        /// <summary>Snippet for SignBlobAsync</summary>
        public async Task SignBlobRequestObjectAsync()
        {
            // Snippet: SignBlobAsync(SignBlobRequest, CallSettings)
            // Additional: SignBlobAsync(SignBlobRequest, CancellationToken)
            // Create client
            IAMCredentialsClient iAMCredentialsClient = await IAMCredentialsClient.CreateAsync();

            // Initialize request argument(s)
            SignBlobRequest request = new SignBlobRequest
            {
                ServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
                Delegates          = { "", },
                Payload            = ByteString.Empty,
            };
            // Make the request
            SignBlobResponse response = await iAMCredentialsClient.SignBlobAsync(request);

            // End snippet
        }
        public async Task <byte[]> SignDataAsync(
            byte[] data, CancellationToken cancellationToken = default(CancellationToken))
        {
            var keyId = await this.GetKeyIdAsync(cancellationToken).ConfigureAwait(false);

            var body = new SignBlobRequest
            {
                BytesToSign = Convert.ToBase64String(data),
            };
            var request = new HttpRequestMessage()
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri(string.Format(SignBlobUrl, keyId)),
                Content    = NewtonsoftJsonSerializer.Instance.CreateJsonHttpContent(body),
            };

            var response = await this.httpClient
                           .SendAndDeserializeAsync <SignBlobResponse>(request, cancellationToken)
                           .ConfigureAwait(false);

            return(Convert.FromBase64String(response.Result.Signature));
        }