Skip to content

Commit 04677ed

Browse files
committed
Add constants
1 parent ff2e254 commit 04677ed

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

codegen/src/main/resources/software/amazon/awssdk/codegen/rules2/RuleArn.java.resource

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public final class RuleArn {
1313
private final String accountId;
1414
private final List<String> resourceId;
1515

16+
private static final int ARN_MIN_LENGTH = 8;
17+
private static final int ARN_PREFIX_LENGTH = 3;
18+
1619
RuleArn(String partition, String service, String region, String accountId, List<String> resourceId) {
1720
this.partition = partition;
1821
this.service = service;
@@ -22,12 +25,12 @@ public final class RuleArn {
2225
}
2326

2427
public static RuleArn parse(String arn) {
25-
if (arn == null || arn.length() < 8 || !arn.startsWith("arn:")) {
28+
if (arn == null || arn.length() < ARN_MIN_LENGTH || !arn.startsWith("arn:")) {
2629
return null;
2730
}
2831

2932
// find each of the first five ':' positions
30-
int p0 = 3; // after "arn"
33+
int p0 = ARN_PREFIX_LENGTH; // after "arn"
3134
int p1 = arn.indexOf(':', p0 + 1);
3235
if (p1 < 0) {
3336
return null;

codegen/src/main/resources/software/amazon/awssdk/codegen/rules2/RulesFunctions.java.resource

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class RulesFunctions {
2020
private static final LazyValue<Partition> AWS_PARTITION = LazyValue.<Partition> builder()
2121
.initializer(RulesFunctions::findAwsPartition).build();
2222

23+
private static final int MAX_HOST_LABEL_SIZE = 63;
24+
private static final int MIN_BUCKET_SIZE = 3;
25+
2326
public static String substring(String value, int startIndex, int stopIndex, boolean reverse) {
2427
if (value == null) {
2528
return null;
@@ -31,6 +34,7 @@ public class RulesFunctions {
3134
}
3235

3336
for (int i = 0; i < len; i++) {
37+
// non-ascii characters (values outside of the 7bit ASCII range)
3438
if (value.charAt(i) > 127) {
3539
return null;
3640
}
@@ -83,7 +87,7 @@ public class RulesFunctions {
8387
if (i == len || hostLabel.charAt(i) == '.') {
8488
// chunk is hostLabel[start..i)
8589
int chunkLen = i - start;
86-
if (chunkLen < 1 || chunkLen > 63) {
90+
if (chunkLen < 1 || chunkLen > MAX_HOST_LABEL_SIZE) {
8791
return false;
8892
} else if (!isValidSingleLabel(hostLabel, start, i)) {
8993
return false;
@@ -97,7 +101,7 @@ public class RulesFunctions {
97101
// Validates a single label in s[start..end): ^[A-Za-z0-9][A-Za-z0-9\-]{0,62}$
98102
private static boolean isValidSingleLabel(String s, int start, int end) {
99103
int length = end - start;
100-
if (length < 1 || length > 63) {
104+
if (length < 1 || length > MAX_HOST_LABEL_SIZE) {
101105
return false;
102106
}
103107

@@ -175,7 +179,7 @@ public class RulesFunctions {
175179
public static boolean awsIsVirtualHostableS3Bucket(String hostLabel, boolean allowDots) {
176180
// Bucket names must be between 3 (min) and 63 (max) characters long.
177181
int bucketLength = hostLabel == null ? 0 : hostLabel.length();
178-
if (bucketLength < 3 || bucketLength > 63) {
182+
if (bucketLength < MIN_BUCKET_SIZE || bucketLength > MAX_HOST_LABEL_SIZE) {
179183
return false;
180184
}
181185

0 commit comments

Comments
 (0)