athrog commented on a change in pull request #120: URL: https://github.com/apache/solr/pull/120#discussion_r667123991
########## File path: solr/contrib/blob-repository/src/java/org/apache/solr/s3/AdobeMockS3StorageClient.java ########## @@ -0,0 +1,79 @@ +/* + * 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.solr.s3; + +import com.amazonaws.client.builder.AwsClientBuilder; +import com.amazonaws.regions.Regions; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; + +/** + * This storage client exists to work around some of the incongruencies Adobe S3Mock has with the S3 API. + * The main difference is that S3Mock does not support paths with a leading '/', but S3 does, and our code + * in {@link S3StorageClient} requires all paths to have a leading '/'. + */ +class AdobeMockS3StorageClient extends S3StorageClient { + + static final int DEFAULT_MOCK_S3_PORT = 9090; + private static final String DEFAULT_MOCK_S3_ENDPOINT = "http://localhost:" + DEFAULT_MOCK_S3_PORT; + + AdobeMockS3StorageClient(String bucketName) { + super(createInternalClient(), bucketName); + } + + @VisibleForTesting + AdobeMockS3StorageClient(AmazonS3 s3client, String bucketName) { + super(s3client, bucketName); + } + + private static AmazonS3 createInternalClient() { + String s3MockEndpoint = System.getenv().getOrDefault("MOCK_S3_ENDPOINT", DEFAULT_MOCK_S3_ENDPOINT); + + return AmazonS3ClientBuilder.standard() + .enablePathStyleAccess() + .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(s3MockEndpoint, Regions.US_EAST_1.name())) + .build(); + } + + /** + * Ensures path adheres to some rules (different than the rules that S3 cares about): + * -Trims leading slash, if given + * -If it's a file, throw an error if it ends with a trailing slash + */ + @Override + String sanitizedPath(String path, boolean isFile) throws S3Exception { + Preconditions.checkArgument(!Strings.isNullOrEmpty(path)); Review comment: > it's causing the example in solr/contrib/blob-repository/README.md to fail Interesting, I tested the example before pushing and it is working for me as written. -- 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. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org