From feab2d9c92bc78bf964d7a48a84aaa9346f173e9 Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Fri, 6 Sep 2019 14:05:47 -0500 Subject: [PATCH] feat(SetServiceUrl): Refactored SetEndpoint to SetServiceUrl BREAKING CHANGE: Use SetServiceUrl to set the service endpoint rather than SetEndpoint --- src/IBM.Cloud.SDK.Core/Service/IBMService.cs | 16 ++++----- src/IBM.Cloud.SDK.Core/Service/IIBMService.cs | 2 +- .../CloudPak4DataAuthTests.cs | 2 +- test/IBM.Cloud.SDK.Core.Tests/NoauthTests.cs | 36 ------------------- 4 files changed, 10 insertions(+), 46 deletions(-) delete mode 100644 test/IBM.Cloud.SDK.Core.Tests/NoauthTests.cs diff --git a/src/IBM.Cloud.SDK.Core/Service/IBMService.cs b/src/IBM.Cloud.SDK.Core/Service/IBMService.cs index d314304a..c5ffe3f0 100644 --- a/src/IBM.Cloud.SDK.Core/Service/IBMService.cs +++ b/src/IBM.Cloud.SDK.Core/Service/IBMService.cs @@ -34,7 +34,7 @@ public abstract class IBMService : IIBMService private const string apikeyAsUsername = "apikey"; public IClient Client { get; set; } public string ServiceName { get; set; } - public string Url { get { return Endpoint; } } + public string ServiceUrl { get { return Endpoint; } } protected Dictionary customRequestHeaders = new Dictionary(); private const string ErrorMessageNoAuthenticator = "Authentication information was not properly configured."; @@ -60,14 +60,14 @@ protected string Endpoint private IAuthenticator authenticator; - protected IBMService(string serviceName, string url, IClient httpClient) + protected IBMService(string serviceName, string serviceUrl, IClient httpClient) { ServiceName = serviceName; Client = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); authenticator = new NoAuthAuthenticator(); if (!string.IsNullOrEmpty(Endpoint)) - Endpoint = url; + Endpoint = serviceUrl; } protected IBMService(string serviceName, IAuthenticator authenticator) @@ -80,10 +80,10 @@ protected IBMService(string serviceName, IAuthenticator authenticator) // Try to retrieve the service URL from either a credential file, environment, or VCAP_SERVICES. Dictionary props = CredentialUtils.GetServiceProperties(serviceName); - props.TryGetValue(PropNameServiceUrl, out string url); - if (!string.IsNullOrEmpty(url)) + props.TryGetValue(PropNameServiceUrl, out string serviceUrl); + if (!string.IsNullOrEmpty(serviceUrl)) { - SetEndpoint(url); + SetServiceUrl(serviceUrl); } // Check to see if "disable ssl" was set in the service properties. @@ -109,9 +109,9 @@ protected void SetAuthentication() } } - public void SetEndpoint(string url) + public void SetServiceUrl(string serviceUrl) { - Endpoint = url; + Endpoint = serviceUrl; } public void DisableSslVerification(bool insecure) diff --git a/src/IBM.Cloud.SDK.Core/Service/IIBMService.cs b/src/IBM.Cloud.SDK.Core/Service/IIBMService.cs index 19139b9e..2656dfde 100644 --- a/src/IBM.Cloud.SDK.Core/Service/IIBMService.cs +++ b/src/IBM.Cloud.SDK.Core/Service/IIBMService.cs @@ -25,7 +25,7 @@ public interface IIBMService IClient Client { get; set; } string ServiceName { get; set; } - void SetEndpoint(string endpoint); + void SetServiceUrl(string serviceUrl); IAuthenticator GetAuthenticator(); } } diff --git a/test/IBM.Cloud.SDK.Core.Tests/CloudPak4DataAuthTests.cs b/test/IBM.Cloud.SDK.Core.Tests/CloudPak4DataAuthTests.cs index 929fe0de..410cb00f 100644 --- a/test/IBM.Cloud.SDK.Core.Tests/CloudPak4DataAuthTests.cs +++ b/test/IBM.Cloud.SDK.Core.Tests/CloudPak4DataAuthTests.cs @@ -205,7 +205,7 @@ public void TestBadPasswordBracketEnd() [TestMethod, ExpectedException(typeof(ArgumentException))] public void TestBadUrlBeginningBracketEnd() { - CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("{url}", "username", "password"); + CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("{serviceUrl}", "username", "password"); } [TestMethod, ExpectedException(typeof(ArgumentException))] diff --git a/test/IBM.Cloud.SDK.Core.Tests/NoauthTests.cs b/test/IBM.Cloud.SDK.Core.Tests/NoauthTests.cs deleted file mode 100644 index 60092232..00000000 --- a/test/IBM.Cloud.SDK.Core.Tests/NoauthTests.cs +++ /dev/null @@ -1,36 +0,0 @@ -/** -* Copyright 2019 IBM Corp. All Rights Reserved. -* -* 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 IBM.Cloud.SDK.Core.Authentication; -using IBM.Cloud.SDK.Core.Authentication.NoAuth; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace IBM.Cloud.SDK.Core.Tests.Authentication.NoAuth -{ - [TestClass] - public class NoAuthTests - { - [TestMethod] - public void TestConstruction() - { - NoAuthAuthenticator authenticator = new NoAuthAuthenticator(); - - Assert.IsNotNull(authenticator); - Assert.IsTrue(authenticator.AuthenticationType == Authenticator.AuthTypeNoAuth); - } - } -}