Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Refactor - Minor #557

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ protected CreateBucketResponse createBucketAndVerifyResponse(
assertTrue(
StringUtils.isNotBlank(bucketFromResponse.getEtag()), "Etag should not be blank");
assertTrue(bucketFromResponse.getFreeformTags().isEmpty(), "FreeformTags should be empty");
assertTrue(
initialMetadata.equals(bucketFromResponse.getMetadata()),
"Metadata should be equal");
assertEquals(initialMetadata, bucketFromResponse.getMetadata(), "Metadata should be equal");
assertEquals(namespace, bucketFromResponse.getNamespace(), "Namespace should be equal");
assertEquals(
Bucket.PublicAccessType.valueOf(pat.name()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ protected CreateBucketResponse createBucketAndVerifyResponse(
assertTrue(
StringUtils.isNotBlank(bucketFromResponse.getEtag()), "Etag should not be blank");
assertTrue(bucketFromResponse.getFreeformTags().isEmpty(), "FreeformTags should be empty");
assertTrue(
initialMetadata.equals(bucketFromResponse.getMetadata()),
"Metadata should be equal");
assertEquals(initialMetadata, bucketFromResponse.getMetadata(), "Metadata should be equal");
assertEquals(namespace, bucketFromResponse.getNamespace(), "Namespace should be equal");
assertEquals(
Bucket.PublicAccessType.valueOf(pat.name()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
package com.oracle.bmc.auth.okeworkloadidentity.internal;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.oracle.bmc.responses.BmcResponse;

import java.util.List;
import java.util.Map;

public class OkeResourcePrincipalSessionToken {
@JsonProperty("token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
package com.oracle.bmc.auth.sasl;

import com.oracle.bmc.auth.BasicAuthenticationDetailsProvider;
import java.io.IOException;
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.UnsupportedCallbackException;

/**
* Callback to handle in the SASL callback handler used when creating a {@link
Expand Down
2 changes: 0 additions & 2 deletions bmc-common/src/main/java/com/oracle/bmc/ConfigFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import java.util.HashMap;
import java.util.Map;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import com.oracle.bmc.util.internal.StringUtils;
import static com.oracle.bmc.util.internal.FileUtils.expandUserHome;
Expand Down
2 changes: 1 addition & 1 deletion bmc-common/src/main/java/com/oracle/bmc/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ private static void readAlloyRegionConfigFile() {
try {
OCI_SDK_ENABLED_SERVICES_SET.addAll(
regionAlloySchema.getServices().stream()
.map(str -> str.toLowerCase())
.map(String::toLowerCase)
.map(str -> str.replaceAll("[^a-z]", ""))
.collect(Collectors.toSet()));
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ protected String autoDetectEndpointUsingMetadataUrl() {
if (federationEndpoint == null) {

executeInstanceFallback();
String regionStr = fetchRegion(resp -> resp.textBody());
String regionStr = fetchRegion(HttpResponse::textBody);
LOG.info("Looking up region for {}", regionStr);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.io.InputStream;
import java.security.KeyPair;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public ConfigFileAuthenticationDetailsProvider(ConfigFile configFile) {
new ConfigFileInstancePrincipalAuthenticationDetailsProvider(configFile);
} else if (RESOURCE_PRINCIPAL_AUTHENTICATION_TYPE_VALUE.equals(authentication_type)) {
LOG.debug(
"Authentication type in config file: "
+ configFile.get(AUTHENTICATION_TYPE_KEY));
"Authentication type in config file: {}"
,configFile.get(AUTHENTICATION_TYPE_KEY));
this.delegate =
new ConfigFileResourcePrincipalAuthenticationDetailsProvider(configFile);
} else {
Expand All @@ -99,7 +99,7 @@ public static Region getRegionFromConfigFile(ConfigFile configFile) {
// if regionId is not defined in config file check env variable
if (StringUtils.isBlank(regionId)) {
regionId = System.getenv(OCI_REGION_ENV_VAR_NAME);
LOG.info("regionId from OCI_REGION env variable: " + regionId);
LOG.info("regionId from OCI_REGION env variable: {}", regionId);
}

if (regionId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
*/
package com.oracle.bmc.auth;

import com.oracle.bmc.auth.internal.JwtClaimsSet;
import org.slf4j.Logger;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.ParseException;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;

/**
* Implementation of {@link ServiceAccountTokenSupplier} that allows to pass in a token path to read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
*/
package com.oracle.bmc.auth;

import com.oracle.bmc.auth.internal.JwtClaimsSet;

import java.text.ParseException;
import java.time.Instant;
import java.util.Date;

/**
* Implementation of {@link ServiceAccountTokenSupplier} that allows to pass in a token to be used
* as a kubernetes service account token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
*/
package com.oracle.bmc.auth;

import java.io.BufferedReader;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
Expand All @@ -20,7 +19,6 @@
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import jakarta.annotation.Nonnull;
import javax.security.auth.Refreshable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static String parseAndGetToken(ConfigFileReader.ConfigFile effectiveConfi
Files.lines(
Paths.get(FileUtils.expandUserHome(delegationTokenFilePath)),
StandardCharsets.UTF_8)) {
stream.forEach(s -> tokenBuilder.append(s));
stream.forEach(tokenBuilder::append);
} catch (IOException e) {
LOG.warn("Exception in reading or parsing delegation token file", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.time.Duration;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package com.oracle.bmc.auth.internal;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.oracle.bmc.requests.BmcRequest;

/** Class is immutable. @Immutable */
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,11 @@ public Optional<RSAPrivateKey> supplyKey(@Nonnull String keyId) {
};

Supplier<String> keyIdSupplier =
new Supplier<String>() {
@Override
public String get() {
return keyIdForX509Request(
tenancyId,
leafCertificateSupplier
.getCertificateAndKeyPair()
.getCertificate());
}
};
() -> keyIdForX509Request(
tenancyId,
leafCertificateSupplier
.getCertificateAndKeyPair()
.getCertificate());

this.httpClient =
HttpProvider.getDefault()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package com.oracle.bmc.http;

import com.oracle.bmc.http.client.HttpClientBuilder;
import org.slf4j.Logger;

/**
* DefaultConnectorConfigurator represents the basic behavior of the transport layer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
import com.oracle.bmc.internal.EndpointBuilder;
import com.oracle.bmc.requests.BmcRequest;
import com.oracle.bmc.responses.BmcResponse;
import com.oracle.bmc.util.internal.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;

import java.time.Duration;
import java.util.ArrayList;
import java.util.EnumMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private BouncyCastleHelper() {
try {
final Class<?> bouncyCastleProviderClass = getBouncyCastleProviderClass();
bouncyCastleProvider = (Provider) bouncyCastleProviderClass.newInstance();
LOG.info("Instantiated provider: " + bouncyCastleProviderClass.getName());
LOG.info("Instantiated provider: {}" ,bouncyCastleProviderClass.getName());
} catch (InstantiationException | IllegalAccessException ex) {
LOG.error("Failed to instantiate any BouncyCastle provider", ex);
throw new BouncyCastleHelperException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/**
* Factory class to create RequestSigner instances. Takes care of setting up the appropriate
* suppliers based on the cacheability of the credentials (indicated by {@link AuthCachingPolicy}.
* suppliers based on the cacheability of the credentials (indicated by {@link AuthCachingPolicy}).
* By default, all credentials are cacheable.
*
* <p>This factory supports authentication providers that inherit from {@link
Expand Down Expand Up @@ -65,22 +65,12 @@ protected Supplier<String> createKeyIdSupplier(

// if keyId caching is disabled, fetch the ID on every request
if (!cacheKeyId) {
return new Supplier<String>() {
@Override
public String get() {
return authenticationDetailsProvider.getKeyId();
}
};
return authenticationDetailsProvider::getKeyId;
}

// else fetch it now and return a fixed supplier
final String keyId = authenticationDetailsProvider.getKeyId();
return new Supplier<String>() {
@Override
public String get() {
return keyId;
}
};
return () -> keyId;
}

public static KeySupplier<RSAPrivateKey> createKeySupplier(
Expand All @@ -93,15 +83,10 @@ public static KeySupplier<RSAPrivateKey> createKeySupplier(

// if private key caching is disabled, parse the stream on every request
if (!cachePrivateKey) {
return new KeySupplier<RSAPrivateKey>() {
@Override
public Optional<RSAPrivateKey> supplyKey(String keyId) {
return new PEMFileRSAPrivateKeySupplier(
authenticationDetailsProvider.getPrivateKey(),
authenticationDetailsProvider.getPassphraseCharacters())
.supplyKey(keyId);
}
};
return keyId -> new PEMFileRSAPrivateKeySupplier(
authenticationDetailsProvider.getPrivateKey(),
authenticationDetailsProvider.getPassphraseCharacters())
.supplyKey(keyId);
}

// else parse once now and return a fixed supplier
Expand Down
4 changes: 2 additions & 2 deletions bmc-common/src/main/java/com/oracle/bmc/model/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public String toString() {
if (endByte != null) {
return String.format(END_ONLY_HEADER_VALUE_FORMAT, endByte);
}
LOG.error("Must provide start/end byte for range request: " + this);
LOG.error("Must provide start/end byte for range request: {}", this);
return "";
}

/**
* Parse the "content-range" header per https://tools.ietf.org/html/rfc7233#section-4.2.
* Parse the "content-range" header per <a href="https://tools.ietf.org/html/rfc7233#section-4.2">...</a>.
*
* <p>Note, this is only for successful responses (206). It does not handle 416 (range not
* satisfiable).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;

public class RegionAlloySchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* Class that represents the conditions documented in
* https://docs.cloud.oracle.com/iaas/Content/API/References/apierrors.htm for which the operation
* <a href="https://docs.cloud.oracle.com/iaas/Content/API/References/apierrors.htm">...</a> for which the operation
* may be retried.
*/
public class DefaultRetryCondition implements RetryCondition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package com.oracle.bmc.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import com.oracle.bmc.io.internal.WrappedByteArrayInputStream;
import com.oracle.bmc.io.internal.WrappedFileInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
import java.util.concurrent.TimeoutException;
import java.util.function.Function;

import com.oracle.bmc.auth.RefreshableOnNotAuthenticatedProvider;
import com.oracle.bmc.model.BmcException;
import com.oracle.bmc.requests.BmcRequest;
import com.oracle.bmc.responses.AsyncHandler;

/**
* Combined future and callbacks for asynchronous requests intended to work with some authenticated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ public interface WaiterScheduler {
* positive.
*/
WaiterScheduler UNSUPPORTED =
new WaiterScheduler() {
@Override
public Future<?> schedule(Runnable command, long time, TimeUnit unit) {
throw new UnsupportedOperationException(
"Delays not supported for async waiter (no scheduler given)");
}
(command, time, unit) -> {
throw new UnsupportedOperationException(
"Delays not supported for async waiter (no scheduler given)");
};
/**
* Scheduler implementation that blocks in the {@link #schedule} method for the given time to
Expand Down