-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix allocator service tls auth for C# client and add a C# sample
- Loading branch information
Showing
7 changed files
with
151 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.IO; | ||
using Grpc.Core; | ||
using V1Alpha1; | ||
using System.Net.Http; | ||
|
||
namespace AllocatorClient | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
if (args.Length < 6) { | ||
throw new Exception("Arguments are missing. Expecting: <private key> <public key> <server CA> <external IP> <namepace> <enable multi-cluster>"); | ||
} | ||
|
||
string clientKey = File.ReadAllText(args[0]); | ||
string clientCert = File.ReadAllText(args[1]); | ||
string serverCa = File.ReadAllText(args[2]); | ||
string externalIp = args[3]; | ||
string namespaceArg = args[4]; | ||
bool multicluster = bool.Parse(args[5]); | ||
|
||
var creds = new SslCredentials(serverCa, new KeyCertificatePair(clientCert, clientKey)); | ||
var channel = new Channel(externalIp + ":443", creds); | ||
var client = new AllocationService.AllocationServiceClient(channel); | ||
|
||
try { | ||
var response = await client.AllocateAsync(new AllocationRequest { | ||
Namespace = namespaceArg, | ||
MultiClusterSetting = new V1Alpha1.MultiClusterSetting { | ||
Enabled = multicluster, | ||
} | ||
}); | ||
Console.WriteLine(response); | ||
} | ||
catch(RpcException e) | ||
{ | ||
Console.WriteLine($"gRPC error: {e}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# A sample Allocator service C# client | ||
|
||
This sample serves as a gRPC C# client sample code for agones-allocator gRPC service. | ||
|
||
Follow instructions in [Allocator Service](https://agones.dev/site/docs/advanced/allocator-service) to set up client and server certificate. | ||
|
||
Run the following to allocate a game server: | ||
``` | ||
#!/bin/bash | ||
NAMESPACE=default # replace with any namespace | ||
EXTERNAL_IP=`kubectl get services agones-allocator -n agones-system -o jsonpath='{.status.loadBalancer.ingress[0].ip}'` | ||
KEY_FILE=client.key | ||
CERT_FILE=client.crt | ||
TLS_CA_FILE=ca.crt | ||
MULTICLUSTER_ENABLED=false | ||
dotnet run $KEY_FILE $CERT_FILE $TLS_CA_FILE $EXTERNAL_IP $NAMESPACE $MULTICLUSTER_ENABLED | ||
``` |
19 changes: 19 additions & 0 deletions
19
examples/allocator-client-csharp/allocator-client-csharp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<RootNamespace>AllocatorClient</RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Google.Api.CommonProtos" Version="1.7.0" /> | ||
<PackageReference Include="Google.Protobuf" Version="3.11.2" /> | ||
<PackageReference Include="Grpc" Version="2.26.0" /> | ||
<PackageReference Include="Grpc.Core" Version="2.26.0" /> | ||
<PackageReference Include="Grpc.Tools" Version="2.26.0" PrivateAssets="all"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Protobuf Include="allocation.proto" ProtoRoot="../../proto/allocation/v1alpha1;../../proto/googleapis" GrpcServices="Client"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters