-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add DynamoDB, S3, SQS and SNS type hints
- Loading branch information
Showing
12 changed files
with
489 additions
and
1 deletion.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/AWS.Deploy.CLI/Commands/TypeHints/DynamoDBTableCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AWS.Deploy.Common; | ||
using AWS.Deploy.Common.Recipes; | ||
using AWS.Deploy.Common.TypeHintData; | ||
using AWS.Deploy.Orchestration.Data; | ||
|
||
namespace AWS.Deploy.CLI.Commands.TypeHints | ||
{ | ||
public class DynamoDBTableCommand : ITypeHintCommand | ||
{ | ||
private readonly IAWSResourceQueryer _awsResourceQueryer; | ||
private readonly IConsoleUtilities _consoleUtilities; | ||
|
||
public DynamoDBTableCommand(IAWSResourceQueryer awsResourceQueryer, IConsoleUtilities consoleUtilities) | ||
{ | ||
_awsResourceQueryer = awsResourceQueryer; | ||
_consoleUtilities = consoleUtilities; | ||
} | ||
|
||
private async Task<List<string>> GetData() | ||
{ | ||
return await _awsResourceQueryer.ListOfDyanmoDBTables(); | ||
} | ||
|
||
public async Task<List<TypeHintResource>?> GetResources(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
var tables = await GetData(); | ||
return tables.Select(tableName => new TypeHintResource(tableName, tableName)).ToList(); | ||
} | ||
|
||
public async Task<object> Execute(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
const string NO_VALUE = "*** Do not select table ***"; | ||
var currentValue = recommendation.GetOptionSettingValue(optionSetting); | ||
var tables = await GetData(); | ||
|
||
tables.Add(NO_VALUE); | ||
var userResponse = _consoleUtilities.AskUserToChoose( | ||
values: tables, | ||
title: "Select a DynamoDB table:", | ||
defaultValue: currentValue.ToString() ?? ""); | ||
|
||
return userResponse == null || string.Equals(NO_VALUE, userResponse, StringComparison.InvariantCultureIgnoreCase) ? string.Empty : userResponse; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/AWS.Deploy.CLI/Commands/TypeHints/S3BucketNameCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AWS.Deploy.Common; | ||
using AWS.Deploy.Common.Recipes; | ||
using AWS.Deploy.Common.TypeHintData; | ||
using AWS.Deploy.Orchestration.Data; | ||
using Amazon.S3.Model; | ||
|
||
namespace AWS.Deploy.CLI.Commands.TypeHints | ||
{ | ||
public class S3BucketNameCommand : ITypeHintCommand | ||
{ | ||
private readonly IAWSResourceQueryer _awsResourceQueryer; | ||
private readonly IConsoleUtilities _consoleUtilities; | ||
|
||
public S3BucketNameCommand(IAWSResourceQueryer awsResourceQueryer, IConsoleUtilities consoleUtilities) | ||
{ | ||
_awsResourceQueryer = awsResourceQueryer; | ||
_consoleUtilities = consoleUtilities; | ||
} | ||
|
||
private async Task<List<S3Bucket>> GetData() | ||
{ | ||
return await _awsResourceQueryer.ListOfS3Buckets(); | ||
} | ||
|
||
public async Task<List<TypeHintResource>?> GetResources(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
var buckets = await GetData(); | ||
return buckets.Select(bucket => new TypeHintResource(bucket.BucketName, bucket.BucketName)).ToList(); | ||
} | ||
|
||
public async Task<object> Execute(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
const string NO_VALUE = "*** Do not select bucket ***"; | ||
var currentValue = recommendation.GetOptionSettingValue(optionSetting); | ||
var buckets = (await GetData()).Select(bucket => bucket.BucketName).ToList(); | ||
|
||
buckets.Add(NO_VALUE); | ||
var userResponse = _consoleUtilities.AskUserToChoose( | ||
values: buckets, | ||
title: "Select a S3 bucket:", | ||
defaultValue: currentValue.ToString() ?? ""); | ||
|
||
return userResponse == null || string.Equals(NO_VALUE, userResponse, StringComparison.InvariantCultureIgnoreCase) ? string.Empty : userResponse; | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/AWS.Deploy.CLI/Commands/TypeHints/SNSTopicArnsCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AWS.Deploy.Common; | ||
using AWS.Deploy.Orchestration.Data; | ||
using AWS.Deploy.Common.Recipes; | ||
using AWS.Deploy.Common.TypeHintData; | ||
|
||
namespace AWS.Deploy.CLI.Commands.TypeHints | ||
{ | ||
public class SNSTopicArnsCommand : ITypeHintCommand | ||
{ | ||
private readonly IAWSResourceQueryer _awsResourceQueryer; | ||
private readonly IConsoleUtilities _consoleUtilities; | ||
|
||
public SNSTopicArnsCommand(IAWSResourceQueryer awsResourceQueryer, IConsoleUtilities consoleUtilities) | ||
{ | ||
_awsResourceQueryer = awsResourceQueryer; | ||
_consoleUtilities = consoleUtilities; | ||
} | ||
|
||
public async Task<List<TypeHintResource>?> GetResources(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
var topicArns = await _awsResourceQueryer.ListOfSNSTopicArns(); | ||
return topicArns.Select(topicArn => new TypeHintResource(topicArn, topicArn.Substring(topicArn.LastIndexOf(':') + 1))).ToList(); | ||
} | ||
|
||
public async Task<object> Execute(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
const string NO_VALUE = "*** Do not select topic ***"; | ||
var currentValue = recommendation.GetOptionSettingValue(optionSetting); | ||
var currentValueStr = currentValue.ToString() ?? string.Empty; | ||
var topicArns = await GetResources(recommendation, optionSetting); | ||
|
||
var topicNames = topicArns.Select(queue => queue.DisplayName).ToList(); | ||
var currentName = string.Empty; | ||
if (currentValue.ToString()?.LastIndexOf(':') != -1) | ||
{ | ||
currentName = currentValueStr.Substring(currentValueStr.LastIndexOf(':') + 1); | ||
} | ||
|
||
topicNames.Add(NO_VALUE); | ||
var userResponse = _consoleUtilities.AskUserToChoose( | ||
values: topicNames, | ||
title: "Select a SNS topic:", | ||
defaultValue: currentName); | ||
|
||
var selectedTopicArn = topicArns.FirstOrDefault(x => string.Equals(x.DisplayName, userResponse, StringComparison.OrdinalIgnoreCase)); | ||
return selectedTopicArn?.SystemName ?? string.Empty; | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/AWS.Deploy.CLI/Commands/TypeHints/SQSQueueUrlCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AWS.Deploy.Common; | ||
using AWS.Deploy.Common.Recipes; | ||
using AWS.Deploy.Common.TypeHintData; | ||
using AWS.Deploy.Orchestration.Data; | ||
|
||
namespace AWS.Deploy.CLI.Commands.TypeHints | ||
{ | ||
public class SQSQueueUrlCommand : ITypeHintCommand | ||
{ | ||
private readonly IAWSResourceQueryer _awsResourceQueryer; | ||
private readonly IConsoleUtilities _consoleUtilities; | ||
|
||
public SQSQueueUrlCommand(IAWSResourceQueryer awsResourceQueryer, IConsoleUtilities consoleUtilities) | ||
{ | ||
_awsResourceQueryer = awsResourceQueryer; | ||
_consoleUtilities = consoleUtilities; | ||
} | ||
|
||
public async Task<List<TypeHintResource>?> GetResources(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
var queueUrls = await _awsResourceQueryer.ListOfSQSQueuesUrls(); | ||
return queueUrls.Select(queueUrl => new TypeHintResource(queueUrl, queueUrl.Substring(queueUrl.LastIndexOf('/') + 1))).ToList(); | ||
} | ||
|
||
public async Task<object> Execute(Recommendation recommendation, OptionSettingItem optionSetting) | ||
{ | ||
const string NO_VALUE = "*** Do not select queue ***"; | ||
var currentValue = recommendation.GetOptionSettingValue(optionSetting); | ||
var currentValueStr = currentValue.ToString() ?? string.Empty; | ||
var queueUrls = await GetResources(recommendation, optionSetting); | ||
|
||
var queueNames = queueUrls.Select(queue => queue.DisplayName).ToList(); | ||
var currentName = string.Empty; | ||
if (currentValue.ToString()?.LastIndexOf('/') != -1) | ||
{ | ||
currentName = currentValueStr.Substring(currentValueStr.LastIndexOf('/') + 1); | ||
} | ||
|
||
queueNames.Add(NO_VALUE); | ||
var userResponse = _consoleUtilities.AskUserToChoose( | ||
values: queueNames, | ||
title: "Select a SQS queue:", | ||
defaultValue: currentName); | ||
|
||
var selectedQueueUrl = queueUrls.FirstOrDefault(x => string.Equals(x.DisplayName, userResponse, StringComparison.OrdinalIgnoreCase)); | ||
return selectedQueueUrl?.SystemName ?? string.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.