Skip to content

Commit f7f6ef7

Browse files
authored
Acquire the proper ETag from Cloudfront-KeyValueStore's DescribeKeyValueStore (#1509)
* Acquire the proper ETag from Cloudfront-KeyValueStore's DescribeKeyValueStore.
1 parent 0a0db52 commit f7f6ef7

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

src/tooling/docs-assembler/Deploying/AwsCloudFrontKeyValueStoreProxy.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ public class AwsCloudFrontKeyValueStoreProxy(DiagnosticsCollector collector, IDi
2121
{
2222
public void UpdateRedirects(string kvsName, IReadOnlyDictionary<string, string> sourcedRedirects)
2323
{
24-
var (kvsArn, eTag) = DescribeKeyValueStore(kvsName);
25-
if (string.IsNullOrEmpty(kvsArn) || string.IsNullOrEmpty(eTag))
24+
var kvsArn = DescribeKeyValueStore(kvsName);
25+
if (string.IsNullOrEmpty(kvsArn))
26+
return;
27+
28+
var eTag = AcquireETag(kvsArn);
29+
if (string.IsNullOrEmpty(eTag))
2630
return;
2731

2832
var existingRedirects = ListAllKeys(kvsArn);
@@ -37,23 +41,43 @@ public void UpdateRedirects(string kvsName, IReadOnlyDictionary<string, string>
3741
_ = ProcessBatchUpdates(kvsArn, eTag, toDelete, KvsOperation.Deletes);
3842
}
3943

40-
private (string? Arn, string? ETag) DescribeKeyValueStore(string kvsName)
44+
private string DescribeKeyValueStore(string kvsName)
4145
{
4246
ConsoleApp.Log("Describing KeyValueStore");
4347
try
4448
{
4549
var json = CaptureMultiple("aws", "cloudfront", "describe-key-value-store", "--name", kvsName);
4650
var describeResponse = JsonSerializer.Deserialize<DescribeKeyValueStoreResponse>(string.Concat(json), AwsCloudFrontKeyValueStoreJsonContext.Default.DescribeKeyValueStoreResponse);
47-
if (describeResponse?.ETag is not null && describeResponse.KeyValueStore is { ARN.Length: > 0 })
48-
return (describeResponse.KeyValueStore.ARN, describeResponse.ETag);
51+
if (describeResponse?.KeyValueStore is { ARN.Length: > 0 })
52+
return describeResponse.KeyValueStore.ARN;
4953

5054
Collector.EmitError("", "Could not deserialize the DescribeKeyValueStoreResponse");
51-
return (null, null);
55+
return string.Empty;
5256
}
5357
catch (Exception e)
5458
{
5559
Collector.EmitError("", "An error occurred while describing the KeyValueStore", e);
56-
return (null, null);
60+
return string.Empty;
61+
}
62+
}
63+
64+
private string AcquireETag(string kvsArn)
65+
{
66+
ConsoleApp.Log("Acquiring ETag for updates");
67+
try
68+
{
69+
var json = CaptureMultiple("aws", "cloudfront-keyvaluestore", "describe-key-value-store", "--kvs-arn", kvsArn);
70+
var describeResponse = JsonSerializer.Deserialize<DescribeKeyValueStoreResponse>(string.Concat(json), AwsCloudFrontKeyValueStoreJsonContext.Default.DescribeKeyValueStoreResponse);
71+
if (describeResponse?.ETag is not null)
72+
return describeResponse.ETag;
73+
74+
Collector.EmitError("", "Could not deserialize Cloudfront-KeyValueStore:DescribeKeyValueStoreResponse");
75+
return string.Empty;
76+
}
77+
catch (Exception e)
78+
{
79+
Collector.EmitError("", "An error occurred while calling Cloudfront-KeyValueStore:DescribeKeyValueStore", e);
80+
return string.Empty;
5781
}
5882
}
5983

0 commit comments

Comments
 (0)