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