Skip to content

Commit

Permalink
Switched region endpoint generation to the partitions.json file.
Browse files Browse the repository at this point in the history
  • Loading branch information
boblodgett committed Sep 12, 2024
1 parent 62fbb3a commit 3d8b704
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
17 changes: 11 additions & 6 deletions generator/ServiceClientGeneratorLib/GeneratorDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,20 +1572,25 @@ public static string ConstructEndpointName(string regionCode)
public static List<EndpointConstant> ExtractEndpoints(GeneratorOptions options, Func<string, string> nameConverter, Func<string, string> codeConverter = null)
{
var coreFilesRoot = Utils.PathCombineAlt(options.SdkRootFolder, "src", "Core");
var endpointsJsonFile = Utils.PathCombineAlt(coreFilesRoot, "endpoints.json");
var partitionsJsonFile = Utils.PathCombineAlt(coreFilesRoot, "partitions.json");

var endpointsJson = JsonMapper.ToObject(File.ReadAllText(endpointsJsonFile));
var partitionsJson = JsonMapper.ToObject(File.ReadAllText(partitionsJsonFile));
var endpoints = new List<EndpointConstant>();

foreach (JsonData partition in endpointsJson["partitions"])
foreach (JsonData partition in partitionsJson["partitions"])
{
var partitionName = partition["partition"].ToString();
var partitionDnsSuffix = partition["dnsSuffix"].ToString();
var hostnameTemplate = partition["defaults"]["hostname"].ToString();
var partitionName = partition["id"].ToString();
var partitionDnsSuffix = partition["outputs"]["dnsSuffix"].ToString();
var hostnameTemplate = "{service}.{region}.{dnsSuffix}";
var partitionRegionRegex = partition["regionRegex"].ToString();
JsonData regions = partition["regions"];
foreach (var regionCode in regions.PropertyNames)
{
if (regionCode.EndsWith("-global", StringComparison.OrdinalIgnoreCase))
{
continue;
}

var regionName = regions[regionCode]["description"].ToString();
endpoints.Add(new EndpointConstant
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace ServiceClientGenerator.Generators.SourceFiles
/// Class to produce the template output
/// </summary>

#line 1 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 1 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")]
public partial class EndpointsGenerator : EndpointsGeneratorBase
{
Expand Down Expand Up @@ -56,13 +56,13 @@ public partial class RegionEndpoint
{
");

#line 31 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 31 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
foreach (var endpoint in Endpoints) {

#line default
#line hidden

#line 32 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 32 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
if (endpoint.RegionCode == "us-east-1") {

#line default
Expand All @@ -74,99 +74,99 @@ public partial class RegionEndpoint
/// </summary>
private static readonly RegionEndpoint USEast1Regional = GetRegionEndpoint(""us-east-1-regional"", ""US East (Virginia) regional"", """);

#line 38 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 38 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.PartitionName));

#line default
#line hidden
this.Write("\", \"");

#line 38 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 38 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.PartitionDnsSuffix));

#line default
#line hidden
this.Write("\", @\"");

#line 38 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 38 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.PartitionRegionRegex));

#line default
#line hidden
this.Write("\", \"");

#line 38 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 38 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.HostnameTemplate));

#line default
#line hidden
this.Write("\");\r\n");

#line 39 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 39 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
}

#line default
#line hidden
this.Write("\r\n /// <summary>\r\n /// The ");

#line 42 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 42 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.RegionName));

#line default
#line hidden
this.Write(" endpoint.\r\n /// </summary>\r\n public static readonly RegionEndpoint" +
" ");

#line 44 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 44 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.Name));

#line default
#line hidden
this.Write(" = GetRegionEndpoint(\"");

#line 44 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 44 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.RegionCode));

#line default
#line hidden
this.Write("\", \"");

#line 44 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 44 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.RegionName));

#line default
#line hidden
this.Write("\", \"");

#line 44 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 44 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.PartitionName));

#line default
#line hidden
this.Write("\", \"");

#line 44 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 44 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.PartitionDnsSuffix));

#line default
#line hidden
this.Write("\", @\"");

#line 44 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 44 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.PartitionRegionRegex));

#line default
#line hidden
this.Write("\", \"");

#line 44 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 44 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(endpoint.HostnameTemplate));

#line default
#line hidden
this.Write("\");\r\n");

#line 45 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 45 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
}

#line default
Expand All @@ -175,7 +175,7 @@ public partial class RegionEndpoint
return this.GenerationEnvironment.ToString();
}

#line 49 "C:\repos\aws-sdk-net-staging\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"
#line 49 "C:\Dev\repos\aws-sdk-net\generator\ServiceClientGeneratorLib\Generators\SourceFiles\EndpointsGenerator.tt"

public System.Collections.Generic.List<ServiceClientGenerator.EndpointConstant> Endpoints { get; set; }

Expand Down

0 comments on commit 3d8b704

Please sign in to comment.