Skip to content

Commit

Permalink
Updates toString calls affected by change in method signature (opense…
Browse files Browse the repository at this point in the history
…arch-project#2418)

Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura authored Jan 30, 2023
1 parent 4b51ea7 commit f808b2a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.http.BindHttpException;
import org.opensearch.node.PluginAwareNode;
import org.opensearch.plugins.Plugin;
Expand Down Expand Up @@ -292,7 +293,7 @@ public void waitForCluster(ClusterHealthStatus status, TimeValue timeout, int ex
.setClusterManagerNodeTimeout(timeout).setWaitForNodes("" + expectedNodeCount).execute().actionGet();

if (log.isDebugEnabled()) {
log.debug("Current ClusterState:\n{}", Strings.toString(healthResponse));
log.debug("Current ClusterState:\n{}", Strings.toString(XContentType.JSON,healthResponse));
}

if (healthResponse.isTimedOut()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.security.DefaultObjectMapper;

import static java.lang.String.format;
Expand Down Expand Up @@ -162,7 +163,7 @@ private StringEntity toStringEntity(String body) {
}

public HttpResponse putJson(String path, ToXContentObject body) {
return putJson(path, Strings.toString(body));
return putJson(path, Strings.toString(XContentType.JSON, body));
}

public HttpResponse put(String path) {
Expand All @@ -181,7 +182,7 @@ public HttpResponse postJson(String path, String body, Header... headers) {
}

public HttpResponse postJson(String path, ToXContentObject body) {
return postJson(path, Strings.toString(body));
return postJson(path, Strings.toString(XContentType.JSON, body));
}

public HttpResponse post(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.xcontent.ToXContent;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentType;

public class WhoAmIResponse extends ActionResponse implements ToXContent {

Expand Down Expand Up @@ -105,6 +106,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public String toString() {
return Strings.toString(this, true, true);
return Strings.toString(XContentType.JSON,this, true, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.util.concurrent.ThreadContext.StoredContext;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.env.Environment;
import org.opensearch.security.auditlog.AuditLog;
import org.opensearch.security.auditlog.config.AuditConfig;
Expand Down Expand Up @@ -379,7 +380,7 @@ public Map<CType, SecurityDynamicConfiguration<?>> getConfigurationsFromIndex(Co
if (logComplianceEvent && auditLog.getComplianceConfig().isEnabled()) {
CType configurationType = configTypes.iterator().next();
Map<String, String> fields = new HashMap<String, String>();
fields.put(configurationType.toLCString(), Strings.toString(retVal.get(configurationType)));
fields.put(configurationType.toLCString(), Strings.toString(XContentType.JSON, retVal.get(configurationType)));
auditLog.logDocumentRead(this.securityIndex, configurationType.toLCString(), null, fields);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.NamedXContentRegistry;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.query.ParsedQuery;
import org.opensearch.rest.RestStatus;
import org.opensearch.search.DocValueFormat;
Expand Down Expand Up @@ -211,10 +212,10 @@ public boolean invoke(String action, ActionRequest request, final ActionListener
StringBuilder sb = new StringBuilder();

if (searchRequest.source() != null) {
sb.append(Strings.toString(searchRequest.source()) + System.lineSeparator());
sb.append(Strings.toString(XContentType.JSON, searchRequest.source()) + System.lineSeparator());
}

sb.append(Strings.toString(af) + System.lineSeparator());
sb.append(Strings.toString(XContentType.JSON, af) + System.lineSeparator());

LogManager.getLogger("debuglogger").error(sb.toString());

Expand All @@ -224,7 +225,7 @@ public boolean invoke(String action, ActionRequest request, final ActionListener
searchRequest.requestCache(Boolean.FALSE);
} else {
LogManager.getLogger("debuglogger").error("Shard requestcache enabled for "
+ (searchRequest.source() == null ? "<NULL>" : Strings.toString(searchRequest.source())));
+ (searchRequest.source() == null ? "<NULL>" : Strings.toString(XContentType.JSON, searchRequest.source())));
}

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ protected static void generateDiagnoseTrace(final RestHighLevelClient restHighLe
try {
sb.append("ClusterHealthRequest:"+System.lineSeparator());
ClusterHealthResponse nir = restHighLevelClient.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT);
sb.append(Strings.toString(nir, true, true));
sb.append(Strings.toString(XContentType.JSON, nir, true, true));
} catch (Exception e1) {
sb.append(ExceptionsHelper.stackTrace(e1));
}
Expand Down
15 changes: 8 additions & 7 deletions src/test/java/org/opensearch/security/ConfigTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.opensearch.common.Strings;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.security.securityconf.Migration;
import org.opensearch.security.securityconf.impl.CType;
import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration;
Expand Down Expand Up @@ -59,18 +60,18 @@ public void testMigrate() throws Exception {
Tuple<SecurityDynamicConfiguration<RoleV7>, SecurityDynamicConfiguration<TenantV7>> rolesResult = Migration.migrateRoles((SecurityDynamicConfiguration<RoleV6>)load("./legacy/securityconfig_v6/roles.yml", CType.ROLES),
(SecurityDynamicConfiguration<RoleMappingsV6>)load("./legacy/securityconfig_v6/roles_mapping.yml", CType.ROLESMAPPING));

System.out.println(Strings.toString(rolesResult.v2(), true, false));
System.out.println(Strings.toString(rolesResult.v1(), true, false));
System.out.println(Strings.toString(XContentType.JSON, rolesResult.v2(), true, false));
System.out.println(Strings.toString(XContentType.JSON, rolesResult.v1(), true, false));


SecurityDynamicConfiguration<ActionGroupsV7> actionGroupsResult = Migration.migrateActionGroups((SecurityDynamicConfiguration<ActionGroupsV6>)load("./legacy/securityconfig_v6/action_groups.yml", CType.ACTIONGROUPS));
System.out.println(Strings.toString(actionGroupsResult, true, false));
System.out.println(Strings.toString(XContentType.JSON, actionGroupsResult, true, false));
SecurityDynamicConfiguration<ConfigV7> configResult =Migration.migrateConfig((SecurityDynamicConfiguration<ConfigV6>)load("./legacy/securityconfig_v6/config.yml", CType.CONFIG));
System.out.println(Strings.toString(configResult, true, false));
System.out.println(Strings.toString(XContentType.JSON, configResult, true, false));
SecurityDynamicConfiguration<InternalUserV7> internalUsersResult = Migration.migrateInternalUsers((SecurityDynamicConfiguration<InternalUserV6>)load("./legacy/securityconfig_v6/internal_users.yml", CType.INTERNALUSERS));
System.out.println(Strings.toString(internalUsersResult, true, false));
System.out.println(Strings.toString(XContentType.JSON, internalUsersResult, true, false));
SecurityDynamicConfiguration<RoleMappingsV7> rolemappingsResult = Migration.migrateRoleMappings((SecurityDynamicConfiguration<RoleMappingsV6>)load("./legacy/securityconfig_v6/roles_mapping.yml", CType.ROLESMAPPING));
System.out.println(Strings.toString(rolemappingsResult, true, false));
System.out.println(Strings.toString(XContentType.JSON, rolemappingsResult, true, false));
}

@Test
Expand Down Expand Up @@ -113,7 +114,7 @@ private void check(String file, CType cType) throws Exception {
//Assert.assertTrue(dc.getCEntries().size() > 0);
String jsonSerialize = DefaultObjectMapper.objectMapper.writeValueAsString(dc);
SecurityDynamicConfiguration<?> conf = SecurityDynamicConfiguration.fromJson(jsonSerialize, cType, configVersion, 0, 0);
SecurityDynamicConfiguration.fromJson(Strings.toString(conf), cType, configVersion, 0, 0);
SecurityDynamicConfiguration.fromJson(Strings.toString(XContentType.JSON, conf), cType, configVersion, 0, 0);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected void populateData(Client tc) {
e.printStackTrace();
}
System.out.println("q");
System.out.println(Strings.toString(tc.search(new SearchRequest().indices(".opendistro_security")).actionGet()));
System.out.println(Strings.toString(XContentType.JSON, tc.search(new SearchRequest().indices(".opendistro_security")).actionGet()));
tc.search(new SearchRequest().indices("deals")).actionGet();
}

Expand Down

0 comments on commit f808b2a

Please sign in to comment.