Skip to content

Commit

Permalink
Add skip bucket/region/object name validation as special usecase (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudgal authored Aug 5, 2024
1 parent 245f63d commit e85d171
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit e85d171

Please sign in to comment.