@@ -21,8 +21,12 @@ public class AwsCloudFrontKeyValueStoreProxy(DiagnosticsCollector collector, IDi
21
21
{
22
22
public void UpdateRedirects ( string kvsName , IReadOnlyDictionary < string , string > sourcedRedirects )
23
23
{
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 ) )
26
30
return ;
27
31
28
32
var existingRedirects = ListAllKeys ( kvsArn ) ;
@@ -37,23 +41,43 @@ public void UpdateRedirects(string kvsName, IReadOnlyDictionary<string, string>
37
41
_ = ProcessBatchUpdates ( kvsArn , eTag , toDelete , KvsOperation . Deletes ) ;
38
42
}
39
43
40
- private ( string ? Arn , string ? ETag ) DescribeKeyValueStore ( string kvsName )
44
+ private string DescribeKeyValueStore ( string kvsName )
41
45
{
42
46
ConsoleApp . Log ( "Describing KeyValueStore" ) ;
43
47
try
44
48
{
45
49
var json = CaptureMultiple ( "aws" , "cloudfront" , "describe-key-value-store" , "--name" , kvsName ) ;
46
50
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 ;
49
53
50
54
Collector . EmitError ( "" , "Could not deserialize the DescribeKeyValueStoreResponse" ) ;
51
- return ( null , null ) ;
55
+ return string . Empty ;
52
56
}
53
57
catch ( Exception e )
54
58
{
55
59
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 ;
57
81
}
58
82
}
59
83
0 commit comments