From 5faed5fa3ffa338a3330507466362d4aff4d4485 Mon Sep 17 00:00:00 2001 From: aws-sdk-dotnet-automation Date: Sat, 28 Dec 2024 04:25:59 +0000 Subject: [PATCH] Restoring custom endpoint functionality for ECR Public --- ...r-public-2020-10-30.endpoint-rule-set.json | 263 ++++++++++++-- .../ecr-public-2020-10-30.endpoint-tests.json | 293 +++++++++++++-- .../AmazonECRPublicEndpointParameters.cs | 19 +- .../AmazonECRPublicEndpointProvider.cs | 47 ++- .../AmazonECRPublicEndpointResolver.cs | 3 +- .../ECRPublicEndpointProviderTests.cs | 335 +++++++++++++++++- 6 files changed, 865 insertions(+), 95 deletions(-) diff --git a/generator/ServiceModels/ecr-public/ecr-public-2020-10-30.endpoint-rule-set.json b/generator/ServiceModels/ecr-public/ecr-public-2020-10-30.endpoint-rule-set.json index 32e8d26a884e..9485fb713f1b 100644 --- a/generator/ServiceModels/ecr-public/ecr-public-2020-10-30.endpoint-rule-set.json +++ b/generator/ServiceModels/ecr-public/ecr-public-2020-10-30.endpoint-rule-set.json @@ -7,19 +7,25 @@ "documentation": "The AWS region used to dispatch the request.", "type": "String" }, - "UseFIPS": { - "builtIn": "AWS::UseFIPS", + "UseDualStack": { + "builtIn": "AWS::UseDualStack", "required": true, "default": false, - "documentation": "When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.", + "documentation": "When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.", "type": "Boolean" }, - "UseDualStack": { - "builtIn": "AWS::UseDualStack", + "UseFIPS": { + "builtIn": "AWS::UseFIPS", "required": true, "default": false, - "documentation": "When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.", + "documentation": "When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.", "type": "Boolean" + }, + "Endpoint": { + "builtIn": "SDK::Endpoint", + "required": false, + "documentation": "Override the endpoint used to send this request", + "type": "String" } }, "rules": [ @@ -29,18 +35,9 @@ "fn": "isSet", "argv": [ { - "ref": "Region" + "ref": "Endpoint" } ] - }, - { - "fn": "aws.partition", - "argv": [ - { - "ref": "Region" - } - ], - "assign": "PartitionResult" } ], "rules": [ @@ -56,7 +53,7 @@ ] } ], - "error": "ECR Public does not support FIPS", + "error": "Invalid Configuration: FIPS and custom endpoint are not supported", "type": "error" }, { @@ -71,57 +68,247 @@ ] } ], + "error": "Invalid Configuration: Dualstack and custom endpoint are not supported", + "type": "error" + }, + { + "conditions": [], + "endpoint": { + "url": { + "ref": "Endpoint" + }, + "properties": {}, + "headers": {} + }, + "type": "endpoint" + } + ], + "type": "tree" + }, + { + "conditions": [ + { + "fn": "isSet", + "argv": [ + { + "ref": "Region" + } + ] + } + ], + "rules": [ + { + "conditions": [ + { + "fn": "aws.partition", + "argv": [ + { + "ref": "Region" + } + ], + "assign": "PartitionResult" + } + ], "rules": [ { "conditions": [ { "fn": "booleanEquals", "argv": [ - true, { - "fn": "getAttr", + "ref": "UseFIPS" + }, + true + ] + }, + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "UseDualStack" + }, + true + ] + } + ], + "rules": [ + { + "conditions": [ + { + "fn": "booleanEquals", "argv": [ + true, { - "ref": "PartitionResult" + "fn": "getAttr", + "argv": [ + { + "ref": "PartitionResult" + }, + "supportsFIPS" + ] + } + ] + }, + { + "fn": "booleanEquals", + "argv": [ + true, + { + "fn": "getAttr", + "argv": [ + { + "ref": "PartitionResult" + }, + "supportsDualStack" + ] + } + ] + } + ], + "rules": [ + { + "conditions": [], + "endpoint": { + "url": "https://api.ecr-public-fips.{Region}.{PartitionResult#dualStackDnsSuffix}", + "properties": {}, + "headers": {} + }, + "type": "endpoint" + } + ], + "type": "tree" + }, + { + "conditions": [], + "error": "FIPS and DualStack are enabled, but this partition does not support one or both", + "type": "error" + } + ], + "type": "tree" + }, + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "UseFIPS" + }, + true + ] + } + ], + "rules": [ + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + { + "fn": "getAttr", + "argv": [ + { + "ref": "PartitionResult" + }, + "supportsFIPS" + ] }, - "supportsDualStack" + true ] } + ], + "rules": [ + { + "conditions": [], + "endpoint": { + "url": "https://api.ecr-public-fips.{Region}.{PartitionResult#dnsSuffix}", + "properties": {}, + "headers": {} + }, + "type": "endpoint" + } + ], + "type": "tree" + }, + { + "conditions": [], + "error": "FIPS is enabled but this partition does not support FIPS", + "type": "error" + } + ], + "type": "tree" + }, + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + { + "ref": "UseDualStack" + }, + true ] } ], "rules": [ + { + "conditions": [ + { + "fn": "booleanEquals", + "argv": [ + true, + { + "fn": "getAttr", + "argv": [ + { + "ref": "PartitionResult" + }, + "supportsDualStack" + ] + } + ] + } + ], + "rules": [ + { + "conditions": [], + "endpoint": { + "url": "https://api.ecr-public.{Region}.{PartitionResult#dualStackDnsSuffix}", + "properties": {}, + "headers": {} + }, + "type": "endpoint" + } + ], + "type": "tree" + }, { "conditions": [], - "endpoint": { - "url": "https://ecr-public.{Region}.{PartitionResult#dualStackDnsSuffix}", - "properties": {}, - "headers": {} - }, - "type": "endpoint" + "error": "DualStack is enabled but this partition does not support DualStack", + "type": "error" } ], "type": "tree" }, { "conditions": [], - "error": "Dualstack is enabled but this partition does not support dualstack", - "type": "error" + "endpoint": { + "url": "https://api.ecr-public.{Region}.{PartitionResult#dnsSuffix}", + "properties": {}, + "headers": {} + }, + "type": "endpoint" } ], "type": "tree" - }, - { - "conditions": [], - "endpoint": { - "url": "https://api.ecr-public.{Region}.{PartitionResult#dnsSuffix}", - "properties": {}, - "headers": {} - }, - "type": "endpoint" } ], "type": "tree" + }, + { + "conditions": [], + "error": "Invalid Configuration: Missing Region", + "type": "error" } ] } \ No newline at end of file diff --git a/generator/ServiceModels/ecr-public/ecr-public-2020-10-30.endpoint-tests.json b/generator/ServiceModels/ecr-public/ecr-public-2020-10-30.endpoint-tests.json index 54a8c84adadb..a5d16d9e714a 100644 --- a/generator/ServiceModels/ecr-public/ecr-public-2020-10-30.endpoint-tests.json +++ b/generator/ServiceModels/ecr-public/ecr-public-2020-10-30.endpoint-tests.json @@ -1,69 +1,312 @@ { "testCases": [ { - "documentation": "Valid with dualstack and FIPS disabled. i.e, IPv4 Only stack with no FIPS, with special prefix", + "documentation": "For region us-east-1 with FIPS enabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public-fips.us-east-1.api.aws" + } + }, + "params": { + "Region": "us-east-1", + "UseFIPS": true, + "UseDualStack": true + } + }, + { + "documentation": "For region us-east-1 with FIPS enabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public-fips.us-east-1.amazonaws.com" + } + }, + "params": { + "Region": "us-east-1", + "UseFIPS": true, + "UseDualStack": false + } + }, + { + "documentation": "For region us-east-1 with FIPS disabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public.us-east-1.api.aws" + } + }, + "params": { + "Region": "us-east-1", + "UseFIPS": false, + "UseDualStack": true + } + }, + { + "documentation": "For region us-east-1 with FIPS disabled and DualStack disabled", "expect": { "endpoint": { "url": "https://api.ecr-public.us-east-1.amazonaws.com" } }, - "operationInputs": [ - { - "builtInParams": { - "AWS::Region": "us-east-1" - }, - "operationName": "DescribeRegistries" + "params": { + "Region": "us-east-1", + "UseFIPS": false, + "UseDualStack": false + } + }, + { + "documentation": "For region cn-north-1 with FIPS enabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public-fips.cn-north-1.api.amazonwebservices.com.cn" } - ], + }, "params": { - "UseDualStack": false, + "Region": "cn-north-1", + "UseFIPS": true, + "UseDualStack": true + } + }, + { + "documentation": "For region cn-north-1 with FIPS enabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public-fips.cn-north-1.amazonaws.com.cn" + } + }, + "params": { + "Region": "cn-north-1", + "UseFIPS": true, + "UseDualStack": false + } + }, + { + "documentation": "For region cn-north-1 with FIPS disabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public.cn-north-1.api.amazonwebservices.com.cn" + } + }, + "params": { + "Region": "cn-north-1", "UseFIPS": false, - "Region": "us-east-1" + "UseDualStack": true } }, { - "documentation": "Valid with dualstack enabled", + "documentation": "For region cn-north-1 with FIPS disabled and DualStack disabled", "expect": { "endpoint": { - "url": "https://ecr-public.us-east-1.api.aws" + "url": "https://api.ecr-public.cn-north-1.amazonaws.com.cn" } }, "params": { - "UseDualStack": true, + "Region": "cn-north-1", "UseFIPS": false, - "Region": "us-east-1" + "UseDualStack": false } }, { - "documentation": "Invalid with FIPS set, dualstack disabled", + "documentation": "For region us-gov-east-1 with FIPS enabled and DualStack enabled", "expect": { - "error": "ECR Public does not support FIPS" + "endpoint": { + "url": "https://api.ecr-public-fips.us-gov-east-1.api.aws" + } }, "params": { - "UseDualStack": false, + "Region": "us-gov-east-1", "UseFIPS": true, - "Region": "us-east-1" + "UseDualStack": true } }, { - "documentation": "Invalid with both dualstack and FIPS enabled", + "documentation": "For region us-gov-east-1 with FIPS enabled and DualStack disabled", "expect": { - "error": "ECR Public does not support FIPS" + "endpoint": { + "url": "https://api.ecr-public-fips.us-gov-east-1.amazonaws.com" + } }, "params": { - "UseDualStack": true, + "Region": "us-gov-east-1", + "UseFIPS": true, + "UseDualStack": false + } + }, + { + "documentation": "For region us-gov-east-1 with FIPS disabled and DualStack enabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public.us-gov-east-1.api.aws" + } + }, + "params": { + "Region": "us-gov-east-1", + "UseFIPS": false, + "UseDualStack": true + } + }, + { + "documentation": "For region us-gov-east-1 with FIPS disabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public.us-gov-east-1.amazonaws.com" + } + }, + "params": { + "Region": "us-gov-east-1", + "UseFIPS": false, + "UseDualStack": false + } + }, + { + "documentation": "For region us-iso-east-1 with FIPS enabled and DualStack enabled", + "expect": { + "error": "FIPS and DualStack are enabled, but this partition does not support one or both" + }, + "params": { + "Region": "us-iso-east-1", + "UseFIPS": true, + "UseDualStack": true + } + }, + { + "documentation": "For region us-iso-east-1 with FIPS enabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public-fips.us-iso-east-1.c2s.ic.gov" + } + }, + "params": { + "Region": "us-iso-east-1", + "UseFIPS": true, + "UseDualStack": false + } + }, + { + "documentation": "For region us-iso-east-1 with FIPS disabled and DualStack enabled", + "expect": { + "error": "DualStack is enabled but this partition does not support DualStack" + }, + "params": { + "Region": "us-iso-east-1", + "UseFIPS": false, + "UseDualStack": true + } + }, + { + "documentation": "For region us-iso-east-1 with FIPS disabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public.us-iso-east-1.c2s.ic.gov" + } + }, + "params": { + "Region": "us-iso-east-1", + "UseFIPS": false, + "UseDualStack": false + } + }, + { + "documentation": "For region us-isob-east-1 with FIPS enabled and DualStack enabled", + "expect": { + "error": "FIPS and DualStack are enabled, but this partition does not support one or both" + }, + "params": { + "Region": "us-isob-east-1", + "UseFIPS": true, + "UseDualStack": true + } + }, + { + "documentation": "For region us-isob-east-1 with FIPS enabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public-fips.us-isob-east-1.sc2s.sgov.gov" + } + }, + "params": { + "Region": "us-isob-east-1", + "UseFIPS": true, + "UseDualStack": false + } + }, + { + "documentation": "For region us-isob-east-1 with FIPS disabled and DualStack enabled", + "expect": { + "error": "DualStack is enabled but this partition does not support DualStack" + }, + "params": { + "Region": "us-isob-east-1", + "UseFIPS": false, + "UseDualStack": true + } + }, + { + "documentation": "For region us-isob-east-1 with FIPS disabled and DualStack disabled", + "expect": { + "endpoint": { + "url": "https://api.ecr-public.us-isob-east-1.sc2s.sgov.gov" + } + }, + "params": { + "Region": "us-isob-east-1", + "UseFIPS": false, + "UseDualStack": false + } + }, + { + "documentation": "For custom endpoint with region set and fips disabled and dualstack disabled", + "expect": { + "endpoint": { + "url": "https://example.com" + } + }, + "params": { + "Region": "us-east-1", + "UseFIPS": false, + "UseDualStack": false, + "Endpoint": "https://example.com" + } + }, + { + "documentation": "For custom endpoint with region not set and fips disabled and dualstack disabled", + "expect": { + "endpoint": { + "url": "https://example.com" + } + }, + "params": { + "UseFIPS": false, + "UseDualStack": false, + "Endpoint": "https://example.com" + } + }, + { + "documentation": "For custom endpoint with fips enabled and dualstack disabled", + "expect": { + "error": "Invalid Configuration: FIPS and custom endpoint are not supported" + }, + "params": { + "Region": "us-east-1", "UseFIPS": true, - "Region": "us-east-1" + "UseDualStack": false, + "Endpoint": "https://example.com" } }, { - "documentation": "Invalid with DualStack enabled and partition does not support Dualstack", + "documentation": "For custom endpoint with fips disabled and dualstack enabled", "expect": { - "error": "Dualstack is enabled but this partition does not support dualstack" + "error": "Invalid Configuration: Dualstack and custom endpoint are not supported" }, "params": { + "Region": "us-east-1", + "UseFIPS": false, "UseDualStack": true, - "Region": "us-isob-east-1" + "Endpoint": "https://example.com" + } + }, + { + "documentation": "Missing region", + "expect": { + "error": "Invalid Configuration: Missing Region" } } ], diff --git a/sdk/src/Services/ECRPublic/Generated/AmazonECRPublicEndpointParameters.cs b/sdk/src/Services/ECRPublic/Generated/AmazonECRPublicEndpointParameters.cs index 73cc67a3a0b4..b28a2594a475 100644 --- a/sdk/src/Services/ECRPublic/Generated/AmazonECRPublicEndpointParameters.cs +++ b/sdk/src/Services/ECRPublic/Generated/AmazonECRPublicEndpointParameters.cs @@ -36,8 +36,8 @@ public class ECRPublicEndpointParameters : EndpointParameters /// public ECRPublicEndpointParameters() { - UseFIPS = false; UseDualStack = false; + UseFIPS = false; } /// @@ -49,6 +49,15 @@ public string Region set { this["Region"] = value; } } + /// + /// UseDualStack parameter + /// + public bool? UseDualStack + { + get { return (bool?)this["UseDualStack"]; } + set { this["UseDualStack"] = value; } + } + /// /// UseFIPS parameter /// @@ -59,12 +68,12 @@ public bool? UseFIPS } /// - /// UseDualStack parameter + /// Endpoint parameter /// - public bool? UseDualStack + public string Endpoint { - get { return (bool?)this["UseDualStack"]; } - set { this["UseDualStack"] = value; } + get { return (string)this["Endpoint"]; } + set { this["Endpoint"] = value; } } } } \ No newline at end of file diff --git a/sdk/src/Services/ECRPublic/Generated/Internal/AmazonECRPublicEndpointProvider.cs b/sdk/src/Services/ECRPublic/Generated/Internal/AmazonECRPublicEndpointProvider.cs index d0adbcf36d4f..88c38aa40ac2 100644 --- a/sdk/src/Services/ECRPublic/Generated/Internal/AmazonECRPublicEndpointProvider.cs +++ b/sdk/src/Services/ECRPublic/Generated/Internal/AmazonECRPublicEndpointProvider.cs @@ -40,33 +40,62 @@ public Endpoint ResolveEndpoint(EndpointParameters parameters) if (parameters == null) throw new ArgumentNullException("parameters"); - if (parameters["UseFIPS"] == null) - throw new AmazonClientException("UseFIPS parameter must be set for endpoint resolution"); if (parameters["UseDualStack"] == null) throw new AmazonClientException("UseDualStack parameter must be set for endpoint resolution"); + if (parameters["UseFIPS"] == null) + throw new AmazonClientException("UseFIPS parameter must be set for endpoint resolution"); var refs = new Dictionary() { ["Region"] = parameters["Region"], - ["UseFIPS"] = parameters["UseFIPS"], ["UseDualStack"] = parameters["UseDualStack"], + ["UseFIPS"] = parameters["UseFIPS"], + ["Endpoint"] = parameters["Endpoint"], }; - if (IsSet(refs["Region"]) && (refs["PartitionResult"] = Partition((string)refs["Region"])) != null) + if (IsSet(refs["Endpoint"])) { if (Equals(refs["UseFIPS"], true)) { - throw new AmazonClientException("ECR Public does not support FIPS"); + throw new AmazonClientException("Invalid Configuration: FIPS and custom endpoint are not supported"); } if (Equals(refs["UseDualStack"], true)) { - if (Equals(true, GetAttr(refs["PartitionResult"], "supportsDualStack"))) + throw new AmazonClientException("Invalid Configuration: Dualstack and custom endpoint are not supported"); + } + return new Endpoint((string)refs["Endpoint"], InterpolateJson(@"", refs), InterpolateJson(@"", refs)); + } + if (IsSet(refs["Region"])) + { + if ((refs["PartitionResult"] = Partition((string)refs["Region"])) != null) + { + if (Equals(refs["UseFIPS"], true) && Equals(refs["UseDualStack"], true)) + { + if (Equals(true, GetAttr(refs["PartitionResult"], "supportsFIPS")) && Equals(true, GetAttr(refs["PartitionResult"], "supportsDualStack"))) + { + return new Endpoint(Interpolate(@"https://api.ecr-public-fips.{Region}.{PartitionResult#dualStackDnsSuffix}", refs), InterpolateJson(@"", refs), InterpolateJson(@"", refs)); + } + throw new AmazonClientException("FIPS and DualStack are enabled, but this partition does not support one or both"); + } + if (Equals(refs["UseFIPS"], true)) + { + if (Equals(GetAttr(refs["PartitionResult"], "supportsFIPS"), true)) + { + return new Endpoint(Interpolate(@"https://api.ecr-public-fips.{Region}.{PartitionResult#dnsSuffix}", refs), InterpolateJson(@"", refs), InterpolateJson(@"", refs)); + } + throw new AmazonClientException("FIPS is enabled but this partition does not support FIPS"); + } + if (Equals(refs["UseDualStack"], true)) { - return new Endpoint(Interpolate(@"https://ecr-public.{Region}.{PartitionResult#dualStackDnsSuffix}", refs), InterpolateJson(@"", refs), InterpolateJson(@"", refs)); + if (Equals(true, GetAttr(refs["PartitionResult"], "supportsDualStack"))) + { + return new Endpoint(Interpolate(@"https://api.ecr-public.{Region}.{PartitionResult#dualStackDnsSuffix}", refs), InterpolateJson(@"", refs), InterpolateJson(@"", refs)); + } + throw new AmazonClientException("DualStack is enabled but this partition does not support DualStack"); } - throw new AmazonClientException("Dualstack is enabled but this partition does not support dualstack"); + return new Endpoint(Interpolate(@"https://api.ecr-public.{Region}.{PartitionResult#dnsSuffix}", refs), InterpolateJson(@"", refs), InterpolateJson(@"", refs)); } - return new Endpoint(Interpolate(@"https://api.ecr-public.{Region}.{PartitionResult#dnsSuffix}", refs), InterpolateJson(@"", refs), InterpolateJson(@"", refs)); } + throw new AmazonClientException("Invalid Configuration: Missing Region"); throw new AmazonClientException("Cannot resolve endpoint"); } diff --git a/sdk/src/Services/ECRPublic/Generated/Internal/AmazonECRPublicEndpointResolver.cs b/sdk/src/Services/ECRPublic/Generated/Internal/AmazonECRPublicEndpointResolver.cs index 00d4745921c3..c9e1ce653a00 100644 --- a/sdk/src/Services/ECRPublic/Generated/Internal/AmazonECRPublicEndpointResolver.cs +++ b/sdk/src/Services/ECRPublic/Generated/Internal/AmazonECRPublicEndpointResolver.cs @@ -51,8 +51,9 @@ protected override EndpointParameters MapEndpointsParameters(IRequestContext req var config = (AmazonECRPublicConfig)requestContext.ClientConfig; var result = new ECRPublicEndpointParameters(); result.Region = config.RegionEndpoint?.SystemName; - result.UseFIPS = config.UseFIPSEndpoint; result.UseDualStack = config.UseDualstackEndpoint; + result.UseFIPS = config.UseFIPSEndpoint; + result.Endpoint = config.ServiceURL; // The region needs to be determined from the ServiceURL if not set. diff --git a/sdk/test/Services/ECRPublic/UnitTests/Generated/Endpoints/ECRPublicEndpointProviderTests.cs b/sdk/test/Services/ECRPublic/UnitTests/Generated/Endpoints/ECRPublicEndpointProviderTests.cs index 66ad42f29dc2..89dff3c610bd 100644 --- a/sdk/test/Services/ECRPublic/UnitTests/Generated/Endpoints/ECRPublicEndpointProviderTests.cs +++ b/sdk/test/Services/ECRPublic/UnitTests/Generated/Endpoints/ECRPublicEndpointProviderTests.cs @@ -32,13 +32,58 @@ public partial class ECRPublicEndpointsTests [TestCategory("UnitTest")] [TestCategory("Endpoints")] [TestCategory("ECRPublic")] - [Description("Valid with dualstack and FIPS disabled. i.e, IPv4 Only stack with no FIPS, with special prefix")] - public void Valid_with_dualstack_and_FIPS_disabled_ie_IPv4_Only_stack_with_no_FIPS_with_special_prefix_Test() + [Description("For region us-east-1 with FIPS enabled and DualStack enabled")] + public void For_region_useast1_with_FIPS_enabled_and_DualStack_enabled_Test() { var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-east-1"; + parameters["UseFIPS"] = true; + parameters["UseDualStack"] = true; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public-fips.us-east-1.api.aws", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-east-1 with FIPS enabled and DualStack disabled")] + public void For_region_useast1_with_FIPS_enabled_and_DualStack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-east-1"; + parameters["UseFIPS"] = true; parameters["UseDualStack"] = false; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public-fips.us-east-1.amazonaws.com", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-east-1 with FIPS disabled and DualStack enabled")] + public void For_region_useast1_with_FIPS_disabled_and_DualStack_enabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-east-1"; parameters["UseFIPS"] = false; + parameters["UseDualStack"] = true; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public.us-east-1.api.aws", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-east-1 with FIPS disabled and DualStack disabled")] + public void For_region_useast1_with_FIPS_disabled_and_DualStack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); parameters["Region"] = "us-east-1"; + parameters["UseFIPS"] = false; + parameters["UseDualStack"] = false; var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); Assert.AreEqual("https://api.ecr-public.us-east-1.amazonaws.com", endpoint.URL); } @@ -47,58 +92,314 @@ public void Valid_with_dualstack_and_FIPS_disabled_ie_IPv4_Only_stack_with_no_FI [TestCategory("UnitTest")] [TestCategory("Endpoints")] [TestCategory("ECRPublic")] - [Description("Valid with dualstack enabled")] - public void Valid_with_dualstack_enabled_Test() + [Description("For region cn-north-1 with FIPS enabled and DualStack enabled")] + public void For_region_cnnorth1_with_FIPS_enabled_and_DualStack_enabled_Test() { var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "cn-north-1"; + parameters["UseFIPS"] = true; parameters["UseDualStack"] = true; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public-fips.cn-north-1.api.amazonwebservices.com.cn", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region cn-north-1 with FIPS enabled and DualStack disabled")] + public void For_region_cnnorth1_with_FIPS_enabled_and_DualStack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "cn-north-1"; + parameters["UseFIPS"] = true; + parameters["UseDualStack"] = false; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public-fips.cn-north-1.amazonaws.com.cn", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region cn-north-1 with FIPS disabled and DualStack enabled")] + public void For_region_cnnorth1_with_FIPS_disabled_and_DualStack_enabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "cn-north-1"; parameters["UseFIPS"] = false; - parameters["Region"] = "us-east-1"; + parameters["UseDualStack"] = true; var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); - Assert.AreEqual("https://ecr-public.us-east-1.api.aws", endpoint.URL); + Assert.AreEqual("https://api.ecr-public.cn-north-1.api.amazonwebservices.com.cn", endpoint.URL); } [TestMethod] [TestCategory("UnitTest")] [TestCategory("Endpoints")] [TestCategory("ECRPublic")] - [Description("Invalid with FIPS set, dualstack disabled")] - [ExpectedException(typeof(AmazonClientException), @"ECR Public does not support FIPS")] - public void Invalid_with_FIPS_set_dualstack_disabled_Test() + [Description("For region cn-north-1 with FIPS disabled and DualStack disabled")] + public void For_region_cnnorth1_with_FIPS_disabled_and_DualStack_disabled_Test() { var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "cn-north-1"; + parameters["UseFIPS"] = false; parameters["UseDualStack"] = false; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public.cn-north-1.amazonaws.com.cn", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-gov-east-1 with FIPS enabled and DualStack enabled")] + public void For_region_usgoveast1_with_FIPS_enabled_and_DualStack_enabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-gov-east-1"; parameters["UseFIPS"] = true; - parameters["Region"] = "us-east-1"; + parameters["UseDualStack"] = true; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public-fips.us-gov-east-1.api.aws", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-gov-east-1 with FIPS enabled and DualStack disabled")] + public void For_region_usgoveast1_with_FIPS_enabled_and_DualStack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-gov-east-1"; + parameters["UseFIPS"] = true; + parameters["UseDualStack"] = false; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public-fips.us-gov-east-1.amazonaws.com", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-gov-east-1 with FIPS disabled and DualStack enabled")] + public void For_region_usgoveast1_with_FIPS_disabled_and_DualStack_enabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-gov-east-1"; + parameters["UseFIPS"] = false; + parameters["UseDualStack"] = true; var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public.us-gov-east-1.api.aws", endpoint.URL); } [TestMethod] [TestCategory("UnitTest")] [TestCategory("Endpoints")] [TestCategory("ECRPublic")] - [Description("Invalid with both dualstack and FIPS enabled")] - [ExpectedException(typeof(AmazonClientException), @"ECR Public does not support FIPS")] - public void Invalid_with_both_dualstack_and_FIPS_enabled_Test() + [Description("For region us-gov-east-1 with FIPS disabled and DualStack disabled")] + public void For_region_usgoveast1_with_FIPS_disabled_and_DualStack_disabled_Test() { var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-gov-east-1"; + parameters["UseFIPS"] = false; + parameters["UseDualStack"] = false; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public.us-gov-east-1.amazonaws.com", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-iso-east-1 with FIPS enabled and DualStack enabled")] + [ExpectedException(typeof(AmazonClientException), @"FIPS and DualStack are enabled, but this partition does not support one or both")] + public void For_region_usisoeast1_with_FIPS_enabled_and_DualStack_enabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-iso-east-1"; + parameters["UseFIPS"] = true; parameters["UseDualStack"] = true; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-iso-east-1 with FIPS enabled and DualStack disabled")] + public void For_region_usisoeast1_with_FIPS_enabled_and_DualStack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-iso-east-1"; parameters["UseFIPS"] = true; - parameters["Region"] = "us-east-1"; + parameters["UseDualStack"] = false; var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public-fips.us-iso-east-1.c2s.ic.gov", endpoint.URL); } [TestMethod] [TestCategory("UnitTest")] [TestCategory("Endpoints")] [TestCategory("ECRPublic")] - [Description("Invalid with DualStack enabled and partition does not support Dualstack")] - [ExpectedException(typeof(AmazonClientException), @"Dualstack is enabled but this partition does not support dualstack")] - public void Invalid_with_DualStack_enabled_and_partition_does_not_support_Dualstack_Test() + [Description("For region us-iso-east-1 with FIPS disabled and DualStack enabled")] + [ExpectedException(typeof(AmazonClientException), @"DualStack is enabled but this partition does not support DualStack")] + public void For_region_usisoeast1_with_FIPS_disabled_and_DualStack_enabled_Test() { var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-iso-east-1"; + parameters["UseFIPS"] = false; + parameters["UseDualStack"] = true; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-iso-east-1 with FIPS disabled and DualStack disabled")] + public void For_region_usisoeast1_with_FIPS_disabled_and_DualStack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-iso-east-1"; + parameters["UseFIPS"] = false; + parameters["UseDualStack"] = false; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public.us-iso-east-1.c2s.ic.gov", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-isob-east-1 with FIPS enabled and DualStack enabled")] + [ExpectedException(typeof(AmazonClientException), @"FIPS and DualStack are enabled, but this partition does not support one or both")] + public void For_region_usisobeast1_with_FIPS_enabled_and_DualStack_enabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-isob-east-1"; + parameters["UseFIPS"] = true; + parameters["UseDualStack"] = true; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-isob-east-1 with FIPS enabled and DualStack disabled")] + public void For_region_usisobeast1_with_FIPS_enabled_and_DualStack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-isob-east-1"; + parameters["UseFIPS"] = true; + parameters["UseDualStack"] = false; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public-fips.us-isob-east-1.sc2s.sgov.gov", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-isob-east-1 with FIPS disabled and DualStack enabled")] + [ExpectedException(typeof(AmazonClientException), @"DualStack is enabled but this partition does not support DualStack")] + public void For_region_usisobeast1_with_FIPS_disabled_and_DualStack_enabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-isob-east-1"; + parameters["UseFIPS"] = false; parameters["UseDualStack"] = true; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For region us-isob-east-1 with FIPS disabled and DualStack disabled")] + public void For_region_usisobeast1_with_FIPS_disabled_and_DualStack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); parameters["Region"] = "us-isob-east-1"; + parameters["UseFIPS"] = false; + parameters["UseDualStack"] = false; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://api.ecr-public.us-isob-east-1.sc2s.sgov.gov", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For custom endpoint with region set and fips disabled and dualstack disabled")] + public void For_custom_endpoint_with_region_set_and_fips_disabled_and_dualstack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-east-1"; + parameters["UseFIPS"] = false; + parameters["UseDualStack"] = false; + parameters["Endpoint"] = "https://example.com"; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://example.com", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For custom endpoint with region not set and fips disabled and dualstack disabled")] + public void For_custom_endpoint_with_region_not_set_and_fips_disabled_and_dualstack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["UseFIPS"] = false; + parameters["UseDualStack"] = false; + parameters["Endpoint"] = "https://example.com"; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + Assert.AreEqual("https://example.com", endpoint.URL); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For custom endpoint with fips enabled and dualstack disabled")] + [ExpectedException(typeof(AmazonClientException), @"Invalid Configuration: FIPS and custom endpoint are not supported")] + public void For_custom_endpoint_with_fips_enabled_and_dualstack_disabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-east-1"; + parameters["UseFIPS"] = true; + parameters["UseDualStack"] = false; + parameters["Endpoint"] = "https://example.com"; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("For custom endpoint with fips disabled and dualstack enabled")] + [ExpectedException(typeof(AmazonClientException), @"Invalid Configuration: Dualstack and custom endpoint are not supported")] + public void For_custom_endpoint_with_fips_disabled_and_dualstack_enabled_Test() + { + var parameters = new ECRPublicEndpointParameters(); + parameters["Region"] = "us-east-1"; + parameters["UseFIPS"] = false; + parameters["UseDualStack"] = true; + parameters["Endpoint"] = "https://example.com"; + var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); + } + + [TestMethod] + [TestCategory("UnitTest")] + [TestCategory("Endpoints")] + [TestCategory("ECRPublic")] + [Description("Missing region")] + [ExpectedException(typeof(AmazonClientException), @"Invalid Configuration: Missing Region")] + public void Missing_region_Test() + { + var parameters = new ECRPublicEndpointParameters(); var endpoint = new AmazonECRPublicEndpointProvider().ResolveEndpoint(parameters); }