remove some more ParseFieldMatcher usages

Original commit: elastic/x-pack-elasticsearch@4d3b7574cc
This commit is contained in:
javanna 2017-01-11 21:42:10 +01:00 committed by Luca Cavanna
parent c5cab37db6
commit 51302608cb
3 changed files with 11 additions and 40 deletions

View File

@ -7,7 +7,6 @@ package org.elasticsearch.xpack.common.http;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

View File

@ -8,8 +8,6 @@ package org.elasticsearch.xpack.notification.email.attachment;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.logging.LoggerMessageFormat;
@ -49,10 +47,9 @@ public class ReportingAttachmentParser implements EmailAttachmentParser<Reportin
public static final Setting<Integer> RETRIES_SETTING =
Setting.intSetting("xpack.notification.reporting.retries", 40, 0, Setting.Property.NodeScope);
private static final ObjectParser<Builder, AuthParseFieldMatcher> PARSER = new ObjectParser<>("reporting_attachment");
private static final ObjectParser<KibanaReportingPayload, ParseFieldMatcherSupplier> PAYLOAD_PARSER =
private static final ObjectParser<Builder, AuthParseContext> PARSER = new ObjectParser<>("reporting_attachment");
private static final ObjectParser<KibanaReportingPayload, Void> PAYLOAD_PARSER =
new ObjectParser<>("reporting_attachment_kibana_payload", true, null);
private static final ParseFieldMatcherSupplier STRICT_PARSING = () -> ParseFieldMatcher.STRICT;
static {
PARSER.declareInt(Builder::retries, new ParseField("retries"));
@ -88,7 +85,7 @@ public class ReportingAttachmentParser implements EmailAttachmentParser<Reportin
@Override
public ReportingAttachment parse(String id, XContentParser parser) throws IOException {
Builder builder = new Builder(id);
PARSER.parse(parser, builder, new AuthParseFieldMatcher(authRegistry));
PARSER.parse(parser, builder, new AuthParseContext(authRegistry));
return builder.build();
}
@ -199,7 +196,7 @@ public class ReportingAttachmentParser implements EmailAttachmentParser<Reportin
// EMPTY is safe here becaus we never call namedObject
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, body)) {
KibanaReportingPayload payload = new KibanaReportingPayload();
PAYLOAD_PARSER.parse(parser, payload, STRICT_PARSING);
PAYLOAD_PARSER.parse(parser, payload, null);
String path = payload.getPath();
if (Strings.isEmpty(path)) {
throw new ElasticsearchException("Watch[{}] reporting[{}] field path found in JSON payload, payload was {}",
@ -213,20 +210,15 @@ public class ReportingAttachmentParser implements EmailAttachmentParser<Reportin
* A helper class to parse the HTTPAuth data, which is read by an old school pull parser, that is handed over in the ctor.
* See the static parser definition at the top
*/
private static class AuthParseFieldMatcher implements ParseFieldMatcherSupplier {
private static class AuthParseContext {
private final HttpAuthRegistry authRegistry;
AuthParseFieldMatcher(HttpAuthRegistry authRegistry) {
AuthParseContext(HttpAuthRegistry authRegistry) {
this.authRegistry = authRegistry;
}
@Override
public ParseFieldMatcher getParseFieldMatcher() {
return ParseFieldMatcher.EMPTY;
}
public HttpAuth parseAuth(XContentParser parser) {
HttpAuth parseAuth(XContentParser parser) {
try {
return authRegistry.parse(parser);
} catch (IOException e) {

View File

@ -7,7 +7,6 @@ package org.elasticsearch.xpack.ssl;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.GeneralNames;
@ -19,11 +18,8 @@ import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.cli.EnvironmentAwareCommand;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@ -31,9 +27,9 @@ import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.Environment;
import org.elasticsearch.node.internal.InternalSettingsPreparer;
import org.elasticsearch.xpack.XPackPlugin;
import javax.security.auth.x500.X500Principal;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
@ -62,8 +58,6 @@ import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.security.auth.x500.X500Principal;
/**
* CLI tool to make generation of certificates or certificate requests easier for users
*/
@ -80,9 +74,9 @@ public class CertificateTool extends EnvironmentAwareCommand {
Pattern.compile("[a-zA-Z0-9!@#$%^&{}\\[\\]()_+\\-=,.~'` ]{1," + MAX_FILENAME_LENGTH + "}");
private static final int DEFAULT_KEY_SIZE = 2048;
private static final ObjectParser<List<CertificateInformation>, CertInfoParseContext> PARSER = new ObjectParser<>("certgen");
private static final ObjectParser<List<CertificateInformation>, Void> PARSER = new ObjectParser<>("certgen");
static {
ConstructingObjectParser<CertificateInformation, CertInfoParseContext> instanceParser =
ConstructingObjectParser<CertificateInformation, Void> instanceParser =
new ConstructingObjectParser<>("instances",
a -> new CertificateInformation((String) a[0], (String) (a[1] == null ? a[0] : a[1]),
(List<String>) a[2], (List<String>) a[3]));
@ -248,7 +242,7 @@ public class CertificateTool extends EnvironmentAwareCommand {
try (Reader reader = Files.newBufferedReader(file)) {
// EMPTY is safe here because we never use namedObject
XContentParser xContentParser = XContentType.YAML.xContent().createParser(NamedXContentRegistry.EMPTY, reader);
return PARSER.parse(xContentParser, new ArrayList<>(), new CertInfoParseContext());
return PARSER.parse(xContentParser, new ArrayList<>(), null);
}
}
@ -632,20 +626,6 @@ public class CertificateTool extends EnvironmentAwareCommand {
}
}
private static class CertInfoParseContext implements ParseFieldMatcherSupplier {
private final ParseFieldMatcher parseFieldMatcher;
CertInfoParseContext() {
this.parseFieldMatcher = ParseFieldMatcher.EMPTY;
}
@Override
public ParseFieldMatcher getParseFieldMatcher() {
return parseFieldMatcher;
}
}
private interface Writer {
void write(ZipOutputStream zipOutputStream, JcaPEMWriter pemWriter) throws Exception;
}