Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs-builder.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
<Project Path="src/authoring/Elastic.Documentation.Refactor/Elastic.Documentation.Refactor.csproj" />
</Folder>
<Folder Name="/src/infra/">
<Project Path="src/infra/docs-lambda-index-publisher/docs-lambda-index-publisher.csproj" />
<Project Path="src/infra/docs-lambda-index-publisher/docs-lambda-index-publisher.csproj" />
<Project Path="src/infra/docs-lambda-changelog-scrubber/docs-lambda-changelog-scrubber.csproj" />
</Folder>
<Folder Name="/src/services/">
<Project Path="src/services/Elastic.Changelog/Elastic.Changelog.csproj" />
Expand Down
18 changes: 17 additions & 1 deletion src/infra/docs-lambda-changelog-scrubber/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ IReadOnlyList<string> BuildAllowlist()

async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
{
using var s3Client = new AmazonS3Client();
var region = Amazon.RegionEndpoint.GetBySystemName(
Environment.GetEnvironmentVariable("AWS_REGION") ?? "us-east-1");
var credentials = new Amazon.Runtime.EnvironmentVariablesAWSCredentials();

using var s3Client = new AmazonS3Client(credentials, new AmazonS3Config
{
RegionEndpoint = region,
Timeout = TimeSpan.FromSeconds(10),
MaxErrorRetry = 2
});

var batchItemFailures = new List<SQSBatchResponse.BatchItemFailure>();

foreach (var message in ev.Records)
Expand Down Expand Up @@ -91,6 +101,7 @@ async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)

async Task DeleteFromPublicBucket(IAmazonS3 s3Client, string key, ILambdaContext context)
{
context.Logger.LogDebug($"Removing {key} from the public bucket", key);
try
{
_ = await s3Client.DeleteObjectAsync(new DeleteObjectRequest
Expand All @@ -108,6 +119,8 @@ async Task DeleteFromPublicBucket(IAmazonS3 s3Client, string key, ILambdaContext

async Task ScrubAndCopyToPublicBucket(IAmazonS3 s3Client, string sourceBucket, string key, ILambdaContext context)
{
context.Logger.LogDebug("Scrubbing {Key} to public bucket", key);

var fileName = Path.GetFileName(key);
if (string.Equals(fileName, "registry-index.json", StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -128,6 +141,7 @@ async Task ScrubAndCopyToPublicBucket(IAmazonS3 s3Client, string sourceBucket, s
return;
}

context.Logger.LogInformation("Getting {Key} from private bucket", key);
var getResponse = await s3Client.GetObjectAsync(new GetObjectRequest
{
BucketName = sourceBucket,
Expand All @@ -138,8 +152,10 @@ async Task ScrubAndCopyToPublicBucket(IAmazonS3 s3Client, string sourceBucket, s
using (var reader = new StreamReader(getResponse.ResponseStream))
content = await reader.ReadToEndAsync();

context.Logger.LogInformation("Performing scrub pass for {Key}", key);
var scrubbed = await ScrubContent(key, content, context);

context.Logger.LogInformation("Putting scrubbed {Key} on public bucket", key);
_ = await s3Client.PutObjectAsync(new PutObjectRequest
{
BucketName = publicBucketName,
Expand Down
Loading