private void Init(string apikey, string url = null, string clientId = null, string clientSecret = null, bool?disableSslVerification = null, Dictionary <string, string> headers = null)
        {
            Apikey = apikey;

            if (string.IsNullOrEmpty(url))
            {
                url = defaultUrl;
            }
            this.Url = url;
            if (!string.IsNullOrEmpty(clientId))
            {
                ClientId = clientId;
            }
            if (!string.IsNullOrEmpty(clientSecret))
            {
                ClientSecret = clientSecret;
            }
            if (disableSslVerification != null)
            {
                DisableSslVerification = disableSslVerification;
            }
            if (headers != null)
            {
                this.Headers = headers;
            }

            Validate();

            Client = new IBMHttpClient()
            {
                ServiceUrl = Url
            };
        }
Example #2
0
        protected IBMService(string serviceName, IAuthenticator authenticator, WebProxy webProxy = null)
        {
            ServiceName = serviceName;

            this.authenticator = authenticator ?? throw new ArgumentNullException(ErrorMessageNoAuthenticator);

            Client = new IBMHttpClient(webProxy);

            // Try to retrieve the service URL from either a credential file, environment, or VCAP_SERVICES.
            Dictionary <string, string> props = CredentialUtils.GetServiceProperties(serviceName);

            props.TryGetValue(PropNameServiceUrl, out string serviceUrl);
            if (!string.IsNullOrEmpty(serviceUrl))
            {
                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 Init()
        {
            Validate();

            Client = new IBMHttpClient()
            {
                ServiceUrl = Url + UrlSuffix
            };
        }
        public void SetServiceUrlPropertyTest()
        {
            IClient client = new IBMHttpClient();

            client.ServiceUrl = "http://www.service-url.com";

            var restRequest = client.GetAsync("/v1/operation");

            Assert.IsTrue(restRequest.Message.RequestUri.AbsoluteUri == "http://www.service-url.com/v1/operation");
        }
        public void TestArgEscape()
        {
            IClient client = new IBMHttpClient()
            {
                ServiceUrl = "http://baseuri.com"
            };

            var restRequest = client.GetAsync("/v1/operation");

            restRequest.WithArgument("myArg", "Is this a valid arg?");

            Assert.IsTrue(restRequest.Message.RequestUri == new Uri("http://baseuri.com/v1/operation?myArg=Is+this+a+valid+arg%3F"));
        }
        public void TestAuthenticate()
        {
            var bearerToken = "bearerToken";

            BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(bearerToken);
            IClient client = new IBMHttpClient();

            authenticator.Authenticate(client);

            Assert.IsNotNull(client);
            Assert.IsNotNull(client.BaseClient);
            Assert.IsNotNull(client.BaseClient.DefaultRequestHeaders.Authorization);
            Assert.IsTrue(client.BaseClient.DefaultRequestHeaders.Authorization.ToString() == "Bearer " + bearerToken);
        }
        public void TestAuthenticate()
        {
            var username = "******";
            var password = "******";
            var auth     = string.Format("{0}:{1}", username, password);
            var auth64   = Convert.ToBase64String(Encoding.ASCII.GetBytes(auth));

            BasicAuthenticator authenticator = new BasicAuthenticator(username, password);
            IClient            client        = new IBMHttpClient();

            authenticator.Authenticate(client);

            Assert.IsNotNull(client);
            Assert.IsNotNull(client.BaseClient);
            Assert.IsNotNull(client.BaseClient.DefaultRequestHeaders.Authorization);
            Assert.IsTrue(client.BaseClient.DefaultRequestHeaders.Authorization.ToString() == "Basic " + auth64);
        }
        private void Init(string url, string username, string password, bool?disableSslVerification = null, Dictionary <string, string> headers = null)
        {
            Url      = url;
            Username = username;
            Password = password;

            if (disableSslVerification != null)
            {
                DisableSslVerification = disableSslVerification;
            }

            if (headers != null)
            {
                Headers = headers;
            }

            Validate();

            Client = new IBMHttpClient()
            {
                ServiceUrl = Url + UrlSuffix
            };
        }
 public void NoUrlTest()
 {
     IClient client      = new IBMHttpClient();
     var     restRequest = client.GetAsync("/v1/operation");
 }