-
Notifications
You must be signed in to change notification settings - Fork 25.6k
HLRC: Get SSL Certificates API #34135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
10bca72
Add request and response objects
jkakavas b20a5d2
Remove ConstructingObjectParser
jkakavas ffb2eeb
Merge remote-tracking branch 'origin/master' into get-certificates-hlrc
jkakavas e4a38a9
-
jkakavas 3c3b262
add docs and tests
jkakavas 9ccbffb
Remove unused import
jkakavas 0be860f
Fix naming convention tests
jkakavas 38504a9
Merge remote-tracking branch 'origin/master' into get-certificates-hlrc
jkakavas c585d97
address feedback
jkakavas 0f9fb3a
Merge remote-tracking branch 'origin/master' into get-certificates-hlrc
jkakavas a21fe6e
Address feedback
jkakavas 205b521
revert unecessary changes
jkakavas bbaa6fc
Merge remote-tracking branch 'origin/master' into get-certificates-hlrc
jkakavas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...high-level/src/main/java/org/elasticsearch/client/security/GetSslCertificatesRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.client.security; | ||
|
|
||
| import org.apache.http.client.methods.HttpGet; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.Validatable; | ||
| import org.elasticsearch.common.xcontent.ToXContentObject; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Request object to retrieve the X.509 certificates that are used to encrypt communications in an Elasticsearch cluster. | ||
| */ | ||
| public final class GetSslCertificatesRequest implements Validatable, ToXContentObject { | ||
|
|
||
| public static final GetSslCertificatesRequest INSTANCE = new GetSslCertificatesRequest(); | ||
| private final Request request; | ||
|
|
||
| private GetSslCertificatesRequest() { | ||
| request = new Request(HttpGet.METHOD_NAME, "/_xpack/ssl/certificates"); | ||
| } | ||
|
|
||
| public Request getRequest() { | ||
| return request; | ||
| } | ||
|
|
||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| return builder.startObject().endObject(); | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
...igh-level/src/main/java/org/elasticsearch/client/security/GetSslCertificatesResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.client.security; | ||
|
|
||
| import org.elasticsearch.client.security.support.CertificateInfo; | ||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.common.xcontent.XContentParserUtils; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Response object when retrieving the X.509 certificates that are used to encrypt communications in an Elasticsearch cluster. | ||
| * Returns a list of {@link CertificateInfo} objects describing each of the certificates. | ||
| */ | ||
| public final class GetSslCertificatesResponse { | ||
|
|
||
| private final List<CertificateInfo> certificates; | ||
|
|
||
| public GetSslCertificatesResponse(List<CertificateInfo> certificates) { | ||
| this.certificates = certificates; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| final GetSslCertificatesResponse that = (GetSslCertificatesResponse) o; | ||
| return Objects.equals(this.certificates, that.certificates); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(certificates); | ||
| } | ||
|
|
||
| public static GetSslCertificatesResponse fromXContent(XContentParser parser) throws IOException { | ||
| List<CertificateInfo> certificates = new ArrayList<>(); | ||
| XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.nextToken(), parser::getTokenLocation); | ||
| while (parser.nextToken() != XContentParser.Token.END_ARRAY) { | ||
| certificates.add(CertificateInfo.PARSER.parse(parser, null)); | ||
| } | ||
| return new GetSslCertificatesResponse(certificates); | ||
| } | ||
|
|
||
| public List<CertificateInfo> getCertificates() { | ||
| return certificates; | ||
| } | ||
| } | ||
133 changes: 133 additions & 0 deletions
133
...t-high-level/src/main/java/org/elasticsearch/client/security/support/CertificateInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.client.security.support; | ||
|
|
||
| import org.elasticsearch.common.Nullable; | ||
| import org.elasticsearch.common.ParseField; | ||
| import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
|
||
| /** | ||
| * Simple model of an X.509 certificate | ||
| */ | ||
| public final class CertificateInfo { | ||
| public static final ParseField PATH = new ParseField("path"); | ||
| public static final ParseField FORMAT = new ParseField("format"); | ||
| public static final ParseField ALIAS = new ParseField("alias"); | ||
| public static final ParseField SUBJECT_DN = new ParseField("subject_dn"); | ||
| public static final ParseField SERIAL_NUMBER = new ParseField("serial_number"); | ||
| public static final ParseField HAS_PRIVATE_KEY = new ParseField("has_private_key"); | ||
| public static final ParseField EXPIRY = new ParseField("expiry"); | ||
|
|
||
| private final String path; | ||
| private final String format; | ||
| private final String alias; | ||
| private final String subjectDn; | ||
| private final String serialNumber; | ||
| private final boolean hasPrivateKey; | ||
| private final String expiry; | ||
|
|
||
| public CertificateInfo(String path, String format, @Nullable String alias, String subjectDn, String serialNumber, boolean hasPrivateKey, | ||
| String expiry) { | ||
| this.path = path; | ||
| this.format = format; | ||
| this.alias = alias; | ||
| this.subjectDn = subjectDn; | ||
| this.serialNumber = serialNumber; | ||
| this.hasPrivateKey = hasPrivateKey; | ||
| this.expiry = expiry; | ||
| } | ||
|
|
||
| public String getPath() { | ||
| return path; | ||
| } | ||
|
|
||
| public String getFormat() { | ||
| return format; | ||
| } | ||
|
|
||
| public String getAlias() { | ||
| return alias; | ||
| } | ||
|
|
||
| public String getSubjectDn() { | ||
| return subjectDn; | ||
| } | ||
|
|
||
| public String getSerialNumber() { | ||
| return serialNumber; | ||
| } | ||
|
|
||
| public boolean isHasPrivateKey() { | ||
| return hasPrivateKey; | ||
| } | ||
|
|
||
| public String getExpiry() { | ||
| return expiry; | ||
| } | ||
|
|
||
jkakavas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @SuppressWarnings("unchecked") | ||
| public static final ConstructingObjectParser<CertificateInfo, Void> PARSER = new ConstructingObjectParser<>("certificate_info", | ||
| true, args -> new CertificateInfo((String) args[0], (String) args[1], (String) args[2], (String) args[3], (String) args[4], | ||
| (boolean) args[5], (String) args[6])); | ||
|
|
||
| static { | ||
| PARSER.declareString(constructorArg(), PATH); | ||
| PARSER.declareString(constructorArg(), FORMAT); | ||
| PARSER.declareStringOrNull(constructorArg(), ALIAS); | ||
| PARSER.declareString(constructorArg(), SUBJECT_DN); | ||
| PARSER.declareString(constructorArg(), SERIAL_NUMBER); | ||
| PARSER.declareBoolean(constructorArg(), HAS_PRIVATE_KEY); | ||
| PARSER.declareString(constructorArg(), EXPIRY); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object other) { | ||
| if (this == other) { | ||
| return true; | ||
| } | ||
| if (other == null || getClass() != other.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| final CertificateInfo that = (CertificateInfo) other; | ||
| return this.path.equals(that.path) | ||
| && this.format.equals(that.format) | ||
| && this.hasPrivateKey == that.hasPrivateKey | ||
| && Objects.equals(this.alias, that.alias) | ||
| && this.serialNumber.equals(that.serialNumber) | ||
| && this.subjectDn.equals(that.subjectDn) | ||
| && this.expiry.equals(that.expiry); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(path, format, alias, subjectDn, serialNumber, hasPrivateKey, expiry); | ||
| } | ||
|
|
||
jkakavas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public static CertificateInfo fromXContent(XContentParser parser) throws IOException { | ||
| return PARSER.parse(parser, null); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't use
ConstructingObjectParseras this API returns an array of Objects