1515
1616package software .amazon .awssdk .codegen .lite .regions ;
1717
18- import static java .util .Collections .emptyList ;
1918import static javax .lang .model .element .Modifier .FINAL ;
2019import static javax .lang .model .element .Modifier .PRIVATE ;
2120import static javax .lang .model .element .Modifier .PUBLIC ;
2928import com .squareup .javapoet .ParameterizedTypeName ;
3029import com .squareup .javapoet .TypeName ;
3130import com .squareup .javapoet .TypeSpec ;
31+ import java .util .Arrays ;
3232import java .util .Collection ;
33+ import java .util .Collections ;
3334import java .util .Map ;
3435import java .util .stream .Collectors ;
3536import java .util .stream .Stream ;
3839import software .amazon .awssdk .annotations .SdkPublicApi ;
3940import software .amazon .awssdk .codegen .lite .PoetClass ;
4041import software .amazon .awssdk .codegen .lite .Utils ;
41- import software .amazon .awssdk .codegen .lite .regions .model .Partition ;
42+ import software .amazon .awssdk .codegen .lite .regions .model .PartitionRegionsMetadata ;
4243import software .amazon .awssdk .utils .ImmutableMap ;
44+ import software .amazon .awssdk .utils .StringUtils ;
4345
4446public class PartitionMetadataGenerator implements PoetClass {
4547
46- private final Partition partition ;
48+ /**
49+ * Hardcoded mapping of partition IDs to display names.
50+ * This preserves backward compatibility since partitions.json only provides
51+ * partition IDs, while the old endpoints.json had separate partitionName fields.
52+ * New partitions will fall back to using their ID as the display name.
53+ */
54+ private static final Map <String , String > PARTITION_DISPLAY_NAMES =
55+ ImmutableMap .<String , String >builder ()
56+ .put ("aws" , "AWS Standard" )
57+ .put ("aws-cn" , "AWS China" )
58+ .put ("aws-us-gov" , "AWS GovCloud (US)" )
59+ .put ("aws-iso" , "AWS ISO (US)" )
60+ .put ("aws-iso-b" , "AWS ISOB (US)" )
61+ .put ("aws-iso-e" , "AWS ISOE (Europe)" )
62+ .put ("aws-iso-f" , "AWS ISOF" )
63+ .put ("aws-eusc" , "AWS EUSC" )
64+ .build ();
65+
66+ private final PartitionRegionsMetadata partition ;
4767 private final String basePackage ;
4868 private final String regionBasePackage ;
4969
50- public PartitionMetadataGenerator (Partition partition ,
70+ public PartitionMetadataGenerator (PartitionRegionsMetadata partition ,
5171 String basePackage ,
5272 String regionBasePackage ) {
5373 this .partition = partition ;
@@ -80,11 +100,12 @@ public TypeSpec poetClass() {
80100 .build ())
81101 .addField (FieldSpec .builder (String .class , "ID" )
82102 .addModifiers (PRIVATE , FINAL , STATIC )
83- .initializer ("$S" , partition .getPartition ())
103+ .initializer ("$S" , partition .getId ())
84104 .build ())
85105 .addField (FieldSpec .builder (String .class , "NAME" )
86106 .addModifiers (PRIVATE , FINAL , STATIC )
87- .initializer ("$S" , partition .getPartitionName ())
107+ .initializer ("$S" , PARTITION_DISPLAY_NAMES .getOrDefault (
108+ partition .getId (), partition .getId ()))
88109 .build ())
89110 .addField (FieldSpec .builder (String .class , "REGION_REGEX" )
90111 .addModifiers (PRIVATE , FINAL , STATIC )
@@ -103,18 +124,33 @@ private CodeBlock dnsSuffixes() {
103124 CodeBlock .builder ()
104125 .add ("$T.<$T, $T>builder()" , ImmutableMap .class , partitionEndpointKeyClass (), String .class );
105126
127+ String defaultDnsSuffix = partition .getOutputs ().getDnsSuffix ();
128+ String dualStackDnsSuffix = partition .getOutputs ().getDualStackDnsSuffix ();
129+ boolean supportsFips = partition .getOutputs ().isSupportsFIPS ();
130+ boolean supportsDualStack = partition .getOutputs ().isSupportsDualStack ();
131+
106132 builder .add (".put(" )
107- .add (partitionEndpointKey (emptyList ()))
108- .add (", $S)" , partition .getDnsSuffix ());
109-
110- if (partition .getDefaults () != null ) {
111- partition .getDefaults ().getVariants ().forEach (variant -> {
112- if (variant .getDnsSuffix () != null ) {
113- builder .add (".put(" )
114- .add (partitionEndpointKey (variant .getTags ()))
115- .add (", $S)" , variant .getDnsSuffix ());
116- }
117- });
133+ .add (partitionEndpointKey (Collections .emptyList ()))
134+ .add (", $S)" , defaultDnsSuffix );
135+
136+ if (supportsFips ) {
137+ builder .add (".put(" )
138+ .add (partitionEndpointKey (Collections .singletonList ("fips" )))
139+ .add (", $S)" , defaultDnsSuffix );
140+ }
141+
142+ if (supportsDualStack && supportsFips ) {
143+ validateDualStackDnsSuffix (dualStackDnsSuffix );
144+ builder .add (".put(" )
145+ .add (partitionEndpointKey (Arrays .asList ("dualstack" , "fips" )))
146+ .add (", $S)" , dualStackDnsSuffix );
147+ }
148+
149+ if (supportsDualStack ) {
150+ validateDualStackDnsSuffix (dualStackDnsSuffix );
151+ builder .add (".put(" )
152+ .add (partitionEndpointKey (Collections .singletonList ("dualstack" )))
153+ .add (", $S)" , dualStackDnsSuffix );
118154 }
119155
120156 return builder .add (".build()" ).build ();
@@ -125,19 +161,32 @@ private CodeBlock hostnames() {
125161 CodeBlock .builder ()
126162 .add ("$T.<$T, $T>builder()" , ImmutableMap .class , partitionEndpointKeyClass (), String .class );
127163
164+ boolean supportsFips = partition .getOutputs ().isSupportsFIPS ();
165+ boolean supportsDualStack = partition .getOutputs ().isSupportsDualStack ();
166+ String dualStackDnsSuffix = partition .getOutputs ().getDualStackDnsSuffix ();
128167
129- if (partition .getDefaults () != null ) {
168+ builder .add (".put(" )
169+ .add (partitionEndpointKey (Collections .emptyList ()))
170+ .add (", $S)" , "{service}.{region}.{dnsSuffix}" );
171+
172+ if (supportsFips ) {
173+ builder .add (".put(" )
174+ .add (partitionEndpointKey (Collections .singletonList ("fips" )))
175+ .add (", $S)" , "{service}-fips.{region}.{dnsSuffix}" );
176+ }
177+
178+ if (supportsDualStack && supportsFips ) {
179+ validateDualStackDnsSuffix (dualStackDnsSuffix );
180+ builder .add (".put(" )
181+ .add (partitionEndpointKey (Arrays .asList ("dualstack" , "fips" )))
182+ .add (", $S)" , "{service}-fips.{region}.{dnsSuffix}" );
183+ }
184+
185+ if (supportsDualStack ) {
186+ validateDualStackDnsSuffix (dualStackDnsSuffix );
130187 builder .add (".put(" )
131- .add (partitionEndpointKey (emptyList ()))
132- .add (", $S)" , partition .getDefaults ().getHostname ());
133-
134- partition .getDefaults ().getVariants ().forEach (variant -> {
135- if (variant .getHostname () != null ) {
136- builder .add (".put(" )
137- .add (partitionEndpointKey (variant .getTags ()))
138- .add (", $S)" , variant .getHostname ());
139- }
140- });
188+ .add (partitionEndpointKey (Collections .singletonList ("dualstack" )))
189+ .add (", $S)" , "{service}.{region}.{dnsSuffix}" );
141190 }
142191
143192 return builder .add (".build()" ).build ();
@@ -165,7 +214,7 @@ private MethodSpec hostnameGetter() {
165214
166215 @ Override
167216 public ClassName className () {
168- return ClassName .get (basePackage , Stream .of (partition .getPartition ().split ("-" ))
217+ return ClassName .get (basePackage , Stream .of (partition .getId ().split ("-" ))
169218 .map (Utils ::capitalize )
170219 .collect (Collectors .joining ()) + "PartitionMetadata" );
171220 }
@@ -179,6 +228,13 @@ private MethodSpec getter(String methodName, String field) {
179228 .build ();
180229 }
181230
231+ private void validateDualStackDnsSuffix (String dualStackDnsSuffix ) {
232+ if (StringUtils .isBlank (dualStackDnsSuffix )) {
233+ throw new IllegalStateException ("Partition " + partition .getId ()
234+ + " claims to support dualstack but dualStackDnsSuffix is null or empty" );
235+ }
236+ }
237+
182238 private CodeBlock partitionEndpointKey (Collection <String > tags ) {
183239 CodeBlock .Builder result = CodeBlock .builder ();
184240 result .add ("$T.builder()" , partitionEndpointKeyClass ());
0 commit comments