Skip to content

Commit adf8f11

Browse files
committed
Update docs for amazon-sqs transport along with config validation
1 parent cb9f6b3 commit adf8f11

File tree

6 files changed

+99
-35
lines changed

6 files changed

+99
-35
lines changed

src/BuslyCLI.Console/Config/AmazonsqsTransportConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
public class AmazonsqsTransportConfig : ITransportConfig
55
{
6+
7+
// Local Stack Only
68
public string ServiceUrl { get; set; }
79
public string RegionName { get; set; }
10+
public string AccessKey { get; set; }
11+
public string SecretKey { get; set; }
12+
813
}

src/BuslyCLI.Console/Config/Validators/AmazonsqsTransportConfigValidator.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ public AmazonsqsTransportConfigValidator()
99
RuleFor(x => x.RegionName)
1010
.NotEmpty();
1111

12-
RuleFor(x => x.ServiceUrl)
13-
.NotEmpty();
12+
RuleFor(x => x)
13+
.Must(x =>
14+
(string.IsNullOrEmpty(x.AccessKey) && string.IsNullOrEmpty(x.SecretKey)) // both empty
15+
|| (!string.IsNullOrEmpty(x.AccessKey) && !string.IsNullOrEmpty(x.SecretKey)) // both set
16+
)
17+
.WithMessage("AWS AccessKey and SecretKey are mutually dependent: if one is set, the other must also be set.");
1418
}
1519
}

src/BuslyCLI.Console/Factories/RawEndpointFactory.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Amazon.Runtime;
1+
using Amazon;
2+
using Amazon.Runtime;
23
using Amazon.SimpleNotificationService;
34
using Amazon.SQS;
45
using BuslyCLI.Config;
@@ -73,19 +74,27 @@ private static ManagementApiConfiguration CreateManagementApiConfig(ManagementAp
7374

7475
private TransportDefinition CreateAmazonSQSTransport(AmazonsqsTransportConfig amazonsqsTransportConfig)
7576
{
76-
var credentials = new BasicAWSCredentials("test", "test");
77-
78-
var sqsClient = new AmazonSQSClient(credentials, new AmazonSQSConfig
77+
var credentials = new BasicAWSCredentials(amazonsqsTransportConfig.AccessKey, amazonsqsTransportConfig.SecretKey);
78+
var amazonSqsConfig = new AmazonSQSConfig();
79+
var amazonSnsConfig = new AmazonSimpleNotificationServiceConfig();
80+
if (!string.IsNullOrWhiteSpace(amazonsqsTransportConfig.RegionName))
7981
{
80-
ServiceURL = amazonsqsTransportConfig.ServiceUrl,
81-
AuthenticationRegion = amazonsqsTransportConfig.RegionName,
82-
});
8382

84-
var snsClient = new AmazonSimpleNotificationServiceClient(credentials, new AmazonSimpleNotificationServiceConfig
83+
amazonSqsConfig.RegionEndpoint = RegionEndpoint.GetBySystemName(amazonsqsTransportConfig.RegionName);
84+
amazonSnsConfig.RegionEndpoint = RegionEndpoint.GetBySystemName(amazonsqsTransportConfig.RegionName);
85+
}
86+
87+
// If ServiceUrl is passed, we are assuming we are using LocalStack
88+
// Without this, local stack will try to really authenticate with aws which will fail
89+
if (!string.IsNullOrWhiteSpace(amazonsqsTransportConfig.ServiceUrl))
8590
{
86-
ServiceURL = amazonsqsTransportConfig.ServiceUrl,
87-
AuthenticationRegion = amazonsqsTransportConfig.RegionName,
88-
});
91+
amazonSnsConfig.ServiceURL = amazonsqsTransportConfig.ServiceUrl;
92+
amazonSqsConfig.ServiceURL = amazonsqsTransportConfig.ServiceUrl;
93+
}
94+
95+
var sqsClient = new AmazonSQSClient(credentials, amazonSqsConfig);
96+
97+
var snsClient = new AmazonSimpleNotificationServiceClient(credentials, amazonSnsConfig);
8998

9099
return new SqsTransport(sqsClient, snsClient);
91100
}

tests/BuslyCLI.Console.Tests/Config/Validators/AmazonsqsTransportConfigValidatorTests.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,49 @@ public async Task ShouldNotErrorWhenRegionNameIsPassed()
4747
}
4848

4949
[Test]
50-
public async Task ShouldErrorWhenServiceUrlIsNotPassed()
50+
public async Task ShouldNotErrorWhenServiceUrlIsPassed()
5151
{
5252
// Arrange
5353
var amazonsqsTransportConfig = new AmazonsqsTransportConfig
5454
{
55-
RegionName = null
55+
ServiceUrl = "us-east-1"
5656
};
57+
// Act
58+
var result = await _validator.TestValidateAsync(amazonsqsTransportConfig);
59+
60+
// Assert
61+
result.ShouldNotHaveValidationErrorFor(c => c.ServiceUrl);
62+
}
5763

64+
[Test]
65+
public async Task ShouldErrorWhenAccessKeyIsPassedWithoutSecretKey()
66+
{
67+
// Arrange
68+
var amazonsqsTransportConfig = new AmazonsqsTransportConfig()
69+
{
70+
AccessKey = "BLAHBLAHBLAH",
71+
SecretKey = null
72+
};
5873
// Act
5974
var result = await _validator.TestValidateAsync(amazonsqsTransportConfig);
6075

6176
// Assert
62-
result.ShouldHaveValidationErrorFor(c => c.ServiceUrl)
63-
.WithErrorMessage("'Service Url' must not be empty.");
77+
result.ShouldHaveValidationErrors().WithErrorMessage("AWS AccessKey and SecretKey are mutually dependent: if one is set, the other must also be set.");
6478
}
6579

6680
[Test]
67-
public async Task ShouldNotErrorWhenServiceUrlIsPassed()
81+
public async Task ShouldErrorWhenSecretIsPassedWithoutAccessKey()
6882
{
6983
// Arrange
70-
var amazonsqsTransportConfig = new AmazonsqsTransportConfig
84+
var amazonsqsTransportConfig = new AmazonsqsTransportConfig()
7185
{
72-
ServiceUrl = "us-east-1"
86+
AccessKey = null,
87+
SecretKey = "BLAHBLAHBLAH"
7388
};
7489
// Act
7590
var result = await _validator.TestValidateAsync(amazonsqsTransportConfig);
7691

7792
// Assert
78-
result.ShouldNotHaveValidationErrorFor(c => c.ServiceUrl);
93+
result.ShouldHaveValidationErrors().WithErrorMessage("AWS AccessKey and SecretKey are mutually dependent: if one is set, the other must also be set.");
7994
}
8095
}
Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Amazon SQS
22

3-
The **Amazon SQS Transport** is used to communicate to Amazon SQS.
3+
The **Amazon SQS Transport** is used to communicate to Amazon SQS. It is suitable for development, testing, and production environments.
44

55
## Configuration
66

@@ -14,46 +14,75 @@ current-transport: local-stack-amazon-sqs
1414
transports:
1515
- name: local-stack-amazon-sqs
1616
amazonsqs-transport-config:
17-
service-url: http://127.0.0.1:32813/
1817
region-name: us-east-1
18+
access-key: test
19+
secret-key: test
20+
service-url: http://127.0.0.1:32813/ # (optional) Only used when connecting to local-stack
1921
```
2022
2123
:::info
2224
23-
The Amazon SQS transport implementation currently works only with the LocalStack emulator.
24-
Pull requests to improve functionality or add support for live AWS SQS are welcome and much appreciated!
25+
The Amazon SQS transport implementation currently works only with **AWS access key and secret key authentication**. Pull requests that add support for additional authentication methods are welcome and greatly appreciated!
2526
2627
:::
2728
2829
---
2930
3031
## `amazonsqs-transport-config` Fields
3132

32-
| Field | Required | Type | Default | Description |
33-
| ------------- | -------- | ------ | ------- | ------------------------------- |
34-
| `service-url` | **Yes** | string | — | The Service Url for Amazon SQS. |
35-
| `region-name` | **Yes** | string | — | The region (EX: us-east-1). |
33+
| Field | Required | Type | Default | Description |
34+
| ------------- | -------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
35+
| `region-name` | **Yes** | string | — | The AWS region. All Region codes can be found [here](https://docs.aws.amazon.com/global-infrastructure/latest/regions/aws-regions.html) (EX: us-east-1, us-east2, us-west1..etc). |
36+
| `access-key` | **Yes** | string | — | The AWS Access Key. |
37+
| `secret-key` | **Yes** | string | — | The AWS Secret Key. |
38+
| `service-url` | No | string | — | The service URL used to connect to LocalStack for local development. |
3639

3740
---
3841

3942
## Field Details
4043

41-
### `service-url` (required)
44+
### `region-name` (required)
4245

43-
The Service Url for Amazon SQS.
46+
The AWS Region SQS is hosted in.
4447

4548
Examples:
4649

4750
```yaml
48-
service-url: http://127.0.0.1:32813/
51+
region-name: us-east-1
4952
```
5053

51-
### `region-name` (optional)
54+
---
55+
56+
### `access-key` (required)
5257

53-
Allows Busly to interact with the RabbitMQ Management API for monitoring or queue management.
58+
The AWS Access Key.
5459

5560
Examples:
5661

5762
```yaml
58-
region-name: us-east-1
63+
access-key: test
64+
```
65+
66+
---
67+
68+
### `secret-key` (required)
69+
70+
The AWS Secret Key.
71+
72+
Examples:
73+
74+
```yaml
75+
secret-key: test
76+
```
77+
78+
---
79+
80+
### `service-url` (optional)
81+
82+
The service URL used to connect to LocalStack for local development.
83+
84+
Examples:
85+
86+
```yaml
87+
service-url: http://127.0.0.1:32813/
5988
```

website/docs/transports/rabbitmq.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ amqp-connection-string: amqp://guest:guest@localhost:5672/
5555
amqp-connection-string: amqps://user:[email protected]:5671/my-vhost
5656
```
5757

58+
---
59+
5860
### `management-api` (optional)
5961

6062
Allows Busly to interact with the RabbitMQ Management API for monitoring or queue management.

0 commit comments

Comments
 (0)