Skip to content

Commit 8e3e8e0

Browse files
committed
Merge branch 'main' into entitlements/relative-home-path
2 parents 4a7ab65 + c211040 commit 8e3e8e0

File tree

2 files changed

+25
-123
lines changed

2 files changed

+25
-123
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FileEntitlement.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FilesEntitlement.java

Lines changed: 25 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -42,85 +42,9 @@ public enum BaseDir {
4242

4343
public sealed interface FileData {
4444

45-
final class AbsolutePathFileData implements FileData {
46-
private final Path path;
47-
private final Mode mode;
48-
49-
private AbsolutePathFileData(Path path, Mode mode) {
50-
this.path = path;
51-
this.mode = mode;
52-
}
53-
54-
@Override
55-
public Stream<Path> resolvePaths(PathLookup pathLookup) {
56-
return Stream.of(path);
57-
}
58-
59-
@Override
60-
public Mode mode() {
61-
return mode;
62-
}
63-
64-
@Override
65-
public boolean equals(Object obj) {
66-
if (obj == this) return true;
67-
if (obj == null || obj.getClass() != this.getClass()) return false;
68-
var that = (AbsolutePathFileData) obj;
69-
return Objects.equals(this.path, that.path) && Objects.equals(this.mode, that.mode);
70-
}
71-
72-
@Override
73-
public int hashCode() {
74-
return Objects.hash(path, mode);
75-
}
76-
}
77-
78-
final class RelativePathFileData implements FileData {
79-
private final Path relativePath;
80-
private final BaseDir baseDir;
81-
private final Mode mode;
82-
83-
private RelativePathFileData(Path relativePath, BaseDir baseDir, Mode mode) {
84-
this.relativePath = relativePath;
85-
this.baseDir = baseDir;
86-
this.mode = mode;
87-
}
88-
89-
@Override
90-
public Stream<Path> resolvePaths(PathLookup pathLookup) {
91-
Objects.requireNonNull(pathLookup);
92-
switch (baseDir) {
93-
case CONFIG:
94-
return Stream.of(pathLookup.configDir().resolve(relativePath));
95-
case DATA:
96-
return Arrays.stream(pathLookup.dataDirs()).map(d -> d.resolve(relativePath));
97-
case HOME:
98-
return pathLookup.homeDir() != null ? Stream.of(pathLookup.homeDir().resolve(relativePath)) : Stream.empty();
99-
default:
100-
throw new IllegalArgumentException();
101-
}
102-
}
103-
104-
@Override
105-
public Mode mode() {
106-
return mode;
107-
}
108-
109-
@Override
110-
public boolean equals(Object obj) {
111-
if (obj == this) return true;
112-
if (obj == null || obj.getClass() != this.getClass()) return false;
113-
var that = (RelativePathFileData) obj;
114-
return Objects.equals(this.mode, that.mode)
115-
&& Objects.equals(this.relativePath, that.relativePath)
116-
&& Objects.equals(this.baseDir, that.baseDir);
117-
}
45+
Stream<Path> resolvePaths(PathLookup pathLookup);
11846

119-
@Override
120-
public int hashCode() {
121-
return Objects.hash(relativePath, baseDir, mode);
122-
}
123-
}
47+
Mode mode();
12448

12549
static FileData ofPath(Path path, Mode mode) {
12650
assert path.isAbsolute();
@@ -131,10 +55,31 @@ static FileData ofRelativePath(Path relativePath, BaseDir baseDir, Mode mode) {
13155
assert relativePath.isAbsolute() == false;
13256
return new RelativePathFileData(relativePath, baseDir, mode);
13357
}
58+
}
13459

135-
Stream<Path> resolvePaths(PathLookup pathLookup);
60+
private record AbsolutePathFileData(Path path, Mode mode) implements FileData {
61+
@Override
62+
public Stream<Path> resolvePaths(PathLookup pathLookup) {
63+
return Stream.of(path);
64+
}
65+
}
13666

137-
Mode mode();
67+
private record RelativePathFileData(Path relativePath, BaseDir baseDir, Mode mode) implements FileData {
68+
69+
@Override
70+
public Stream<Path> resolvePaths(PathLookup pathLookup) {
71+
Objects.requireNonNull(pathLookup);
72+
switch (baseDir) {
73+
case CONFIG:
74+
return Stream.of(pathLookup.configDir().resolve(relativePath));
75+
case DATA:
76+
return Arrays.stream(pathLookup.dataDirs()).map(d -> d.resolve(relativePath));
77+
case HOME:
78+
return pathLookup.homeDir() != null ? Stream.of(pathLookup.homeDir().resolve(relativePath)) : Stream.empty();
79+
default:
80+
throw new IllegalArgumentException();
81+
}
82+
}
13883
}
13984

14085
private static Mode parseMode(String mode) {

0 commit comments

Comments
 (0)