Skip to content

Commit

Permalink
fix(ibm-service): add httpconfigs to set a proxy and disable ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkowa committed Mar 3, 2022
1 parent 36bd1e7 commit 2b717c1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
34 changes: 34 additions & 0 deletions src/IBM.Cloud.SDK.Core/Model/HttpConfigOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Net;

namespace IBM.Cloud.SDK.Core.Model
{
public class HttpConfigOptions
{
public static string ErrorMessagePropMissing = "The {0} property is required but was not specified.";
public WebProxy Proxy { get; private set; }
public bool DisableSslVerification { get; private set; }

// this empty constructor will be used by the builder
public HttpConfigOptions()
{
}

public HttpConfigOptions SetProxy(WebProxy proxy)
{
Proxy = proxy;
return this;
}

public HttpConfigOptions SetDisableSslVerification(bool disableSslVerification)
{
DisableSslVerification = disableSslVerification;
return this;
}

public HttpConfigOptions Build()
{
return this;
}
}
}
35 changes: 19 additions & 16 deletions src/IBM.Cloud.SDK.Core/Service/IBMService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
using IBM.Cloud.SDK.Core.Authentication.NoAuth;
using IBM.Cloud.SDK.Core.Http;
using IBM.Cloud.SDK.Core.Util;

using IBM.Cloud.SDK.Core.Model;

namespace IBM.Cloud.SDK.Core.Service
{
public abstract class IBMService : IIBMService
Expand Down Expand Up @@ -84,16 +85,23 @@ protected IBMService(string serviceName, IAuthenticator authenticator, WebProxy
{
SetServiceUrl(serviceUrl);
}

// Check to see if "disable ssl" was set in the service properties.
bool disableSsl = false;
props.TryGetValue(PropNameServiceDisableSslVerification, out string tempDisableSsl);
if (!string.IsNullOrEmpty(tempDisableSsl))
{
bool.TryParse(tempDisableSsl, out disableSsl);
}

DisableSslVerification(disableSsl);
}

public void ConfigureClient(HttpConfigOptions httpConfigOptions)
{
string CurrentServiceUrl = ServiceUrl;

if (httpConfigOptions.Proxy != null)
{
Client = new IBMHttpClient(httpConfigOptions.Proxy);
}

if (httpConfigOptions.DisableSslVerification)
{
Client.DisableSslVerification(httpConfigOptions.DisableSslVerification);
}

SetServiceUrl(CurrentServiceUrl);
}

protected void SetAuthentication()
Expand All @@ -113,11 +121,6 @@ public void SetServiceUrl(string serviceUrl)
Endpoint = serviceUrl;
}

public void DisableSslVerification(bool insecure)
{
Client.DisableSslVerification(insecure);
}

public void WithHeader(string name, string value)
{
if (!customRequestHeaders.ContainsKey(name))
Expand Down

0 comments on commit 2b717c1

Please sign in to comment.