Exemplo n.º 1
0
        /// <summary>
        /// Try to login into the account using the credentials.
        /// If succeed, it will return the account details.
        /// </summary>
        /// <returns>The CaaS connection</returns>
        private async Task <ComputeServiceConnection> LoginTask()
        {
            var newCloudComputeConnection = new ComputeServiceConnection(new ComputeApiClient(ApiBaseUri));;

            WriteDebug("Trying to login into the CaaS");
            await newCloudComputeConnection.ApiClient.LoginAsync(ApiCredentials.GetNetworkCredential());

            return(newCloudComputeConnection);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Try to login into the account using the credentials.
        ///     If succeed, it will return the account details.
        /// </summary>
        /// <returns>
        ///     The CaaS connection
        /// </returns>
        private async Task <ComputeServiceConnection> LoginTask()
        {
            var messageHandler = GetMessageHandler(ApiCredentials.GetNetworkCredential());
            var baseUri        = KnownApiUri.Instance.GetBaseUri(Vendor, Region);
            var httpClient     = new HttpClientAdapter(
                new HttpClient(messageHandler, disposeHandler: true)
            {
                BaseAddress = baseUri,
                Timeout     = TimeSpan.FromMinutes(5),
            });


            // we will not try to login again, assuming the clientId remains the same accross the regions
            var apiClient = new ComputeApiClient(httpClient);

            var newCloudComputeConnection = new ComputeServiceConnection(apiClient, messageHandler);

            WriteDebug("Trying to login into the CaaS");

            await apiClient.LoginAsync();

            return(newCloudComputeConnection);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Try to login into the account using the credentials.
        ///     If succeed, it will return the account details.
        /// </summary>
        /// <returns>
        /// The CaaS connection
        /// </returns>
        private async Task <ComputeServiceConnection> LoginTask()
        {
            var ftpHost = string.Empty;
            ComputeApiClient apiClient = null;

            if (ParameterSetName == "KnownApiUri")
            {
                apiClient = ComputeApiClient.GetComputeApiClient(Vendor, Region, ApiCredentials.GetNetworkCredential());
                ftpHost   = ComputeApiClient.GetFtpHost(Vendor, Region);
            }

            if (ParameterSetName == "ApiDomainName")
            {
                var baseUri = new Uri(ApiDomainName);
                WriteWarning("This parameter is obselete and will not work for MCP2.0 commands, use Vendor and Region");
                apiClient = ComputeApiClient.GetComputeApiClient(baseUri, ApiCredentials.GetNetworkCredential());
                ftpHost   = ApiDomainName;
            }

            var newCloudComputeConnection = new ComputeServiceConnection(apiClient);

            WriteDebug("Trying to login into the CaaS");
            newCloudComputeConnection.Account = await newCloudComputeConnection.ApiClient.Login();

            // Right now we dont need to do a connect, as ftp is used in only a few commands
            newCloudComputeConnection.FtpClient = new FtpClient
            {
                Host                     = ftpHost,
                EncryptionMode           = FtpEncryptionMode.Explicit,
                DataConnectionEncryption = true,
                Credentials              = ApiCredentials.GetNetworkCredential()
                                           .GetCredential(new Uri(string.Format("ftp://{0}", ftpHost)), "Basic")
            };

            return(newCloudComputeConnection);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Try to login into the account using the credentials.
        ///     If succeed, it will return the account details.
        /// </summary>
        /// <returns>
        ///     The CaaS connection
        /// </returns>
        private async Task <ComputeServiceConnection> LoginTask()
        {
            string            ftpHost   = string.Empty;
            IComputeApiClient apiClient = null;
            var messageHandler          = GetMessageHandler(ApiCredentials.GetNetworkCredential());

            _logger = new HttpTraceLogger(this);
            messageHandler.LogEventHandler += _logger.LogRequestHandler;

            if (ParameterSetName == "KnownApiUri")
            {
                var baseUri = KnownApiUri.Instance.GetBaseUri(Vendor, Region);
                apiClient = GetComputeApiClient(baseUri, messageHandler);
                ftpHost   = ComputeApiClient.GetFtpHost(Vendor, Region);
            }

            if (ParameterSetName == "ApiDomainName")
            {
                Uri baseUri;
                // Support ApiDomainName containing https://
                if (Uri.TryCreate(ApiDomainName, UriKind.Absolute, out baseUri))
                {
                    ftpHost = baseUri.Host;
                }
                else
                {
                    // Support ApiDomainName as in just the domainName
                    baseUri = new Uri(string.Format("https://{0}/", ApiDomainName));
                    ftpHost = ApiDomainName;
                }

                // Handle explicit FTP host name
                if (!string.IsNullOrWhiteSpace(FtpDomainName))
                {
                    ftpHost = FtpDomainName;
                    Uri ftpUri;
                    if (Uri.TryCreate(FtpDomainName, UriKind.Absolute, out ftpUri))
                    {
                        ftpHost = ftpUri.Host;
                    }
                }

                apiClient = GetComputeApiClient(baseUri, messageHandler);
            }
            if (ParameterSetName == "HttpClient")
            {
                apiClient = new ComputeApiClient(new HttpClientAdapter(HttpClient));
            }

            var newCloudComputeConnection = new ComputeServiceConnection(apiClient, messageHandler);

            WriteDebug("Trying to login into the CaaS");
            newCloudComputeConnection.User = await apiClient.LoginAsync();

            // await newCloudComputeConnection.ApiClient.LoginAsync();

            if (!string.IsNullOrWhiteSpace(ftpHost))
            {
                // Right now we dont need to do a connect, as ftp is used in only a few commands
                newCloudComputeConnection.FtpClient = new FtpClient
                {
                    Host                     = ftpHost,
                    EncryptionMode           = FtpEncryptionMode.Explicit,
                    DataConnectionEncryption = true,
                    Credentials              = ApiCredentials.GetNetworkCredential()
                                               .GetCredential(new Uri(string.Format("ftp://{0}", ftpHost)), "Basic")
                };
            }
            messageHandler.LogEventHandler -= _logger.LogRequestHandler;
            return(newCloudComputeConnection);
        }
        /// <summary>
        /// Try to login into the account using the credentials.
        ///     If succeed, it will return the account details.
        /// </summary>
        /// <returns>
        /// The CaaS connection
        /// </returns>
        private async Task <ComputeServiceConnection> LoginTask()
        {
            ComputeApiClient apiClient = ComputeApiClient.GetComputeApiClient(Vendor, Region, ApiCredentials.GetNetworkCredential());

            var newCloudComputeConnection = new ComputeServiceConnection(apiClient);

            WriteDebug("Trying to login into the CaaS");

            await newCloudComputeConnection.ApiClient.Login();

            return(newCloudComputeConnection);
        }