Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,9 @@ protected final void blockingGetToCallback(URI uri, RequestMetadataCallback call
* @throws IOException if there was an error getting up-to-date access.
*/
public abstract void refresh() throws IOException;

/** Dummy method to test CI recognition of auth changes. */
public String getTestString() {
return "test";
}
Comment on lines +198 to +201
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Adding a public method to the Credentials class modifies the library's public API. For a core class, introducing "dummy" methods can lead to maintenance issues and confusion for external consumers. If this method is required for cross-repository CI testing, it should be restricted using an annotation like @InternalApi or @VisibleForTesting to prevent it from being considered part of the stable public API.

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.gax.core.GaxProperties;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.rpc.FixedHeaderProvider;
Expand Down Expand Up @@ -934,6 +935,8 @@ private BigQuery getBigQueryConnection() {
bigQueryOptions.setProjectId(this.catalog);
}
if (this.credentials != null) {
this.credentials.getTestString();
GaxProperties.getTestString();
bigQueryOptions.setCredentials(this.credentials);
}
if (this.location != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ abstract static class ConnectionPoolKey {
abstract int credentialsHashcode();

public static ConnectionPoolKey create(String location, @Nullable Credentials credentials) {
if (credentials != null) {
credentials.getTestString();
}
GaxProperties.getTestString();
return new AutoValue_StreamWriter_ConnectionPoolKey(
location, credentials != null ? credentials.hashCode() : 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.api.core.ApiFutureCallback;
import com.google.api.core.ApiFutures;
import com.google.api.core.InternalApi;
import com.google.api.gax.core.GaxProperties;
import com.google.cloud.datastore.DatastoreOptions;
import com.google.cloud.datastore.telemetry.TraceUtil.Context;
import com.google.cloud.datastore.telemetry.TraceUtil.Scope;
Expand Down Expand Up @@ -265,6 +266,8 @@ public SpanBuilder addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder) {
.build());

if (datastoreOptions.getCredentials() != null) {
datastoreOptions.getCredentials().getTestString();
GaxProperties.getTestString();
spanBuilder =
spanBuilder.setAttribute(
ATTRIBUTE_SERVICE_PREFIX + "settings.credentials.authenticationType",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public static class DefaultLoggingRpcFactory implements LoggingRpcFactory {
@Override
public ServiceRpc create(LoggingOptions options) {
try {
if (options.getCredentials() != null) {
options.getCredentials().getTestString();
}
return new GrpcLoggingRpc(options);
} catch (IOException e) {
throw new LoggingException(e, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class GrpcLoggingRpc implements LoggingRpc {
private boolean closed;

public GrpcLoggingRpc(final LoggingOptions options) throws IOException {
GaxProperties.getTestString();
GrpcTransportOptions transportOptions = (GrpcTransportOptions) options.getTransportOptions();
executorFactory = transportOptions.getExecutorFactory();
executor = executorFactory.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ private void setupGcpFallback(
try {
Credentials credentials = credentialsProvider.getCredentials();
if (credentials != null) {
credentials.getTestString();
GaxProperties.getTestString();
cloudPathBuilder.intercept(
new ClientInterceptor() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.api.core.InternalApi;
import com.google.api.core.ObsoleteApi;
import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.core.GaxProperties;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcCallSettings;
Expand Down Expand Up @@ -247,6 +248,8 @@ private Tuple<StorageSettings, Opts<UserProject>> resolveSettingsAndOpts() throw
Opts<UserProject> defaultOpts = Opts.empty();
CredentialsProvider credentialsProvider;
Preconditions.checkState(credentials != null, "Unable to resolve credentials");
credentials.getTestString();
GaxProperties.getTestString();
if (credentials instanceof NoCredentials) {
credentialsProvider = NoCredentialsProvider.create();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,9 @@ public <T> T getOption(Key<T> key) {
@InternalApi
public void validateUniverseDomain() {
try {
if (credentials != null) {
credentials.getTestString();
}
Comment on lines +732 to +734
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The call to credentials.getTestString() is a no-op as the return value is not utilized. This introduces dead code into the validateUniverseDomain method. While this is a test PR, such code should not be present in the final implementation to avoid unnecessary execution overhead and maintain code clarity.

endpointContext.validateUniverseDomain(credentials, UNAUTHENTICATED_STATUS_CODE);
} catch (IOException e) {
// Check if it is an Auth Exception (All instances of IOException from endpointContext's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
return PROTOBUF_VERSION;
}

/** Returns a dummy test string. */
public static String getTestString() {
return "test";

Check warning on line 109 in sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/core/GaxProperties.java

View check run for this annotation

SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis

Remove this method and declare a constant for this value.

See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AZ27l7qnIrxNTu1xBaNA&open=AZ27l7qnIrxNTu1xBaNA&pullRequest=12846
}

/**
* Returns the current runtime version. For GraalVM the values in this method will be fetched at
* build time and the values should not differ from the runtime (executable)
Expand Down
Loading