Skip to content

Commit 7379b72

Browse files
jdconradcbuescher
authored andcommitted
Remove entitlement parameter (#117597)
Removes the "entitlement" parameter from policy parsing.
1 parent df06c47 commit 7379b72

File tree

3 files changed

+18
-36
lines changed

3 files changed

+18
-36
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyParser.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
package org.elasticsearch.entitlement.runtime.policy;
1111

12-
import org.elasticsearch.xcontent.ParseField;
1312
import org.elasticsearch.xcontent.XContentParser;
1413
import org.elasticsearch.xcontent.XContentParserConfiguration;
1514
import org.elasticsearch.xcontent.yaml.YamlXContent;
@@ -31,8 +30,6 @@
3130
*/
3231
public class PolicyParser {
3332

34-
protected static final ParseField ENTITLEMENTS_PARSEFIELD = new ParseField("entitlements");
35-
3633
protected static final String entitlementPackageName = Entitlement.class.getPackage().getName();
3734

3835
protected final XContentParser policyParser;
@@ -65,13 +62,6 @@ public Policy parsePolicy() {
6562

6663
protected Scope parseScope(String scopeName) throws IOException {
6764
try {
68-
if (policyParser.nextToken() != XContentParser.Token.START_OBJECT) {
69-
throw newPolicyParserException(scopeName, "expected object [" + ENTITLEMENTS_PARSEFIELD.getPreferredName() + "]");
70-
}
71-
if (policyParser.nextToken() != XContentParser.Token.FIELD_NAME
72-
|| policyParser.currentName().equals(ENTITLEMENTS_PARSEFIELD.getPreferredName()) == false) {
73-
throw newPolicyParserException(scopeName, "expected object [" + ENTITLEMENTS_PARSEFIELD.getPreferredName() + "]");
74-
}
7565
if (policyParser.nextToken() != XContentParser.Token.START_ARRAY) {
7666
throw newPolicyParserException(scopeName, "expected array of <entitlement type>");
7767
}
@@ -90,9 +80,6 @@ protected Scope parseScope(String scopeName) throws IOException {
9080
throw newPolicyParserException(scopeName, "expected closing object");
9181
}
9282
}
93-
if (policyParser.nextToken() != XContentParser.Token.END_OBJECT) {
94-
throw newPolicyParserException(scopeName, "expected closing object");
95-
}
9683
return new Scope(scopeName, entitlements);
9784
} catch (IOException ioe) {
9885
throw new UncheckedIOException(ioe);

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyParserFailureTests.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ public void testParserSyntaxFailures() {
2929
public void testEntitlementDoesNotExist() throws IOException {
3030
PolicyParserException ppe = expectThrows(PolicyParserException.class, () -> new PolicyParser(new ByteArrayInputStream("""
3131
entitlement-module-name:
32-
entitlements:
33-
- does_not_exist: {}
32+
- does_not_exist: {}
3433
""".getBytes(StandardCharsets.UTF_8)), "test-failure-policy.yaml").parsePolicy());
3534
assertEquals(
36-
"[3:7] policy parsing error for [test-failure-policy.yaml] in scope [entitlement-module-name]: "
35+
"[2:5] policy parsing error for [test-failure-policy.yaml] in scope [entitlement-module-name]: "
3736
+ "unknown entitlement type [does_not_exist]",
3837
ppe.getMessage()
3938
);
@@ -42,23 +41,21 @@ public void testEntitlementDoesNotExist() throws IOException {
4241
public void testEntitlementMissingParameter() throws IOException {
4342
PolicyParserException ppe = expectThrows(PolicyParserException.class, () -> new PolicyParser(new ByteArrayInputStream("""
4443
entitlement-module-name:
45-
entitlements:
46-
- file: {}
44+
- file: {}
4745
""".getBytes(StandardCharsets.UTF_8)), "test-failure-policy.yaml").parsePolicy());
4846
assertEquals(
49-
"[3:14] policy parsing error for [test-failure-policy.yaml] in scope [entitlement-module-name] "
47+
"[2:12] policy parsing error for [test-failure-policy.yaml] in scope [entitlement-module-name] "
5048
+ "for entitlement type [file]: missing entitlement parameter [path]",
5149
ppe.getMessage()
5250
);
5351

5452
ppe = expectThrows(PolicyParserException.class, () -> new PolicyParser(new ByteArrayInputStream("""
5553
entitlement-module-name:
56-
entitlements:
57-
- file:
58-
path: test-path
54+
- file:
55+
path: test-path
5956
""".getBytes(StandardCharsets.UTF_8)), "test-failure-policy.yaml").parsePolicy());
6057
assertEquals(
61-
"[5:1] policy parsing error for [test-failure-policy.yaml] in scope [entitlement-module-name] "
58+
"[4:1] policy parsing error for [test-failure-policy.yaml] in scope [entitlement-module-name] "
6259
+ "for entitlement type [file]: missing entitlement parameter [actions]",
6360
ppe.getMessage()
6461
);
@@ -67,15 +64,14 @@ public void testEntitlementMissingParameter() throws IOException {
6764
public void testEntitlementExtraneousParameter() throws IOException {
6865
PolicyParserException ppe = expectThrows(PolicyParserException.class, () -> new PolicyParser(new ByteArrayInputStream("""
6966
entitlement-module-name:
70-
entitlements:
71-
- file:
72-
path: test-path
73-
actions:
74-
- read
75-
extra: test
67+
- file:
68+
path: test-path
69+
actions:
70+
- read
71+
extra: test
7672
""".getBytes(StandardCharsets.UTF_8)), "test-failure-policy.yaml").parsePolicy());
7773
assertEquals(
78-
"[8:1] policy parsing error for [test-failure-policy.yaml] in scope [entitlement-module-name] "
74+
"[7:1] policy parsing error for [test-failure-policy.yaml] in scope [entitlement-module-name] "
7975
+ "for entitlement type [file]: extraneous entitlement parameter(s) {extra=test}",
8076
ppe.getMessage()
8177
);
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
entitlement-module-name:
2-
entitlements:
3-
- file:
4-
path: "test/path/to/file"
5-
actions:
6-
- "read"
7-
- "write"
2+
- file:
3+
path: "test/path/to/file"
4+
actions:
5+
- "read"
6+
- "write"

0 commit comments

Comments
 (0)