-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean up scenarios
- Loading branch information
Showing
7 changed files
with
54 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...e-aws-construct-common/src/main/java/clusterless/cls/substrate/aws/resources/Buckets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2023 Chris K Wensel <[email protected]>. All Rights Reserved. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package clusterless.cls.substrate.aws.resources; | ||
|
||
public class Buckets { | ||
/** | ||
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html">Naming Rules</a> | ||
* | ||
* @param bucketName | ||
* @return | ||
*/ | ||
public static String verifyBucketName(String bucketName) { | ||
// try to be helpful, then be strict | ||
if (bucketName.length() > 63) { | ||
throw new IllegalStateException("bucket name too long, must be < 64 characters, got: " + bucketName); | ||
} | ||
|
||
if (!bucketName.equals(bucketName.toLowerCase())) { | ||
throw new IllegalStateException("bucket name may not contain uppercase characters, got: " + bucketName); | ||
} | ||
|
||
if (bucketName.contains("..")) { | ||
throw new IllegalStateException("bucket name may not contain two adjacent periods, got: " + bucketName); | ||
} | ||
|
||
if (!bucketName.matches("^[0-9a-z].*")) { | ||
throw new IllegalStateException("bucket name must start with a letter or number, got: " + bucketName); | ||
} | ||
|
||
if (!bucketName.matches(".*[0-9a-z]$")) { | ||
throw new IllegalStateException("bucket name must end with a letter or number, got: " + bucketName); | ||
} | ||
|
||
if (!bucketName.matches("(?!(^((2(5[0-5]|[0-4][0-9])|[01]?[0-9]{1,2})\\.){3}(2(5[0-5]|[0-4][0-9])|[01]?[0-9]{1,2})$|^xn--|.+-s3alias$))^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$")) { | ||
throw new IllegalStateException("bucket name is not valid, got: " + bucketName); | ||
} | ||
|
||
return bucketName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters