unitysvc-core 0.3.2__tar.gz → 0.3.3__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 (54) hide show
  1. {unitysvc_core-0.3.2/src/unitysvc_core.egg-info → unitysvc_core-0.3.3}/PKG-INFO +13 -10
  2. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/README.md +12 -9
  3. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/pyproject.toml +1 -1
  4. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/grants.py +155 -57
  5. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3/src/unitysvc_core.egg-info}/PKG-INFO +13 -10
  6. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_grants.py +217 -17
  7. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_validator.py +1 -1
  8. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/LICENSE +0 -0
  9. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/setup.cfg +0 -0
  10. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/__init__.py +0 -0
  11. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/__init__.py +0 -0
  12. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/base.py +0 -0
  13. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/channel.py +0 -0
  14. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/documents.py +0 -0
  15. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/listing_data.py +0 -0
  16. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/listing_v1.py +0 -0
  17. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/offering_data.py +0 -0
  18. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/offering_v1.py +0 -0
  19. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/pricing.py +0 -0
  20. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/promotion_data.py +0 -0
  21. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/provider_data.py +0 -0
  22. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/provider_v1.py +0 -0
  23. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/service.py +0 -0
  24. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/service_group_data.py +0 -0
  25. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/models/validators.py +0 -0
  26. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/parameter_usage.py +0 -0
  27. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/py.typed +0 -0
  28. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/schema/base.json +0 -0
  29. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/schema/listing_v1.json +0 -0
  30. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/schema/offering_v1.json +0 -0
  31. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/schema/promotion_v1.json +0 -0
  32. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/schema/provider_v1.json +0 -0
  33. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/schema/service_group_v1.json +0 -0
  34. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/utils.py +0 -0
  35. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core/validator.py +0 -0
  36. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core.egg-info/SOURCES.txt +0 -0
  37. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core.egg-info/dependency_links.txt +0 -0
  38. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core.egg-info/requires.txt +0 -0
  39. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/src/unitysvc_core.egg-info/top_level.txt +0 -0
  40. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_access_interface_routing.py +0 -0
  41. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_canonical_interfaces.py +0 -0
  42. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_channel.py +0 -0
  43. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_effective_price.py +0 -0
  44. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_hidden_path_skip.py +0 -0
  45. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_listing_audience.py +0 -0
  46. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_offering_data.py +0 -0
  47. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_parameter_usage.py +0 -0
  48. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_pricing.py +0 -0
  49. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_provider_account_rate_limits.py +0 -0
  50. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_service_group.py +0 -0
  51. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_service_status.py +0 -0
  52. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_utils.py +0 -0
  53. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_validate_service.py +0 -0
  54. {unitysvc_core-0.3.2 → unitysvc_core-0.3.3}/tests/test_validators.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitysvc-core
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Shared data models and validation helpers for UnitySVC packages
5
5
  Author-email: Bo Peng <bo.peng@unitysvc.com>
6
6
  Maintainer-email: Bo Peng <bo.peng@unitysvc.com>
@@ -199,7 +199,7 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
199
199
  - `permissions`: a name (lowercase letters, digits and `_`) → the routes it covers, each `"<METHOD> /<path>"` (`*` for any method, `*` globs in the path). Permissions are never inferred from HTTP methods.
200
200
  - `options`: a JSON Schema (draft 7) object of the customizations a grant may set on the service, like a channel's `params.schema`, with an optional react-jsonschema-form `options_ui_schema`; the frontend renders it with the same form component. It covers limits only the service can apply (a message size). Restrictions so a grant can write every value in query-string syntax: property names are lowercase letters, digits and `_`; each property is a `string`, `integer`, `number`, `boolean` or an `array` of strings, serialized as an OpenAPI form-style query parameter with arrays comma-joined (`style: form, explode: false`); options are optional (no `required`) and only declared properties are accepted; the schema is self-contained (no `$ref`), so validating against it never fetches anything. A property's `default` is what the service does when the policy does not set the option.
201
201
 
202
- **2. A customer access request (`upstream_access_config.<channel>.customer_access_requests`), and the policy entry it becomes.** Any channel may declare its own list; each approved request becomes an entry (a grant) in the issued key's policy, in the same shape:
202
+ **2. A customer access request (`upstream_access_config.<channel>.customer_access_requests`), and the policy entry it becomes.** Any channel may declare its own list: a fixed list of items the customer works on, and nothing else (unitysvc/unitysvc#2831). Each approved request becomes an entry (a grant) in the issued key's policy, in the same shape:
203
203
 
204
204
  ```json
205
205
  "customer_access_requests": [{"object": "service:log", "permissions": ["invoke"], "required": true,
@@ -208,11 +208,13 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
208
208
  "limits": {"count_per_day": 1000}}]
209
209
  ```
210
210
 
211
- - `object` names one service (`service:<name>`, no wildcards), or `apikey` for the leased key's lifespan (below).
211
+ - `object` names one service (`service:<name>`, no wildcards), or `apikey` for the leased key's lifespan (below). `permissions` are plain names (lowercase letters, digits and `_`; no wildcards), checked against the target's exports with a catalog.
212
+ - `required` (`true` or `false`, on every entry, `apikey` included) says whether the customer may decline the request. A stored declaration from before this rule reads as optional when a policy is built.
212
213
  - `options` is written in query-string syntax (`parse_options`; a notation, not how options are delivered): each name once, each value non-empty; with a catalog, each value is converted to its declared type and validated against the target's `options` schema.
213
- - **Enrollment is where options and limits are set.** In a request, `options` and `limits` only pre-fill the enrollment form for convenience. When enrolling, the customer confirms and sets the options (a form rendered from the target's `options` schema) and the limits, and adds their own limits; the result is the issued key's policy.
214
- - `limits` (`validate_limits`): `count_per_hour` / `count_per_day` / `count_per_month` / `count_total` (positive integer) and the same for `amount_` (finite positive decimal, as a number or a string). Limits are universal: the platform meters every call, so any service can be limited without exporting anything. The seller's limits are a pre-fill; the customer sets them at enrollment, and an enrollment's own limits (unitysvc/unitysvc#2687) use the same shape. They are counted per policy entry (the enrollment's calls to that service) from the usage stream (counters keyed by scope, metric and window bucket), and the gateway refuses calls once one is exceeded.
215
- - **A longer-lived leased key** is asked for with one `apikey` entry: `{"object": "apikey", "limits": {"api_key_lifespan": 14400}, "justification": "Batch runs take up to four hours"}`. It names the key itself, so it takes only `limits` (exactly `api_key_lifespan`, whole seconds from 1 to 86400) and a `justification`, needs no catalog lookup, and grants nothing. Without it, a key the seller leases for the enrollment lives `DEFAULT_API_KEY_LIFESPAN` (3600 s). `api_key_lifespan` is valid only on this entry.
214
+ - **A request's `options` are fixed.** Every option it declares is in the policy of an approved request, with the declared value; the customer may repeat it but not change or drop it. An option the request does not declare is the customer's to set at enrollment (a form rendered from the target's `options` schema). So `{"object": "service:ai", ...}` lets the customer pick the AI service, and `"options": "service=labs/llm-balanced"` pins it.
215
+ - Several requests may name one object (two kinds of room) only if each fixes some option to a different value (`kind=chat`, `kind=feed`), so an approval says which one it is.
216
+ - `limits` (`validate_limits`): `count_per_hour` / `count_per_day` / `count_per_month` / `count_total` (positive integer) and the same for `amount_` (finite positive decimal, as a number or a string). Limits are universal: the platform meters every call, so any service can be limited without exporting anything. The seller's limits only pre-fill the form; the customer sets them at enrollment, and an enrollment's own limits (unitysvc/unitysvc#2687) use the same shape. They are counted per policy entry (the enrollment's calls to that service) from the usage stream (counters keyed by scope, metric and window bucket), and the gateway refuses calls once one is exceeded.
217
+ - **A longer-lived leased key** is asked for with one `apikey` entry: `{"object": "apikey", "required": false, "limits": {"api_key_lifespan": 14400}, "justification": "Batch runs take up to four hours"}`. It names the key itself, so it takes only `limits` (exactly `api_key_lifespan`, whole seconds from 1 to 86400), `required` and a `justification`, needs no catalog lookup, and grants nothing. Without it, a key the seller leases for the enrollment lives `DEFAULT_API_KEY_LIFESPAN` (3600 s). `api_key_lifespan` is valid only on this entry.
216
218
 
217
219
  **3. How options reach the service.** Not through the upstream URL: the gateway never changes a target's `base_url` or query to carry policy. How an option is applied is up to the service's implementation:
218
220
 
@@ -236,10 +238,11 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
236
238
  {"object": "apikey", "limits": {"api_key_lifespan": 7200}}]
237
239
  ```
238
240
 
239
- - Each approval names a requested object, at most once, with some of the permissions requested. Every `required` request must be approved; optional ones may be left out.
240
- - Options and limits are the customer's. They are checked against the target's `exports` (with `resolve`) and `validate_limits`, not against the request, whose values only pre-fill the form.
241
+ - Each approval matches one request (`match_request`): the request of its object whose fixed options it does not contradict. One that fits none is refused, as is one that fits several (it names the option that tells them apart). A request is approved at most once; every `required` one must be; optional ones may be left out. Nothing else may be added, apart from the `enrollment` entry below.
242
+ - An approved request keeps exactly its permissions (in any order) and its fixed options; the approval may leave the options out. Values compare as the target's schema types them (`max_size=02000` repeats `2000`).
243
+ - The options the request leaves open, and the limits, are the customer's, checked against the target's `exports` (with `resolve`) and `validate_limits`.
241
244
  - The `apikey` lifespan may be shortened, never lengthened beyond the request.
242
- - The result drops `required` / `justification` and empty `options` / `limits`. `api_key_lifespan(policy)` reads the lifespan back (the default when there is none).
245
+ - The result drops `required` / `justification` and empty `options` / `limits`, and writes options as one canonical query string (`options_text`: names sorted, only what must be escaped escaped), so equal policies are equal. `match_request` finds a stored entry's request again, for a readout or a diff. `api_key_lifespan(policy)` reads the lifespan back (the default when there is none).
243
246
 
244
247
  A policy has three kinds of entry (unitysvc/unitysvc#2770):
245
248
 
@@ -247,7 +250,7 @@ A policy has three kinds of entry (unitysvc/unitysvc#2770):
247
250
  | --- | --- |
248
251
  | `{"object": "enrollment", "limits": {"amount_per_day": "1.00"}}` | This enrollment's own limits (total spending, say). The customer adds it without a request; it takes only `limits`, at least one, at most one entry. It grants nothing. |
249
252
  | `{"object": "service:ai", ...}` | A service the app calls for the customer. A seller may name a specific one (`service:labs/llm-premium` instead of `service:ai` with `options="service=labs/llm-premium"`), at the cost of the customer's choice of provider, which a customer may decline. |
250
- | `{"object": "service:<name>", "enrollment": "<CODE>", ...}` | One of the customer's enrollments of a service that requires enrolling (a chain enrollment), called through `/e/<CODE>`. The customer picks the enrollment when approving the request for `service:<name>`, so a request never carries a code. A canonical code, no `options` (the enrollment's params are fixed), permissions and limits as for any service entry. Core checks the code's form; the caller checks the enrollment is the customer's. |
253
+ | `{"object": "service:<name>", "enrollment": "<CODE>", ...}` | One of the customer's enrollments of a service that requires enrolling (a chain enrollment), called through `/e/<CODE>`. The customer picks the enrollment when approving the request for `service:<name>`, so a request never carries a code; a request with fixed options can't be approved with one, since an enrollment carries no options. A canonical code, no `options` (the enrollment's params are fixed), permissions and limits as for any service entry. Core checks the code's form; the caller checks the enrollment is the customer's. |
251
254
 
252
255
  ### Upstream access channels
253
256
 
@@ -164,7 +164,7 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
164
164
  - `permissions`: a name (lowercase letters, digits and `_`) → the routes it covers, each `"<METHOD> /<path>"` (`*` for any method, `*` globs in the path). Permissions are never inferred from HTTP methods.
165
165
  - `options`: a JSON Schema (draft 7) object of the customizations a grant may set on the service, like a channel's `params.schema`, with an optional react-jsonschema-form `options_ui_schema`; the frontend renders it with the same form component. It covers limits only the service can apply (a message size). Restrictions so a grant can write every value in query-string syntax: property names are lowercase letters, digits and `_`; each property is a `string`, `integer`, `number`, `boolean` or an `array` of strings, serialized as an OpenAPI form-style query parameter with arrays comma-joined (`style: form, explode: false`); options are optional (no `required`) and only declared properties are accepted; the schema is self-contained (no `$ref`), so validating against it never fetches anything. A property's `default` is what the service does when the policy does not set the option.
166
166
 
167
- **2. A customer access request (`upstream_access_config.<channel>.customer_access_requests`), and the policy entry it becomes.** Any channel may declare its own list; each approved request becomes an entry (a grant) in the issued key's policy, in the same shape:
167
+ **2. A customer access request (`upstream_access_config.<channel>.customer_access_requests`), and the policy entry it becomes.** Any channel may declare its own list: a fixed list of items the customer works on, and nothing else (unitysvc/unitysvc#2831). Each approved request becomes an entry (a grant) in the issued key's policy, in the same shape:
168
168
 
169
169
  ```json
170
170
  "customer_access_requests": [{"object": "service:log", "permissions": ["invoke"], "required": true,
@@ -173,11 +173,13 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
173
173
  "limits": {"count_per_day": 1000}}]
174
174
  ```
175
175
 
176
- - `object` names one service (`service:<name>`, no wildcards), or `apikey` for the leased key's lifespan (below).
176
+ - `object` names one service (`service:<name>`, no wildcards), or `apikey` for the leased key's lifespan (below). `permissions` are plain names (lowercase letters, digits and `_`; no wildcards), checked against the target's exports with a catalog.
177
+ - `required` (`true` or `false`, on every entry, `apikey` included) says whether the customer may decline the request. A stored declaration from before this rule reads as optional when a policy is built.
177
178
  - `options` is written in query-string syntax (`parse_options`; a notation, not how options are delivered): each name once, each value non-empty; with a catalog, each value is converted to its declared type and validated against the target's `options` schema.
178
- - **Enrollment is where options and limits are set.** In a request, `options` and `limits` only pre-fill the enrollment form for convenience. When enrolling, the customer confirms and sets the options (a form rendered from the target's `options` schema) and the limits, and adds their own limits; the result is the issued key's policy.
179
- - `limits` (`validate_limits`): `count_per_hour` / `count_per_day` / `count_per_month` / `count_total` (positive integer) and the same for `amount_` (finite positive decimal, as a number or a string). Limits are universal: the platform meters every call, so any service can be limited without exporting anything. The seller's limits are a pre-fill; the customer sets them at enrollment, and an enrollment's own limits (unitysvc/unitysvc#2687) use the same shape. They are counted per policy entry (the enrollment's calls to that service) from the usage stream (counters keyed by scope, metric and window bucket), and the gateway refuses calls once one is exceeded.
180
- - **A longer-lived leased key** is asked for with one `apikey` entry: `{"object": "apikey", "limits": {"api_key_lifespan": 14400}, "justification": "Batch runs take up to four hours"}`. It names the key itself, so it takes only `limits` (exactly `api_key_lifespan`, whole seconds from 1 to 86400) and a `justification`, needs no catalog lookup, and grants nothing. Without it, a key the seller leases for the enrollment lives `DEFAULT_API_KEY_LIFESPAN` (3600 s). `api_key_lifespan` is valid only on this entry.
179
+ - **A request's `options` are fixed.** Every option it declares is in the policy of an approved request, with the declared value; the customer may repeat it but not change or drop it. An option the request does not declare is the customer's to set at enrollment (a form rendered from the target's `options` schema). So `{"object": "service:ai", ...}` lets the customer pick the AI service, and `"options": "service=labs/llm-balanced"` pins it.
180
+ - Several requests may name one object (two kinds of room) only if each fixes some option to a different value (`kind=chat`, `kind=feed`), so an approval says which one it is.
181
+ - `limits` (`validate_limits`): `count_per_hour` / `count_per_day` / `count_per_month` / `count_total` (positive integer) and the same for `amount_` (finite positive decimal, as a number or a string). Limits are universal: the platform meters every call, so any service can be limited without exporting anything. The seller's limits only pre-fill the form; the customer sets them at enrollment, and an enrollment's own limits (unitysvc/unitysvc#2687) use the same shape. They are counted per policy entry (the enrollment's calls to that service) from the usage stream (counters keyed by scope, metric and window bucket), and the gateway refuses calls once one is exceeded.
182
+ - **A longer-lived leased key** is asked for with one `apikey` entry: `{"object": "apikey", "required": false, "limits": {"api_key_lifespan": 14400}, "justification": "Batch runs take up to four hours"}`. It names the key itself, so it takes only `limits` (exactly `api_key_lifespan`, whole seconds from 1 to 86400), `required` and a `justification`, needs no catalog lookup, and grants nothing. Without it, a key the seller leases for the enrollment lives `DEFAULT_API_KEY_LIFESPAN` (3600 s). `api_key_lifespan` is valid only on this entry.
181
183
 
182
184
  **3. How options reach the service.** Not through the upstream URL: the gateway never changes a target's `base_url` or query to carry policy. How an option is applied is up to the service's implementation:
183
185
 
@@ -201,10 +203,11 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
201
203
  {"object": "apikey", "limits": {"api_key_lifespan": 7200}}]
202
204
  ```
203
205
 
204
- - Each approval names a requested object, at most once, with some of the permissions requested. Every `required` request must be approved; optional ones may be left out.
205
- - Options and limits are the customer's. They are checked against the target's `exports` (with `resolve`) and `validate_limits`, not against the request, whose values only pre-fill the form.
206
+ - Each approval matches one request (`match_request`): the request of its object whose fixed options it does not contradict. One that fits none is refused, as is one that fits several (it names the option that tells them apart). A request is approved at most once; every `required` one must be; optional ones may be left out. Nothing else may be added, apart from the `enrollment` entry below.
207
+ - An approved request keeps exactly its permissions (in any order) and its fixed options; the approval may leave the options out. Values compare as the target's schema types them (`max_size=02000` repeats `2000`).
208
+ - The options the request leaves open, and the limits, are the customer's, checked against the target's `exports` (with `resolve`) and `validate_limits`.
206
209
  - The `apikey` lifespan may be shortened, never lengthened beyond the request.
207
- - The result drops `required` / `justification` and empty `options` / `limits`. `api_key_lifespan(policy)` reads the lifespan back (the default when there is none).
210
+ - The result drops `required` / `justification` and empty `options` / `limits`, and writes options as one canonical query string (`options_text`: names sorted, only what must be escaped escaped), so equal policies are equal. `match_request` finds a stored entry's request again, for a readout or a diff. `api_key_lifespan(policy)` reads the lifespan back (the default when there is none).
208
211
 
209
212
  A policy has three kinds of entry (unitysvc/unitysvc#2770):
210
213
 
@@ -212,7 +215,7 @@ A policy has three kinds of entry (unitysvc/unitysvc#2770):
212
215
  | --- | --- |
213
216
  | `{"object": "enrollment", "limits": {"amount_per_day": "1.00"}}` | This enrollment's own limits (total spending, say). The customer adds it without a request; it takes only `limits`, at least one, at most one entry. It grants nothing. |
214
217
  | `{"object": "service:ai", ...}` | A service the app calls for the customer. A seller may name a specific one (`service:labs/llm-premium` instead of `service:ai` with `options="service=labs/llm-premium"`), at the cost of the customer's choice of provider, which a customer may decline. |
215
- | `{"object": "service:<name>", "enrollment": "<CODE>", ...}` | One of the customer's enrollments of a service that requires enrolling (a chain enrollment), called through `/e/<CODE>`. The customer picks the enrollment when approving the request for `service:<name>`, so a request never carries a code. A canonical code, no `options` (the enrollment's params are fixed), permissions and limits as for any service entry. Core checks the code's form; the caller checks the enrollment is the customer's. |
218
+ | `{"object": "service:<name>", "enrollment": "<CODE>", ...}` | One of the customer's enrollments of a service that requires enrolling (a chain enrollment), called through `/e/<CODE>`. The customer picks the enrollment when approving the request for `service:<name>`, so a request never carries a code; a request with fixed options can't be approved with one, since an enrollment carries no options. A canonical code, no `options` (the enrollment's params are fixed), permissions and limits as for any service entry. Core checks the code's form; the caller checks the enrollment is the customer's. |
216
219
 
217
220
  ### Upstream access channels
218
221
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "unitysvc-core"
7
- version = "0.3.2"
7
+ version = "0.3.3"
8
8
  description = "Shared data models and validation helpers for UnitySVC packages"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Bo Peng", email = "bo.peng@unitysvc.com" }]
@@ -42,13 +42,19 @@ Three stages (unitysvc/unitysvc#2720):
42
42
  "options": "log_level=warn",
43
43
  "limits": {"count_per_day": 1000}}
44
44
 
45
- A request grants nothing by itself. Its ``options`` and ``limits`` only
46
- pre-fill the enrollment form.
45
+ A request grants nothing by itself. ``required`` says whether the customer
46
+ may decline it. Its ``object`` and ``permissions`` are fixed, and so are
47
+ its ``options``: the values the seller declares are the values the policy
48
+ holds (unitysvc/unitysvc#2831). An option it does not declare is the
49
+ customer's to set. Its ``limits`` only pre-fill the enrollment form.
50
+ Several requests may name one object (two kinds of room) if each fixes an
51
+ option to a different value, so an approval says which one it is.
47
52
 
48
53
  * **The key's policy** — what the customer actually approves when enrolling:
49
- they confirm or decline each request, set its options and limits, and may
50
- add limits of their own. Each approved request becomes an entry (a grant) in
51
- the policy of the key issued for that enrollment, in the same shape.
54
+ they keep every required request, keep or decline each optional one, add
55
+ options the request leaves open, and set limits, their own included. Each
56
+ approved request becomes an entry (a grant) in the policy of the key issued
57
+ for that enrollment, in the same shape, with the request's fixed options.
52
58
 
53
59
  **Invariant.** Calls made under an approved request run under the enrolling
54
60
  customer's delegated identity, within the approved permissions, options and
@@ -110,7 +116,7 @@ from collections.abc import Callable
110
116
  from dataclasses import dataclass
111
117
  from decimal import Decimal, InvalidOperation
112
118
  from typing import Any
113
- from urllib.parse import parse_qsl
119
+ from urllib.parse import parse_qsl, urlencode
114
120
 
115
121
  from jsonschema import Draft7Validator
116
122
  from jsonschema.exceptions import SchemaError
@@ -174,7 +180,7 @@ DEFAULT_PERMISSIONS: dict[str, tuple[str, ...]] = {INVOKE: (ALL_ROUTES,)}
174
180
  DEFAULT_EXPORTS = Exports(DEFAULT_PERMISSIONS, {})
175
181
 
176
182
  _REQUEST_KEYS = frozenset({"object", "permissions", "required", "justification", "options", "limits"})
177
- _APIKEY_REQUEST_KEYS = frozenset({"object", "justification", "limits"})
183
+ _APIKEY_REQUEST_KEYS = frozenset({"object", "required", "justification", "limits"})
178
184
  # What a policy entry (an approved request) holds.
179
185
  _POLICY_KEYS = frozenset({"object", "permissions", "options", "limits"})
180
186
  # This enrollment itself: an entry capping what it may cost. It grants nothing.
@@ -384,7 +390,9 @@ def validate_limits(where: str, limits: Any, *, apikey: bool = False) -> None:
384
390
  raise ValueError(f"{at} must be a positive amount")
385
391
 
386
392
 
387
- def validate_access_requests(where: str, requests: Any, resolve: ExportsResolver | None = None) -> None:
393
+ def validate_access_requests(
394
+ where: str, requests: Any, resolve: ExportsResolver | None = None, *, explicit_required: bool = True
395
+ ) -> None:
388
396
  """Refuse a channel's ``customer_access_requests`` unless every entry is a
389
397
  valid request.
390
398
 
@@ -395,20 +403,25 @@ def validate_access_requests(where: str, requests: Any, resolve: ExportsResolver
395
403
  declares permissions may not export it), and an unknown target is
396
404
  refused. Limits need no lookup. Without ``resolve``, only the shape is
397
405
  checked.
406
+
407
+ Every entry says whether it is ``required``. :func:`build_policy` passes
408
+ ``explicit_required=False``: a declaration stored before that rule reads
409
+ as optional, as it always did.
398
410
  """
399
411
  if not isinstance(requests, list):
400
412
  raise ValueError(f"{where} must be a list of access request objects")
401
- seen: set[str] = set()
413
+ seen: list[tuple[str, dict[str, str], Exports | None]] = []
402
414
  for index, entry in enumerate(requests):
403
415
  at = f"{where}[{index}]"
404
416
  if not isinstance(entry, dict) or not isinstance(entry.get("object"), str):
405
417
  raise ValueError(f'{at} must be {{"object": "service:<name>", ...}}')
406
418
  obj = entry["object"]
407
419
  if obj == APIKEY_OBJECT:
408
- if obj in seen:
420
+ if any(other == obj for other, _, _ in seen):
409
421
  raise ValueError(f"{at}: {obj} is listed twice")
410
- seen.add(obj)
422
+ seen.append((obj, {}, None))
411
423
  _check_apikey_request(at, entry)
424
+ _check_required(at, entry, explicit_required)
412
425
  continue
413
426
  if obj == SERVICE_WILDCARD:
414
427
  raise ValueError(_service_wildcard_refusal(at, "requested"))
@@ -419,9 +432,6 @@ def validate_access_requests(where: str, requests: Any, resolve: ExportsResolver
419
432
  validate_service_identifier(name, "requested service")
420
433
  except ValueError as exc:
421
434
  raise ValueError(f"{at}: {obj!r} cannot be requested: {exc}") from None
422
- if obj in seen:
423
- raise ValueError(f"{at}: {obj} is listed twice")
424
- seen.add(obj)
425
435
  if extra := set(entry) - _REQUEST_KEYS:
426
436
  raise ValueError(f"{at}: unknown keys {sorted(extra)}")
427
437
  justification = entry.get("justification")
@@ -429,19 +439,89 @@ def validate_access_requests(where: str, requests: Any, resolve: ExportsResolver
429
439
  raise ValueError(
430
440
  f"{at}.justification must say why the service needs {obj}; the customer reads it before approving"
431
441
  )
432
- if not isinstance(entry.get("required", False), bool):
433
- raise ValueError(f"{at}.required must be true or false")
442
+ _check_required(at, entry, explicit_required)
434
443
  permissions: list[str] = entry.get("permissions") or []
435
- if not _strings(permissions):
436
- raise ValueError(f"{at}.permissions must be a non-empty list of distinct names")
444
+ if not _strings(permissions) or not all(_PERMISSION_NAME.match(p) for p in permissions):
445
+ raise ValueError(
446
+ f"{at}.permissions must be a non-empty list of distinct permission names "
447
+ "(lowercase letters, digits and '_'; no wildcards)"
448
+ )
437
449
  options = parse_options(f"{at}.options", entry.get("options", ""))
438
450
  validate_limits(f"{at}.limits", entry.get("limits", {}))
439
- if resolve is None:
440
- continue
441
- declared = resolve(name)
442
- if declared is None:
443
- raise ValueError(f"{at}: {obj} is not a published service")
444
- check_claim(at, obj, permissions, options, parse_exports(f"{obj} exports", declared))
451
+ exports = None
452
+ if resolve is not None:
453
+ declared = resolve(name)
454
+ if declared is None:
455
+ raise ValueError(f"{at}: {obj} is not a published service")
456
+ exports = parse_exports(f"{obj} exports", declared)
457
+ check_claim(at, obj, permissions, options, exports)
458
+ for other_index, (other, other_options, _) in enumerate(seen):
459
+ if other == obj and _conflict(exports, options, other_options) is None:
460
+ raise ValueError(
461
+ f"{at}: {obj} is listed twice; requests of one object must each fix an option "
462
+ f"to a different value (kind=chat, kind=feed), or the customer can't say which "
463
+ f"one they approve (see [{other_index}])"
464
+ )
465
+ seen.append((obj, options, exports))
466
+
467
+
468
+ def _check_required(at: str, entry: dict[str, Any], explicit: bool) -> None:
469
+ if "required" in entry:
470
+ if not isinstance(entry["required"], bool):
471
+ raise ValueError(f"{at}.required must be true or false")
472
+ elif explicit:
473
+ raise ValueError(f"{at}.required must be true or false: say whether the customer may decline it")
474
+
475
+
476
+ def _conflict(exports: Exports | None, a: dict[str, str], b: dict[str, str]) -> str | None:
477
+ """The first option ``a`` and ``b`` both set, to different values, or
478
+ ``None``. Values are compared as the target's ``exports`` type them
479
+ (``100`` and ``0100`` are one integer); without exports, as written."""
480
+ properties = exports.options.get("properties", {}) if exports else {}
481
+ for name in sorted(set(a) & set(b)):
482
+ prop = properties.get(name, {})
483
+ if _typed(prop, a[name]) != _typed(prop, b[name]):
484
+ return name
485
+ return None
486
+
487
+
488
+ def _label(request: dict[str, Any]) -> str:
489
+ """A request as the customer tells it apart: its object, and its fixed options."""
490
+ return f"{request['object']} ({request['options']})" if request.get("options") else str(request["object"])
491
+
492
+
493
+ def match_request(
494
+ where: str, requests: list[dict[str, Any]], entry: dict[str, Any], exports: Exports | None = None
495
+ ) -> int:
496
+ """The index of the request in ``requests`` (already valid) that ``entry``,
497
+ an approval or a stored policy entry, approves.
498
+
499
+ It is the request of the same object whose fixed options the entry does
500
+ not contradict: one the entry repeats, or leaves out. Requests of one
501
+ object each fix an option to a different value, so only an entry that
502
+ leaves all of those out can fit more than one; it is refused, naming the
503
+ option that tells them apart. Raises ``ValueError``.
504
+ """
505
+ obj = entry.get("object")
506
+ options = parse_options(f"{where}.options", entry.get("options", ""))
507
+ same = [i for i, request in enumerate(requests) if request["object"] == obj]
508
+ if not same:
509
+ raise ValueError(f"{where}: {obj} is not requested")
510
+ fixed = {i: parse_options("options", requests[i].get("options", "")) for i in same}
511
+ fitting = [i for i in same if _conflict(exports, fixed[i], options) is None]
512
+ if not fitting:
513
+ if len(same) == 1:
514
+ name = _conflict(exports, fixed[same[0]], options)
515
+ assert name is not None
516
+ raise ValueError(f"{where}.options.{name}: the service fixes it to {fixed[same[0]][name]!r}")
517
+ raise ValueError(
518
+ f"{where}: no request of {obj} has these options; the service requests "
519
+ + ", ".join(_label(requests[i]) for i in same)
520
+ )
521
+ if len(fitting) > 1:
522
+ name = _conflict(exports, fixed[fitting[0]], fixed[fitting[1]])
523
+ raise ValueError(f"{where}.options: {obj} is requested {len(fitting)} times; set {name} to say which")
524
+ return fitting[0]
445
525
 
446
526
 
447
527
  def _service_wildcard_refusal(at: str, verb: str) -> str:
@@ -492,31 +572,35 @@ def validate_channel_access_requests(config: Any, resolve: ExportsResolver | Non
492
572
 
493
573
  def build_policy(requests: Any, approvals: Any, resolve: ExportsResolver | None = None) -> list[dict[str, Any]]:
494
574
  """The key policy a customer's ``approvals`` of a channel's ``requests``
495
- make (unitysvc/unitysvc#2766).
575
+ make (unitysvc/unitysvc#2766, #2831).
496
576
 
497
577
  ``requests`` is the channel's ``customer_access_requests``; ``approvals``
498
578
  lists the requests the customer approves, each ``{"object", "permissions",
499
579
  "options", "limits"}`` (the ``apikey`` entry only ``{"object", "limits"}``).
500
- Each approval names a requested object, at most once; its permissions are
501
- some of those requested; every ``required`` request is approved. The
502
- customer sets options and limits: a request's own only pre-fill them, so
503
- they are checked against the target's ``exports`` (with ``resolve``) and
504
- :func:`validate_limits`, not against the request. A key lifespan may only
505
- be shortened. Returns the approvals as policy entries, without empty
580
+ Each approval matches one request (:func:`match_request`), at most once,
581
+ and every ``required`` request is approved. An approved request keeps
582
+ exactly its permissions and its fixed options: the approval may repeat
583
+ them, or leave the options out, but not change them. Beside them the
584
+ customer sets the options the request leaves open and the limits, checked
585
+ against the target's ``exports`` (with ``resolve``) and
586
+ :func:`validate_limits`; a request's limits only pre-fill the form. A key
587
+ lifespan may only be shortened. Returns the approvals as policy entries,
588
+ their options in one canonical query string (names sorted), without empty
506
589
  ``options`` / ``limits``. Raises ``ValueError``.
507
590
 
508
591
  The customer may also add, at most once and without a request, this
509
592
  enrollment's own limits: ``{"object": "enrollment", "limits": {...}}``,
510
593
  with at least one limit and nothing else (unitysvc/unitysvc#2770). And an
511
- approval of a service may select one of the customer's enrollments of it
512
- (``"enrollment": "<CODE>"``, a chain enrollment): a canonical code, and no
513
- ``options``. The caller checks the enrollment is the customer's.
594
+ approval of a request that fixes no options may select one of the
595
+ customer's enrollments of its service (``"enrollment": "<CODE>"``, a chain
596
+ enrollment): a canonical code, and no ``options``. The caller checks the
597
+ enrollment is the customer's.
514
598
  """
515
- validate_access_requests("requests", requests)
516
- requested = {entry["object"]: entry for entry in requests}
599
+ validate_access_requests("requests", requests, explicit_required=False)
517
600
  if not isinstance(approvals, list):
518
601
  raise ValueError("approvals must be a list of approved requests")
519
602
  policy: list[dict[str, Any]] = []
603
+ approved: set[int] = set()
520
604
  for index, approval in enumerate(approvals):
521
605
  at = f"approvals[{index}]"
522
606
  if not isinstance(approval, dict) or not isinstance(approval.get("object"), str):
@@ -529,56 +613,70 @@ def build_policy(requests: Any, approvals: Any, resolve: ExportsResolver | None
529
613
  raise ValueError(f"{at}: {obj} is listed twice")
530
614
  policy.append(_enrollment_entry(at, approval))
531
615
  continue
532
- request = requested.get(obj)
533
- if request is None:
534
- raise ValueError(f"{at}: {obj} is not requested")
535
- if any(entry["object"] == obj for entry in policy):
536
- raise ValueError(f"{at}: {obj} is approved twice")
537
616
  if obj == APIKEY_OBJECT:
538
617
  if extra := set(approval) - {"object", "limits"}:
539
618
  raise ValueError(f"{at}: unknown keys {sorted(extra)} (the {APIKEY_OBJECT} entry takes only limits)")
619
+ elif extra := set(approval) - _POLICY_KEYS - {ENROLLMENT_KEY}:
620
+ raise ValueError(f"{at}: unknown keys {sorted(extra)}")
621
+ exports = None
622
+ if resolve is not None and obj.startswith(SERVICE_PREFIX) and any(r["object"] == obj for r in requests):
623
+ declared = resolve(obj.removeprefix(SERVICE_PREFIX))
624
+ if declared is None:
625
+ raise ValueError(f"{at}: {obj} is not a published service")
626
+ exports = parse_exports(f"{obj} exports", declared)
627
+ matched = match_request(at, requests, approval, exports)
628
+ if matched in approved:
629
+ raise ValueError(f"{at}: {_label(requests[matched])} is approved twice")
630
+ approved.add(matched)
631
+ request = requests[matched]
632
+ if obj == APIKEY_OBJECT:
540
633
  validate_limits(f"{at}.limits", approval.get("limits"), apikey=True)
541
634
  asked = request["limits"][API_KEY_LIFESPAN]
542
635
  if approval["limits"][API_KEY_LIFESPAN] > asked:
543
636
  raise ValueError(f"{at}.limits.{API_KEY_LIFESPAN}: the service asks for at most {asked} seconds")
544
637
  policy.append({"object": obj, "limits": dict(approval["limits"])})
545
638
  continue
546
- if extra := set(approval) - _POLICY_KEYS - {ENROLLMENT_KEY}:
547
- raise ValueError(f"{at}: unknown keys {sorted(extra)}")
639
+ fixed = parse_options("options", request.get("options", ""))
548
640
  code = approval.get(ENROLLMENT_KEY)
549
641
  if ENROLLMENT_KEY in approval:
550
642
  if not isinstance(code, str) or not _ENROLLMENT_CODE.match(code):
551
643
  raise ValueError(f"{at}.{ENROLLMENT_KEY} must be an enrollment code, like JYY87Y")
552
644
  if approval.get("options"):
553
645
  raise ValueError(f"{at}.options: an enrollment's params are fixed; it takes no options")
646
+ if fixed:
647
+ raise ValueError(
648
+ f"{at}.{ENROLLMENT_KEY}: the service fixes options of {obj} ({request['options']}), "
649
+ "which an enrollment cannot carry; approve it without one"
650
+ )
554
651
  permissions: list[str] = approval.get("permissions") or []
555
- if not _strings(permissions):
556
- raise ValueError(f"{at}.permissions must be a non-empty list of distinct names")
557
- if not set(permissions) <= set(request["permissions"]):
558
- raise ValueError(f"{at}.permissions: the service requests only {request['permissions']}")
559
- options_text = approval.get("options", "")
560
- options = parse_options(f"{at}.options", options_text)
652
+ if not _strings(permissions) or set(permissions) != set(request["permissions"]):
653
+ raise ValueError(f"{at}.permissions: the service requests exactly {request['permissions']}")
654
+ # The request's values win over an equal value written another way.
655
+ options = {**parse_options(f"{at}.options", approval.get("options", "")), **fixed}
561
656
  limits = approval.get("limits", {})
562
657
  validate_limits(f"{at}.limits", limits)
563
- if resolve is not None:
564
- declared = resolve(obj.removeprefix(SERVICE_PREFIX))
565
- if declared is None:
566
- raise ValueError(f"{at}: {obj} is not a published service")
567
- check_claim(at, obj, permissions, options, parse_exports(f"{obj} exports", declared))
658
+ if exports is not None:
659
+ check_claim(at, obj, permissions, options, exports)
568
660
  entry: dict[str, Any] = {"object": obj, "permissions": list(permissions)}
569
661
  if code is not None:
570
662
  entry[ENROLLMENT_KEY] = code
571
663
  if options:
572
- entry["options"] = options_text
664
+ entry["options"] = options_text(options)
573
665
  if limits:
574
666
  entry["limits"] = dict(limits)
575
667
  policy.append(entry)
576
- approved = {entry["object"] for entry in policy}
577
- if missing := sorted(obj for obj, request in requested.items() if request.get("required") and obj not in approved):
668
+ if missing := [_label(r) for i, r in enumerate(requests) if r.get("required") and i not in approved]:
578
669
  raise ValueError(f"approvals: the service requires {', '.join(missing)}")
579
670
  return policy
580
671
 
581
672
 
673
+ def options_text(options: dict[str, str]) -> str:
674
+ """``options`` as the one query string a policy stores: names sorted, and
675
+ only what must be escaped escaped (``service=labs/llm-fast``,
676
+ ``profile=a,b``), so equal options are equal text."""
677
+ return urlencode(sorted(options.items()), safe=",/")
678
+
679
+
582
680
  def _enrollment_entry(at: str, approval: dict[str, Any]) -> dict[str, Any]:
583
681
  """This enrollment's own entry: limits only, and at least one."""
584
682
  if extra := set(approval) - {"object", "limits"}:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitysvc-core
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Shared data models and validation helpers for UnitySVC packages
5
5
  Author-email: Bo Peng <bo.peng@unitysvc.com>
6
6
  Maintainer-email: Bo Peng <bo.peng@unitysvc.com>
@@ -199,7 +199,7 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
199
199
  - `permissions`: a name (lowercase letters, digits and `_`) → the routes it covers, each `"<METHOD> /<path>"` (`*` for any method, `*` globs in the path). Permissions are never inferred from HTTP methods.
200
200
  - `options`: a JSON Schema (draft 7) object of the customizations a grant may set on the service, like a channel's `params.schema`, with an optional react-jsonschema-form `options_ui_schema`; the frontend renders it with the same form component. It covers limits only the service can apply (a message size). Restrictions so a grant can write every value in query-string syntax: property names are lowercase letters, digits and `_`; each property is a `string`, `integer`, `number`, `boolean` or an `array` of strings, serialized as an OpenAPI form-style query parameter with arrays comma-joined (`style: form, explode: false`); options are optional (no `required`) and only declared properties are accepted; the schema is self-contained (no `$ref`), so validating against it never fetches anything. A property's `default` is what the service does when the policy does not set the option.
201
201
 
202
- **2. A customer access request (`upstream_access_config.<channel>.customer_access_requests`), and the policy entry it becomes.** Any channel may declare its own list; each approved request becomes an entry (a grant) in the issued key's policy, in the same shape:
202
+ **2. A customer access request (`upstream_access_config.<channel>.customer_access_requests`), and the policy entry it becomes.** Any channel may declare its own list: a fixed list of items the customer works on, and nothing else (unitysvc/unitysvc#2831). Each approved request becomes an entry (a grant) in the issued key's policy, in the same shape:
203
203
 
204
204
  ```json
205
205
  "customer_access_requests": [{"object": "service:log", "permissions": ["invoke"], "required": true,
@@ -208,11 +208,13 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
208
208
  "limits": {"count_per_day": 1000}}]
209
209
  ```
210
210
 
211
- - `object` names one service (`service:<name>`, no wildcards), or `apikey` for the leased key's lifespan (below).
211
+ - `object` names one service (`service:<name>`, no wildcards), or `apikey` for the leased key's lifespan (below). `permissions` are plain names (lowercase letters, digits and `_`; no wildcards), checked against the target's exports with a catalog.
212
+ - `required` (`true` or `false`, on every entry, `apikey` included) says whether the customer may decline the request. A stored declaration from before this rule reads as optional when a policy is built.
212
213
  - `options` is written in query-string syntax (`parse_options`; a notation, not how options are delivered): each name once, each value non-empty; with a catalog, each value is converted to its declared type and validated against the target's `options` schema.
213
- - **Enrollment is where options and limits are set.** In a request, `options` and `limits` only pre-fill the enrollment form for convenience. When enrolling, the customer confirms and sets the options (a form rendered from the target's `options` schema) and the limits, and adds their own limits; the result is the issued key's policy.
214
- - `limits` (`validate_limits`): `count_per_hour` / `count_per_day` / `count_per_month` / `count_total` (positive integer) and the same for `amount_` (finite positive decimal, as a number or a string). Limits are universal: the platform meters every call, so any service can be limited without exporting anything. The seller's limits are a pre-fill; the customer sets them at enrollment, and an enrollment's own limits (unitysvc/unitysvc#2687) use the same shape. They are counted per policy entry (the enrollment's calls to that service) from the usage stream (counters keyed by scope, metric and window bucket), and the gateway refuses calls once one is exceeded.
215
- - **A longer-lived leased key** is asked for with one `apikey` entry: `{"object": "apikey", "limits": {"api_key_lifespan": 14400}, "justification": "Batch runs take up to four hours"}`. It names the key itself, so it takes only `limits` (exactly `api_key_lifespan`, whole seconds from 1 to 86400) and a `justification`, needs no catalog lookup, and grants nothing. Without it, a key the seller leases for the enrollment lives `DEFAULT_API_KEY_LIFESPAN` (3600 s). `api_key_lifespan` is valid only on this entry.
214
+ - **A request's `options` are fixed.** Every option it declares is in the policy of an approved request, with the declared value; the customer may repeat it but not change or drop it. An option the request does not declare is the customer's to set at enrollment (a form rendered from the target's `options` schema). So `{"object": "service:ai", ...}` lets the customer pick the AI service, and `"options": "service=labs/llm-balanced"` pins it.
215
+ - Several requests may name one object (two kinds of room) only if each fixes some option to a different value (`kind=chat`, `kind=feed`), so an approval says which one it is.
216
+ - `limits` (`validate_limits`): `count_per_hour` / `count_per_day` / `count_per_month` / `count_total` (positive integer) and the same for `amount_` (finite positive decimal, as a number or a string). Limits are universal: the platform meters every call, so any service can be limited without exporting anything. The seller's limits only pre-fill the form; the customer sets them at enrollment, and an enrollment's own limits (unitysvc/unitysvc#2687) use the same shape. They are counted per policy entry (the enrollment's calls to that service) from the usage stream (counters keyed by scope, metric and window bucket), and the gateway refuses calls once one is exceeded.
217
+ - **A longer-lived leased key** is asked for with one `apikey` entry: `{"object": "apikey", "required": false, "limits": {"api_key_lifespan": 14400}, "justification": "Batch runs take up to four hours"}`. It names the key itself, so it takes only `limits` (exactly `api_key_lifespan`, whole seconds from 1 to 86400), `required` and a `justification`, needs no catalog lookup, and grants nothing. Without it, a key the seller leases for the enrollment lives `DEFAULT_API_KEY_LIFESPAN` (3600 s). `api_key_lifespan` is valid only on this entry.
216
218
 
217
219
  **3. How options reach the service.** Not through the upstream URL: the gateway never changes a target's `base_url` or query to carry policy. How an option is applied is up to the service's implementation:
218
220
 
@@ -236,10 +238,11 @@ Three stages (unitysvc/unitysvc#2720): a target service's **`exports`** (what it
236
238
  {"object": "apikey", "limits": {"api_key_lifespan": 7200}}]
237
239
  ```
238
240
 
239
- - Each approval names a requested object, at most once, with some of the permissions requested. Every `required` request must be approved; optional ones may be left out.
240
- - Options and limits are the customer's. They are checked against the target's `exports` (with `resolve`) and `validate_limits`, not against the request, whose values only pre-fill the form.
241
+ - Each approval matches one request (`match_request`): the request of its object whose fixed options it does not contradict. One that fits none is refused, as is one that fits several (it names the option that tells them apart). A request is approved at most once; every `required` one must be; optional ones may be left out. Nothing else may be added, apart from the `enrollment` entry below.
242
+ - An approved request keeps exactly its permissions (in any order) and its fixed options; the approval may leave the options out. Values compare as the target's schema types them (`max_size=02000` repeats `2000`).
243
+ - The options the request leaves open, and the limits, are the customer's, checked against the target's `exports` (with `resolve`) and `validate_limits`.
241
244
  - The `apikey` lifespan may be shortened, never lengthened beyond the request.
242
- - The result drops `required` / `justification` and empty `options` / `limits`. `api_key_lifespan(policy)` reads the lifespan back (the default when there is none).
245
+ - The result drops `required` / `justification` and empty `options` / `limits`, and writes options as one canonical query string (`options_text`: names sorted, only what must be escaped escaped), so equal policies are equal. `match_request` finds a stored entry's request again, for a readout or a diff. `api_key_lifespan(policy)` reads the lifespan back (the default when there is none).
243
246
 
244
247
  A policy has three kinds of entry (unitysvc/unitysvc#2770):
245
248
 
@@ -247,7 +250,7 @@ A policy has three kinds of entry (unitysvc/unitysvc#2770):
247
250
  | --- | --- |
248
251
  | `{"object": "enrollment", "limits": {"amount_per_day": "1.00"}}` | This enrollment's own limits (total spending, say). The customer adds it without a request; it takes only `limits`, at least one, at most one entry. It grants nothing. |
249
252
  | `{"object": "service:ai", ...}` | A service the app calls for the customer. A seller may name a specific one (`service:labs/llm-premium` instead of `service:ai` with `options="service=labs/llm-premium"`), at the cost of the customer's choice of provider, which a customer may decline. |
250
- | `{"object": "service:<name>", "enrollment": "<CODE>", ...}` | One of the customer's enrollments of a service that requires enrolling (a chain enrollment), called through `/e/<CODE>`. The customer picks the enrollment when approving the request for `service:<name>`, so a request never carries a code. A canonical code, no `options` (the enrollment's params are fixed), permissions and limits as for any service entry. Core checks the code's form; the caller checks the enrollment is the customer's. |
253
+ | `{"object": "service:<name>", "enrollment": "<CODE>", ...}` | One of the customer's enrollments of a service that requires enrolling (a chain enrollment), called through `/e/<CODE>`. The customer picks the enrollment when approving the request for `service:<name>`, so a request never carries a code; a request with fixed options can't be approved with one, since an enrollment carries no options. A canonical code, no `options` (the enrollment's params are fixed), permissions and limits as for any service entry. Core checks the code's form; the caller checks the enrollment is the customer's. |
251
254
 
252
255
  ### Upstream access channels
253
256
 
@@ -12,6 +12,8 @@ from unitysvc_core.grants import (
12
12
  api_key_lifespan,
13
13
  build_policy,
14
14
  check_claim,
15
+ match_request,
16
+ options_text,
15
17
  parse_exports,
16
18
  parse_options,
17
19
  validate_access_requests,
@@ -44,6 +46,15 @@ _CATALOG: dict[str, dict[str, Any]] = {
44
46
  "ai": {"options": _options(model={"type": "string", "minLength": 1})},
45
47
  "bill": {"options": _options(max_charge={"type": "number", "exclusiveMinimum": 0})},
46
48
  "resp200": {}, # declares nothing: invoke only
49
+ # Stands in for a resource with kinds (unitysvc/unitysvc#2830).
50
+ "rooms": {
51
+ "permissions": {"create": ["POST /rooms"]},
52
+ "options": _options(
53
+ kind={"type": "string", "enum": ["chat", "feed"]},
54
+ max_members={"type": "integer", "minimum": 1},
55
+ topic={"type": "string"},
56
+ ),
57
+ },
47
58
  }
48
59
 
49
60
 
@@ -56,6 +67,7 @@ def _dep(obj: str = "service:log", **fields: Any) -> dict[str, Any]:
56
67
  "object": obj,
57
68
  "permissions": ["invoke"],
58
69
  "justification": "Records each check you run",
70
+ "required": False,
59
71
  **fields,
60
72
  }
61
73
 
@@ -370,6 +382,7 @@ def _lifespan(seconds: Any = 14400, **fields: Any) -> dict[str, Any]:
370
382
  "object": "apikey",
371
383
  "limits": {"api_key_lifespan": seconds},
372
384
  "justification": "Batch runs take up to four hours",
385
+ "required": False,
373
386
  **fields,
374
387
  }
375
388
 
@@ -389,7 +402,7 @@ def test_a_key_lifespan_may_be_requested_without_a_lookup() -> None:
389
402
  (_lifespan("3600"), "from 1 to 86400"),
390
403
  (_lifespan(True), "from 1 to 86400"),
391
404
  (_lifespan(permissions=["invoke"]), "takes only limits"),
392
- (_lifespan(required=True), "takes only limits"),
405
+ (_lifespan(required="yes"), "required must be true or false"),
393
406
  ({**_lifespan(), "limits": {"api_key_lifespan": 7200, "count_per_day": 2}}, "must be"),
394
407
  ({**_lifespan(), "limits": {}}, "must be"),
395
408
  ],
@@ -410,7 +423,7 @@ def test_the_lifespan_is_requested_once_and_only_on_the_apikey_entry() -> None:
410
423
 
411
424
  _REQUESTS: list[dict[str, Any]] = [
412
425
  _dep("service:log", required=True, options="log_level=warn", limits={"count_per_day": 1000}),
413
- _dep("service:me", permissions=["read", "write"], options="profile=address.state"),
426
+ _dep("service:me", permissions=["read", "write"]),
414
427
  _lifespan(),
415
428
  ]
416
429
 
@@ -422,22 +435,23 @@ def _approve(*approvals: dict[str, Any]) -> list[dict[str, Any]]:
422
435
  return build_policy(_REQUESTS, list(approvals), _resolve)
423
436
 
424
437
 
425
- def test_approvals_become_a_policy_with_the_customers_options_and_limits() -> None:
438
+ def test_approvals_become_a_policy_with_the_fixed_options_and_the_customers_choices() -> None:
426
439
  policy = _approve(
427
- {"object": "service:log", "permissions": ["invoke"], "options": "log_level=error"},
440
+ {"object": "service:log", "permissions": ["invoke"], "options": "include_attributes=true"},
428
441
  {
429
442
  "object": "service:me",
430
- "permissions": ["read"],
443
+ "permissions": ["write", "read"],
431
444
  "options": "profile=address",
432
445
  "limits": {"count_per_hour": 10, "amount_total": "5.00"},
433
446
  },
434
447
  {"object": "apikey", "limits": {"api_key_lifespan": 7200}},
435
448
  )
436
449
  assert policy == [
437
- {"object": "service:log", "permissions": ["invoke"], "options": "log_level=error"},
450
+ # The request's log_level=warn is fixed: it is in the policy though the approval leaves it out.
451
+ {"object": "service:log", "permissions": ["invoke"], "options": "include_attributes=true&log_level=warn"},
438
452
  {
439
453
  "object": "service:me",
440
- "permissions": ["read"],
454
+ "permissions": ["write", "read"],
441
455
  "options": "profile=address",
442
456
  "limits": {"count_per_hour": 10, "amount_total": "5.00"},
443
457
  },
@@ -446,9 +460,9 @@ def test_approvals_become_a_policy_with_the_customers_options_and_limits() -> No
446
460
  assert api_key_lifespan(policy) == 7200
447
461
 
448
462
 
449
- def test_optional_requests_may_be_declined_and_empty_options_are_dropped() -> None:
463
+ def test_optional_requests_may_be_declined_and_empty_limits_are_dropped() -> None:
450
464
  policy = _approve({"object": "service:log", "permissions": ["invoke"], "options": "", "limits": {}})
451
- assert policy == [{"object": "service:log", "permissions": ["invoke"]}]
465
+ assert policy == [{"object": "service:log", "permissions": ["invoke"], "options": "log_level=warn"}]
452
466
  assert api_key_lifespan(policy) == DEFAULT_API_KEY_LIFESPAN
453
467
 
454
468
 
@@ -456,12 +470,16 @@ def test_optional_requests_may_be_declined_and_empty_options_are_dropped() -> No
456
470
  ("approvals", "error"),
457
471
  [
458
472
  ([], "requires service:log"),
459
- ([{"object": "service:me", "permissions": ["read"]}], "requires service:log"),
473
+ ([{"object": "service:me", "permissions": ["read", "write"]}], "requires service:log"),
460
474
  ([{"object": "service:ai", "permissions": ["invoke"]}], "service:ai is not requested"),
461
475
  ([_LOG_APPROVAL, _LOG_APPROVAL], "approved twice"),
462
- ([{"object": "service:log", "permissions": []}], "permissions must be"),
463
- ([{"object": "service:log", "permissions": ["invoke", "admin"]}], "requests only"),
464
- ([{"object": "service:log", "permissions": ["invoke"], "options": "log_level=trace"}], "log_level 'trace'"),
476
+ ([{"object": "service:log", "permissions": []}], "requests exactly"),
477
+ ([{"object": "service:log", "permissions": ["invoke", "admin"]}], "requests exactly"),
478
+ ([{"object": "service:log", "permissions": ["invoke"], "options": "log_level=error"}], "fixes it to 'warn'"),
479
+ (
480
+ [{"object": "service:log", "permissions": ["invoke"], "options": "include_attributes=yes"}],
481
+ "include_attributes 'yes'",
482
+ ),
465
483
  ([{"object": "service:log", "permissions": ["invoke"], "options": "cap=1"}], "accepts no option 'cap'"),
466
484
  ([{"object": "service:log", "permissions": ["invoke"], "limits": {"count_per_week": 1}}], "count_/amount_"),
467
485
  ([{"object": "service:log", "permissions": ["invoke"], "required": True}], "unknown keys"),
@@ -487,6 +505,177 @@ def test_an_approval_outside_the_requests_or_exports_is_refused(approvals: Any,
487
505
  build_policy(_REQUESTS, approvals, _resolve)
488
506
 
489
507
 
508
+ # Every included request keeps exactly its permissions (unitysvc/unitysvc#2831) -----
509
+
510
+
511
+ @pytest.mark.parametrize("required", [True, False])
512
+ @pytest.mark.parametrize(
513
+ "permissions",
514
+ [["read"], ["write"], ["read", "write", "admin"], ["read", "admin"]],
515
+ ids=lambda p: "+".join(p),
516
+ )
517
+ def test_permissions_cannot_be_removed_added_or_replaced(required: bool, permissions: list[str]) -> None:
518
+ requests = [_dep("service:me", permissions=["read", "write"], required=required)]
519
+ with pytest.raises(ValueError, match=r"requests exactly \['read', 'write'\]"):
520
+ build_policy(requests, [{"object": "service:me", "permissions": permissions}], _resolve)
521
+
522
+
523
+ @pytest.mark.parametrize("required", [True, False])
524
+ def test_permissions_may_be_listed_in_any_order(required: bool) -> None:
525
+ requests = [_dep("service:me", permissions=["read", "write"], required=required)]
526
+ policy = build_policy(requests, [{"object": "service:me", "permissions": ["write", "read"]}], _resolve)
527
+ assert policy == [{"object": "service:me", "permissions": ["write", "read"]}]
528
+
529
+
530
+ # A request's options are fixed; options it leaves open are the customer's ---------
531
+
532
+
533
+ def test_an_open_option_is_the_customers_choice() -> None:
534
+ """service:ai with no model fixed: the customer picks one, or none."""
535
+ requests = [_dep("service:ai", required=True)]
536
+ assert build_policy(requests, [{"object": "service:ai", "permissions": ["invoke"]}], _resolve) == [
537
+ {"object": "service:ai", "permissions": ["invoke"]}
538
+ ]
539
+ assert build_policy(
540
+ requests, [{"object": "service:ai", "permissions": ["invoke"], "options": "model=labs/llm-premium"}], _resolve
541
+ ) == [{"object": "service:ai", "permissions": ["invoke"], "options": "model=labs/llm-premium"}]
542
+
543
+
544
+ @pytest.mark.parametrize("required", [True, False])
545
+ def test_a_declared_option_is_fixed(required: bool) -> None:
546
+ requests = [_dep("service:ai", required=required, options="model=labs%2Fllm-balanced")]
547
+ expected = [{"object": "service:ai", "permissions": ["invoke"], "options": "model=labs/llm-balanced"}]
548
+ for options in ["", "model=labs/llm-balanced", "model=labs%2Fllm-balanced"]:
549
+ approval = {"object": "service:ai", "permissions": ["invoke"], "options": options}
550
+ assert build_policy(requests, [approval], _resolve) == expected
551
+ with pytest.raises(
552
+ ValueError, match=r"approvals\[0\]\.options\.model: the service fixes it to 'labs/llm-balanced'"
553
+ ):
554
+ build_policy(
555
+ requests,
556
+ [{"object": "service:ai", "permissions": ["invoke"], "options": "model=labs/llm-premium"}],
557
+ _resolve,
558
+ )
559
+
560
+
561
+ def test_an_optional_request_with_fixed_options_may_still_be_declined() -> None:
562
+ assert build_policy([_dep("service:ai", options="model=labs/llm-balanced")], [], _resolve) == []
563
+
564
+
565
+ def test_fixed_values_compare_as_their_type() -> None:
566
+ """02000 is the integer 2000, so repeating it does not change the fixed value."""
567
+ requests = [_dep("service:notify", options="max_size=2000")]
568
+ approval = {"object": "service:notify", "permissions": ["invoke"], "options": "max_size=02000"}
569
+ assert build_policy(requests, [approval], _resolve) == [
570
+ {"object": "service:notify", "permissions": ["invoke"], "options": "max_size=2000"}
571
+ ]
572
+ with pytest.raises(ValueError, match="fixes it to '2000'"):
573
+ build_policy(requests, [{**approval, "options": "max_size=2001"}], _resolve)
574
+
575
+
576
+ def test_without_a_resolver_fixed_values_compare_as_written() -> None:
577
+ requests = [_dep("service:notify", options="max_size=2000")]
578
+ with pytest.raises(ValueError, match="fixes it to '2000'"):
579
+ build_policy(requests, [{"object": "service:notify", "permissions": ["invoke"], "options": "max_size=02000"}])
580
+
581
+
582
+ def test_policy_options_are_one_canonical_query_string() -> None:
583
+ assert options_text({"topic": "a&b", "kind": "chat", "profile": "x,y", "service": "labs/llm"}) == (
584
+ "kind=chat&profile=x,y&service=labs/llm&topic=a%26b"
585
+ )
586
+
587
+
588
+ # Several requests of one object, told apart by a fixed option ---------------------
589
+
590
+ _ROOMS: list[dict[str, Any]] = [
591
+ _dep("service:rooms", permissions=["create"], required=True, options="kind=chat&max_members=100"),
592
+ _dep("service:rooms", permissions=["create"], options="kind=feed"),
593
+ ]
594
+
595
+
596
+ def _room(options: str = "", **fields: Any) -> dict[str, Any]:
597
+ return {"object": "service:rooms", "permissions": ["create"], "options": options, **fields}
598
+
599
+
600
+ def test_requests_of_one_object_are_approved_separately() -> None:
601
+ policy = build_policy(_ROOMS, [_room("kind=feed&topic=news"), _room("kind=chat")], _resolve)
602
+ assert policy == [
603
+ {"object": "service:rooms", "permissions": ["create"], "options": "kind=feed&topic=news"},
604
+ {"object": "service:rooms", "permissions": ["create"], "options": "kind=chat&max_members=100"},
605
+ ]
606
+ # A stored entry finds its request again, by its fixed options.
607
+ assert [match_request("policy", _ROOMS, entry) for entry in policy] == [1, 0]
608
+
609
+
610
+ def test_declining_one_kind_leaves_the_other() -> None:
611
+ assert build_policy(_ROOMS, [_room("kind=chat")], _resolve) == [
612
+ {"object": "service:rooms", "permissions": ["create"], "options": "kind=chat&max_members=100"}
613
+ ]
614
+
615
+
616
+ @pytest.mark.parametrize(
617
+ ("approvals", "error"),
618
+ [
619
+ ([_room()], r"service:rooms is requested 2 times; set kind to say which"),
620
+ ([_room("topic=news")], "set kind to say which"),
621
+ ([_room("kind=feed")], r"requires service:rooms \(kind=chat&max_members=100\)"),
622
+ ([_room("kind=chat"), _room("kind=chat&max_members=100")], "approved twice"),
623
+ ([_room("kind=chat&max_members=50")], "no request of service:rooms has these options"),
624
+ ],
625
+ )
626
+ def test_an_approval_must_say_which_request_it_approves(approvals: list[dict[str, Any]], error: str) -> None:
627
+ with pytest.raises(ValueError, match=error):
628
+ build_policy(_ROOMS, approvals, _resolve)
629
+
630
+
631
+ @pytest.mark.parametrize(
632
+ "second",
633
+ [
634
+ _dep("service:rooms", permissions=["create"], options="kind=chat"),
635
+ _dep("service:rooms", permissions=["create"], options="topic=news"),
636
+ _dep("service:rooms", permissions=["create"]),
637
+ _dep("service:rooms", permissions=["create"], options="kind=chat&max_members=0100"),
638
+ ],
639
+ ids=["same-kind", "other-key", "no-options", "same-typed-value"],
640
+ )
641
+ def test_requests_of_one_object_must_fix_an_option_differently(second: dict[str, Any]) -> None:
642
+ with pytest.raises(ValueError, match="listed twice; requests of one object must each fix an option"):
643
+ _check(_ROOMS[0], second)
644
+
645
+
646
+ # Whether the customer may decline a request ----------------------------------------
647
+
648
+
649
+ def test_every_request_says_whether_it_is_required() -> None:
650
+ unstated = {k: v for k, v in _dep().items() if k != "required"}
651
+ with pytest.raises(ValueError, match=r"\[0\]\.required must be true or false: say whether"):
652
+ _check(unstated)
653
+ lifespan = {k: v for k, v in _lifespan().items() if k != "required"}
654
+ with pytest.raises(ValueError, match=r"\[0\]\.required must be true or false: say whether"):
655
+ _check(lifespan)
656
+
657
+
658
+ def test_a_stored_request_without_required_reads_as_optional() -> None:
659
+ """Declarations stored before the rule still build policies."""
660
+ unstated = {k: v for k, v in _dep().items() if k != "required"}
661
+ assert build_policy([unstated], [], _resolve) == []
662
+
663
+
664
+ def test_a_key_lifespan_may_be_required() -> None:
665
+ requests = [_lifespan(required=True)]
666
+ with pytest.raises(ValueError, match="requires apikey"):
667
+ build_policy(requests, [])
668
+ assert build_policy(requests, [{"object": "apikey", "limits": {"api_key_lifespan": 600}}]) == [
669
+ {"object": "apikey", "limits": {"api_key_lifespan": 600}}
670
+ ]
671
+
672
+
673
+ @pytest.mark.parametrize("permission", ["*", "read*", "Read", "read-all", ""])
674
+ def test_a_permission_is_a_plain_name_even_without_a_resolver(permission: str) -> None:
675
+ with pytest.raises(ValueError, match="permission names"):
676
+ validate_access_requests(_WHERE, [_dep(permissions=[permission])])
677
+
678
+
490
679
  def test_an_approval_of_an_unpublished_target_is_refused() -> None:
491
680
  with pytest.raises(ValueError, match="service:gone is not a published service"):
492
681
  build_policy([_dep("service:gone")], [{"object": "service:gone", "permissions": ["invoke"]}], _resolve)
@@ -551,11 +740,16 @@ def test_the_enrollment_entry_appears_once() -> None:
551
740
  def test_an_approval_may_select_one_of_the_customers_enrollments() -> None:
552
741
  policy = _approve(
553
742
  _LOG_APPROVAL,
554
- {"object": "service:me", "permissions": ["read"], "enrollment": "JYY87Y", "limits": {"count_per_day": 3}},
743
+ {
744
+ "object": "service:me",
745
+ "permissions": ["read", "write"],
746
+ "enrollment": "JYY87Y",
747
+ "limits": {"count_per_day": 3},
748
+ },
555
749
  )
556
750
  assert policy[-1] == {
557
751
  "object": "service:me",
558
- "permissions": ["read"],
752
+ "permissions": ["read", "write"],
559
753
  "enrollment": "JYY87Y",
560
754
  "limits": {"count_per_day": 3},
561
755
  }
@@ -574,16 +768,22 @@ def test_an_approval_may_select_one_of_the_customers_enrollments() -> None:
574
768
  )
575
769
  def test_a_chain_enrollment_names_a_code_and_takes_no_options(extra: dict[str, Any], error: str) -> None:
576
770
  with pytest.raises(ValueError, match=error):
577
- _approve(_LOG_APPROVAL, {"object": "service:me", "permissions": ["read"], **extra})
771
+ _approve(_LOG_APPROVAL, {"object": "service:me", "permissions": ["read", "write"], **extra})
578
772
 
579
773
 
580
774
  def test_a_chain_enrollment_is_still_an_approval_of_a_request() -> None:
581
775
  with pytest.raises(ValueError, match="is not requested"):
582
776
  _approve(_LOG_APPROVAL, {"object": "service:notify", "permissions": ["invoke"], "enrollment": "JYY87Y"})
583
- with pytest.raises(ValueError, match="requests only"):
777
+ with pytest.raises(ValueError, match="requests exactly"):
584
778
  _approve(_LOG_APPROVAL, {"object": "service:me", "permissions": ["delete"], "enrollment": "JYY87Y"})
585
779
 
586
780
 
781
+ def test_a_chain_enrollment_cannot_bypass_fixed_options() -> None:
782
+ """An enrollment carries no options, so it can't carry the fixed ones either."""
783
+ with pytest.raises(ValueError, match=r"fixes options of service:log \(log_level=warn\)"):
784
+ _approve({**_LOG_APPROVAL, "enrollment": "JYY87Y"})
785
+
786
+
587
787
  def test_a_request_never_names_an_enrollment() -> None:
588
788
  with pytest.raises(ValueError, match="unknown keys"):
589
789
  validate_access_requests(_WHERE, [_dep("service:me", enrollment="JYY87Y")])
@@ -159,7 +159,7 @@ def test_validate_service_json_checks_access_requests_against_the_resolver(schem
159
159
  offering_file, offering = _offering_with(tmp_path, example_data_dir)
160
160
  channel = next(iter(offering["upstream_access_config"]))
161
161
  offering["upstream_access_config"][channel]["customer_access_requests"] = [
162
- {"object": "service:no-such-svc", "permissions": ["read"], "justification": "x"}
162
+ {"object": "service:no-such-svc", "permissions": ["read"], "justification": "x", "required": False}
163
163
  ]
164
164
  offering_file.write_text(json.dumps(offering))
165
165
 
File without changes
File without changes