Skip to content

Commit 531f785

Browse files
committed
commit 9
1 parent 9badd2e commit 531f785

16 files changed

+1112
-1514
lines changed

src/AWS.Deploy.CLI/Commands/DeleteDeploymentCommand.cs

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class DeleteDeploymentCommand : CancellableAsyncCommand<DeleteDeploymentC
3636
private readonly IAWSResourceQueryer _awsResourceQueryer;
3737
private const int MAX_RETRIES = 4;
3838

39+
/// <summary>
40+
/// Constructor for <see cref="DeleteDeploymentCommand"/>
41+
/// </summary>
3942
public DeleteDeploymentCommand(
4043
IAWSClientFactory awsClientFactory,
4144
IToolInteractiveService interactiveService,
@@ -58,7 +61,11 @@ public DeleteDeploymentCommand(
5861
/// <summary>
5962
/// Deletes given CloudFormation stack
6063
/// </summary>
64+
/// <param name="context">Command context</param>
65+
/// <param name="settings">Command settings</param>
66+
/// <param name="cancellationTokenSource">Cancellation token source</param>
6167
/// <exception cref="FailedToDeleteException">Thrown when deletion fails</exception>
68+
/// <returns>The command exit code</returns>
6269
public override async Task<int> ExecuteAsync(CommandContext context, DeleteDeploymentCommandSettings settings, CancellationTokenSource cancellationTokenSource)
6370
{
6471
_interactiveService.Diagnostics = settings.Diagnostics;

src/AWS.Deploy.CLI/Commands/DeployCommand.cs

+661-653
Large diffs are not rendered by default.

src/AWS.Deploy.CLI/Commands/GenerateDeploymentProjectCommand.cs

+204-201
Large diffs are not rendered by default.

src/AWS.Deploy.CLI/Commands/ListDeploymentsCommand.cs

+39-30
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,52 @@
1313
using AWS.Deploy.Orchestration.Utilities;
1414
using Spectre.Console.Cli;
1515

16-
namespace AWS.Deploy.CLI.Commands
16+
namespace AWS.Deploy.CLI.Commands;
17+
18+
/// <summary>
19+
/// Represents a List command that allows listing deployed applications
20+
/// </summary>
21+
public class ListDeploymentsCommand(
22+
IToolInteractiveService toolInteractiveService,
23+
IDeployedApplicationQueryer deployedApplicationQueryer,
24+
IAWSUtilities awsUtilities,
25+
IAWSClientFactory awsClientFactory,
26+
IAWSResourceQueryer awsResourceQueryer) : CancellableAsyncCommand<ListDeploymentsCommandSettings>
1727
{
18-
public class ListDeploymentsCommand(
19-
IToolInteractiveService toolInteractiveService,
20-
IDeployedApplicationQueryer deployedApplicationQueryer,
21-
IAWSUtilities awsUtilities,
22-
IAWSClientFactory awsClientFactory,
23-
IAWSResourceQueryer awsResourceQueryer) : CancellableAsyncCommand<ListDeploymentsCommandSettings>
28+
/// <summary>
29+
/// List deployed applications
30+
/// </summary>
31+
/// <param name="context">Command context</param>
32+
/// <param name="settings">Command settings</param>
33+
/// <param name="cancellationTokenSource">Cancellation token source</param>
34+
/// <returns>The command exit code</returns>
35+
public override async Task<int> ExecuteAsync(CommandContext context, ListDeploymentsCommandSettings settings, CancellationTokenSource cancellationTokenSource)
2436
{
25-
public override async Task<int> ExecuteAsync(CommandContext context, ListDeploymentsCommandSettings settings, CancellationTokenSource cancellationTokenSource)
26-
{
27-
toolInteractiveService.Diagnostics = settings.Diagnostics;
28-
29-
var (awsCredentials, regionFromProfile) = await awsUtilities.ResolveAWSCredentials(settings.Profile);
30-
var awsRegion = awsUtilities.ResolveAWSRegion(settings.Region ?? regionFromProfile);
37+
toolInteractiveService.Diagnostics = settings.Diagnostics;
3138

32-
awsClientFactory.ConfigureAWSOptions(awsOptions =>
33-
{
34-
awsOptions.Credentials = awsCredentials;
35-
awsOptions.Region = RegionEndpoint.GetBySystemName(awsRegion);
36-
});
39+
var (awsCredentials, regionFromProfile) = await awsUtilities.ResolveAWSCredentials(settings.Profile);
40+
var awsRegion = awsUtilities.ResolveAWSRegion(settings.Region ?? regionFromProfile);
3741

38-
await awsResourceQueryer.GetCallerIdentity(awsRegion);
42+
awsClientFactory.ConfigureAWSOptions(awsOptions =>
43+
{
44+
awsOptions.Credentials = awsCredentials;
45+
awsOptions.Region = RegionEndpoint.GetBySystemName(awsRegion);
46+
});
3947

40-
// Add Header
41-
toolInteractiveService.WriteLine();
42-
toolInteractiveService.WriteLine("Cloud Applications:");
43-
toolInteractiveService.WriteLine("-------------------");
48+
await awsResourceQueryer.GetCallerIdentity(awsRegion);
4449

45-
var deploymentTypes = new List<DeploymentTypes>(){ DeploymentTypes.CdkProject, DeploymentTypes.BeanstalkEnvironment };
46-
var existingApplications = await deployedApplicationQueryer.GetExistingDeployedApplications(deploymentTypes);
47-
foreach (var app in existingApplications)
48-
{
49-
toolInteractiveService.WriteLine(app.DisplayName);
50-
}
50+
// Add Header
51+
toolInteractiveService.WriteLine();
52+
toolInteractiveService.WriteLine("Cloud Applications:");
53+
toolInteractiveService.WriteLine("-------------------");
5154

52-
return CommandReturnCodes.SUCCESS;
55+
var deploymentTypes = new List<DeploymentTypes>(){ DeploymentTypes.CdkProject, DeploymentTypes.BeanstalkEnvironment };
56+
var existingApplications = await deployedApplicationQueryer.GetExistingDeployedApplications(deploymentTypes);
57+
foreach (var app in existingApplications)
58+
{
59+
toolInteractiveService.WriteLine(app.DisplayName);
5360
}
61+
62+
return CommandReturnCodes.SUCCESS;
5463
}
5564
}
+10-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
22
// SPDX-License-Identifier: Apache-2.0
33

4-
using System.Reflection;
54
using AWS.Deploy.CLI.Commands.Settings;
65
using AWS.Deploy.CLI.Utilities;
76
using Spectre.Console.Cli;
87

98
namespace AWS.Deploy.CLI.Commands;
109

10+
/// <summary>
11+
/// Represents the root command which displays information about the tool
12+
/// </summary>
1113
public class RootCommand(
1214
IToolInteractiveService toolInteractiveService) : Command<RootCommandSettings>
1315
{
16+
/// <summary>
17+
/// Displays information about the tool
18+
/// </summary>
19+
/// <param name="context">Command context</param>
20+
/// <param name="settings">Command settings</param>
21+
/// <returns>The command exit code</returns>
1422
public override int Execute(CommandContext context, RootCommandSettings settings)
1523
{
1624
if (settings.Version)
@@ -19,6 +27,6 @@ public override int Execute(CommandContext context, RootCommandSettings settings
1927
toolInteractiveService.WriteLine($"Version: {toolVersion}");
2028
}
2129

22-
return 0;
30+
return CommandReturnCodes.SUCCESS;
2331
}
2432
}

src/AWS.Deploy.CLI/Commands/ServerModeCommand.cs

+73-48
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,72 @@
1818

1919
namespace AWS.Deploy.CLI.Commands;
2020

21+
/// <summary>
22+
/// Represents a Server mode command that allows communication between this CLI and the AWS Toolkit for Visual Studio.
23+
/// </summary>
2124
public class ServerModeCommand(
2225
IToolInteractiveService toolInteractiveService) : CancellableAsyncCommand<ServerModeCommandSettings>
2326
{
27+
/// <summary>
28+
/// Runs tool in server mode
29+
/// </summary>
30+
/// <param name="context">Command context</param>
31+
/// <param name="settings">Command settings</param>
32+
/// <param name="cancellationTokenSource">Cancellation token source</param>
33+
/// <returns>The command exit code</returns>
34+
public override async Task<int> ExecuteAsync(CommandContext context, ServerModeCommandSettings settings, CancellationTokenSource cancellationTokenSource)
35+
{
36+
toolInteractiveService.Diagnostics = settings.Diagnostics;
37+
38+
toolInteractiveService.WriteLine("Server mode allows communication between this CLI and the AWS Toolkit for Visual Studio.");
39+
40+
IEncryptionProvider encryptionProvider = CreateEncryptionProvider(settings.UnsecureMode);
41+
42+
if (IsPortInUse(settings.Port))
43+
throw new TcpPortInUseException(DeployToolErrorCode.TcpPortInUse, "The port you have selected is currently in use by another process.");
44+
45+
var url = $"http://localhost:{settings.Port}";
46+
47+
var builder = new WebHostBuilder()
48+
.UseKestrel()
49+
.UseUrls(url)
50+
.ConfigureServices(services =>
51+
{
52+
services.AddSingleton<IEncryptionProvider>(encryptionProvider);
53+
})
54+
.UseStartup<Startup>();
55+
56+
var host = builder.Build();
57+
58+
if (settings.ParentPid.GetValueOrDefault() == 0)
59+
{
60+
await host.RunAsync(cancellationTokenSource.Token);
61+
}
62+
else
63+
{
64+
try
65+
{
66+
var process = Process.GetProcessById(settings.ParentPid.GetValueOrDefault());
67+
process.EnableRaisingEvents = true;
68+
process.Exited += async (sender, args) => { await ShutDownHost(host, cancellationTokenSource.Token); };
69+
}
70+
catch (Exception exception)
71+
{
72+
toolInteractiveService.WriteDebugLine(exception.PrettyPrint());
73+
return CommandReturnCodes.SUCCESS;
74+
}
75+
76+
await host.RunAsync(cancellationTokenSource.Token);
77+
}
78+
79+
return CommandReturnCodes.SUCCESS;
80+
}
81+
82+
/// <summary>
83+
/// Shuts down the web host
84+
/// </summary>
85+
/// <param name="host">Web host</param>
86+
/// <param name="cancellationToken">Cancellation token</param>
2487
private async Task ShutDownHost(IWebHost host, CancellationToken cancellationToken)
2588
{
2689
toolInteractiveService.WriteLine(string.Empty);
@@ -29,6 +92,11 @@ private async Task ShutDownHost(IWebHost host, CancellationToken cancellationTok
2992
await host.StopAsync(cancellationToken);
3093
}
3194

95+
/// <summary>
96+
/// Creates encryption provider
97+
/// </summary>
98+
/// <param name="noEncryptionKeyInfo">Indicates that no encryption key info will be provided</param>
99+
/// <returns>Encryption provider</returns>
32100
private IEncryptionProvider CreateEncryptionProvider(bool noEncryptionKeyInfo)
33101
{
34102
IEncryptionProvider encryptionProvider;
@@ -66,59 +134,16 @@ private IEncryptionProvider CreateEncryptionProvider(bool noEncryptionKeyInfo)
66134
return encryptionProvider;
67135
}
68136

137+
/// <summary>
138+
/// Checks if a port is in use
139+
/// </summary>
140+
/// <param name="port">Tcp port</param>
141+
/// <returns>true, if port is in use. false if not.</returns>
69142
private bool IsPortInUse(int port)
70143
{
71144
var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
72145
var listeners = ipGlobalProperties.GetActiveTcpListeners();
73146

74147
return listeners.Any(x => x.Port == port);
75148
}
76-
77-
public override async Task<int> ExecuteAsync(CommandContext context, ServerModeCommandSettings settings, CancellationTokenSource cancellationTokenSource)
78-
{
79-
toolInteractiveService.Diagnostics = settings.Diagnostics;
80-
81-
toolInteractiveService.WriteLine("Server mode allows communication between this CLI and the AWS Toolkit for Visual Studio.");
82-
83-
IEncryptionProvider encryptionProvider = CreateEncryptionProvider(settings.UnsecureMode);
84-
85-
if (IsPortInUse(settings.Port))
86-
throw new TcpPortInUseException(DeployToolErrorCode.TcpPortInUse, "The port you have selected is currently in use by another process.");
87-
88-
var url = $"http://localhost:{settings.Port}";
89-
90-
var builder = new WebHostBuilder()
91-
.UseKestrel()
92-
.UseUrls(url)
93-
.ConfigureServices(services =>
94-
{
95-
services.AddSingleton<IEncryptionProvider>(encryptionProvider);
96-
})
97-
.UseStartup<Startup>();
98-
99-
var host = builder.Build();
100-
101-
if (settings.ParentPid.GetValueOrDefault() == 0)
102-
{
103-
await host.RunAsync(cancellationTokenSource.Token);
104-
}
105-
else
106-
{
107-
try
108-
{
109-
var process = Process.GetProcessById(settings.ParentPid.GetValueOrDefault());
110-
process.EnableRaisingEvents = true;
111-
process.Exited += async (sender, args) => { await ShutDownHost(host, cancellationTokenSource.Token); };
112-
}
113-
catch (Exception exception)
114-
{
115-
toolInteractiveService.WriteDebugLine(exception.PrettyPrint());
116-
return CommandReturnCodes.SUCCESS;
117-
}
118-
119-
await host.RunAsync(cancellationTokenSource.Token);
120-
}
121-
122-
return CommandReturnCodes.SUCCESS;
123-
}
124149
}

src/AWS.Deploy.CLI/Commands/Settings/DeleteDeploymentCommandSettings.cs

+21
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,49 @@
77

88
namespace AWS.Deploy.CLI.Commands.Settings;
99

10+
/// <summary>
11+
/// Represents the settings for configuring the <see cref="DeleteDeploymentCommand"/>.
12+
/// </summary>
1013
public class DeleteDeploymentCommandSettings : CommandSettings
1114
{
15+
/// <summary>
16+
/// AWS credential profile used to make calls to AWS
17+
/// </summary>
1218
[CommandOption("--profile")]
1319
[Description("AWS credential profile used to make calls to AWS.")]
1420
public string? Profile { get; set; }
1521

22+
/// <summary>
23+
/// AWS region to deploy the application to
24+
/// </summary>
1625
[CommandOption("--region")]
1726
[Description("AWS region to deploy the application to. For example, us-west-2.")]
1827
public string? Region { get; set; }
1928

29+
/// <summary>
30+
/// Path to the project to deploy
31+
/// </summary>
2032
[CommandOption("--project-path")]
2133
[Description("Path to the project to deploy.")]
2234
public string ProjectPath { get; set; } = Directory.GetCurrentDirectory();
2335

36+
/// <summary>
37+
/// Enable diagnostic output
38+
/// </summary>
2439
[CommandOption("-d|--diagnostics")]
2540
[Description("Enable diagnostic output.")]
2641
public bool Diagnostics { get; set; }
2742

43+
/// <summary>
44+
/// Disable interactivity to execute commands without any prompts for user input
45+
/// </summary>
2846
[CommandOption("-s|--silent")]
2947
[Description("Disable interactivity to execute commands without any prompts for user input.")]
3048
public bool Silent { get; set; }
3149

50+
/// <summary>
51+
/// The name of the deployment to be deleted
52+
/// </summary>
3253
[CommandArgument(0, "<deployment-name>")]
3354
[Description("The name of the deployment to be deleted.")]
3455
public required string DeploymentName { get; set; }

0 commit comments

Comments
 (0)