@@ -91,12 +91,8 @@ static FileData ofRelativePath(Path relativePath, BaseDir baseDir, Mode mode) {
9191 return new RelativePathFileData (relativePath , baseDir , mode , null , false );
9292 }
9393
94- static FileData ofPathSetting (String setting , Mode mode , boolean ignoreUrl ) {
95- return new PathSettingFileData (setting , mode , ignoreUrl , null , false );
96- }
97-
98- static FileData ofRelativePathSetting (String setting , BaseDir baseDir , Mode mode , boolean ignoreUrl ) {
99- return new RelativePathSettingFileData (setting , baseDir , mode , ignoreUrl , null , false );
94+ static FileData ofConfigPathSetting (String setting , Mode mode , boolean ignoreUrl ) {
95+ return new ConfigPathSettingFileData (setting , mode , ignoreUrl , null , false );
10096 }
10197
10298 /**
@@ -225,71 +221,39 @@ public FileData withPlatform(Platform platform) {
225221 }
226222 }
227223
228- private record PathSettingFileData (String setting , Mode mode , boolean ignoreUrl , Platform platform , boolean exclusive )
224+ private record ConfigPathSettingFileData (String setting , Mode mode , boolean ignoreUrl , Platform platform , boolean exclusive )
229225 implements
230226 FileData {
231227
232228 @ Override
233- public PathSettingFileData withExclusive (boolean exclusive ) {
234- return new PathSettingFileData (setting , mode , ignoreUrl , platform , exclusive );
229+ public ConfigPathSettingFileData withExclusive (boolean exclusive ) {
230+ return new ConfigPathSettingFileData (setting , mode , ignoreUrl , platform , exclusive );
235231 }
236232
237233 @ Override
238234 public Stream <Path > resolvePaths (PathLookup pathLookup ) {
239- return resolvePathSettings (pathLookup , setting , ignoreUrl );
240- }
241-
242- @ Override
243- public FileData withPlatform (Platform platform ) {
244- if (platform == platform ()) {
245- return this ;
235+ Stream <String > result ;
236+ if (setting .contains ("*" )) {
237+ result = pathLookup .settingGlobResolver ().apply (setting );
238+ } else {
239+ String path = pathLookup .settingResolver ().apply (setting );
240+ result = path == null ? Stream .of () : Stream .of (path );
246241 }
247- return new PathSettingFileData (setting , mode , ignoreUrl , platform , exclusive );
248- }
249- }
250-
251- private record RelativePathSettingFileData (
252- String setting ,
253- BaseDir baseDir ,
254- Mode mode ,
255- boolean ignoreUrl ,
256- Platform platform ,
257- boolean exclusive
258- ) implements FileData , RelativeFileData {
259-
260- @ Override
261- public RelativePathSettingFileData withExclusive (boolean exclusive ) {
262- return new RelativePathSettingFileData (setting , baseDir , mode , ignoreUrl , platform , exclusive );
263- }
264-
265- @ Override
266- public Stream <Path > resolveRelativePaths (PathLookup pathLookup ) {
267- return resolvePathSettings (pathLookup , setting , ignoreUrl );
242+ if (ignoreUrl ) {
243+ result = result .filter (s -> s .toLowerCase (Locale .ROOT ).startsWith ("https://" ) == false );
244+ }
245+ return result .map (pathLookup .configDir ()::resolve );
268246 }
269247
270248 @ Override
271249 public FileData withPlatform (Platform platform ) {
272250 if (platform == platform ()) {
273251 return this ;
274252 }
275- return new RelativePathSettingFileData (setting , baseDir , mode , ignoreUrl , platform , exclusive );
253+ return new ConfigPathSettingFileData (setting , mode , ignoreUrl , platform , exclusive );
276254 }
277255 }
278256
279- private static Stream <Path > resolvePathSettings (PathLookup pathLookup , String setting , boolean ignoreUrl ) {
280- Stream <String > result ;
281- if (setting .contains ("*" )) {
282- result = pathLookup .settingGlobResolver ().apply (setting );
283- } else {
284- String path = pathLookup .settingResolver ().apply (setting );
285- result = path == null ? Stream .of () : Stream .of (path );
286- }
287- if (ignoreUrl ) {
288- result = result .filter (s -> s .toLowerCase (Locale .ROOT ).startsWith ("https://" ) == false );
289- }
290- return result .map (Path ::of );
291- }
292-
293257 private static Mode parseMode (String mode ) {
294258 if (mode .equals ("read" )) {
295259 return Mode .READ ;
@@ -370,8 +334,7 @@ public static FilesEntitlement build(List<Object> paths) {
370334 String pathAsString = checkString .apply (file , "path" );
371335 String relativePathAsString = checkString .apply (file , "relative_path" );
372336 String relativeTo = checkString .apply (file , "relative_to" );
373- String pathSetting = checkString .apply (file , "path_setting" );
374- String relativePathSetting = checkString .apply (file , "relative_path_setting" );
337+ String configPathSetting = checkString .apply (file , "config_path_setting" );
375338 String modeAsString = checkString .apply (file , "mode" );
376339 String platformAsString = checkString .apply (file , "platform" );
377340 Boolean ignoreUrlAsStringBoolean = checkBoolean .apply (file , "ignore_url" );
@@ -382,11 +345,10 @@ public static FilesEntitlement build(List<Object> paths) {
382345 if (file .isEmpty () == false ) {
383346 throw new PolicyValidationException ("unknown key(s) [" + file + "] in a listed file for files entitlement" );
384347 }
385- int foundKeys = (pathAsString != null ? 1 : 0 ) + (relativePathAsString != null ? 1 : 0 ) + (pathSetting != null ? 1 : 0 )
386- + (relativePathSetting != null ? 1 : 0 );
348+ int foundKeys = (pathAsString != null ? 1 : 0 ) + (relativePathAsString != null ? 1 : 0 ) + (configPathSetting != null ? 1 : 0 );
387349 if (foundKeys != 1 ) {
388350 throw new PolicyValidationException (
389- "a files entitlement entry must contain one of " + "[path, relative_path, path_setting, relative_path_setting ]"
351+ "a files entitlement entry must contain one of " + "[path, relative_path, config_path_setting ]"
390352 );
391353 }
392354
@@ -405,7 +367,7 @@ public static FilesEntitlement build(List<Object> paths) {
405367 }
406368
407369 if (ignoreUrlAsStringBoolean != null && (relativePathAsString != null || pathAsString != null )) {
408- throw new PolicyValidationException ("'ignore_url' may only be used with `path_setting` or `relative_path_setting` " );
370+ throw new PolicyValidationException ("'ignore_url' may only be used with 'config_path_setting' " );
409371 }
410372
411373 final FileData fileData ;
@@ -424,13 +386,8 @@ public static FilesEntitlement build(List<Object> paths) {
424386 throw new PolicyValidationException ("'path' [" + pathAsString + "] must be absolute" );
425387 }
426388 fileData = FileData .ofPath (path , mode );
427- } else if (pathSetting != null ) {
428- fileData = FileData .ofPathSetting (pathSetting , mode , ignoreUrlAsString );
429- } else if (relativePathSetting != null ) {
430- if (baseDir == null ) {
431- throw new PolicyValidationException ("files entitlement with a 'relative_path_setting' must specify 'relative_to'" );
432- }
433- fileData = FileData .ofRelativePathSetting (relativePathSetting , baseDir , mode , ignoreUrlAsString );
389+ } else if (configPathSetting != null ) {
390+ fileData = FileData .ofConfigPathSetting (configPathSetting , mode , ignoreUrlAsString );
434391 } else {
435392 throw new AssertionError ("File entry validation error" );
436393 }
0 commit comments