Options used to change the behaviour of OctopusAsyncClient
        /// <summary>
        ///     Creates an instance of the client.
        /// </summary>
        /// <param name="serverEndpoint">The server endpoint.</param>
        /// <returns>The <see cref="IOctopusClient" /> instance.</returns>
        /// <param name="options">The configuration options for this client instance.</param>
        public IOctopusClient CreateClient(OctopusServerEndpoint serverEndpoint, OctopusClientOptions options = default)
        {
            options ??= new OctopusClientOptions();
            var requestingTool = DetermineRequestingTool();

            return(new OctopusClient(serverEndpoint, requestingTool, options));
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OctopusAsyncClient" /> class.
        /// </summary>
        /// <param name="serverEndpoint">The server endpoint.</param>
        /// <param name="options">The <see cref="OctopusClientOptions" /> used to configure the behavour of the client, may be null.</param>
        OctopusAsyncClient(OctopusServerEndpoint serverEndpoint, OctopusClientOptions options)
        {
            options    = options ?? new OctopusClientOptions();
            Repository = new OctopusAsyncRepository(this);

            this.serverEndpoint = serverEndpoint;
            var handler = new HttpClientHandler()
            {
                Credentials = serverEndpoint.Credentials ?? CredentialCache.DefaultNetworkCredentials,
            };

#if HTTP_CLIENT_SUPPORTS_SSL_OPTIONS
            handler.SslProtocols = options.SslProtocols;
            ignoreSslErrors      = options.IgnoreSslErrors;
            handler.ServerCertificateCustomValidationCallback = IgnoreServerCertificateCallback;
#endif

            if (serverEndpoint.Proxy != null)
            {
                handler.Proxy = serverEndpoint.Proxy;
            }

            client = new HttpClient(handler, true);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add(ApiConstants.ApiKeyHttpHeaderName, serverEndpoint.ApiKey);
        }
        /// <summary>
        ///     Creates an instance of the client.
        /// </summary>
        /// <param name="serverEndpoint">The server endpoint.</param>
        /// <param name="octopusClientOptions"></param>
        /// <returns>The <see cref="IOctopusAsyncClient" /> instance.</returns>
        public Task <IOctopusAsyncClient> CreateAsyncClient(OctopusServerEndpoint serverEndpoint,
                                                            OctopusClientOptions octopusClientOptions = null)
        {
            var requestingTool = DetermineRequestingTool();

            return(OctopusAsyncClient.Create(serverEndpoint, octopusClientOptions, requestingTool));
        }
        // Use the Create method to instantiate
        protected OctopusAsyncClient(OctopusServerEndpoint serverEndpoint, OctopusClientOptions options, bool addCertificateCallback, string requestingTool, IHttpRouteExtractor httpRouteExtractor)
        {
            var clientOptions = options ?? new OctopusClientOptions();

            this.serverEndpoint     = serverEndpoint;
            this.httpRouteExtractor = httpRouteExtractor;
            cookieOriginUri         = BuildCookieUri(serverEndpoint);
            var handler = new HttpClientHandler
            {
                CookieContainer = cookieContainer,
                Credentials     = serverEndpoint.Credentials ?? CredentialCache.DefaultNetworkCredentials,
                UseProxy        = clientOptions.AllowDefaultProxy
            };

            if (clientOptions.Proxy != null)
            {
                handler.UseProxy = true;
                handler.Proxy    = new ClientProxy(clientOptions.Proxy, clientOptions.ProxyUsername, clientOptions.ProxyPassword);
            }

#if HTTP_CLIENT_SUPPORTS_SSL_OPTIONS
            handler.SslProtocols = options.SslProtocols;
            if (addCertificateCallback)
            {
                ignoreSslErrors = options.IgnoreSslErrors;
                handler.ServerCertificateCustomValidationCallback = IgnoreServerCertificateCallback;
            }
#endif

            if (serverEndpoint.Proxy != null)
            {
                handler.UseProxy = true;
                handler.Proxy    = serverEndpoint.Proxy;
            }

            client         = new HttpClient(handler, true);
            client.Timeout = clientOptions.Timeout;
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add(ApiConstants.ApiKeyHttpHeaderName, serverEndpoint.ApiKey);
            client.DefaultRequestHeaders.Add("User-Agent", new OctopusCustomHeaders(requestingTool).UserAgent);
            Repository = new OctopusAsyncRepository(this);
        }
        protected OctopusAsyncClient(OctopusServerEndpoint serverEndpoint, OctopusClientOptions options, bool addCertificateCallback)
        {
            options    = options ?? new OctopusClientOptions();
            Repository = new OctopusAsyncRepository(this);

            this.serverEndpoint = serverEndpoint;
            cookieOriginUri     = BuildCookieUri(serverEndpoint);
            var handler = new HttpClientHandler
            {
                CookieContainer = cookieContainer,
                Credentials     = serverEndpoint.Credentials ?? CredentialCache.DefaultNetworkCredentials,
            };

            if (options.Proxy != null)
            {
                handler.UseProxy = true;
                handler.Proxy    = new ClientProxy(options.Proxy, options.ProxyUsername, options.ProxyPassword);
            }

#if HTTP_CLIENT_SUPPORTS_SSL_OPTIONS
            handler.SslProtocols = options.SslProtocols;
            if (addCertificateCallback)
            {
                ignoreSslErrors = options.IgnoreSslErrors;
                handler.ServerCertificateCustomValidationCallback = IgnoreServerCertificateCallback;
            }
#endif

            if (serverEndpoint.Proxy != null)
            {
                handler.Proxy = serverEndpoint.Proxy;
            }

            client         = new HttpClient(handler, true);
            client.Timeout = options.Timeout;
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add(ApiConstants.ApiKeyHttpHeaderName, serverEndpoint.ApiKey);
            client.DefaultRequestHeaders.Add("User-Agent", $"{ApiConstants.OctopusUserAgentProductName}/{GetType().GetSemanticVersion().ToNormalizedString()}");
        }
        /// <summary>
        ///     Creates an instance of the client.
        /// </summary>
        /// <param name="serverEndpoint">The server endpoint.</param>
        /// <param name="options">The configuration options for this client instance.</param>
        /// <returns>The <see cref="IOctopusAsyncClient" /> instance.</returns>
        public Task <IOctopusAsyncClient> CreateAsyncClient(OctopusServerEndpoint serverEndpoint, OctopusClientOptions options = default)
        {
            options ??= new OctopusClientOptions();
            var requestingTool = DetermineRequestingTool();

            return(OctopusAsyncClient.Create(serverEndpoint, options, requestingTool));
        }
        private static async Task <IOctopusAsyncClient> Create(OctopusServerEndpoint serverEndpoint, OctopusClientOptions options, bool addHandler)
        {
            var client = new OctopusAsyncClient(serverEndpoint, options ?? new OctopusClientOptions(), addHandler);

            try
            {
                client.RootDocument = await client.EstablishSession().ConfigureAwait(false);

                return(client);
            }
            catch
            {
                client.Dispose();
                throw;
            }
        }
        public static async Task <IOctopusAsyncClient> Create(OctopusServerEndpoint serverEndpoint, OctopusClientOptions options = null)
        {
#if HTTP_CLIENT_SUPPORTS_SSL_OPTIONS
            try
            {
                return(await Create(serverEndpoint, options, true));
            }
            catch (PlatformNotSupportedException)
            {
                if (options?.IgnoreSslErrors ?? false)
                {
                    throw new Exception("This platform does not support ignoring SSL certificate errors");
                }
                return(await Create(serverEndpoint, options, false));
            }
#else
            return(await Create(serverEndpoint, options, false));
#endif
        }
예제 #9
0
        private static async Task <IOctopusAsyncClient> Create(OctopusServerEndpoint serverEndpoint, OctopusClientOptions options, bool addHandler, string requestingTool = null)
        {
            var client = new OctopusAsyncClient(serverEndpoint, options ?? new OctopusClientOptions(), addHandler, requestingTool);
            // User used to see this exception
            // System.PlatformNotSupportedException: The handler does not support custom handling of certificates with this combination of libcurl (7.29.0) and its SSL backend
            await client.Repository.LoadRootDocument().ConfigureAwait(false);

            return(client);
        }
예제 #10
0
 /// <summary>
 /// Creates an instance of the client.
 /// </summary>
 /// <param name="serverEndpoint">The server endpoint.</param>
 /// <param name="octopusClientOptions"></param>
 /// <returns>The <see cref="IOctopusAsyncClient" /> instance.</returns>
 public Task<IOctopusAsyncClient> CreateAsyncClient(OctopusServerEndpoint serverEndpoint, OctopusClientOptions octopusClientOptions = null)
 {
     return OctopusAsyncClient.Create(serverEndpoint, octopusClientOptions);
 }
예제 #11
0
 /// <summary>
 /// Creates an instance of the client.
 /// </summary>
 /// <param name="serverEndpoint">The server endpoint.</param>
 /// <param name="octopusClientOptions"></param>
 /// <returns>The <see cref="IOctopusAsyncClient" /> instance.</returns>
 public Task <IOctopusAsyncClient> CreateAsyncClient(OctopusServerEndpoint serverEndpoint, OctopusClientOptions octopusClientOptions = null)
 {
     return(OctopusAsyncClient.Create(serverEndpoint, octopusClientOptions));
 }
예제 #12
0
        internal OctopusClient(OctopusServerEndpoint serverEndpoint, string requestingTool, OctopusClientOptions options = default)
        {
            this.serverEndpoint = serverEndpoint;
            options ??= new OctopusClientOptions();

            httpRouteExtractor   = new HttpRouteExtractor(options.ScanForHttpRouteTypes);
            cookieOriginUri      = BuildCookieUri(serverEndpoint);
            octopusCustomHeaders = new OctopusCustomHeaders(requestingTool);
            Repository           = new OctopusRepository(this);
        }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OctopusClient" /> class.
 /// </summary>
 /// <param name="serverEndpoint">The server endpoint.</param>
 /// <param name="options">The configuration options for this client instance.</param>
 public OctopusClient(OctopusServerEndpoint serverEndpoint, OctopusClientOptions options = default) : this(serverEndpoint, null, options)
 {
 }