Exemple #1
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);
        }
        // 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);
        }