diff --git a/src/AWS.Deploy.CLI/Commands/TypeHints/InstanceTypeCommand.cs b/src/AWS.Deploy.CLI/Commands/TypeHints/InstanceTypeCommand.cs index 098b2b800..33c0ecea7 100644 --- a/src/AWS.Deploy.CLI/Commands/TypeHints/InstanceTypeCommand.cs +++ b/src/AWS.Deploy.CLI/Commands/TypeHints/InstanceTypeCommand.cs @@ -23,24 +23,24 @@ public InstanceTypeCommand(IAWSResourceQueryer awsResourceQueryer, IConsoleUtili _consoleUtilities = consoleUtilities; } - private async Task?> GetData(Recommendation recommendation, OptionSettingItem optionSetting) + private async Task?> GetData() { return await _awsResourceQueryer.ListOfAvailableInstanceTypes(); } public async Task?> GetResources(Recommendation recommendation, OptionSettingItem optionSetting) { - var instanceType = await GetData(recommendation, optionSetting); + var instanceType = await GetData(); + return instanceType? + .OrderBy(x => x.InstanceType.Value) .Select(x => new TypeHintResource(x.InstanceType.Value, x.InstanceType.Value)) - .Distinct() - .OrderBy(x => x) .ToList(); } public async Task Execute(Recommendation recommendation, OptionSettingItem optionSetting) { - var instanceTypes = await GetData(recommendation, optionSetting); + var instanceTypes = await GetData(); var instanceTypeDefaultValue = recommendation.GetOptionSettingDefaultValue(optionSetting); if (instanceTypes == null) { diff --git a/src/AWS.Deploy.ServerMode.Client/ServerModeSession.cs b/src/AWS.Deploy.ServerMode.Client/ServerModeSession.cs index 642930f57..84667a9c9 100644 --- a/src/AWS.Deploy.ServerMode.Client/ServerModeSession.cs +++ b/src/AWS.Deploy.ServerMode.Client/ServerModeSession.cs @@ -186,6 +186,27 @@ public bool TryGetRestAPIClient(Func> credentialsGenerator, return true; } + /// + /// Builds client based on a deploy tool server mode running on the specified port. + /// + public static bool TryGetRestAPIClient(int port, Aes? aes, Func> credentialsGenerator, out IRestAPIClient? restApiClient) + { + // This ensures that deploy tool CLI doesn't try on the in-use port + // because server availability task will return success response for + // an in-use port + if (!IsPortInUse(port)) + { + restApiClient = null; + throw new PortUnavailableException($"There is no running process on port {port}."); + } + + var baseUrl = $"http://localhost:{port}"; + + var httpClient = ServerModeHttpClientFactory.ConstructHttpClient(credentialsGenerator, aes); + restApiClient = new RestAPIClient(baseUrl, httpClient); + return true; + } + public bool TryGetDeploymentCommunicationClient(out IDeploymentCommunicationClient? deploymentCommunicationClient) { if (_baseUrl == null || _aes == null)