Skip to content

Commit

Permalink
fix: crlf
Browse files Browse the repository at this point in the history
  • Loading branch information
esoubiran-aneo committed Jan 17, 2023
1 parent 01ae5e9 commit 29803ad
Show file tree
Hide file tree
Showing 18 changed files with 1,978 additions and 1,978 deletions.
190 changes: 95 additions & 95 deletions packages/csharp/ArmoniK.Api.Client/Submitter/GrpcChannelFactory.cs
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
// This file is part of the ArmoniK project
//
// Copyright (C) ANEO, 2021-2022. All rights reserved.
// W. Kirschenmann <[email protected]>
// J. Gurhem <[email protected]>
// D. Dubuc <[email protected]>
// L. Ziane Khodja <[email protected]>
// F. Lemaitre <[email protected]>
// S. Djebbar <[email protected]>
// J. Fonseca <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.IO;
using System.Net.Http;

using ArmoniK.Api.Client.Options;

using Grpc.Core;
using Grpc.Net.Client;

using JetBrains.Annotations;

namespace ArmoniK.Api.Client.Submitter
{
/// <summary>
/// Factory for creating a secure GrpcChannel
/// </summary>
[PublicAPI]
public static class GrpcChannelFactory
{
/// <summary>
/// Creates the GrpcChannel
/// </summary>
/// <param name="optionsGrpcClient">Options for the creation of the channel</param>
/// <returns>
/// The initialized GrpcChannel
/// </returns>
/// <exception cref="InvalidOperationException">Endpoint passed through options is missing</exception>
public static GrpcChannel CreateChannel(GrpcClient optionsGrpcClient)
{
if (string.IsNullOrEmpty(optionsGrpcClient.Endpoint))
{
throw new InvalidOperationException($"{nameof(optionsGrpcClient.Endpoint)} should not be null or empty");
}

var uri = new Uri(optionsGrpcClient.Endpoint);

var credentials = uri.Scheme == Uri.UriSchemeHttps
? new SslCredentials()
: ChannelCredentials.Insecure;
var httpClientHandler = new HttpClientHandler();

if (optionsGrpcClient.AllowUnsafeConnection)
{
httpClientHandler.ServerCertificateCustomValidationCallback = (_,
_,
_,
_) => true;
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport",
true);
}

if (!string.IsNullOrEmpty(optionsGrpcClient.CertPem) && !string.IsNullOrEmpty(optionsGrpcClient.KeyPem))
{
var clientCertPem = File.ReadAllText(optionsGrpcClient.CertPem);
var clientKeyPem = File.ReadAllText(optionsGrpcClient.KeyPem);

credentials = new SslCredentials(clientCertPem,
new KeyCertificatePair(clientCertPem,
clientKeyPem));
}

var channelOptions = new GrpcChannelOptions
{
Credentials = credentials,
HttpHandler = httpClientHandler,
};

return GrpcChannel.ForAddress(optionsGrpcClient.Endpoint!,
channelOptions);
}
}
}
// This file is part of the ArmoniK project
//
// Copyright (C) ANEO, 2021-2022. All rights reserved.
// W. Kirschenmann <[email protected]>
// J. Gurhem <[email protected]>
// D. Dubuc <[email protected]>
// L. Ziane Khodja <[email protected]>
// F. Lemaitre <[email protected]>
// S. Djebbar <[email protected]>
// J. Fonseca <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.IO;
using System.Net.Http;

using ArmoniK.Api.Client.Options;

using Grpc.Core;
using Grpc.Net.Client;

using JetBrains.Annotations;

namespace ArmoniK.Api.Client.Submitter
{
/// <summary>
/// Factory for creating a secure GrpcChannel
/// </summary>
[PublicAPI]
public static class GrpcChannelFactory
{
/// <summary>
/// Creates the GrpcChannel
/// </summary>
/// <param name="optionsGrpcClient">Options for the creation of the channel</param>
/// <returns>
/// The initialized GrpcChannel
/// </returns>
/// <exception cref="InvalidOperationException">Endpoint passed through options is missing</exception>
public static GrpcChannel CreateChannel(GrpcClient optionsGrpcClient)
{
if (string.IsNullOrEmpty(optionsGrpcClient.Endpoint))
{
throw new InvalidOperationException($"{nameof(optionsGrpcClient.Endpoint)} should not be null or empty");
}

var uri = new Uri(optionsGrpcClient.Endpoint);

var credentials = uri.Scheme == Uri.UriSchemeHttps
? new SslCredentials()
: ChannelCredentials.Insecure;
var httpClientHandler = new HttpClientHandler();

if (optionsGrpcClient.AllowUnsafeConnection)
{
httpClientHandler.ServerCertificateCustomValidationCallback = (_,
_,
_,
_) => true;
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport",
true);
}

if (!string.IsNullOrEmpty(optionsGrpcClient.CertPem) && !string.IsNullOrEmpty(optionsGrpcClient.KeyPem))
{
var clientCertPem = File.ReadAllText(optionsGrpcClient.CertPem);
var clientKeyPem = File.ReadAllText(optionsGrpcClient.KeyPem);

credentials = new SslCredentials(clientCertPem,
new KeyCertificatePair(clientCertPem,
clientKeyPem));
}

var channelOptions = new GrpcChannelOptions
{
Credentials = credentials,
HttpHandler = httpClientHandler,
};

return GrpcChannel.ForAddress(optionsGrpcClient.Endpoint!,
channelOptions);
}
}
}
Loading

0 comments on commit 29803ad

Please sign in to comment.