-
Notifications
You must be signed in to change notification settings - Fork 796
/
Partition.java
188 lines (159 loc) · 4.73 KB
/
Partition.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package software.amazon.awssdk.codegen.lite.regions.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
import java.util.regex.Pattern;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.utils.Validate;
/**
* This class models a AWS partition and contains all metadata about it.
*/
@SdkInternalApi
public final class Partition {
/**
* The name of the partition.
*/
private String partition;
/**
* Supported regions.
*/
private Map<String, PartitionRegion> regions;
/**
* Supported services;
*/
private Map<String, Service> services;
/**
* description of the partition.
*/
private String partitionName;
/**
* dns suffix for the endpoints in the partition.
*/
private String dnsSuffix;
/**
* region name regex for regions in the partition.
*/
private String regionRegex;
/**
* default endpoint configuration.
*/
private Endpoint defaults;
public Partition() {}
public Partition(@JsonProperty(value = "partition") String partition,
@JsonProperty(value = "regions") Map<String, PartitionRegion>
regions,
@JsonProperty(value = "services") Map<String,
Service> services) {
this.partition = Validate.paramNotNull(partition, "Partition");
this.regions = regions;
this.services = services;
}
/**
* Returns the name of the partition.
*/
public String getPartition() {
return partition;
}
public void setPartition(String partition) {
this.partition = partition;
}
/**
* Returns the description of the partition.
*/
public String getPartitionName() {
return partitionName;
}
/**
* Sets the description of the partition.
*/
public void setPartitionName(String partitionName) {
this.partitionName = partitionName;
}
/**
* Returns the dns suffix of the partition.
*/
public String getDnsSuffix() {
return dnsSuffix;
}
/**
* Sets the dns suffix of the partition.
*/
public void setDnsSuffix(String dnsSuffix) {
this.dnsSuffix = dnsSuffix;
}
/**
* Returns the regex for the regions in the partition.
*/
public String getRegionRegex() {
return regionRegex;
}
/**
* Sets the regex for the regions in the partition.
*/
public void setRegionRegex(String regionRegex) {
this.regionRegex = regionRegex;
}
/**
* Returns the default endpoint configuration of the partition.
*/
public Endpoint getDefaults() {
return defaults;
}
/**
* Sets the default endpoint configuration of the partition.
*/
public void setDefaults(Endpoint defaults) {
this.defaults = defaults;
}
/**
* Returns the set of regions associated with the partition.
*/
public Map<String, PartitionRegion> getRegions() {
return regions;
}
public void setRegions(Map<String, PartitionRegion> regions) {
this.regions = regions;
}
/**
* Returns the set of services supported by the partition.
*/
public Map<String, Service> getServices() {
return services;
}
public void setServices(Map<String, Service> services) {
this.services = services;
}
/**
* Returns true if the region is explicitly configured in the partition
* or if the region matches the {@link #regionRegex} of the partition.
*/
public boolean hasRegion(String region) {
return regions.containsKey(region) || matchesRegionRegex(region) || hasServiceEndpoint(region);
}
private boolean matchesRegionRegex(String region) {
Pattern p = Pattern.compile(regionRegex);
return p.matcher(region).matches();
}
@Deprecated
private boolean hasServiceEndpoint(String endpoint) {
for (Service s : services.values()) {
if (s.getEndpoints().containsKey(endpoint)) {
return true;
}
}
return false;
}
}