gianm commented on a change in pull request #8903: S3 input source URL: https://github.com/apache/incubator-druid/pull/8903#discussion_r350515824
########## File path: core/src/main/java/org/apache/druid/data/input/impl/CloudObjectLocation.java ########## @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License 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 org.apache.druid.data.input.impl; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Preconditions; +import org.apache.druid.java.util.common.StringUtils; + +import java.net.URI; +import java.util.Objects; + +/** + * Common type for 'bucket' and 'path' concept of cloud objects to allow code sharing between cloud specific + * implementations. {@link #bucket} and {@link #path} should NOT be URL encoded. + * + * The intention is that this is used as a common representation for storage objects as an alternative to dealing in + * {@link URI} directly, but still provide a mechanism to round-trip with a URI. + * + * In common clouds, bucket names must be dns compliant: + * https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html + * https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata + * https://cloud.google.com/storage/docs/naming + * + * The constructor ensures that bucket names are DNS compliant by checking that the URL encoded form of the bucket + * matches the supplied value. Technically it should probably confirm that the bucket is also all lower-case, but + * S3 has a legacy mode where buckets did not have to be compliant so we can't enforce that here unfortunately. + */ +public class CloudObjectLocation +{ + private final String bucket; + private final String path; + + @JsonCreator + public CloudObjectLocation(@JsonProperty("bucket") String bucket, @JsonProperty("path") String path) + { + this.bucket = Preconditions.checkNotNull(StringUtils.maybeRemoveTrailingSlash(bucket)); + this.path = Preconditions.checkNotNull(StringUtils.maybeRemoveLeadingSlash(path)); + Preconditions.checkArgument(this.bucket.equals(StringUtils.urlEncode(this.bucket))); Review comment: This exception might get thrown in response to user input, so please add a nice error message. As is, the user would get an IllegalArgumentException with no message. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
