Skip to content

Commit

Permalink
Address Checkstyle violations
Browse files Browse the repository at this point in the history
  • Loading branch information
gaul committed Dec 26, 2023
1 parent e5fb361 commit 1dac9cc
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 53 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/gaul/s3proxy/AliasBlobStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/gaul/s3proxy/EncryptedBlobStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -92,7 +92,7 @@ static BlobStore newEncryptedBlobStore(BlobStore blobStore,
}

private void initStore(String password, String salt)
throws IllegalArgumentException {
throws IllegalArgumentException {
try {
SecretKeyFactory factory =
SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/gaul/s3proxy/EventualBlobStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gaul/s3proxy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private static BlobStore parseMiddlewareProperties(BlobStore blobStore,

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);
}
Expand Down
47 changes: 32 additions & 15 deletions src/main/java/org/gaul/s3proxy/RegexBlobStore.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +31,8 @@
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;
Expand All @@ -25,8 +43,6 @@
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:
Expand All @@ -39,37 +55,38 @@
* 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);

Expand All @@ -78,14 +95,14 @@ public static ImmutableList<Map.Entry<Pattern, String>> parseRegexs(Properties p
".",
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));
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/gaul/s3proxy/S3Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/gaul/s3proxy/S3ProxyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ private void doHandleAnonymous(HttpServletRequest request,
throw new S3Exception(S3ErrorCode.NOT_IMPLEMENTED);
}

private void handleGetContainerAcl(HttpServletRequest request,
private void handleGetContainerAcl(HttpServletRequest request,
HttpServletResponse response, BlobStore blobStore,
String containerName) throws IOException, S3Exception {
if (!blobStore.containerExists(containerName)) {
Expand Down Expand Up @@ -962,7 +962,7 @@ private void handleSetContainerAcl(HttpServletRequest request,
addCorsResponseHeader(request, response);
}

private void handleGetBlobAcl(HttpServletRequest request,
private void handleGetBlobAcl(HttpServletRequest request,
HttpServletResponse response, BlobStore blobStore,
String containerName, String blobName) throws IOException {
BlobAccess access = blobStore.getBlobAccess(containerName, blobName);
Expand Down Expand Up @@ -1334,7 +1334,7 @@ private void handleContainerCreate(HttpServletRequest request,
addCorsResponseHeader(request, response);
}

private void handleContainerDelete(HttpServletRequest request,
private void handleContainerDelete(HttpServletRequest request,
HttpServletResponse response, BlobStore blobStore,
String containerName) throws IOException, S3Exception {
if (!blobStore.containerExists(containerName)) {
Expand Down Expand Up @@ -1564,7 +1564,7 @@ private void handleBlobList(HttpServletRequest request,
}
}

private void handleBlobRemove(HttpServletRequest request,
private void handleBlobRemove(HttpServletRequest request,
HttpServletResponse response, BlobStore blobStore,
String containerName, String blobName)
throws IOException, S3Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gaul/s3proxy/crypto/Encryption.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gaul/s3proxy/crypto/PartPadding.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/gaul/s3proxy/AliasBlobStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
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;
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/gaul/s3proxy/AwsSdkAnonymousTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.common.io.ByteSource;

import org.jclouds.blobstore.BlobStoreContext;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/gaul/s3proxy/AwsSdkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,10 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
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;

Expand All @@ -59,10 +58,8 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
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;

Expand All @@ -59,10 +58,8 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void testMultipartSynchronously() {
@Override
@Test
public void testUpdateObjectACL() throws InterruptedException,
ExecutionException, TimeoutException, IOException {
ExecutionException, TimeoutException, IOException {
try {
super.testUpdateObjectACL();
Fail.failBecauseExceptionWasNotThrown(AWSResponseException.class);
Expand All @@ -255,7 +255,7 @@ public void testUpdateObjectACL() throws InterruptedException,
@Override
@Test
public void testPublicWriteOnObject() throws InterruptedException,
ExecutionException, TimeoutException, IOException {
ExecutionException, TimeoutException, IOException {
try {
super.testPublicWriteOnObject();
Fail.failBecauseExceptionWasNotThrown(AWSResponseException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
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;

Expand Down
13 changes: 5 additions & 8 deletions src/test/java/org/gaul/s3proxy/RegexBlobStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,27 @@

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;
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;
Expand Down Expand Up @@ -134,4 +131,4 @@ public void testParseMatchWithoutReplace() {
private static String createRandomContainerName() {
return "container-" + new Random().nextInt(Integer.MAX_VALUE);
}
}
}
1 change: 0 additions & 1 deletion src/test/java/org/gaul/s3proxy/ShardedBlobStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
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;
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/gaul/s3proxy/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.google.inject.Module;

import org.eclipse.jetty.util.component.AbstractLifeCycle;

import org.jclouds.Constants;
import org.jclouds.ContextBuilder;
import org.jclouds.JcloudsVersion;
Expand Down

0 comments on commit 1dac9cc

Please sign in to comment.