/// <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); }
public static ComputeApiClient GetComputeClient(this ConnectionSettings connectionSettings) { // The Provisioning SDK currently only supports a single "default" connection // credential, consisting of a username and password pair (although these can also // be treated as API/secret keys). UserCredential defaultCredential = connectionSettings.Credentials["Default"]; // We support multiple service addresses, but REST APIs endpoints are typically just a // single address, so let's assume that pattern here. string endpoint = connectionSettings.ServiceAddresses[0]; // Create a client. return(ComputeApiClient.GetComputeApiClient(new System.Uri(endpoint), new NetworkCredential(defaultCredential.UserName, defaultCredential.Password))); }
/// <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); }