Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skip bucket/region/object name validation as special usecase #1576

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion api/src/main/java/io/minio/BucketArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ public abstract static class Builder<B extends Builder<B, A>, A extends BucketAr
extends BaseArgs.Builder<B, A> {
private static final Pattern BUCKET_NAME_REGEX =
Pattern.compile("^[a-z0-9][a-z0-9\\.\\-]{1,61}[a-z0-9]$");
protected boolean skipValidation = false;

protected void validateBucketName(String name) {
validateNotNull(name, "bucket name");
if (skipValidation) {
return;
}

if (!BUCKET_NAME_REGEX.matcher(name).find()) {
throw new IllegalArgumentException(
Expand All @@ -63,7 +67,7 @@ protected void validateBucketName(String name) {
}

private void validateRegion(String region) {
if (region != null && !HttpUtils.REGION_REGEX.matcher(region).find()) {
if (!skipValidation && region != null && !HttpUtils.REGION_REGEX.matcher(region).find()) {
throw new IllegalArgumentException("invalid region " + region);
}
}
Expand All @@ -80,6 +84,12 @@ public B bucket(String name) {
return (B) this;
}

@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
public B skipValidation(boolean skipValidation) {
this.skipValidation = skipValidation;
return (B) this;
}

@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
public B region(String region) {
validateRegion(region);
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/java/io/minio/ObjectArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public abstract static class Builder<B extends Builder<B, A>, A extends ObjectAr
extends BucketArgs.Builder<B, A> {
protected void validateObjectName(String name) {
validateNotEmptyString(name, "object name");
if (skipValidation) {
return;
}
for (String token : name.split("/")) {
if (token.equals(".") || token.equals("..")) {
throw new IllegalArgumentException(
Expand Down
Loading