コード例 #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Kubernetes" /> class.
        /// </summary>
        /// <param name='config'>
        ///     Optional. The delegating handlers to add to the http client pipeline.
        /// </param>
        /// <param name="handlers">
        ///     Optional. The delegating handlers to add to the http client pipeline.
        /// </param>
        public Kubernetes(KubernetesClientConfiguration config, params DelegatingHandler[] handlers) : this(new Xamarin.Android.Net.AndroidClientHandler(), handlers)
        {
            if (string.IsNullOrWhiteSpace(config.Host))
            {
                throw new KubeConfigException("Host url must be set");
            }

            try
            {
                BaseUri = new Uri(config.Host);
            }
            catch (UriFormatException e)
            {
                throw new KubeConfigException("Bad host url", e);
            }

            CaCerts       = config.SslCaCerts;
            SkipTlsVerify = config.SkipTlsVerify;

            if (BaseUri.Scheme == "https")
            {
                if (config.SkipTlsVerify)
                {
                    System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
                    {
                        return(true);
                    };
                }
                else
                {
                    if (CaCerts == null)
                    {
                        throw new KubeConfigException("a CA must be set when SkipTlsVerify === false");
                    }

                    var certList = new System.Collections.Generic.List <Java.Security.Cert.Certificate>();

                    foreach (X509Certificate2 caCert in CaCerts)
                    {
                        using (System.IO.MemoryStream certStream = new System.IO.MemoryStream(caCert.RawData))
                        {
                            Java.Security.Cert.Certificate cert = Java.Security.Cert.CertificateFactory.GetInstance("X509").GenerateCertificate(certStream);

                            certList.Add(cert);
                        }
                    }

                    Xamarin.Android.Net.AndroidClientHandler handler = (Xamarin.Android.Net.AndroidClientHandler) this.HttpClientHandler;

                    handler.TrustedCerts = certList;
                }
            }

            // set credentails for the kubernernet client
            SetCredentials(config, HttpClientHandler);
        }
        internal HttpMessageHandler BuildHandlerPipeline(CookieStore store, IRetryStrategy retryStrategy)
#endif
        {
#if __MOBILE__
            var handler = default(HttpClientHandler);
#if __ANDROID__
            if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.Lollipop)
            {
                handler = new Xamarin.Android.Net.AndroidClientHandler
                {
                    CookieContainer = store,
                    UseCookies      = true
                };

                if (selfSignedCert != null)
                {
                    ((Xamarin.Android.Net.AndroidClientHandler)handler).TrustedCerts = new List <Java.Security.Cert.Certificate> {
                        selfSignedCert
                    };
                }
            }
            else
#endif
            {
                handler = new HttpClientHandler
                {
                    CookieContainer = store,
                    UseCookies      = true
                };
            }
#else
            var handler = new WebRequestHandler {
                CookieContainer  = store,
                UseCookies       = true,
                ReadWriteTimeout = (int)SocketTimeout.TotalMilliseconds
            };
#endif

            if (handler.SupportsAutomaticDecompression)
            {
                handler.AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate;
            }

            var authHandler = new DefaultAuthHandler(handler, store, SocketTimeout);
            if (retryStrategy == null)
            {
                return(authHandler);
            }

            var retryHandler = new TransientErrorRetryHandler(authHandler, retryStrategy);
            return(retryHandler);
        }
コード例 #3
0
        public void HttpProvider_CustomAndroidClientHandler()
        {
            var proxy = new WebProxy("https://test.com");

            using (var httpClientHandler = new Xamarin.Android.Net.AndroidClientHandler {
                Proxy = proxy
            })
                using (var httpProvider = new HttpProvider(httpClientHandler, false, null))
                {
                    Assert.Equal(httpClientHandler, httpProvider.httpMessageHandler);
                    Assert.True(httpProvider.httpClient.DefaultRequestHeaders.Contains(CoreConstants.Headers.FeatureFlag));
                    Assert.False(httpProvider.disposeHandler);
                    Assert.Same((httpProvider.httpMessageHandler as Xamarin.Android.Net.AndroidClientHandler).Proxy, proxy);
                }
        }