Skip to content

Commit

Permalink
Add Stephen's formatting changes after applying all non java files
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Jun 13, 2023
1 parent 9ec33b7 commit 1d30c96
Show file tree
Hide file tree
Showing 327 changed files with 18,444 additions and 12,090 deletions.
58 changes: 56 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/


import com.diffplug.gradle.spotless.JavaExtension
import org.opensearch.gradle.test.RestIntegTestTask

buildscript {
Expand Down Expand Up @@ -51,7 +52,7 @@ plugins {
id 'idea'
id 'jacoco'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.18.0'
id 'com.diffplug.spotless' version '6.19.0'
id 'checkstyle'
id 'com.netflix.nebula.ospackage' version "11.1.0"
id "org.gradle.test-retry" version "1.5.2"
Expand All @@ -69,7 +70,60 @@ apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.pluginzip'
apply plugin: 'opensearch.rest-test'
apply plugin: 'opensearch.testclusters'
apply from: 'gradle/formatting.gradle'
// apply from: 'gradle/formatting.gradle'

spotless {
java {
// Normally this isn't necessary, but we have Java sources in
// non-standard places
target '**/com/amazon/dlic/**/*.java'
target '**/com/amazon/security/**/*.java'
target '**/test/java/org/opensearch/security/**/*.java'

removeUnusedImports()
eclipse().configFile rootProject.file('formatter/formatterConfig.xml')
trimTrailingWhitespace()
endWithNewline();

// note: you can use an empty string for all the imports you didn't specify explicitly, and '\\#` prefix for static imports
importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#')

custom 'Refuse wildcard imports', {
// Wildcard imports can't be resolved; fail the build
if (it =~ /\s+import .*\*;/) {
throw new AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.")
}
}

// See DEVELOPER_GUIDE.md for details of when to enable this.
if (System.getProperty('spotless.paddedcell') != null) {
paddedCell()
}
}
format 'misc', {
target '*.md', '*.gradle', '**/*.json', '**/*.yaml', '**/*.yml', '**/*.svg'

trimTrailingWhitespace()
endWithNewline()
}
format('javaFoo', JavaExtension) {

importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#')
target '**/*.java'
targetExclude '**/com/amazon/dlic/**/*.java'
targetExclude '**/com/amazon/security/**/*.java'
targetExclude '**/test/java/org/opensearch/security/**/*.java'
targetExclude 'src/integrationTest/**'

trimTrailingWhitespace()
endWithNewline();
}
format("integrationTest", JavaExtension) {
target('src/integrationTest/java/**/*.java')
importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#')
indentWithTabs(4)
}
}

licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')
Expand Down
8 changes: 4 additions & 4 deletions bwc-test/src/test/java/SecurityBackwardsCompatibilityIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
import java.util.Set;
import java.util.stream.Collectors;

import org.junit.Assume;
import com.google.common.collect.ImmutableMap;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;

import org.opensearch.Version;
import org.opensearch.client.Response;
import org.opensearch.common.settings.Settings;
import org.opensearch.rest.RestStatus;
import org.opensearch.test.rest.OpenSearchRestTestCase;

import org.opensearch.Version;
import com.google.common.collect.ImmutableMap;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class JwtVerifier {
private final int clockSkewToleranceSeconds;
private final String requiredIssuer;
private final String requiredAudience;

public JwtVerifier(KeyProvider keyProvider, int clockSkewToleranceSeconds, String requiredIssuer, String requiredAudience) {
this.keyProvider = keyProvider;
this.clockSkewToleranceSeconds = clockSkewToleranceSeconds;
Expand All @@ -54,13 +54,13 @@ public JwtToken getVerifiedJwtToken(String encodedJwt) throws BadCredentialsExce
kid = StringEscapeUtils.unescapeJava(escapedKid);
}
JsonWebKey key = keyProvider.getKey(kid);

// Algorithm is not mandatory for the key material, so we set it to the same as the JWT
if (key.getAlgorithm() == null && key.getPublicKeyUse() == PublicKeyUse.SIGN && key.getKeyType() == KeyType.RSA)
{
key.setAlgorithm(jwt.getJwsHeaders().getAlgorithm());
}

JwsSignatureVerifier signatureVerifier = getInitializedSignatureVerifier(key, jwt);


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/amazon/dlic/auth/ldap/LdapUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public LdapUser(final String name, String originalUsername, final LdapEntry user

/**
* May return null because ldapEntry is transient
*
*
* @return ldapEntry or null if object was deserialized
*/
public LdapEntry getUserEntry() {
Expand All @@ -55,7 +55,7 @@ public String getDn() {
public String getOriginalUsername() {
return originalUsername;
}

public static Map<String, String> extractLdapAttributes(String originalUsername, final LdapEntry userEntry,
int customAttrMaxValueLen, WildcardMatcher allowlistedCustomLdapAttrMatcher) {
Map<String, String> attributes = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ public boolean exists(final User user) {
ldapConnection = LDAPAuthorizationBackend.getConnection(settings, configPath);
LdapEntry userEntry = exists(userName, ldapConnection, settings, userBaseSettings, this.returnAttributes, this.shouldFollowReferrals);
boolean exists = userEntry != null;

if(exists) {
user.addAttributes(LdapUser.extractLdapAttributes(userName, userEntry, customAttrMaxValueLen, allowlistedCustomLdapAttrMatcher));
}

return exists;

} catch (final Exception e) {
log.warn("User {} does not exist due to ", userName, e);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,29 +398,29 @@ public Response<Void> reopen() throws LdapException {

@Override
public Response<Void> open(BindRequest request) throws LdapException {

try {
if(isDebugEnabled && delegate != null && delegate.isOpen()) {
log.debug("Opened a connection, total count is now {}", CONNECTION_COUNTER.incrementAndGet());
}
} catch (Throwable e) {
//ignore
}

return delegate.open(request);
}

@Override
public Response<Void> open() throws LdapException {

try {
if(isDebugEnabled && delegate != null && delegate.isOpen()) {
log.debug("Opened a connection, total count is now {}", CONNECTION_COUNTER.incrementAndGet());
}
} catch (Throwable e) {
//ignore
}

return delegate.open();
}

Expand All @@ -441,15 +441,15 @@ public ConnectionConfig getConnectionConfig() {

@Override
public void close(RequestControl[] controls) {

try {
if(isDebugEnabled && delegate != null && delegate.isOpen()) {
log.debug("Closed a connection, total count is now {}", CONNECTION_COUNTER.decrementAndGet());
}
} catch (Throwable e) {
//ignore
}

try {
delegate.close(controls);
} finally {
Expand All @@ -459,15 +459,15 @@ public void close(RequestControl[] controls) {

@Override
public void close() {

try {
if(isDebugEnabled && delegate != null && delegate.isOpen()) {
log.debug("Closed a connection, total count is now {}", CONNECTION_COUNTER.decrementAndGet());
}
} catch (Throwable e) {
//ignore
}

try {
delegate.close();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ private boolean exists0(final User user) {
ldapConnection = this.connectionFactory.getConnection();
ldapConnection.open();
LdapEntry userEntry = this.userSearcher.exists(ldapConnection, userName, this.returnAttributes, this.shouldFollowReferrals);

boolean exists = userEntry != null;

if(exists) {
user.addAttributes(LdapUser.extractLdapAttributes(userName, userEntry, customAttrMaxValueLen, whitelistedCustomLdapAttrMatcher));
}

return exists;
} catch (final Exception e) {
log.warn("User {} does not exist due to exception", userName, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public ConnectionPool createConnectionPool() {

checkForDeprecatedSetting(settings, ConfigConstants.LDAP_LEGACY_POOL_PRUNING_PERIOD, ConfigConstants.LDAP_POOL_PRUNING_PERIOD);
checkForDeprecatedSetting(settings, ConfigConstants.LDAP_LEGACY_POOL_IDLE_TIME, ConfigConstants.LDAP_POOL_IDLE_TIME);

result.setPruneStrategy(new IdlePruneStrategy(
Duration.ofMinutes(this.settings.getAsLong(ConfigConstants.LDAP_POOL_PRUNING_PERIOD, this.settings.getAsLong(ConfigConstants.LDAP_LEGACY_POOL_PRUNING_PERIOD, 5l))),
Duration.ofMinutes(this.settings.getAsLong(ConfigConstants.LDAP_POOL_IDLE_TIME, this.settings.getAsLong(ConfigConstants.LDAP_LEGACY_POOL_IDLE_TIME, 10l))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class DefaultObjectMapper {
public static final ObjectMapper objectMapper = new ObjectMapper();
public final static ObjectMapper YAML_MAPPER = new ObjectMapper(new YAMLFactory());
private static final ObjectMapper defaulOmittingObjectMapper = new ObjectMapper();

static {
objectMapper.setSerializationInclusion(Include.NON_NULL);
//objectMapper.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
Expand Down Expand Up @@ -116,7 +116,7 @@ public T run() throws Exception {
throw (IOException) e.getCause();
}
}

@SuppressWarnings("removal")
public static <T> T readValue(String string, Class<T> clazz) throws IOException {

Expand All @@ -137,7 +137,7 @@ public T run() throws Exception {
throw (IOException) e.getCause();
}
}

@SuppressWarnings("removal")
public static JsonNode readTree(String string) throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ public Collection<Object> createComponents(Client localClient, ClusterService cl

securityRestHandler = new SecurityRestFilter(backendRegistry, auditLog, threadPool,
principalExtractor, settings, configPath, compatConfig);

HTTPOnBehalfOfJwtAuthenticator acInstance = new HTTPOnBehalfOfJwtAuthenticator();

final DynamicConfigFactory dcf = new DynamicConfigFactory(cr, settings, configPath, localClient, threadPool, cih);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
import org.opensearch.core.xcontent.XContentBuilder;

public class ConfigUpdateNodeResponse extends BaseNodeResponse implements ToXContentObject {

private String[] updatedConfigTypes;
private String message;

public ConfigUpdateNodeResponse(StreamInput in) throws IOException {
super(in);
this.updatedConfigTypes = in.readStringArray();
Expand All @@ -52,19 +52,19 @@ public ConfigUpdateNodeResponse(final DiscoveryNode node, String[] updatedConfig
this.updatedConfigTypes = updatedConfigTypes;
this.message = message;
}

public static ConfigUpdateNodeResponse readNodeResponse(StreamInput in) throws IOException {
return new ConfigUpdateNodeResponse(in);
}

public String[] getUpdatedConfigTypes() {
return updatedConfigTypes==null?null:Arrays.copyOf(updatedConfigTypes, updatedConfigTypes.length);
}

public String getMessage() {
return message;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public class TransportConfigUpdateAction
private final Provider<BackendRegistry> backendRegistry;
private final ConfigurationRepository configurationRepository;
private DynamicConfigFactory dynamicConfigFactory;

@Inject
public TransportConfigUpdateAction(final Settings settings,
final ThreadPool threadPool, final ClusterService clusterService, final TransportService transportService,
final ConfigurationRepository configurationRepository, final ActionFilters actionFilters,
Provider<BackendRegistry> backendRegistry, DynamicConfigFactory dynamicConfigFactory) {
Provider<BackendRegistry> backendRegistry, DynamicConfigFactory dynamicConfigFactory) {
super(ConfigUpdateAction.NAME, threadPool, clusterService, transportService, actionFilters,
ConfigUpdateRequest::new, TransportConfigUpdateAction.NodeConfigUpdateRequest::new,
ThreadPool.Names.MANAGEMENT, ConfigUpdateNodeResponse.class);
Expand Down Expand Up @@ -96,14 +96,14 @@ public void writeTo(final StreamOutput out) throws IOException {
protected ConfigUpdateNodeResponse newNodeResponse(StreamInput in) throws IOException {
return new ConfigUpdateNodeResponse(in);
}

@Override
protected ConfigUpdateResponse newResponse(ConfigUpdateRequest request, List<ConfigUpdateNodeResponse> responses,
List<FailedNodeException> failures) {
return new ConfigUpdateResponse(this.clusterService.getClusterName(), responses, failures);

}

@Override
protected ConfigUpdateNodeResponse nodeOperation(final NodeConfigUpdateRequest request) {
configurationRepository.reloadConfiguration(CType.fromStringValues((request.request.getConfigTypes())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ protected void doExecute(Task task, WhoAmIRequest request, ActionListener<WhoAmI
final String dn = user==null?threadPool.getThreadContext().getTransient(ConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_PRINCIPAL):user.getName();
final boolean isAdmin = adminDNs.isAdminDN(dn);
final boolean isAuthenticated = isAdmin?true: user != null;
final boolean isNodeCertificateRequest = HeaderHelper.isInterClusterRequest(threadPool.getThreadContext()) ||
final boolean isNodeCertificateRequest = HeaderHelper.isInterClusterRequest(threadPool.getThreadContext()) ||
HeaderHelper.isTrustedClusterRequest(threadPool.getThreadContext());

listener.onResponse(new WhoAmIResponse(dn, isAdmin, isAuthenticated, isNodeCertificateRequest));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.opensearch.client.OpenSearchClient;

public class WhoAmIRequestBuilder extends
ActionRequestBuilder<WhoAmIRequest, WhoAmIResponse> {
ActionRequestBuilder<WhoAmIRequest, WhoAmIResponse> {
public WhoAmIRequestBuilder(final ClusterAdminClient client) throws IOException {
this(client, WhoAmIAction.INSTANCE);
}
Expand Down
Loading

0 comments on commit 1d30c96

Please sign in to comment.