kopia lustrzana https://github.com/gaul/s3proxy
Address Checkstyle violations
rodzic
e5fb3619df
commit
1dac9ccd12
|
@ -17,7 +17,6 @@
|
|||
package org.gaul.s3proxy;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
|
@ -71,7 +71,7 @@ public final class EncryptedBlobStore extends ForwardingBlobStore {
|
|||
private SecretKeySpec secretKey;
|
||||
|
||||
private EncryptedBlobStore(BlobStore blobStore, Properties properties)
|
||||
throws IllegalArgumentException {
|
||||
throws IllegalArgumentException {
|
||||
super(blobStore);
|
||||
|
||||
String password = properties.getProperty(
|
||||
|
@ -92,7 +92,7 @@ public final class EncryptedBlobStore extends ForwardingBlobStore {
|
|||
}
|
||||
|
||||
private void initStore(String password, String salt)
|
||||
throws IllegalArgumentException {
|
||||
throws IllegalArgumentException {
|
||||
try {
|
||||
SecretKeyFactory factory =
|
||||
SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.gaul.s3proxy;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import java.util.Deque;
|
||||
|
|
|
@ -250,7 +250,7 @@ public final class Main {
|
|||
|
||||
ImmutableList<Map.Entry<Pattern, String>> regexs = RegexBlobStore.parseRegexs(
|
||||
properties);
|
||||
if (!regexs.isEmpty()){
|
||||
if (!regexs.isEmpty()) {
|
||||
System.err.println("Using regex backend");
|
||||
blobStore = RegexBlobStore.newRegexBlobStore(blobStore, regexs);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2014-2021 Andrew Gaul <andrew@gaul.org>
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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.gaul.s3proxy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
@ -15,6 +31,8 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.domain.BlobAccess;
|
||||
|
@ -25,8 +43,6 @@ import org.jclouds.blobstore.util.ForwardingBlobStore;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* This class implements a middleware to apply regex to blob names.
|
||||
* The regex are configured as:
|
||||
|
@ -39,37 +55,38 @@ import com.google.common.collect.ImmutableList;
|
|||
* end,
|
||||
* stopping as soon as the first regex matches.
|
||||
*/
|
||||
public class RegexBlobStore extends ForwardingBlobStore {
|
||||
private final ImmutableList<Entry<Pattern, String>> regexs;
|
||||
public final class RegexBlobStore extends ForwardingBlobStore {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RegexBlobStore.class);
|
||||
|
||||
static BlobStore newRegexBlobStore(BlobStore delegate, ImmutableList<Entry<Pattern, String>> regexs) {
|
||||
return new RegexBlobStore(delegate, regexs);
|
||||
}
|
||||
private final ImmutableList<Entry<Pattern, String>> regexs;
|
||||
|
||||
private RegexBlobStore(BlobStore blobStore, ImmutableList<Entry<Pattern, String>> regexs) {
|
||||
super(blobStore);
|
||||
this.regexs = requireNonNull(regexs);
|
||||
}
|
||||
|
||||
static BlobStore newRegexBlobStore(BlobStore delegate, ImmutableList<Entry<Pattern, String>> regexs) {
|
||||
return new RegexBlobStore(delegate, regexs);
|
||||
}
|
||||
|
||||
public static ImmutableList<Map.Entry<Pattern, String>> parseRegexs(Properties properties) {
|
||||
|
||||
List<Entry<String, String>> config_regex = new ArrayList<>();
|
||||
List<Entry<String, String>> configRegex = new ArrayList<>();
|
||||
List<Entry<Pattern, String>> regexs = new ArrayList<>();
|
||||
|
||||
for (String key : properties.stringPropertyNames()) {
|
||||
if (key.startsWith(S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE)) {
|
||||
String prop_key = key.substring(S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE.length() + 1);
|
||||
String propKey = key.substring(S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE.length() + 1);
|
||||
String value = properties.getProperty(key);
|
||||
|
||||
config_regex.add(new SimpleEntry<>(prop_key, value));
|
||||
configRegex.add(new SimpleEntry<>(propKey, value));
|
||||
}
|
||||
}
|
||||
|
||||
for (Entry<String, String> entry : config_regex) {
|
||||
for (Entry<String, String> entry : configRegex) {
|
||||
String key = entry.getKey();
|
||||
if (key.startsWith(S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE_MATCH)) {
|
||||
String regex_name = key.substring(S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE_MATCH.length() + 1);
|
||||
String regexName = key.substring(S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE_MATCH.length() + 1);
|
||||
String regex = entry.getValue();
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
|
||||
|
@ -78,14 +95,14 @@ public class RegexBlobStore extends ForwardingBlobStore {
|
|||
".",
|
||||
S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE,
|
||||
S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE_REPLACE,
|
||||
regex_name));
|
||||
regexName));
|
||||
|
||||
checkArgument(
|
||||
replace != null,
|
||||
"Regex %s has no replace property associated",
|
||||
regex_name);
|
||||
regexName);
|
||||
|
||||
logger.info("Adding new regex with name {} replaces with {} to {}", regex_name, regex, replace);
|
||||
logger.info("Adding new regex with name {} replaces with {} to {}", regexName, regex, replace);
|
||||
|
||||
regexs.add(new SimpleEntry<>(pattern, replace));
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.gaul.s3proxy;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import java.net.URI;
|
||||
|
|
|
@ -77,9 +77,8 @@ public class DecryptionInputStream extends FilterInputStream {
|
|||
* @throws IOException if cipher fails
|
||||
*/
|
||||
public DecryptionInputStream(InputStream is, SecretKey key,
|
||||
TreeMap<Integer, PartPadding> parts, int skipParts,
|
||||
long skipPartBytes)
|
||||
throws IOException {
|
||||
TreeMap<Integer, PartPadding> parts, int skipParts,
|
||||
long skipPartBytes) throws IOException {
|
||||
super(is);
|
||||
in = is;
|
||||
this.parts = parts;
|
||||
|
|
|
@ -33,7 +33,7 @@ public class Encryption {
|
|||
private final int part;
|
||||
|
||||
public Encryption(SecretKeySpec key, InputStream isRaw, int partNumber)
|
||||
throws Exception {
|
||||
throws Exception {
|
||||
iv = generateIV();
|
||||
|
||||
Cipher cipher = Cipher.getInstance(Constants.AES_CIPHER);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class PartPadding {
|
|||
private short version;
|
||||
|
||||
public static PartPadding readPartPaddingFromBlob(Blob blob)
|
||||
throws IOException {
|
||||
throws IOException {
|
||||
PartPadding partPadding = new PartPadding();
|
||||
|
||||
InputStream is = blob.getPayload().openStream();
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.jclouds.blobstore.domain.StorageMetadata;
|
|||
import org.jclouds.blobstore.options.PutOptions;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -35,7 +35,6 @@ import com.amazonaws.services.s3.model.S3Object;
|
|||
import com.google.common.io.ByteSource;
|
||||
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -96,12 +96,10 @@ import com.google.common.collect.Maps;
|
|||
import com.google.common.io.ByteSource;
|
||||
|
||||
import org.assertj.core.api.Fail;
|
||||
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.rest.HttpClient;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
|
|
|
@ -40,7 +40,6 @@ import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
|
|||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import com.amazonaws.services.s3.model.CannedAccessControlList;
|
||||
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
|
||||
|
@ -59,10 +58,8 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -40,7 +40,6 @@ import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
|
|||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import com.amazonaws.services.s3.model.CannedAccessControlList;
|
||||
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
|
||||
|
@ -59,10 +58,8 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -242,7 +242,7 @@ public final class EncryptedBlobStoreLiveTest extends S3ClientLiveTest {
|
|||
@Override
|
||||
@Test
|
||||
public void testUpdateObjectACL() throws InterruptedException,
|
||||
ExecutionException, TimeoutException, IOException {
|
||||
ExecutionException, TimeoutException, IOException {
|
||||
try {
|
||||
super.testUpdateObjectACL();
|
||||
Fail.failBecauseExceptionWasNotThrown(AWSResponseException.class);
|
||||
|
@ -255,7 +255,7 @@ public final class EncryptedBlobStoreLiveTest extends S3ClientLiveTest {
|
|||
@Override
|
||||
@Test
|
||||
public void testPublicWriteOnObject() throws InterruptedException,
|
||||
ExecutionException, TimeoutException, IOException {
|
||||
ExecutionException, TimeoutException, IOException {
|
||||
try {
|
||||
super.testPublicWriteOnObject();
|
||||
Fail.failBecauseExceptionWasNotThrown(AWSResponseException.class);
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.jclouds.ContextBuilder;
|
|||
import org.jclouds.blobstore.BlobStore;
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -20,23 +20,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.inject.Module;
|
||||
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
|
@ -44,6 +38,9 @@ import org.jclouds.blobstore.BlobStoreContext;
|
|||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public final class RegexBlobStoreTest {
|
||||
private BlobStoreContext context;
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.jclouds.blobstore.domain.PageSet;
|
|||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
import org.jclouds.blobstore.options.CopyOptions;
|
||||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -34,7 +34,6 @@ import com.google.common.io.Resources;
|
|||
import com.google.inject.Module;
|
||||
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.JcloudsVersion;
|
||||
|
|
Ładowanie…
Reference in New Issue