aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2015-04-27 16:11:59 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2015-04-27 16:11:59 -0700
commit0bbfa382eadee4796e30f71c7dccf8d72ed7af5b (patch)
tree2130a3605692234bf29ee570bf3e5d4fbed0f424 /src/csharp
parent1f18e80a5ac6bddb56d4cb55782ef84e684fc4d6 (diff)
attempt to support compute_engine_creds interop test
Diffstat (limited to 'src/csharp')
-rw-r--r--src/csharp/Grpc.Auth/GoogleCredential.cs8
-rw-r--r--src/csharp/Grpc.Core/Status.cs2
-rw-r--r--src/csharp/Grpc.IntegrationTesting/InteropClient.cs25
3 files changed, 31 insertions, 4 deletions
diff --git a/src/csharp/Grpc.Auth/GoogleCredential.cs b/src/csharp/Grpc.Auth/GoogleCredential.cs
index 3e31755bfc..36d43d3207 100644
--- a/src/csharp/Grpc.Auth/GoogleCredential.cs
+++ b/src/csharp/Grpc.Auth/GoogleCredential.cs
@@ -78,8 +78,14 @@ namespace Grpc.Auth
public GoogleCredential CreateScoped(IEnumerable<string> scopes)
{
- // TODO(jtattermusch): also support compute credential.
var credsPath = Environment.GetEnvironmentVariable(GoogleApplicationCredentialsEnvName);
+ if (credsPath == null)
+ {
+ // Default to ComputeCredentials if path to JSON key is not set.
+ // ComputeCredential is not scoped actually, but for our use case it's
+ // fine to treat is as such.
+ return new GoogleCredential(new ComputeCredential(new ComputeCredential.Initializer()));
+ }
JObject o1 = JObject.Parse(File.ReadAllText(credsPath));
string clientEmail = o1.GetValue(ClientEmailFieldName).Value<string>();
diff --git a/src/csharp/Grpc.Core/Status.cs b/src/csharp/Grpc.Core/Status.cs
index 2c3c2a5d8e..7d76aec4d1 100644
--- a/src/csharp/Grpc.Core/Status.cs
+++ b/src/csharp/Grpc.Core/Status.cs
@@ -74,7 +74,5 @@ namespace Grpc.Core
{
return string.Format("Status(StatusCode={0}, Detail=\"{1}\")", statusCode, detail);
}
-
-
}
}
diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
index 3b909de013..c05a5cc6ce 100644
--- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
@@ -120,7 +120,7 @@ namespace Grpc.IntegrationTesting
using (Channel channel = new Channel(addr, credentials, channelArgs))
{
var stubConfig = StubConfiguration.Default;
- if (options.testCase == "service_account_creds")
+ if (options.testCase == "service_account_creds" || options.testCase == "compute_engine_creds")
{
var credential = GoogleCredential.GetApplicationDefault();
if (credential.IsCreateScopedRequired)
@@ -162,6 +162,9 @@ namespace Grpc.IntegrationTesting
case "service_account_creds":
RunServiceAccountCreds(client);
break;
+ case "compute_engine_creds":
+ RunComputeEngineCreds(client);
+ break;
case "benchmark_empty_unary":
RunBenchmarkEmptyUnary(client);
break;
@@ -325,6 +328,26 @@ namespace Grpc.IntegrationTesting
Console.WriteLine("Passed!");
}
+ public static void RunComputeEngineCreds(TestServiceGrpc.ITestServiceClient client)
+ {
+ Console.WriteLine("running compute_engine_creds");
+ var request = SimpleRequest.CreateBuilder()
+ .SetResponseType(PayloadType.COMPRESSABLE)
+ .SetResponseSize(314159)
+ .SetPayload(CreateZerosPayload(271828))
+ .SetFillUsername(true)
+ .SetFillOauthScope(true)
+ .Build();
+
+ var response = client.UnaryCall(request);
+
+ Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
+ Assert.AreEqual(314159, response.Payload.Body.Length);
+ Assert.AreEqual(AuthScopeResponse, response.OauthScope);
+ Assert.AreEqual(ServiceAccountUser, response.Username);
+ Console.WriteLine("Passed!");
+ }
+
// This is not an official interop test, but it's useful.
public static void RunBenchmarkEmptyUnary(TestServiceGrpc.ITestServiceClient client)
{