optify 0.10.2__tar.gz → 0.11.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. {optify-0.10.2 → optify-0.11.0}/PKG-INFO +6 -1
  2. {optify-0.10.2 → optify-0.11.0}/README.md +5 -0
  3. {optify-0.10.2 → optify-0.11.0}/pyproject.toml +2 -2
  4. {optify-0.10.2 → optify-0.11.0}/python/optify/Cargo.lock +85 -8
  5. {optify-0.10.2 → optify-0.11.0}/python/optify/Cargo.toml +2 -2
  6. {optify-0.10.2 → optify-0.11.0}/python/optify/README.md +5 -0
  7. {optify-0.10.2 → optify-0.11.0}/rust/optify/Cargo.toml +5 -4
  8. {optify-0.10.2 → optify-0.11.0}/rust/optify/README.md +6 -0
  9. {optify-0.10.2 → optify-0.11.0}/rust/optify/benches/get_all_options_benchmark.rs +5 -2
  10. {optify-0.10.2 → optify-0.11.0}/rust/optify/benches/get_options_benchmark.rs +6 -3
  11. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/builder/builder_impl.rs +56 -15
  12. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/builder/loading_result.rs +2 -1
  13. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/provider/get_options_preferences.rs +17 -0
  14. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/provider/provider_impl.rs +85 -1
  15. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/provider/provider_trait.rs +20 -1
  16. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/provider/watcher.rs +21 -1
  17. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/schema/feature.rs +5 -2
  18. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/schema/mod.rs +1 -0
  19. optify-0.11.0/rust/optify/src/schema/policies.rs +88 -0
  20. {optify-0.10.2 → optify-0.11.0}/LICENSE.txt +0 -0
  21. {optify-0.10.2 → optify-0.11.0}/optify/__init__.py +0 -0
  22. {optify-0.10.2 → optify-0.11.0}/optify/optify.pyi +0 -0
  23. {optify-0.10.2 → optify-0.11.0}/optify/py.typed +0 -0
  24. {optify-0.10.2 → optify-0.11.0}/python/optify/.gitignore +0 -0
  25. {optify-0.10.2 → optify-0.11.0}/python/optify/.vscode/settings.json +0 -0
  26. {optify-0.10.2 → optify-0.11.0}/python/optify/LICENSE.txt +0 -0
  27. {optify-0.10.2 → optify-0.11.0}/python/optify/src/lib.rs +0 -0
  28. {optify-0.10.2 → optify-0.11.0}/python/optify/src/preferences.rs +0 -0
  29. {optify-0.10.2 → optify-0.11.0}/python/optify/src/provider.rs +0 -0
  30. {optify-0.10.2 → optify-0.11.0}/python/optify/src/watcher.rs +0 -0
  31. {optify-0.10.2 → optify-0.11.0}/python/optify/tests/test_builder.py +0 -0
  32. {optify-0.10.2 → optify-0.11.0}/python/optify/tests/test_dacite.py +0 -0
  33. {optify-0.10.2 → optify-0.11.0}/python/optify/tests/test_optify.py +0 -0
  34. {optify-0.10.2 → optify-0.11.0}/python/optify/tests/test_provider.py +0 -0
  35. {optify-0.10.2 → optify-0.11.0}/python/optify/tests/test_pydantic.py +0 -0
  36. {optify-0.10.2 → optify-0.11.0}/rust/Cargo.toml +0 -0
  37. {optify-0.10.2 → optify-0.11.0}/rust/optify/benches/caching_benchmark.rs +0 -0
  38. {optify-0.10.2 → optify-0.11.0}/rust/optify/benches/loading_benchmark.rs +0 -0
  39. {optify-0.10.2 → optify-0.11.0}/rust/optify/build.rs +0 -0
  40. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/builder/builder_options.rs +0 -0
  41. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/builder/builder_trait.rs +0 -0
  42. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/builder/extract_configurable_string_files_from_config.rs +0 -0
  43. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/builder/extract_files_from_config.rs +0 -0
  44. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/builder/get_canonical_feature_name.rs +0 -0
  45. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/builder/get_supported_extensions.rs +0 -0
  46. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/builder/mod.rs +0 -0
  47. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/builder/watcher_builder.rs +0 -0
  48. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/configurable_string/configurable_string_impl.rs +0 -0
  49. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/configurable_string/mod.rs +0 -0
  50. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/configurable_values/configurable_list_impl.rs +0 -0
  51. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/configurable_values/locator.rs +0 -0
  52. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/configurable_values/mod.rs +0 -0
  53. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/json/escape_json_pointer.rs +0 -0
  54. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/json/merge.rs +0 -0
  55. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/json/mod.rs +0 -0
  56. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/json/reader.rs +0 -0
  57. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/lib.rs +0 -0
  58. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/provider/constraints.rs +0 -0
  59. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/provider/mod.rs +0 -0
  60. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/provider/watcher_options.rs +0 -0
  61. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/schema/conditions.rs +0 -0
  62. {optify-0.10.2 → optify-0.11.0}/rust/optify/src/schema/metadata.rs +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: optify
3
- Version: 0.10.2
3
+ Version: 0.11.0
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -30,6 +30,7 @@ This is just meant to be minimal to get started and help build a Python library.
30
30
  See the [homepage] for details about how feature files are combined to build the options to process at runtime.
31
31
 
32
32
  ## Usage
33
+
33
34
  ```Python
34
35
  import json
35
36
  from optify import OptionsProvider
@@ -40,6 +41,7 @@ print(config)
40
41
  ```
41
42
 
42
43
  Outputs:
44
+
43
45
  ```JSON
44
46
  {
45
47
  "myArray": [
@@ -174,12 +176,15 @@ pytest
174
176
  ```
175
177
 
176
178
  ### Formatting
179
+
177
180
  To automatically change the Rust code, run:
181
+
178
182
  ```shell
179
183
  cargo fmt && cargo clippy --fix --allow-dirty --allow-staged
180
184
  ```
181
185
 
182
186
  # Publishing
187
+
183
188
  A GitHub Action will automatically publish new versions: https://github.com/juharris/optify/actions/workflows/python_publish.yml
184
189
 
185
190
  [homepage]: https://github.com/juharris/optify
@@ -10,6 +10,7 @@ This is just meant to be minimal to get started and help build a Python library.
10
10
  See the [homepage] for details about how feature files are combined to build the options to process at runtime.
11
11
 
12
12
  ## Usage
13
+
13
14
  ```Python
14
15
  import json
15
16
  from optify import OptionsProvider
@@ -20,6 +21,7 @@ print(config)
20
21
  ```
21
22
 
22
23
  Outputs:
24
+
23
25
  ```JSON
24
26
  {
25
27
  "myArray": [
@@ -154,12 +156,15 @@ pytest
154
156
  ```
155
157
 
156
158
  ### Formatting
159
+
157
160
  To automatically change the Rust code, run:
161
+
158
162
  ```shell
159
163
  cargo fmt && cargo clippy --fix --allow-dirty --allow-staged
160
164
  ```
161
165
 
162
166
  # Publishing
167
+
163
168
  A GitHub Action will automatically publish new versions: https://github.com/juharris/optify/actions/workflows/python_publish.yml
164
169
 
165
170
  [homepage]: https://github.com/juharris/optify
@@ -26,11 +26,11 @@ build-backend = "maturin"
26
26
 
27
27
  [package]
28
28
  name = "optify"
29
- version = "0.10.2"
29
+ version = "0.11.0"
30
30
 
31
31
  [tool.poetry]
32
32
  name = "optify"
33
- version = "0.10.2"
33
+ version = "0.11.0"
34
34
  description = "Simplifies getting the right configuration options for a process using pre-loaded configurations from files to manage options for experiments or flights."
35
35
  authors = ["Justin D. Harris"]
36
36
  maintainers = ["Justin D. Harris"]
@@ -351,6 +351,15 @@ version = "0.2.0"
351
351
  source = "registry+https://github.com/rust-lang/crates.io-index"
352
352
  checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
353
353
 
354
+ [[package]]
355
+ name = "form_urlencoded"
356
+ version = "1.2.2"
357
+ source = "registry+https://github.com/rust-lang/crates.io-index"
358
+ checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
359
+ dependencies = [
360
+ "percent-encoding",
361
+ ]
362
+
354
363
  [[package]]
355
364
  name = "fraction"
356
365
  version = "0.15.4"
@@ -416,6 +425,15 @@ name = "hashbrown"
416
425
  version = "0.16.1"
417
426
  source = "registry+https://github.com/rust-lang/crates.io-index"
418
427
  checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
428
+ dependencies = [
429
+ "foldhash",
430
+ ]
431
+
432
+ [[package]]
433
+ name = "hashbrown"
434
+ version = "0.17.1"
435
+ source = "registry+https://github.com/rust-lang/crates.io-index"
436
+ checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
419
437
  dependencies = [
420
438
  "allocator-api2",
421
439
  "equivalent",
@@ -599,9 +617,9 @@ dependencies = [
599
617
 
600
618
  [[package]]
601
619
  name = "jsonschema"
602
- version = "0.46.5"
620
+ version = "0.48.5"
603
621
  source = "registry+https://github.com/rust-lang/crates.io-index"
604
- checksum = "6a5fe5206f06e589caf25e79fc05ccdf91fca745685fe9fe1a13bbdfb479a631"
622
+ checksum = "f05a6cff806294a7699d48761d4ae2bdebab7fa2eef05e4a0b83320f0ff46901"
605
623
  dependencies = [
606
624
  "ahash",
607
625
  "bytecount",
@@ -612,18 +630,43 @@ dependencies = [
612
630
  "getrandom 0.3.4",
613
631
  "idna",
614
632
  "itoa",
633
+ "jsonschema-regex",
634
+ "jsonschema-value",
615
635
  "num-cmp",
616
636
  "num-traits",
617
637
  "percent-encoding",
618
638
  "referencing",
619
639
  "regex",
620
- "regex-syntax",
621
640
  "serde",
622
641
  "serde_json",
642
+ "strum",
623
643
  "unicode-general-category",
624
644
  "uuid-simd",
625
645
  ]
626
646
 
647
+ [[package]]
648
+ name = "jsonschema-regex"
649
+ version = "0.48.5"
650
+ source = "registry+https://github.com/rust-lang/crates.io-index"
651
+ checksum = "84708dd3f6c5327478a96f37378adb27deed6a626cf84d19de780d9e8ae84b17"
652
+ dependencies = [
653
+ "regex-syntax",
654
+ ]
655
+
656
+ [[package]]
657
+ name = "jsonschema-value"
658
+ version = "0.48.5"
659
+ source = "registry+https://github.com/rust-lang/crates.io-index"
660
+ checksum = "fd8c04ab4ce60e42c4e302d3bd9d184652bb56f212495d2eea23573bcbf72556"
661
+ dependencies = [
662
+ "ahash",
663
+ "bytecount",
664
+ "fraction",
665
+ "num-cmp",
666
+ "num-traits",
667
+ "serde_json",
668
+ ]
669
+
627
670
  [[package]]
628
671
  name = "kqueue"
629
672
  version = "1.1.1"
@@ -898,7 +941,7 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
898
941
 
899
942
  [[package]]
900
943
  name = "optify"
901
- version = "1.3.2"
944
+ version = "1.4.0"
902
945
  dependencies = [
903
946
  "config",
904
947
  "cow-utils",
@@ -912,12 +955,13 @@ dependencies = [
912
955
  "serde",
913
956
  "serde_json",
914
957
  "unicase",
958
+ "url",
915
959
  "walkdir",
916
960
  ]
917
961
 
918
962
  [[package]]
919
963
  name = "optify-python"
920
- version = "0.10.2"
964
+ version = "0.11.0"
921
965
  dependencies = [
922
966
  "optify",
923
967
  "pyo3",
@@ -1170,14 +1214,14 @@ dependencies = [
1170
1214
 
1171
1215
  [[package]]
1172
1216
  name = "referencing"
1173
- version = "0.46.5"
1217
+ version = "0.48.5"
1174
1218
  source = "registry+https://github.com/rust-lang/crates.io-index"
1175
- checksum = "69e4e17ef386c5383591d07623d3de49cbc601156e7582973e6db98d66a57de2"
1219
+ checksum = "980e77f5cfffc592c0e7dfb6d20770a0b96a6ab94d403de7454ed9799505e4ba"
1176
1220
  dependencies = [
1177
1221
  "ahash",
1178
1222
  "fluent-uri",
1179
1223
  "getrandom 0.3.4",
1180
- "hashbrown 0.16.1",
1224
+ "hashbrown 0.17.1",
1181
1225
  "itoa",
1182
1226
  "micromap",
1183
1227
  "parking_lot",
@@ -1352,6 +1396,27 @@ version = "1.1.0"
1352
1396
  source = "registry+https://github.com/rust-lang/crates.io-index"
1353
1397
  checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
1354
1398
 
1399
+ [[package]]
1400
+ name = "strum"
1401
+ version = "0.28.0"
1402
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1403
+ checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd"
1404
+ dependencies = [
1405
+ "strum_macros",
1406
+ ]
1407
+
1408
+ [[package]]
1409
+ name = "strum_macros"
1410
+ version = "0.28.0"
1411
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1412
+ checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664"
1413
+ dependencies = [
1414
+ "heck",
1415
+ "proc-macro2",
1416
+ "quote",
1417
+ "syn",
1418
+ ]
1419
+
1355
1420
  [[package]]
1356
1421
  name = "syn"
1357
1422
  version = "2.0.117"
@@ -1503,6 +1568,18 @@ version = "1.13.2"
1503
1568
  source = "registry+https://github.com/rust-lang/crates.io-index"
1504
1569
  checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c"
1505
1570
 
1571
+ [[package]]
1572
+ name = "url"
1573
+ version = "2.5.8"
1574
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1575
+ checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
1576
+ dependencies = [
1577
+ "form_urlencoded",
1578
+ "idna",
1579
+ "percent-encoding",
1580
+ "serde",
1581
+ ]
1582
+
1506
1583
  [[package]]
1507
1584
  name = "utf8_iter"
1508
1585
  version = "1.0.4"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "optify-python"
3
- version = "0.10.2"
3
+ version = "0.11.0"
4
4
  edition = "2021"
5
5
 
6
6
  description = "Simplifies getting the right configuration options for a process using pre-loaded configurations from files (JSON, YAML, etc.) to manage options for experiments or flights. This library is mainly made to support building implementations for other languages such as Node.js, Python, and Ruby. It is not meant to be consumed directly yet."
@@ -15,5 +15,5 @@ name = "optify"
15
15
  crate-type = ["cdylib"]
16
16
 
17
17
  [dependencies]
18
- optify = { path = "../../rust/optify", version = "1.3.2" }
18
+ optify = { path = "../../rust/optify", version = "1.4.0" }
19
19
  pyo3 = "0.29.0"
@@ -10,6 +10,7 @@ This is just meant to be minimal to get started and help build a Python library.
10
10
  See the [homepage] for details about how feature files are combined to build the options to process at runtime.
11
11
 
12
12
  ## Usage
13
+
13
14
  ```Python
14
15
  import json
15
16
  from optify import OptionsProvider
@@ -20,6 +21,7 @@ print(config)
20
21
  ```
21
22
 
22
23
  Outputs:
24
+
23
25
  ```JSON
24
26
  {
25
27
  "myArray": [
@@ -154,12 +156,15 @@ pytest
154
156
  ```
155
157
 
156
158
  ### Formatting
159
+
157
160
  To automatically change the Rust code, run:
161
+
158
162
  ```shell
159
163
  cargo fmt && cargo clippy --fix --allow-dirty --allow-staged
160
164
  ```
161
165
 
162
166
  # Publishing
167
+
163
168
  A GitHub Action will automatically publish new versions: https://github.com/juharris/optify/actions/workflows/python_publish.yml
164
169
 
165
170
  [homepage]: https://github.com/juharris/optify
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "optify"
3
- version = "1.3.2"
3
+ version = "1.4.0"
4
4
  edition = "2021"
5
5
  build = "build.rs"
6
6
 
@@ -21,10 +21,10 @@ exclude = [
21
21
  config = "0.15.23"
22
22
  cow-utils = "0.1.3"
23
23
  dunce = "1.0.5"
24
- # HTTP/file schema resolution (`resolve-http`, `resolve-file`) requires a TLS backend.
24
+ # HTTP/file schema resolution (`resolve-http`) requires a TLS backend.
25
25
  # `tls-ring` fails to cross-compile for aarch64; the default `tls-aws-lc-rs` needs cmake/lld unavailable in CI Docker containers.
26
- # All current schema `$ref` are internal (`#/definitions/...`), so resolution features are disabled for now.
27
- jsonschema = { version = "0.46.5", default-features = false }
26
+ # The embedded Optify schema is registered explicitly, while local file resolution supports relative references from custom schemas.
27
+ jsonschema = { version = "0.48.0", default-features = false, features = ["resolve-file"] }
28
28
  liquid = "0.26.11"
29
29
  notify = "8.2.0"
30
30
  # For fetching JSON schema files from the web, but it requires OpenSSL, which is tricky to install in CI environments in Docker containers.
@@ -36,6 +36,7 @@ regex = "1.12.3"
36
36
  serde = { version = "1.0.228", features = ["derive"] }
37
37
  serde_json = "1.0.149"
38
38
  unicase = "2.9.0"
39
+ url = "2.5.8"
39
40
  walkdir = "2.5.0"
40
41
 
41
42
  [dev-dependencies]
@@ -72,18 +72,23 @@ Optionally, when working locally, there is support to watch for changes to the c
72
72
  ## Testing
73
73
 
74
74
  Run:
75
+
75
76
  ```shell
76
77
  cargo test
77
78
  ```
78
79
 
79
80
  ## Formatting
81
+
80
82
  To automatically change code, run:
83
+
81
84
  ```shell
82
85
  cargo fmt && cargo clippy --fix --allow-dirty --allow-staged
83
86
  ```
84
87
 
85
88
  ## Benchmarking
89
+
86
90
  Run:
91
+
87
92
  ```shell
88
93
  cargo build --release
89
94
  cargo bench
@@ -97,6 +102,7 @@ open target/criterion/*/report/index.html
97
102
  ```
98
103
 
99
104
  ## Publishing
105
+
100
106
  ```shell
101
107
  cargo login
102
108
  cargo publish
@@ -1,10 +1,13 @@
1
1
  use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
2
2
  use optify::provider::{GetOptionsPreferences, OptionsProvider, OptionsRegistry};
3
3
 
4
- const CONFIGS_DIR: &str = "../../tests/test_suites/configurable_values/configs";
4
+ const CONFIGS_DIRS: &[&str] = &[
5
+ "../../tests/test_suites/configurable_values/configs",
6
+ "../../tests/test_suites/configurable_values_no_schema/configs",
7
+ ];
5
8
 
6
9
  fn get_provider() -> OptionsProvider {
7
- OptionsProvider::build(CONFIGS_DIR).unwrap()
10
+ OptionsProvider::build_from_directories(CONFIGS_DIRS).unwrap()
8
11
  }
9
12
 
10
13
  fn benchmark_get_all_options_breakdown(c: &mut Criterion) {
@@ -1,10 +1,13 @@
1
1
  use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
2
2
  use optify::provider::{CacheOptions, GetOptionsPreferences, OptionsProvider, OptionsRegistry};
3
3
 
4
- const CONFIGS_DIR: &str = "../../tests/test_suites/configurable_values/configs";
4
+ const CONFIGS_DIRS: &[&str] = &[
5
+ "../../tests/test_suites/configurable_values/configs",
6
+ "../../tests/test_suites/configurable_values_no_schema/configs",
7
+ ];
5
8
 
6
9
  fn get_provider() -> OptionsProvider {
7
- OptionsProvider::build(CONFIGS_DIR).unwrap()
10
+ OptionsProvider::build_from_directories(CONFIGS_DIRS).unwrap()
8
11
  }
9
12
 
10
13
  fn benchmark_get_options_with_preferences_breakdown(c: &mut Criterion) {
@@ -78,7 +81,7 @@ fn benchmark_get_options_with_preferences_breakdown(c: &mut Criterion) {
78
81
  let cache_options = CacheOptions {};
79
82
  // Pre-populate cache
80
83
  let _ = provider
81
- .get_options_with_preferences(*key, *features, Some(&cache_options), None)
84
+ .get_options_with_preferences(key, features, Some(&cache_options), None)
82
85
  .unwrap();
83
86
 
84
87
  b.iter(|| {
@@ -1,5 +1,5 @@
1
1
  use config;
2
- use jsonschema::{Draft, Registry, Validator};
2
+ use jsonschema::{Registry, Validator};
3
3
  use rayon::prelude::*;
4
4
  use std::collections::{HashMap, HashSet};
5
5
  use std::path::Path;
@@ -17,7 +17,8 @@ use crate::configurable_values::locator::{find_configurable_values, Configurable
17
17
  use crate::json::merge::{merge_json_with_defaults, FrozenPaths};
18
18
  use crate::json::reader::read_json_from_file_as;
19
19
  use crate::provider::{
20
- Aliases, Conditions, Features, OptionsProvider, ReferencedFileToFeatureNames, Sources,
20
+ Aliases, Conditions, Features, OptionsProvider, PoliciesMap, ReferencedFileToFeatureNames,
21
+ Sources,
21
22
  };
22
23
  use crate::schema::feature::FeatureConfiguration;
23
24
  use crate::schema::metadata::OptionsMetadata;
@@ -39,6 +40,7 @@ pub struct OptionsProviderBuilder {
39
40
  features: Features,
40
41
  imports: Imports,
41
42
  loaded_files: LoadedFiles,
43
+ policies: PoliciesMap,
42
44
  /// A map of files to the features that reference them.
43
45
  /// The keys are relative file paths and the values are lists of canonical feature names.
44
46
  /// This is only populated if the `BuilderOptions` enable file reference tracking.
@@ -67,6 +69,34 @@ fn add_alias(
67
69
  Ok(())
68
70
  }
69
71
 
72
+ fn drain_sorted_pointers(pointers: &mut HashSet<String>) -> Vec<String> {
73
+ drain_sorted_pointers_from_set(std::mem::take(pointers))
74
+ }
75
+
76
+ fn drain_sorted_pointers_from_set(pointers: HashSet<String>) -> Vec<String> {
77
+ let mut sorted_pointers: Vec<String> = pointers.into_iter().collect();
78
+ sort_pointers_deepest_first(&mut sorted_pointers);
79
+ sorted_pointers
80
+ }
81
+
82
+ fn sorted_pointers_from_set(pointers: &HashSet<String>) -> Vec<String> {
83
+ let mut sorted_pointers: Vec<String> = pointers.iter().cloned().collect();
84
+ sort_pointers_deepest_first(&mut sorted_pointers);
85
+ sorted_pointers
86
+ }
87
+
88
+ fn sort_pointers_deepest_first(pointers: &mut [String]) {
89
+ pointers.sort_unstable_by(|a, b| {
90
+ pointer_depth(b)
91
+ .cmp(&pointer_depth(a))
92
+ .then_with(|| a.cmp(b))
93
+ });
94
+ }
95
+
96
+ fn pointer_depth(pointer: &str) -> usize {
97
+ pointer.matches('/').count()
98
+ }
99
+
70
100
  #[allow(clippy::too_many_arguments)]
71
101
  fn resolve_imports(
72
102
  canonical_feature_name: &str,
@@ -169,6 +199,7 @@ impl OptionsProviderBuilder {
169
199
  features: Features::new(),
170
200
  imports: HashMap::new(),
171
201
  loaded_files: LoadedFiles::new(),
202
+ policies: PoliciesMap::new(),
172
203
  referenced_file_to_feature_names: HashMap::new(),
173
204
  schema: None,
174
205
  sources: Sources::new(),
@@ -179,9 +210,7 @@ impl OptionsProviderBuilder {
179
210
  self.prepare_build()?;
180
211
 
181
212
  let all_configurable_list_pointers =
182
- std::mem::take(&mut self.all_configurable_list_pointers)
183
- .into_iter()
184
- .collect();
213
+ drain_sorted_pointers(&mut self.all_configurable_list_pointers);
185
214
  let all_configurable_string_pointers =
186
215
  std::mem::take(&mut self.all_configurable_string_pointers)
187
216
  .into_iter()
@@ -189,7 +218,7 @@ impl OptionsProviderBuilder {
189
218
  let keyed_configurable_list_pointers =
190
219
  std::mem::take(&mut self.keyed_configurable_list_pointers)
191
220
  .into_iter()
192
- .map(|(key, set)| (key, set.into_iter().collect()))
221
+ .map(|(key, set)| (key, drain_sorted_pointers_from_set(set)))
193
222
  .collect();
194
223
  let keyed_configurable_string_pointers =
195
224
  std::mem::take(&mut self.keyed_configurable_string_pointers)
@@ -211,6 +240,7 @@ impl OptionsProviderBuilder {
211
240
  keyed_configurable_string_pointers,
212
241
  std::mem::take(&mut self.conditions),
213
242
  std::mem::take(&mut self.features),
243
+ std::mem::take(&mut self.policies),
214
244
  referenced_file_to_feature_names,
215
245
  std::mem::take(&mut self.loaded_files),
216
246
  std::mem::take(&mut self.sources),
@@ -281,6 +311,7 @@ impl OptionsProviderBuilder {
281
311
  relative_path,
282
312
  }))
283
313
  }
314
+
284
315
  Err(e) => Err(format!("Error reading file {}: {e}", path.display())),
285
316
  }
286
317
  }
@@ -312,6 +343,10 @@ impl OptionsProviderBuilder {
312
343
  self.conditions
313
344
  .insert(canonical_feature_name.clone(), conditions);
314
345
  }
346
+ if let Some(policies) = info.policies {
347
+ self.policies
348
+ .insert(canonical_feature_name.clone(), policies);
349
+ }
315
350
  if let Some(imports) = info.imports {
316
351
  self.imports.insert(canonical_feature_name.clone(), imports);
317
352
  }
@@ -498,6 +533,7 @@ fn process_config_file_entry(
498
533
  configurable_value_pointers,
499
534
  imports: feature_config.imports,
500
535
  metadata,
536
+ policies: feature_config.policies,
501
537
  source,
502
538
  }))
503
539
  }
@@ -587,9 +623,16 @@ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
587
623
  }
588
624
 
589
625
  fn with_schema(&mut self, schema_path: impl AsRef<Path>) -> Result<&Self, String> {
590
- let schema_path = schema_path.as_ref();
591
- let schema_json = crate::json::reader::read_json_from_file(schema_path)
626
+ let schema_path = dunce::canonicalize(schema_path.as_ref())
627
+ .map_err(|e| format!("Failed to resolve schema path: {e}"))?;
628
+ let schema_json = crate::json::reader::read_json_from_file(&schema_path)
592
629
  .map_err(|e| format!("Failed to read schema file: {e}"))?;
630
+ let schema_uri = url::Url::from_file_path(&schema_path).map_err(|()| {
631
+ format!(
632
+ "Failed to convert schema path to a file URI: {}",
633
+ schema_path.display()
634
+ )
635
+ })?;
593
636
 
594
637
  // Load the embedded schema file (this is resolved at compile time).
595
638
  const EMBEDDED_SCHEMA: &[u8] =
@@ -606,7 +649,7 @@ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
606
649
  .map_err(|e| format!("Failed to prepare schema registry: {e}"))?;
607
650
 
608
651
  let validator = Validator::options()
609
- .with_draft(Draft::Draft7)
652
+ .with_base_uri(schema_uri.as_str())
610
653
  .with_registry(&registry)
611
654
  .build(&schema_json)
612
655
  .map_err(|e| format!("Invalid schema: {e}"))?;
@@ -624,15 +667,12 @@ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
624
667
  .iter()
625
668
  .cloned()
626
669
  .collect();
627
- let all_configurable_list_pointers = self
628
- .all_configurable_list_pointers
629
- .iter()
630
- .cloned()
631
- .collect();
670
+ let all_configurable_list_pointers =
671
+ sorted_pointers_from_set(&self.all_configurable_list_pointers);
632
672
  let keyed_configurable_list_pointers = self
633
673
  .keyed_configurable_list_pointers
634
674
  .iter()
635
- .map(|(key, set)| (key.clone(), set.iter().cloned().collect()))
675
+ .map(|(key, set)| (key.clone(), sorted_pointers_from_set(set)))
636
676
  .collect();
637
677
  let keyed_configurable_string_pointers = self
638
678
  .keyed_configurable_string_pointers
@@ -654,6 +694,7 @@ impl OptionsRegistryBuilder<OptionsProvider> for OptionsProviderBuilder {
654
694
  keyed_configurable_string_pointers,
655
695
  self.conditions.clone(),
656
696
  self.features.clone(),
697
+ self.policies.clone(),
657
698
  referenced_file_to_feature_names,
658
699
  self.loaded_files.clone(),
659
700
  self.sources.clone(),
@@ -1,7 +1,7 @@
1
1
  use crate::{
2
2
  configurable_values::locator::ConfigurableValuePointers,
3
3
  provider::SourceValue,
4
- schema::{conditions::ConditionExpression, metadata::OptionsMetadata},
4
+ schema::{conditions::ConditionExpression, metadata::OptionsMetadata, policies::Policies},
5
5
  };
6
6
 
7
7
  #[allow(clippy::large_enum_variant)]
@@ -20,6 +20,7 @@ pub(crate) struct FeatureLoadingResult {
20
20
  pub configurable_value_pointers: ConfigurableValuePointers,
21
21
  pub imports: Option<Vec<String>>,
22
22
  pub metadata: OptionsMetadata,
23
+ pub policies: Option<Policies>,
23
24
  pub source: SourceValue,
24
25
  }
25
26
 
@@ -12,6 +12,21 @@ pub struct GetOptionsPreferences {
12
12
  pub constraints: Option<Constraints>,
13
13
  /// Overrides to apply after the built configuration.
14
14
  pub overrides: Option<SourceValue>,
15
+ /// The identifier of the requester making this request.
16
+ ///
17
+ /// Used to enforce `policies.requester` on features.
18
+ ///
19
+ /// **Important**: If `None`, requester-based policies are **not** checked, meaning callers
20
+ /// that do not set this field bypass requester policy enforcement entirely.
21
+ /// Only trusted internal callers that are not subject to requester policies should omit this field.
22
+ /// For all external or user-facing requests, always set this to the requester's identifier.
23
+ pub requester: Option<String>,
24
+ /// Whether to raise an error if a feature's policies deny the requester.
25
+ ///
26
+ /// When `true` and `requester` is set, any feature denied by its policies will cause an error.
27
+ /// When `false` (the default), denied features are silently filtered out, matching the behaviour
28
+ /// of condition-based filtering.
29
+ pub raise_if_policy_denied: bool,
15
30
  /// Determines if the feature names should be converted to canonical feature names.
16
31
  /// Defaults to false: given features names will be converted to canonical feature names before looking for features or options.
17
32
  pub skip_feature_name_conversion: bool,
@@ -30,6 +45,8 @@ impl GetOptionsPreferences {
30
45
  are_configurable_values_enabled: false,
31
46
  constraints: None,
32
47
  overrides: None,
48
+ raise_if_policy_denied: false,
49
+ requester: None,
33
50
  skip_feature_name_conversion: false,
34
51
  }
35
52
  }
@@ -8,7 +8,11 @@ use crate::{
8
8
  configurable_string::LoadedFiles,
9
9
  json::merge::{merge_json_with_defaults, FrozenPaths},
10
10
  provider::GetOptionsPreferences,
11
- schema::{conditions::ConditionExpression, metadata::OptionsMetadata},
11
+ schema::{
12
+ conditions::ConditionExpression,
13
+ metadata::OptionsMetadata,
14
+ policies::{Policies, PolicyDeniedError},
15
+ },
12
16
  };
13
17
 
14
18
  use super::OptionsRegistry;
@@ -22,6 +26,7 @@ pub(crate) type SourceValue = serde_json::Value;
22
26
  pub(crate) type Aliases = HashMap<unicase::UniCase<String>, String>;
23
27
  pub(crate) type Conditions = HashMap<String, ConditionExpression>;
24
28
  pub(crate) type Features = HashMap<String, OptionsMetadata>;
29
+ pub(crate) type PoliciesMap = HashMap<String, Policies>;
25
30
  pub(crate) type ReferencedFileToFeatureNames = HashMap<String, Vec<String>>;
26
31
  pub(crate) type Sources = HashMap<String, SourceValue>;
27
32
 
@@ -40,6 +45,7 @@ pub struct OptionsProvider {
40
45
  aliases: Aliases,
41
46
  conditions: Conditions,
42
47
  features: Features,
48
+ policies: PoliciesMap,
43
49
  /// A map of files to their referencing features.
44
50
  /// The keys are relative file paths and the values are lists of canonical feature names.
45
51
  /// This allows fast lookup of features when a specific file is modified.
@@ -63,6 +69,7 @@ impl OptionsProvider {
63
69
  keyed_configurable_string_pointers: HashMap<String, Vec<String>>,
64
70
  conditions: Conditions,
65
71
  features: Features,
72
+ policies: PoliciesMap,
66
73
  referenced_file_to_feature_names: Option<ReferencedFileToFeatureNames>,
67
74
  loaded_files: LoadedFiles,
68
75
  sources: Sources,
@@ -75,6 +82,7 @@ impl OptionsProvider {
75
82
  aliases,
76
83
  conditions,
77
84
  features,
85
+ policies,
78
86
  referenced_file_to_feature_names,
79
87
  loaded_files,
80
88
  sources,
@@ -425,6 +433,32 @@ impl OptionsProvider {
425
433
  }
426
434
  Ok(())
427
435
  }
436
+
437
+ /// Checks whether the requester is permitted for the given feature.
438
+ ///
439
+ /// Returns `Ok(true)` if permitted, no policy is set, or no requester is given.
440
+ /// Returns `Ok(false)` if denied and `raise_if_policy_denied` is false.
441
+ /// Returns `Err(message)` if denied and `raise_if_policy_denied` is true.
442
+ fn is_feature_permitted_for_requester(
443
+ &self,
444
+ canonical_feature_name: &str,
445
+ requester: Option<&str>,
446
+ raise_if_policy_denied: bool,
447
+ ) -> Result<bool, String> {
448
+ if let Some(requester) = requester {
449
+ if let Some(policies) = self.policies.get(canonical_feature_name) {
450
+ if !policies.is_requester_permitted(requester) {
451
+ if raise_if_policy_denied {
452
+ return Err(
453
+ PolicyDeniedError::new(canonical_feature_name, requester).to_string()
454
+ );
455
+ }
456
+ return Ok(false);
457
+ }
458
+ }
459
+ }
460
+ Ok(true)
461
+ }
428
462
  }
429
463
 
430
464
  impl OptionsRegistry for OptionsProvider {
@@ -539,9 +573,13 @@ impl OptionsRegistry for OptionsProvider {
539
573
  ) -> Result<Vec<String>, String> {
540
574
  let mut skip_feature_name_conversion = false;
541
575
  let mut constraints = None;
576
+ let mut requester: Option<&str> = None;
577
+ let mut raise_if_policy_denied = false;
542
578
  if let Some(preferences) = preferences {
543
579
  skip_feature_name_conversion = preferences.skip_feature_name_conversion;
544
580
  constraints = preferences.constraints.as_ref();
581
+ requester = preferences.requester.as_deref();
582
+ raise_if_policy_denied = preferences.raise_if_policy_denied;
545
583
  }
546
584
 
547
585
  let mut result = Vec::new();
@@ -562,6 +600,15 @@ impl OptionsRegistry for OptionsProvider {
562
600
  continue;
563
601
  }
564
602
  }
603
+
604
+ if !self.is_feature_permitted_for_requester(
605
+ &canonical_feature_name,
606
+ requester,
607
+ raise_if_policy_denied,
608
+ )? {
609
+ continue;
610
+ }
611
+
565
612
  result.push(canonical_feature_name);
566
613
  }
567
614
 
@@ -626,6 +673,29 @@ impl OptionsRegistry for OptionsProvider {
626
673
  self.conditions.contains_key(canonical_feature_name)
627
674
  }
628
675
 
676
+ fn check_policies(
677
+ &self,
678
+ requester: &str,
679
+ feature_names: &[impl AsRef<str>],
680
+ _cache_options: Option<&CacheOptions>,
681
+ ) -> Result<(), String> {
682
+ for feature_name in feature_names {
683
+ let canonical_feature_name = self.get_canonical_feature_name(feature_name.as_ref())?;
684
+ if let Some(policies) = self.policies.get(&canonical_feature_name) {
685
+ if !policies.is_requester_permitted(requester) {
686
+ return Err(
687
+ PolicyDeniedError::new(&canonical_feature_name, requester).to_string()
688
+ );
689
+ }
690
+ }
691
+ }
692
+ Ok(())
693
+ }
694
+
695
+ fn get_policies(&self, canonical_feature_name: &str) -> Option<Policies> {
696
+ self.policies.get(canonical_feature_name).cloned()
697
+ }
698
+
629
699
  fn map_feature_names(
630
700
  &self,
631
701
  feature_names: &[impl AsRef<str>],
@@ -633,9 +703,13 @@ impl OptionsRegistry for OptionsProvider {
633
703
  ) -> Result<Vec<Option<String>>, String> {
634
704
  let mut skip_feature_name_conversion = false;
635
705
  let mut constraints = None;
706
+ let mut requester: Option<&str> = None;
707
+ let mut raise_if_policy_denied = false;
636
708
  if let Some(preferences) = preferences {
637
709
  skip_feature_name_conversion = preferences.skip_feature_name_conversion;
638
710
  constraints = preferences.constraints.as_ref();
711
+ requester = preferences.requester.as_deref();
712
+ raise_if_policy_denied = preferences.raise_if_policy_denied;
639
713
  }
640
714
 
641
715
  let mut result = Vec::new();
@@ -657,6 +731,16 @@ impl OptionsRegistry for OptionsProvider {
657
731
  continue;
658
732
  }
659
733
  }
734
+
735
+ if !self.is_feature_permitted_for_requester(
736
+ &canonical_feature_name,
737
+ requester,
738
+ raise_if_policy_denied,
739
+ )? {
740
+ result.push(None);
741
+ continue;
742
+ }
743
+
660
744
  result.push(Some(canonical_feature_name));
661
745
  }
662
746
 
@@ -6,7 +6,7 @@ use crate::builder::builder_options::BuilderOptions;
6
6
 
7
7
  use crate::{
8
8
  provider::{CacheOptions, Features, GetOptionsPreferences},
9
- schema::metadata::OptionsMetadata,
9
+ schema::{metadata::OptionsMetadata, policies::Policies},
10
10
  };
11
11
 
12
12
  /// Trait defining the core functionality for an options provider
@@ -125,6 +125,25 @@ pub trait OptionsRegistry {
125
125
  /// Indicates if the feature has conditions.
126
126
  fn has_conditions(&self, canonical_feature_name: &str) -> bool;
127
127
 
128
+ /// Checks policies for a list of features for the given requester.
129
+ /// `CacheOptions` is not used yet.
130
+ ///
131
+ /// Returns `Ok(())` if there are no policy issues (or no policies defined).
132
+ /// Returns `Err(String)` with an error message for the first feature that is not allowed.
133
+ fn check_policies(
134
+ &self,
135
+ requester: &str,
136
+ feature_names: &[impl AsRef<str>],
137
+ cache_options: Option<&CacheOptions>,
138
+ ) -> Result<(), String>;
139
+
140
+ /// Returns the policies for the given canonical feature name, if any.
141
+ ///
142
+ /// Policies are only checked for top-level features in a request.
143
+ /// Features that are imported by other features may have policies, but those policies
144
+ /// are not checked when the feature is used as an import.
145
+ fn get_policies(&self, canonical_feature_name: &str) -> Option<Policies>;
146
+
128
147
  /// Filters `feature_names` based on the preferences,
129
148
  /// such as the `preferences.constraints`.
130
149
  /// Returns a Vec of optional strings matching the input order.
@@ -8,7 +8,7 @@ use crate::builder::{OptionsRegistryBuilder, OptionsWatcherBuilder};
8
8
  use crate::provider::{
9
9
  CacheOptions, Features, GetOptionsPreferences, OptionsProvider, OptionsRegistry, WatcherOptions,
10
10
  };
11
- use crate::schema::metadata::OptionsMetadata;
11
+ use crate::schema::{metadata::OptionsMetadata, policies::Policies};
12
12
 
13
13
  pub type OptionsWatcherListener = Arc<dyn Fn(&HashSet<PathBuf>) + Send + Sync>;
14
14
 
@@ -329,6 +329,19 @@ impl OptionsRegistry for OptionsWatcher {
329
329
  .get_options_with_preferences(key, feature_names, cache_options, preferences)
330
330
  }
331
331
 
332
+ fn check_policies(
333
+ &self,
334
+ requester: &str,
335
+ feature_names: &[impl AsRef<str>],
336
+ cache_options: Option<&CacheOptions>,
337
+ ) -> Result<(), String> {
338
+ self.current_provider.read().unwrap().check_policies(
339
+ requester,
340
+ feature_names,
341
+ cache_options,
342
+ )
343
+ }
344
+
332
345
  fn has_conditions(&self, canonical_feature_name: &str) -> bool {
333
346
  self.current_provider
334
347
  .read()
@@ -336,6 +349,13 @@ impl OptionsRegistry for OptionsWatcher {
336
349
  .has_conditions(canonical_feature_name)
337
350
  }
338
351
 
352
+ fn get_policies(&self, canonical_feature_name: &str) -> Option<Policies> {
353
+ self.current_provider
354
+ .read()
355
+ .unwrap()
356
+ .get_policies(canonical_feature_name)
357
+ }
358
+
339
359
  fn map_feature_names(
340
360
  &self,
341
361
  feature_names: &[impl AsRef<str>],
@@ -1,9 +1,8 @@
1
- // Similar to https://github.com/juharris/dotnet-OptionsProvider/blob/main/src/OptionsProvider/OptionsProvider/FeatureConfiguration.cs
2
-
3
1
  use serde::Deserialize;
4
2
 
5
3
  use super::conditions::ConditionExpression;
6
4
  use super::metadata::OptionsMetadata;
5
+ use super::policies::Policies;
7
6
 
8
7
  pub(crate) type ConfigurationOptions = serde_json::Value;
9
8
 
@@ -16,5 +15,9 @@ pub(crate) struct FeatureConfiguration {
16
15
  ///
17
16
  /// More details in the JSON schema.
18
17
  pub conditions: Option<ConditionExpression>,
18
+ /// Policies that restrict which requesters may use this feature.
19
+ ///
20
+ /// More details in the JSON schema.
21
+ pub policies: Option<Policies>,
19
22
  pub options: Option<ConfigurationOptions>,
20
23
  }
@@ -1,3 +1,4 @@
1
1
  pub mod conditions;
2
2
  pub(crate) mod feature;
3
3
  pub mod metadata;
4
+ pub mod policies;
@@ -0,0 +1,88 @@
1
+ use std::collections::HashSet;
2
+ use std::fmt;
3
+
4
+ use serde::{Deserialize, Serialize};
5
+
6
+ /// Error returned when a requester is not permitted to use a feature.
7
+ #[derive(Clone, Debug)]
8
+ pub struct PolicyDeniedError {
9
+ pub feature_name: String,
10
+ pub requester: String,
11
+ }
12
+
13
+ impl PolicyDeniedError {
14
+ pub fn new(feature_name: impl Into<String>, requester: impl Into<String>) -> Self {
15
+ Self {
16
+ feature_name: feature_name.into(),
17
+ requester: requester.into(),
18
+ }
19
+ }
20
+ }
21
+
22
+ impl fmt::Display for PolicyDeniedError {
23
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24
+ write!(
25
+ f,
26
+ "Requester \"{}\" is not permitted to use feature \"{}\".",
27
+ self.requester, self.feature_name
28
+ )
29
+ }
30
+ }
31
+
32
+ impl std::error::Error for PolicyDeniedError {}
33
+
34
+ /// The policy for the requester identifier passed via preferences.
35
+ ///
36
+ /// Either `allow` or `block` must be specified, not both.
37
+ ///
38
+ /// - `allow`: Only the listed requesters may use this feature.
39
+ /// An empty set means no requester is currently allowed.
40
+ /// - `block`: The listed requesters may not use this feature.
41
+ /// All other requesters are allowed.
42
+ ///
43
+ /// See https://github.com/juharris/optify#policies for more information.
44
+ #[derive(Clone, Debug, Deserialize, Serialize)]
45
+ #[serde(untagged)]
46
+ pub enum RequesterPolicy {
47
+ Allow { allow: HashSet<String> },
48
+ Block { block: HashSet<String> },
49
+ }
50
+
51
+ impl RequesterPolicy {
52
+ /// Returns `true` if the given requester is permitted by this policy.
53
+ pub fn is_permitted(&self, value: &str) -> bool {
54
+ match self {
55
+ Self::Allow { allow } => allow.contains(value),
56
+ Self::Block { block } => !block.contains(value),
57
+ }
58
+ }
59
+ }
60
+
61
+ /// Policies that restrict access to a feature based on values in the request's preferences.
62
+ ///
63
+ /// Policies are checked for the **top-level features** in a request.
64
+ /// Unlike conditions, policies are **not** evaluated on imported features — a feature may
65
+ /// freely import another feature that has policies without those policies being enforced.
66
+ ///
67
+ /// See https://github.com/juharris/optify#policies for details and a comparison with conditions.
68
+ #[derive(Clone, Debug, Deserialize, Serialize)]
69
+ #[serde(deny_unknown_fields)]
70
+ pub struct Policies {
71
+ /// Restrictions based on the requester identifier passed via preferences.
72
+ ///
73
+ /// Use `allow` to specify an allowlist (only those requesters may use this feature).
74
+ /// Use `block` to specify a denylist (all requesters except those listed may use this feature).
75
+ /// `allow` and `block` are mutually exclusive.
76
+ pub requester: Option<RequesterPolicy>,
77
+ }
78
+
79
+ impl Policies {
80
+ /// Returns `true` if the given requester is permitted to use the feature.
81
+ ///
82
+ /// If no `requester` policy is set, all requesters are permitted.
83
+ pub fn is_requester_permitted(&self, requester: &str) -> bool {
84
+ self.requester
85
+ .as_ref()
86
+ .is_none_or(|p| p.is_permitted(requester))
87
+ }
88
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes