Skip to content

Commit

Permalink
Migrate Identity libraries to new linting format (#42833)
Browse files Browse the repository at this point in the history
Migrate Identity libraries to new linting format
  • Loading branch information
alzimmermsft authored and billwert committed Nov 15, 2024
1 parent b964943 commit 6fc9690
Show file tree
Hide file tree
Showing 31 changed files with 934 additions and 1,033 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@
<!-- Requires static access to logger to report errors while loading i18n messages (from within a static initializer )-->
<suppress checks="com.azure.tools.checkstyle.checks.GoodLoggingCheck" files="Messages.java"/>

<!-- TODO: Synapse access control API does not support PagedResponse and Response. -->
<!-- Checkstyle suppressions for naming issues reported in the Synapse artifacts related clients-->
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" files=".*[/\\]synapse[/\\].*"/>
<!-- Suppress the check on synapse code-gen classes -->
<suppress checks="Indentation" files="com.azure.analytics.synapse.accesscontrol.implementation..*Impl" /> <!-- *Impl infers *ClientImpl -->
<suppress checks="Indentation" files="com.azure.analytics.synapse.artifacts.implementation..*Impl" /> <!-- *Impl infers *ClientImpl -->
<suppress checks="Indentation" files="com.azure.analytics.synapse.spark.implementation..*Impl" /> <!-- *Impl infers *ClientImpl -->
<suppress checks="Indentation" files="com.azure.analytics.synapse.managedprivateendpoints.implementation..*Impl" /> <!-- *Impl infers *ClientImpl -->
<suppress checks="Indentation" files="com.azure.analytics.synapse.monitoring.implementation..*Impl" /> <!-- *Impl infers *ClientImpl -->

<!-- Suppress the long package name in Synapse managed private endpoints -->
<suppress checks="PackageName" files="com.azure.analytics.synapse.managedprivateendpoints.*" />
<!-- Suppress the long line in endpoint path -->
<suppress checks="LineLength" files="com.azure.analytics.synapse.managedprivateendpoints.implementation.ManagedPrivateEndpointsImpl.java"/>

<!-- Allows the HttpPipelinePolicy derived class in Implementation folder -->
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicy" files="com.azure.containers.containerregistry.implementation.authentication.ContainerRegistryCredentialsPolicy.java"/>
<suppress checks="com.azure.tools.checkstyle.checks.HttpPipelinePolicy" files="com.azure.messaging.eventgrid.implementation.CloudEventTracingPipelinePolicy.java"/>
Expand Down
126 changes: 126 additions & 0 deletions sdk/identity/azure-identity/checkstyle-suppressions.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions sdk/identity/azure-identity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
--add-exports com.azure.core/com.azure.core.implementation.util=ALL-UNNAMED
</javaModulesSurefireArgLine>

<checkstyle.suppressionsLocation>checkstyle-suppressions.xml</checkstyle.suppressionsLocation>

<spotbugs.skip>false</spotbugs.skip>
<spotbugs.excludeFilterFile>spotbugs-exclude.xml</spotbugs.excludeFilterFile>
<spotbugs.includeTests>true</spotbugs.includeTests>
</properties>

Expand Down
203 changes: 203 additions & 0 deletions sdk/identity/azure-identity/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<?xml version="1.0" encoding="UTF-8"?>

<FindBugsFilter xmlns="https://github.com/spotbugs/filter/3.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
<Match>
<Bug pattern="BC_UNCONFIRMED_CAST_OF_RETURN_VALUE" />
<Or>
<Class name="com.azure.jedis.ApiManager" />
<Class name="com.azure.redisson.sample.AuthenticateWithTokenCache" />
<Class name="com.azure.redisson.sample.HandleReauthentication" />
<Class name="com.azure.redisson.sample.HelloWorld" />
</Or>
</Match>
<Match>
<Bug pattern="CT_CONSTRUCTOR_THROW" />
<Or>
<Class name="com.azure.identity.AzurePipelinesCredential" />
<Class name="com.azure.identity.implementation.IdentityClient" />
<Class name="com.azure.identity.implementation.IdentitySyncClient" />
</Or>
</Match>
<Match>
<Bug pattern="DE_MIGHT_IGNORE" />
<Class name="com.azure.identity.implementation.IdentitySyncClient" />
</Match>
<Match>
<Bug pattern="DLS_DEAD_LOCAL_STORE" />
<Or>
<Class name="com.azure.identity.credential.JavaDocCodeSnippets" />
<Class name="com.azure.lettuce.sample.HandleReauthentication" />
<Class name="com.azure.lettuce.sample.withcredentialprovider.HandleReauthentication" />
<Class name="com.azure.redisson.sample.AuthenticateWithTokenCache" />
<Class name="com.azure.redisson.sample.HandleReauthentication" />
<Class name="com.azure.redisson.sample.HelloWorld" />
</Or>
</Match>
<Match>
<Bug pattern="DMI_HARDCODED_ABSOLUTE_FILENAME" />
<Or>
<Class name="com.azure.identity.implementation.ValidationUtilTests" />
<Class name="com.azure.identity.implementation.util.ValidationUtil" />
</Or>
</Match>
<Match>
<Bug pattern="DM_DEFAULT_ENCODING" />
<Or>
<Class name="LiveManagedIdentityTests" />
<Class name="com.azure.identity.AuthenticationRecordTest" />
<Class name="com.azure.identity.implementation.PowershellManager" />
</Or>
</Match>
<Match>
<Bug pattern="DM_STRING_TOSTRING" />
<Class name="com.azure.redisson.sample.AuthenticateWithTokenCache" />
</Match>
<Match>
<Bug pattern="EI_EXPOSE_REP" />
<Or>
<Class name="com.azure.identity.implementation.IdentityClient" />
<Class name="com.azure.identity.implementation.IdentityClientOptions" />
<Class name="com.azure.identity.implementation.IdentitySyncClient" />
<Class name="com.azure.identity.implementation.MsalAuthenticationAccount" />
<Class name="com.azure.identity.util.EmptyEnvironmentConfigurationSource" />
</Or>
</Match>
<Match>
<Bug pattern="EI_EXPOSE_REP2" />
<Or>
<Class name="com.azure.identity.implementation.IdentityClientBuilder" />
<Class name="com.azure.identity.implementation.IdentityClientOptions" />
<Class name="com.azure.identity.implementation.MsalAuthenticationAccount" />
<Class name="com.azure.jedis.sample.AuthenticateWithTokenCache$TokenRefreshCache" />
</Or>
</Match>
<Match>
<Bug pattern="EQ_DOESNT_OVERRIDE_EQUALS" />
<Class name="com.azure.identity.implementation.ValidationUtilTests$TestFile" />
</Match>
<Match>
<Bug pattern="MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR" />
<Or>
<Class name="com.azure.identity.DeviceCodeCredentialBuilder" />
<Class name="com.azure.identity.implementation.IdentityClient" />
<Class name="com.azure.identity.implementation.IdentitySyncClient" />
<Class name="com.azure.identity.implementation.LinuxKeyRingAccessor$GError" />
<Class name="com.azure.identity.implementation.WindowsCredentialApi$CREDENTIAL" />
<Class name="com.azure.identity.implementation.WindowsCredentialApi$PCREDENTIAL" />
</Or>
</Match>
<Match>
<Bug pattern="NM_FIELD_NAMING_CONVENTION" />
<Or>
<Class name="com.azure.identity.implementation.WindowsCredentialApi$CREDENTIAL" />
<Class name="com.azure.identity.implementation.WindowsCredentialApi$CREDENTIAL_ATTRIBUTE" />
</Or>
</Match>
<Match>
<Bug pattern="NP_NULL_ON_SOME_PATH" />
<Or>
<Class name="com.azure.identity.implementation.IdentityClient" />
<Class name="com.azure.identity.implementation.ValidationUtilTests" />
</Or>
</Match>
<Match>
<Bug pattern="NP_NULL_ON_SOME_PATH_EXCEPTION" />
<Class name="com.azure.identity.implementation.IdentityClient" />
</Match>
<Match>
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" />
<Or>
<Class name="com.azure.identity.implementation.IdentityClientTests" />
<Class name="com.azure.identity.implementation.SynchronizedAccessorTests" />
<Class name="com.azure.identity.implementation.util.ValidationUtil" />
<Class name="com.azure.jedis.Authenticator" />
<Class name="com.azure.lettuce.sample.HellloWorld" />
<Class name="com.azure.lettuce.sample.withcredentialprovider.AuthenticateWithTokenCache$AzureRedisCredentials" />
<Class name="com.azure.lettuce.sample.withcredentialprovider.HandleReauthentication$AzureRedisCredentials" />
<Class name="com.azure.lettuce.sample.withcredentialprovider.HelloWorld$AzureRedisCredentials" />
<Class name="com.azure.redisson.sample.HelloWorld" />
</Or>
</Match>
<Match>
<Bug pattern="NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD" />
<Class name="com.azure.identity.implementation.WindowsCredentialAccessor" />
</Match>
<Match>
<Bug pattern="OBL_UNSATISFIED_OBLIGATION" />
<Class name="com.azure.identity.credential.JavaDocCodeSnippets" />
</Match>
<Match>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
<Class name="com.azure.identity.implementation.IdentityClient" />
</Match>
<Match>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE" />
<Class name="com.azure.identity.implementation.IdentityClient" />
</Match>
<Match>
<Bug pattern="REC_CATCH_EXCEPTION" />
<Or>
<Class name="com.azure.identity.DeviceCodeCredential" />
<Class name="com.azure.identity.InteractiveBrowserCredential" />
<Class name="com.azure.identity.UsernamePasswordCredential" />
<Class name="com.azure.identity.implementation.IdentitySyncClient" />
</Or>
</Match>
<Match>
<Bug pattern="SE_NO_SERIALVERSIONID" />
<Class name="com.azure.identity.implementation.ValidationUtilTests$TestFile" />
</Match>
<Match>
<Bug pattern="SE_TRANSIENT_FIELD_NOT_RESTORED" />
<Class name="com.azure.identity.implementation.MsalAuthenticationAccount" />
</Match>
<Match>
<Bug pattern="UI_INHERITANCE_UNSAFE_GETRESOURCE" />
<Class name="com.azure.identity.implementation.IdentityClientTests" />
</Match>
<Match>
<Bug pattern="UL_UNRELEASED_LOCK_EXCEPTION_PATH" />
<Class name="com.azure.jedis.Authenticator" />
</Match>
<Match>
<Bug pattern="UPM_UNCALLED_PRIVATE_METHOD" />
<Or>
<Class name="com.azure.identity.implementation.IdentityClient" />
<Class name="com.azure.jedis.implementation.authentication.AccessTokenCache" />
</Or>
</Match>
<Match>
<Bug pattern="UUF_UNUSED_FIELD" />
<Class name="com.azure.identity.implementation.IdentityClientOptions" />
</Match>
<Match>
<Bug pattern="UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD" />
<Or>
<Class name="com.azure.identity.implementation.WindowsCredentialApi$CREDENTIAL" />
<Class name="com.azure.identity.implementation.WindowsCredentialApi$CREDENTIAL_ATTRIBUTE" />
</Or>
</Match>
<Match>
<Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" />
<Or>
<Class name="com.azure.identity.implementation.PersistentTokenCacheImpl" />
<Class name="com.azure.jedis.AzureJedisClientBuilder" />
</Or>
</Match>
<Match>
<Bug pattern="UWF_UNWRITTEN_FIELD" />
<Class name="com.azure.identity.implementation.LinuxKeyRingAccessor$GError" />
</Match>
<Match>
<Bug pattern="UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD" />
<Or>
<Class name="com.azure.identity.implementation.WindowsCredentialApi$CREDENTIAL" />
<Class name="com.azure.identity.implementation.WindowsCredentialApi$PCREDENTIAL" />
</Or>
</Match>
<Match>
<Bug pattern="VA_FORMAT_STRING_USES_NEWLINE" />
<Class name="com.azure.identity.implementation.models.AzureCliTokenTests" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

/**
* Package containing implementation model classes.
*/
package com.azure.identity.implementation.models;
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* Manages Api calls for Azure Redis Client.
*/
class ApiManager {
private final ClientLogger clientLogger = new ClientLogger(ApiManager.class);
private Authenticator authenticator;
private RetryStrategy retryStrategy;
private static final ClientLogger LOGGER = new ClientLogger(ApiManager.class);
private final Authenticator authenticator;
private final RetryStrategy retryStrategy;

/**
* Creates an instance of ApiManager class.
Expand All @@ -43,23 +43,24 @@ <T> T execute(Supplier<T> supplier, AzureJedisClient jedisClient, RetryStrategy
authenticator.authenticateIfRequired(jedisClient);
T out = supplier.get();
String methodName = getMethodName(4);
clientLogger.log(LogLevel.INFORMATIONAL, () -> "Successfully executed API call: " + methodName);
LOGGER.log(LogLevel.INFORMATIONAL, () -> "Successfully executed API call: " + methodName);
return out;
} catch (Exception e) {
retries++;
if (retries >= retryStrategy.getMaxRetries()) {
throw clientLogger.logThrowableAsError((e instanceof JedisException ? (JedisException) e : new RuntimeException(e)));
throw LOGGER.logThrowableAsError((e instanceof JedisException ? (JedisException) e : new RuntimeException(e)));
}
clientLogger.logThrowableAsWarning((e instanceof JedisException ? (JedisException) e : new RuntimeException(e)));
clientLogger.log(LogLevel.INFORMATIONAL, () -> "Retrying to execute the command.");
LOGGER.logThrowableAsWarning((e instanceof JedisException ? (JedisException) e : new RuntimeException(e)));
LOGGER.log(LogLevel.INFORMATIONAL, () -> "Retrying to execute the command.");
try {
Thread.sleep(retryStrategy.calculateRetryDelay(retries).toMillis());
} catch (InterruptedException ex) {
throw clientLogger.logExceptionAsError(new RuntimeException(ex));
e.addSuppressed(ex);
throw LOGGER.logExceptionAsError(new RuntimeException(ex));
}
}
}
throw clientLogger.logExceptionAsError(new IllegalStateException("Failed to execute the command"));
throw LOGGER.logExceptionAsError(new IllegalStateException("Failed to execute the command"));
}

private RetryStrategy getRetryStrategy(RetryOptions retryOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.azure.jedis;

import com.azure.core.credential.TokenRequestContext;
import com.azure.core.util.logging.ClientLogger;
import com.azure.jedis.implementation.authentication.AccessTokenCache;
import com.azure.jedis.implementation.authentication.AccessTokenResult;
import com.azure.jedis.implementation.authentication.AuthenticationInfo;
Expand All @@ -19,11 +18,10 @@
* Authenticator manages authentication for Jedis client connection.
*/
class Authenticator {
private final ClientLogger clientLogger = new ClientLogger(Authenticator.class);
private AccessTokenCache tokenCache;
private TokenRequestContext tokenRequestContext;
private final AccessTokenCache tokenCache;
private final TokenRequestContext tokenRequestContext;
private volatile boolean authenticated;
ReentrantLock lock;
private final ReentrantLock lock;

Authenticator(AccessTokenCache tokenCache) {
this.tokenCache = tokenCache;
Expand Down
Loading

0 comments on commit 6fc9690

Please sign in to comment.