From 2537957c78b537eddb1f286f344b32d3f2c15568 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 24 Jun 2021 21:39:51 +1200 Subject: [PATCH] [C#] Add ChannelCredentials.SecureSsl property for better codecompletion with ChannelCredentials (#26472) * Add ChannelCredentials.Secure * Update * Test * PR feedback --- src/csharp/Grpc.Core.Api/ChannelCredentials.cs | 17 +++++++++++++++++ .../Grpc.Core.Tests/ChannelCredentialsTest.cs | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/csharp/Grpc.Core.Api/ChannelCredentials.cs b/src/csharp/Grpc.Core.Api/ChannelCredentials.cs index 19b808037d3..4d6ede3b3f0 100644 --- a/src/csharp/Grpc.Core.Api/ChannelCredentials.cs +++ b/src/csharp/Grpc.Core.Api/ChannelCredentials.cs @@ -31,6 +31,7 @@ namespace Grpc.Core public abstract class ChannelCredentials { static readonly ChannelCredentials InsecureInstance = new InsecureCredentials(); + static readonly ChannelCredentials SecureSslInstance = new SslCredentials(); /// /// Creates a new instance of channel credentials @@ -51,6 +52,22 @@ namespace Grpc.Core } } + /// + /// Returns instance of credentials that provides SSL security. + /// + /// These credentials are the same as creating without parameters. + /// Apps that are using Grpc.Core can create directly to customize + /// the secure SSL credentials. + /// + /// + public static ChannelCredentials SecureSsl + { + get + { + return SecureSslInstance; + } + } + /// /// Creates a new instance of ChannelCredentials class by composing /// given channel credentials with call credentials. diff --git a/src/csharp/Grpc.Core.Tests/ChannelCredentialsTest.cs b/src/csharp/Grpc.Core.Tests/ChannelCredentialsTest.cs index 4be6a06131c..f5d06ad1e03 100644 --- a/src/csharp/Grpc.Core.Tests/ChannelCredentialsTest.cs +++ b/src/csharp/Grpc.Core.Tests/ChannelCredentialsTest.cs @@ -30,6 +30,12 @@ namespace Grpc.Core.Tests Assert.IsFalse(ChannelCredentials.Insecure.IsComposable); } + [Test] + public void SecureCredentials_IsComposable() + { + Assert.IsTrue(ChannelCredentials.SecureSsl.IsComposable); + } + [Test] public void ChannelCredentials_CreateComposite() { @@ -52,6 +58,10 @@ namespace Grpc.Core.Tests var nativeCreds1 = creds.ToNativeCredentials(); var nativeCreds2 = creds.ToNativeCredentials(); Assert.AreSame(nativeCreds1, nativeCreds2); + + var nativeCreds3 = ChannelCredentials.SecureSsl.ToNativeCredentials(); + var nativeCreds4 = ChannelCredentials.SecureSsl.ToNativeCredentials(); + Assert.AreSame(nativeCreds3, nativeCreds4); } } }