Address Checkstyle violations

pull/583/head
Andrew Gaul 2023-12-26 13:45:42 +09:00 zatwierdzone przez Andrew Gaul
rodzic e5fb3619df
commit 1dac9ccd12
20 zmienionych plików z 50 dodań i 53 usunięć

Wyświetl plik

@ -17,7 +17,6 @@
package org.gaul.s3proxy; package org.gaul.s3proxy;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import java.util.HashMap; import java.util.HashMap;

Wyświetl plik

@ -71,7 +71,7 @@ public final class EncryptedBlobStore extends ForwardingBlobStore {
private SecretKeySpec secretKey; private SecretKeySpec secretKey;
private EncryptedBlobStore(BlobStore blobStore, Properties properties) private EncryptedBlobStore(BlobStore blobStore, Properties properties)
throws IllegalArgumentException { throws IllegalArgumentException {
super(blobStore); super(blobStore);
String password = properties.getProperty( String password = properties.getProperty(
@ -92,7 +92,7 @@ public final class EncryptedBlobStore extends ForwardingBlobStore {
} }
private void initStore(String password, String salt) private void initStore(String password, String salt)
throws IllegalArgumentException { throws IllegalArgumentException {
try { try {
SecretKeyFactory factory = SecretKeyFactory factory =
SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");

Wyświetl plik

@ -17,7 +17,6 @@
package org.gaul.s3proxy; package org.gaul.s3proxy;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import java.util.Deque; import java.util.Deque;

Wyświetl plik

@ -250,7 +250,7 @@ public final class Main {
ImmutableList<Map.Entry<Pattern, String>> regexs = RegexBlobStore.parseRegexs( ImmutableList<Map.Entry<Pattern, String>> regexs = RegexBlobStore.parseRegexs(
properties); properties);
if (!regexs.isEmpty()){ if (!regexs.isEmpty()) {
System.err.println("Using regex backend"); System.err.println("Using regex backend");
blobStore = RegexBlobStore.newRegexBlobStore(blobStore, regexs); blobStore = RegexBlobStore.newRegexBlobStore(blobStore, regexs);
} }

Wyświetl plik

@ -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; package org.gaul.s3proxy;
import static com.google.common.base.Preconditions.checkArgument; 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.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.google.common.collect.ImmutableList;
import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobAccess; import org.jclouds.blobstore.domain.BlobAccess;
@ -25,8 +43,6 @@ import org.jclouds.blobstore.util.ForwardingBlobStore;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableList;
/** /**
* This class implements a middleware to apply regex to blob names. * This class implements a middleware to apply regex to blob names.
* The regex are configured as: * The regex are configured as:
@ -39,37 +55,38 @@ import com.google.common.collect.ImmutableList;
* end, * end,
* stopping as soon as the first regex matches. * stopping as soon as the first regex matches.
*/ */
public class RegexBlobStore extends ForwardingBlobStore { public final class RegexBlobStore extends ForwardingBlobStore {
private final ImmutableList<Entry<Pattern, String>> regexs;
private static final Logger logger = LoggerFactory.getLogger(RegexBlobStore.class); private static final Logger logger = LoggerFactory.getLogger(RegexBlobStore.class);
static BlobStore newRegexBlobStore(BlobStore delegate, ImmutableList<Entry<Pattern, String>> regexs) { private final ImmutableList<Entry<Pattern, String>> regexs;
return new RegexBlobStore(delegate, regexs);
}
private RegexBlobStore(BlobStore blobStore, ImmutableList<Entry<Pattern, String>> regexs) { private RegexBlobStore(BlobStore blobStore, ImmutableList<Entry<Pattern, String>> regexs) {
super(blobStore); super(blobStore);
this.regexs = requireNonNull(regexs); 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) { 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<>(); List<Entry<Pattern, String>> regexs = new ArrayList<>();
for (String key : properties.stringPropertyNames()) { for (String key : properties.stringPropertyNames()) {
if (key.startsWith(S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE)) { 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); 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(); String key = entry.getKey();
if (key.startsWith(S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE_MATCH)) { 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(); String regex = entry.getValue();
Pattern pattern = Pattern.compile(regex); Pattern pattern = Pattern.compile(regex);
@ -78,14 +95,14 @@ public class RegexBlobStore extends ForwardingBlobStore {
".", ".",
S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE, S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE,
S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE_REPLACE, S3ProxyConstants.PROPERTY_REGEX_BLOBSTORE_REPLACE,
regex_name)); regexName));
checkArgument( checkArgument(
replace != null, replace != null,
"Regex %s has no replace property associated", "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)); regexs.add(new SimpleEntry<>(pattern, replace));
} }

Wyświetl plik

@ -17,7 +17,6 @@
package org.gaul.s3proxy; package org.gaul.s3proxy;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import java.net.URI; import java.net.URI;

Wyświetl plik

@ -859,7 +859,7 @@ public class S3ProxyHandler {
throw new S3Exception(S3ErrorCode.NOT_IMPLEMENTED); throw new S3Exception(S3ErrorCode.NOT_IMPLEMENTED);
} }
private void handleGetContainerAcl(HttpServletRequest request, private void handleGetContainerAcl(HttpServletRequest request,
HttpServletResponse response, BlobStore blobStore, HttpServletResponse response, BlobStore blobStore,
String containerName) throws IOException, S3Exception { String containerName) throws IOException, S3Exception {
if (!blobStore.containerExists(containerName)) { if (!blobStore.containerExists(containerName)) {
@ -962,7 +962,7 @@ public class S3ProxyHandler {
addCorsResponseHeader(request, response); addCorsResponseHeader(request, response);
} }
private void handleGetBlobAcl(HttpServletRequest request, private void handleGetBlobAcl(HttpServletRequest request,
HttpServletResponse response, BlobStore blobStore, HttpServletResponse response, BlobStore blobStore,
String containerName, String blobName) throws IOException { String containerName, String blobName) throws IOException {
BlobAccess access = blobStore.getBlobAccess(containerName, blobName); BlobAccess access = blobStore.getBlobAccess(containerName, blobName);
@ -1334,7 +1334,7 @@ public class S3ProxyHandler {
addCorsResponseHeader(request, response); addCorsResponseHeader(request, response);
} }
private void handleContainerDelete(HttpServletRequest request, private void handleContainerDelete(HttpServletRequest request,
HttpServletResponse response, BlobStore blobStore, HttpServletResponse response, BlobStore blobStore,
String containerName) throws IOException, S3Exception { String containerName) throws IOException, S3Exception {
if (!blobStore.containerExists(containerName)) { if (!blobStore.containerExists(containerName)) {
@ -1564,7 +1564,7 @@ public class S3ProxyHandler {
} }
} }
private void handleBlobRemove(HttpServletRequest request, private void handleBlobRemove(HttpServletRequest request,
HttpServletResponse response, BlobStore blobStore, HttpServletResponse response, BlobStore blobStore,
String containerName, String blobName) String containerName, String blobName)
throws IOException, S3Exception { throws IOException, S3Exception {

Wyświetl plik

@ -77,9 +77,8 @@ public class DecryptionInputStream extends FilterInputStream {
* @throws IOException if cipher fails * @throws IOException if cipher fails
*/ */
public DecryptionInputStream(InputStream is, SecretKey key, public DecryptionInputStream(InputStream is, SecretKey key,
TreeMap<Integer, PartPadding> parts, int skipParts, TreeMap<Integer, PartPadding> parts, int skipParts,
long skipPartBytes) long skipPartBytes) throws IOException {
throws IOException {
super(is); super(is);
in = is; in = is;
this.parts = parts; this.parts = parts;

Wyświetl plik

@ -33,7 +33,7 @@ public class Encryption {
private final int part; private final int part;
public Encryption(SecretKeySpec key, InputStream isRaw, int partNumber) public Encryption(SecretKeySpec key, InputStream isRaw, int partNumber)
throws Exception { throws Exception {
iv = generateIV(); iv = generateIV();
Cipher cipher = Cipher.getInstance(Constants.AES_CIPHER); Cipher cipher = Cipher.getInstance(Constants.AES_CIPHER);

Wyświetl plik

@ -40,7 +40,7 @@ public class PartPadding {
private short version; private short version;
public static PartPadding readPartPaddingFromBlob(Blob blob) public static PartPadding readPartPaddingFromBlob(Blob blob)
throws IOException { throws IOException {
PartPadding partPadding = new PartPadding(); PartPadding partPadding = new PartPadding();
InputStream is = blob.getPayload().openStream(); InputStream is = blob.getPayload().openStream();

Wyświetl plik

@ -44,7 +44,6 @@ import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.options.PutOptions; import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

Wyświetl plik

@ -35,7 +35,6 @@ import com.amazonaws.services.s3.model.S3Object;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

Wyświetl plik

@ -96,12 +96,10 @@ import com.google.common.collect.Maps;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import org.assertj.core.api.Fail; import org.assertj.core.api.Fail;
import org.jclouds.ContextBuilder; import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.rest.HttpClient; import org.jclouds.rest.HttpClient;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;

Wyświetl plik

@ -40,7 +40,6 @@ import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import com.google.common.net.HttpHeaders; 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.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.ssl.SSLContextBuilder;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

Wyświetl plik

@ -40,7 +40,6 @@ import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import com.google.common.net.HttpHeaders; 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.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.ssl.SSLContextBuilder;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

Wyświetl plik

@ -242,7 +242,7 @@ public final class EncryptedBlobStoreLiveTest extends S3ClientLiveTest {
@Override @Override
@Test @Test
public void testUpdateObjectACL() throws InterruptedException, public void testUpdateObjectACL() throws InterruptedException,
ExecutionException, TimeoutException, IOException { ExecutionException, TimeoutException, IOException {
try { try {
super.testUpdateObjectACL(); super.testUpdateObjectACL();
Fail.failBecauseExceptionWasNotThrown(AWSResponseException.class); Fail.failBecauseExceptionWasNotThrown(AWSResponseException.class);
@ -255,7 +255,7 @@ public final class EncryptedBlobStoreLiveTest extends S3ClientLiveTest {
@Override @Override
@Test @Test
public void testPublicWriteOnObject() throws InterruptedException, public void testPublicWriteOnObject() throws InterruptedException,
ExecutionException, TimeoutException, IOException { ExecutionException, TimeoutException, IOException {
try { try {
super.testPublicWriteOnObject(); super.testPublicWriteOnObject();
Fail.failBecauseExceptionWasNotThrown(AWSResponseException.class); Fail.failBecauseExceptionWasNotThrown(AWSResponseException.class);

Wyświetl plik

@ -32,7 +32,6 @@ import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

Wyświetl plik

@ -20,23 +20,17 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.AbstractMap.SimpleEntry;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Random; import java.util.Random;
import java.util.regex.Pattern; 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.collect.ImmutableList;
import com.google.common.hash.HashCode;
import com.google.common.hash.Hashing; import com.google.common.hash.Hashing;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import com.google.inject.Module; import com.google.inject.Module;
import java.util.AbstractMap.SimpleEntry;
import org.assertj.core.api.Assertions; import org.assertj.core.api.Assertions;
import org.jclouds.ContextBuilder; import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.BlobStore; 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.Blob;
import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public final class RegexBlobStoreTest { public final class RegexBlobStoreTest {
private BlobStoreContext context; private BlobStoreContext context;
@ -134,4 +131,4 @@ public final class RegexBlobStoreTest {
private static String createRandomContainerName() { private static String createRandomContainerName() {
return "container-" + new Random().nextInt(Integer.MAX_VALUE); return "container-" + new Random().nextInt(Integer.MAX_VALUE);
} }
} }

Wyświetl plik

@ -35,7 +35,6 @@ import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.options.CopyOptions; import org.jclouds.blobstore.options.CopyOptions;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

Wyświetl plik

@ -34,7 +34,6 @@ import com.google.common.io.Resources;
import com.google.inject.Module; import com.google.inject.Module;
import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.ContextBuilder; import org.jclouds.ContextBuilder;
import org.jclouds.JcloudsVersion; import org.jclouds.JcloudsVersion;