Exemplo n.º 1
0
        /// <summary>
        ///     Set credentials for the Client
        /// </summary>
        /// <param name="config">k8s client configuration</param>
        /// <param name="handler">http client handler for the rest client</param>
        /// <returns>Task</returns>
        private void SetCredentials(KubernetesClientConfiguration config, HttpClientHandler handler)
        {
            // set the Credentails for token based auth
            if (!string.IsNullOrWhiteSpace(config.AccessToken))
            {
                Credentials = new TokenCredentials(config.AccessToken);
            }
            else if (!string.IsNullOrWhiteSpace(config.Username) && !string.IsNullOrWhiteSpace(config.Password))
            {
                Credentials = new BasicAuthenticationCredentials
                {
                    UserName = config.Username,
                    Password = config.Password
                };
            }

#if XAMARINIOS1_0 || MONOANDROID8_1
            // handle.ClientCertificates is not implemented in Xamarin.
            return;
#endif

            if ((!string.IsNullOrWhiteSpace(config.ClientCertificateData) ||
                 !string.IsNullOrWhiteSpace(config.ClientCertificateFilePath)) &&
                (!string.IsNullOrWhiteSpace(config.ClientCertificateKeyData) ||
                 !string.IsNullOrWhiteSpace(config.ClientKeyFilePath)))
            {
                var cert = CertUtils.GeneratePfx(config);

#if NET452
                ((WebRequestHandler)handler).ClientCertificates.Add(cert);
#else
                handler.ClientCertificates.Add(cert);
#endif
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Set credentials for the Client
        /// </summary>
        /// <param name="config">k8s client configuration</param>
        /// <param name="handler">http client handler for the rest client</param>
        /// <returns>Task</returns>
        private void SetCredentials(KubernetesClientConfiguration config, HttpClientHandler handler)
        {
            // set the Credentails for token based auth
            if (!string.IsNullOrWhiteSpace(config.AccessToken))
            {
                Credentials = new TokenCredentials(config.AccessToken);
            }
            else if (!string.IsNullOrWhiteSpace(config.Username) && !string.IsNullOrWhiteSpace(config.Password))
            {
                Credentials = new BasicAuthenticationCredentials
                {
                    UserName = config.Username,
                    Password = config.Password
                };
            }
            // othwerwise set handler for clinet cert based auth
            else if ((!string.IsNullOrWhiteSpace(config.ClientCertificateData) ||
                      !string.IsNullOrWhiteSpace(config.ClientCertificateFilePath)) &&
                     (!string.IsNullOrWhiteSpace(config.ClientCertificateKeyData) ||
                      !string.IsNullOrWhiteSpace(config.ClientKeyFilePath)))
            {
                var cert = CertUtils.GeneratePfx(config);

                handler.ClientCertificates.Add(cert);
            }
        }
        public void AddCertificates(HttpClientHandler handler)
        {
            if ((!string.IsNullOrWhiteSpace(this.ClientCertificateData) ||
                 !string.IsNullOrWhiteSpace(this.ClientCertificateFilePath)) &&
                (!string.IsNullOrWhiteSpace(this.ClientCertificateKeyData) ||
                 !string.IsNullOrWhiteSpace(this.ClientKeyFilePath)))
            {
                var cert = CertUtils.GeneratePfx(this);

#if NET452
                ((WebRequestHandler)handler).ClientCertificates.Add(cert);
#else
                handler.ClientCertificates.Add(cert);
#endif
            }
        }
        public void AddCertificates(HttpClientHandler handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            if ((!string.IsNullOrWhiteSpace(ClientCertificateData) ||
                 !string.IsNullOrWhiteSpace(ClientCertificateFilePath)) &&
                (!string.IsNullOrWhiteSpace(ClientCertificateKeyData) ||
                 !string.IsNullOrWhiteSpace(ClientKeyFilePath)))
            {
                var cert = CertUtils.GeneratePfx(this);

                handler.ClientCertificates.Add(cert);
            }
        }
Exemplo n.º 5
0
        public void AddCertificates(HttpClientHandler handler)
        {
#if XAMARINIOS1_0 || MONOANDROID8_1
            // handle.ClientCertificates is not implemented in Xamarin.
            return;
#endif

            if ((!string.IsNullOrWhiteSpace(this.ClientCertificateData) ||
                 !string.IsNullOrWhiteSpace(this.ClientCertificateFilePath)) &&
                (!string.IsNullOrWhiteSpace(this.ClientCertificateKeyData) ||
                 !string.IsNullOrWhiteSpace(this.ClientKeyFilePath)))
            {
                var cert = CertUtils.GeneratePfx(this);

#if NET452
                ((WebRequestHandler)handler).ClientCertificates.Add(cert);
#else
                handler.ClientCertificates.Add(cert);
#endif
            }
        }