Skip to content

Commit

Permalink
fix: InstanceType hint returns 500 in server mode
Browse files Browse the repository at this point in the history
  • Loading branch information
philasmar committed Jan 18, 2022
1 parent 8ef07dc commit e2a1c6d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/AWS.Deploy.CLI/Commands/TypeHints/InstanceTypeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ public InstanceTypeCommand(IAWSResourceQueryer awsResourceQueryer, IConsoleUtili
_consoleUtilities = consoleUtilities;
}

private async Task<List<InstanceTypeInfo>?> GetData(Recommendation recommendation, OptionSettingItem optionSetting)
private async Task<List<InstanceTypeInfo>?> GetData()
{
return await _awsResourceQueryer.ListOfAvailableInstanceTypes();
}

public async Task<List<TypeHintResource>?> 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<object> Execute(Recommendation recommendation, OptionSettingItem optionSetting)
{
var instanceTypes = await GetData(recommendation, optionSetting);
var instanceTypes = await GetData();
var instanceTypeDefaultValue = recommendation.GetOptionSettingDefaultValue<string>(optionSetting);
if (instanceTypes == null)
{
Expand Down
21 changes: 21 additions & 0 deletions src/AWS.Deploy.ServerMode.Client/ServerModeSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,27 @@ public bool TryGetRestAPIClient(Func<Task<AWSCredentials>> credentialsGenerator,
return true;
}

/// <summary>
/// Builds <see cref="IRestAPIClient"/> client based on a deploy tool server mode running on the specified port.
/// </summary>
public static bool TryGetRestAPIClient(int port, Aes? aes, Func<Task<AWSCredentials>> 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)
Expand Down

0 comments on commit e2a1c6d

Please sign in to comment.