A simplified interface to commonly-used parts of the API. Functionality not exposed by this interface can be accessed using IOctopusAsyncRepository.Client.
Create using: using(var client = new OctopusAsyncClient(new OctopusServerEndpoint("http://myoctopus/")) { var repository = client.CreateRepository(); }
Inheritance: IOctopusAsyncRepository
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public async Task SignIn(LoginCommand loginCommand)
        {
            if (loginCommand.State == null)
            {
                loginCommand.State = new LoginState {
                    UsingSecureConnection = IsUsingSecureConnection
                };
            }
            await Post(await Repository.Link("SignIn").ConfigureAwait(false), loginCommand).ConfigureAwait(false);

            // Capture the cookie name here so that the Dispatch method does not rely on the rootDocument to get the InstallationId
            antiforgeryCookieName = cookieContainer.GetCookies(cookieOriginUri)
                                    .Cast <Cookie>()
                                    .Single(c => c.Name.StartsWith(ApiConstants.AntiforgeryTokenCookiePrefix)).Name;

            Repository = new OctopusAsyncRepository(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);
        }
Ejemplo n.º 4
0
        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()}");
        }