openmeter 1.0.0b54__py3-none-any.whl → 2.0.0__py3-none-any.whl
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.
Potentially problematic release.
This version of openmeter might be problematic. Click here for more details.
- openmeter/__init__.py +89 -15
- openmeter/_base_client.py +2041 -0
- openmeter/_client.py +518 -70
- openmeter/_compat.py +221 -0
- openmeter/_constants.py +14 -0
- openmeter/_exceptions.py +108 -0
- openmeter/_files.py +127 -0
- openmeter/_models.py +777 -0
- openmeter/_qs.py +150 -0
- openmeter/_resource.py +43 -0
- openmeter/_response.py +820 -0
- openmeter/_streaming.py +333 -0
- openmeter/_types.py +222 -0
- openmeter/_utils/__init__.py +56 -0
- openmeter/_utils/_logs.py +25 -0
- openmeter/_utils/_proxy.py +63 -0
- openmeter/_utils/_reflection.py +42 -0
- openmeter/_utils/_streams.py +12 -0
- openmeter/_utils/_sync.py +81 -0
- openmeter/_utils/_transform.py +387 -0
- openmeter/_utils/_typing.py +120 -0
- openmeter/_utils/_utils.py +419 -0
- openmeter/_version.py +4 -0
- openmeter/lib/.keep +4 -0
- openmeter/py.typed +0 -1
- openmeter/resources/__init__.py +103 -0
- openmeter/resources/debug/__init__.py +33 -0
- openmeter/resources/debug/debug.py +102 -0
- openmeter/resources/debug/metrics.py +146 -0
- openmeter/resources/entitlements/__init__.py +47 -0
- openmeter/resources/entitlements/entitlements.py +450 -0
- openmeter/resources/entitlements/features.py +578 -0
- openmeter/resources/entitlements/grants.py +389 -0
- openmeter/resources/events.py +442 -0
- openmeter/resources/meters/__init__.py +33 -0
- openmeter/resources/meters/meters.py +666 -0
- openmeter/resources/meters/subjects.py +163 -0
- openmeter/resources/notifications/__init__.py +75 -0
- openmeter/resources/notifications/channels.py +686 -0
- openmeter/resources/notifications/events.py +365 -0
- openmeter/resources/notifications/notifications.py +198 -0
- openmeter/resources/notifications/rules.py +781 -0
- openmeter/resources/notifications/webhook.py +208 -0
- openmeter/resources/portal/__init__.py +47 -0
- openmeter/resources/portal/meters.py +230 -0
- openmeter/resources/portal/portal.py +112 -0
- openmeter/resources/portal/tokens.py +359 -0
- openmeter/resources/subjects/entitlements/__init__.py +33 -0
- openmeter/resources/subjects/entitlements/entitlements.py +1881 -0
- openmeter/resources/subjects/entitlements/grants.py +453 -0
- openmeter/resources/subjects.py +419 -0
- openmeter/types/__init__.py +21 -0
- openmeter/types/debug/__init__.py +5 -0
- openmeter/types/debug/metric_list_response.py +7 -0
- openmeter/types/entitlement.py +238 -0
- openmeter/types/entitlements/__init__.py +11 -0
- openmeter/types/entitlements/feature.py +61 -0
- openmeter/types/entitlements/feature_create_params.py +43 -0
- openmeter/types/entitlements/feature_list_params.py +23 -0
- openmeter/types/entitlements/grant_list_params.py +57 -0
- openmeter/types/entitlements/grant_list_response.py +11 -0
- openmeter/types/entitlements/grant_paginated_response.py +24 -0
- openmeter/types/entitlements/list_features_result.py +28 -0
- openmeter/types/event_ingest_params.py +46 -0
- openmeter/types/event_ingest_response.py +43 -0
- openmeter/types/event_list_params.py +22 -0
- openmeter/types/event_list_response.py +9 -0
- openmeter/types/ingested_event.py +59 -0
- openmeter/types/list_entitlements_result.py +28 -0
- openmeter/types/meter.py +53 -0
- openmeter/types/meter_create_params.py +50 -0
- openmeter/types/meter_list_response.py +9 -0
- openmeter/types/meter_query_params.py +50 -0
- openmeter/types/meter_query_result.py +35 -0
- openmeter/types/meters/__init__.py +5 -0
- openmeter/types/meters/subject_list_response.py +8 -0
- openmeter/types/notifications/__init__.py +18 -0
- openmeter/types/notifications/channel_create_params.py +34 -0
- openmeter/types/notifications/channel_list_params.py +41 -0
- openmeter/types/notifications/channel_list_response.py +24 -0
- openmeter/types/notifications/channel_update_params.py +34 -0
- openmeter/types/notifications/event_list_params.py +61 -0
- openmeter/types/notifications/event_list_response.py +24 -0
- openmeter/types/notifications/notification_channel.py +47 -0
- openmeter/types/notifications/notification_event.py +215 -0
- openmeter/types/notifications/notification_rule.py +70 -0
- openmeter/types/notifications/rule_create_params.py +39 -0
- openmeter/types/notifications/rule_list_params.py +54 -0
- openmeter/types/notifications/rule_list_response.py +24 -0
- openmeter/types/notifications/rule_update_params.py +39 -0
- openmeter/types/notifications/webhook_svix_params.py +26 -0
- openmeter/types/portal/__init__.py +10 -0
- openmeter/types/portal/meter_query_params.py +44 -0
- openmeter/types/portal/portal_token.py +28 -0
- openmeter/types/portal/token_create_params.py +17 -0
- openmeter/types/portal/token_invalidate_params.py +15 -0
- openmeter/types/portal/token_list_params.py +12 -0
- openmeter/types/portal/token_list_response.py +9 -0
- openmeter/types/shared/__init__.py +3 -0
- openmeter/types/subject.py +37 -0
- openmeter/types/subject_list_response.py +9 -0
- openmeter/types/subject_param.py +27 -0
- openmeter/types/subject_upsert_params.py +39 -0
- openmeter/types/subject_upsert_response.py +10 -0
- openmeter/types/subjects/__init__.py +13 -0
- openmeter/types/subjects/entitlement_history_params.py +35 -0
- openmeter/types/subjects/entitlement_history_response.py +98 -0
- openmeter/types/subjects/entitlement_list_response.py +10 -0
- openmeter/types/subjects/entitlements/__init__.py +8 -0
- openmeter/types/subjects/entitlements/entitlement_grant.py +103 -0
- openmeter/types/subjects/entitlements/grant_list_response.py +10 -0
- openmeter-2.0.0.dist-info/METADATA +396 -0
- openmeter-2.0.0.dist-info/RECORD +115 -0
- {openmeter-1.0.0b54.dist-info → openmeter-2.0.0.dist-info}/WHEEL +1 -1
- openmeter-2.0.0.dist-info/licenses/LICENSE +201 -0
- openmeter/_configuration.py +0 -36
- openmeter/_operations/__init__.py +0 -17
- openmeter/_operations/_operations.py +0 -2105
- openmeter/_operations/_patch.py +0 -20
- openmeter/_patch.py +0 -20
- openmeter/_serialization.py +0 -2008
- openmeter/_vendor.py +0 -24
- openmeter/aio/__init__.py +0 -21
- openmeter/aio/_client.py +0 -83
- openmeter/aio/_configuration.py +0 -36
- openmeter/aio/_operations/__init__.py +0 -17
- openmeter/aio/_operations/_operations.py +0 -1778
- openmeter/aio/_operations/_patch.py +0 -20
- openmeter/aio/_patch.py +0 -20
- openmeter/aio/_vendor.py +0 -24
- openmeter-1.0.0b54.dist-info/METADATA +0 -92
- openmeter-1.0.0b54.dist-info/RECORD +0 -21
|
@@ -0,0 +1,1881 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, Union, cast
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing_extensions import Literal, overload
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
from .grants import (
|
|
12
|
+
GrantsResource,
|
|
13
|
+
AsyncGrantsResource,
|
|
14
|
+
GrantsResourceWithRawResponse,
|
|
15
|
+
AsyncGrantsResourceWithRawResponse,
|
|
16
|
+
GrantsResourceWithStreamingResponse,
|
|
17
|
+
AsyncGrantsResourceWithStreamingResponse,
|
|
18
|
+
)
|
|
19
|
+
from ...._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
|
|
20
|
+
from ...._utils import (
|
|
21
|
+
required_args,
|
|
22
|
+
maybe_transform,
|
|
23
|
+
async_maybe_transform,
|
|
24
|
+
)
|
|
25
|
+
from ...._compat import cached_property
|
|
26
|
+
from ...._resource import SyncAPIResource, AsyncAPIResource
|
|
27
|
+
from ...._response import (
|
|
28
|
+
to_raw_response_wrapper,
|
|
29
|
+
to_streamed_response_wrapper,
|
|
30
|
+
async_to_raw_response_wrapper,
|
|
31
|
+
async_to_streamed_response_wrapper,
|
|
32
|
+
)
|
|
33
|
+
from ...._base_client import make_request_options
|
|
34
|
+
from ....types.subjects import (
|
|
35
|
+
entitlement_list_params,
|
|
36
|
+
entitlement_reset_params,
|
|
37
|
+
entitlement_value_params,
|
|
38
|
+
entitlement_create_params,
|
|
39
|
+
entitlement_history_params,
|
|
40
|
+
entitlement_override_params,
|
|
41
|
+
)
|
|
42
|
+
from ....types.entitlement import Entitlement
|
|
43
|
+
from ....types.subjects.entitlement_value import EntitlementValue
|
|
44
|
+
from ....types.subjects.entitlement_list_response import EntitlementListResponse
|
|
45
|
+
from ....types.subjects.entitlement_history_response import EntitlementHistoryResponse
|
|
46
|
+
|
|
47
|
+
__all__ = ["EntitlementsResource", "AsyncEntitlementsResource"]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class EntitlementsResource(SyncAPIResource):
|
|
51
|
+
@cached_property
|
|
52
|
+
def grants(self) -> GrantsResource:
|
|
53
|
+
return GrantsResource(self._client)
|
|
54
|
+
|
|
55
|
+
@cached_property
|
|
56
|
+
def with_raw_response(self) -> EntitlementsResourceWithRawResponse:
|
|
57
|
+
"""
|
|
58
|
+
This property can be used as a prefix for any HTTP method call to return the
|
|
59
|
+
the raw response object instead of the parsed content.
|
|
60
|
+
|
|
61
|
+
For more information, see https://www.github.com/openmeterio/openmeter-python#accessing-raw-response-data-eg-headers
|
|
62
|
+
"""
|
|
63
|
+
return EntitlementsResourceWithRawResponse(self)
|
|
64
|
+
|
|
65
|
+
@cached_property
|
|
66
|
+
def with_streaming_response(self) -> EntitlementsResourceWithStreamingResponse:
|
|
67
|
+
"""
|
|
68
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
69
|
+
|
|
70
|
+
For more information, see https://www.github.com/openmeterio/openmeter-python#with_streaming_response
|
|
71
|
+
"""
|
|
72
|
+
return EntitlementsResourceWithStreamingResponse(self)
|
|
73
|
+
|
|
74
|
+
@overload
|
|
75
|
+
def create(
|
|
76
|
+
self,
|
|
77
|
+
subject_id_or_key: str,
|
|
78
|
+
*,
|
|
79
|
+
type: Literal["metered"],
|
|
80
|
+
usage_period: entitlement_create_params.EntitlementMeteredCreateInputsUsagePeriod,
|
|
81
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
82
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
83
|
+
is_soft_limit: bool | NotGiven = NOT_GIVEN,
|
|
84
|
+
issue_after_reset: float | NotGiven = NOT_GIVEN,
|
|
85
|
+
issue_after_reset_priority: int | NotGiven = NOT_GIVEN,
|
|
86
|
+
is_unlimited: bool | NotGiven = NOT_GIVEN,
|
|
87
|
+
measure_usage_from: Union[Literal["CURRENT_PERIOD_START", "NOW"], Union[str, datetime]] | NotGiven = NOT_GIVEN,
|
|
88
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
89
|
+
preserve_overage_at_reset: bool | NotGiven = NOT_GIVEN,
|
|
90
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
91
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
92
|
+
extra_headers: Headers | None = None,
|
|
93
|
+
extra_query: Query | None = None,
|
|
94
|
+
extra_body: Body | None = None,
|
|
95
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
96
|
+
) -> Entitlement:
|
|
97
|
+
"""OpenMeter has three types of entitlements: metered, boolean, and static.
|
|
98
|
+
|
|
99
|
+
The
|
|
100
|
+
type property determines the type of entitlement. The underlying feature has to
|
|
101
|
+
be compatible with the entitlement type specified in the request (e.g., a
|
|
102
|
+
metered entitlement needs a feature associated with a meter).
|
|
103
|
+
|
|
104
|
+
- Boolean entitlements define static feature access, e.g. "Can use SSO
|
|
105
|
+
authentication".
|
|
106
|
+
- Static entitlements let you pass along a configuration while granting access,
|
|
107
|
+
e.g. "Using this feature with X Y settings" (passed in the config).
|
|
108
|
+
- Metered entitlements have many use cases, from setting up usage-based access
|
|
109
|
+
to implementing complex credit systems. Example: The customer can use 10000 AI
|
|
110
|
+
tokens during the usage period of the entitlement.
|
|
111
|
+
|
|
112
|
+
A given subject can only have one active (non-deleted) entitlement per
|
|
113
|
+
featureKey. If you try to create a new entitlement for a featureKey that already
|
|
114
|
+
has an active entitlement, the request will fail with a 409 error.
|
|
115
|
+
|
|
116
|
+
Once an entitlement is created you cannot modify it, only delete it.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
120
|
+
|
|
121
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
122
|
+
required.
|
|
123
|
+
|
|
124
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
125
|
+
required.
|
|
126
|
+
|
|
127
|
+
is_soft_limit: If softLimit=true the subject can use the feature even if the entitlement is
|
|
128
|
+
exhausted, hasAccess will always be true.
|
|
129
|
+
|
|
130
|
+
issue_after_reset: You can grant usage automatically alongside the entitlement, the example
|
|
131
|
+
scenario would be creating a starting balance. If an amount is specified here, a
|
|
132
|
+
grant will be created alongside the entitlement with the specified amount. That
|
|
133
|
+
grant will have it's rollover settings configured in a way that after each reset
|
|
134
|
+
operation, the balance will return the original amount specified here. Manually
|
|
135
|
+
creating such a grant would mean having the "amount", "minRolloverAmount", and
|
|
136
|
+
"maxRolloverAmount" fields all be the same.
|
|
137
|
+
|
|
138
|
+
issue_after_reset_priority: Defines the grant priority for the default grant.
|
|
139
|
+
|
|
140
|
+
is_unlimited: Deprecated, ignored by the backend. Please use isSoftLimit instead; this field
|
|
141
|
+
will be removed in the future.
|
|
142
|
+
|
|
143
|
+
measure_usage_from: Measure usage from
|
|
144
|
+
|
|
145
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
146
|
+
about a resource.
|
|
147
|
+
|
|
148
|
+
preserve_overage_at_reset: If true, the overage is preserved at reset. If false, the usage is reset to 0.
|
|
149
|
+
|
|
150
|
+
extra_headers: Send extra headers
|
|
151
|
+
|
|
152
|
+
extra_query: Add additional query parameters to the request
|
|
153
|
+
|
|
154
|
+
extra_body: Add additional JSON properties to the request
|
|
155
|
+
|
|
156
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
157
|
+
"""
|
|
158
|
+
...
|
|
159
|
+
|
|
160
|
+
@overload
|
|
161
|
+
def create(
|
|
162
|
+
self,
|
|
163
|
+
subject_id_or_key: str,
|
|
164
|
+
*,
|
|
165
|
+
config: str,
|
|
166
|
+
type: Literal["static"],
|
|
167
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
168
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
169
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
170
|
+
usage_period: entitlement_create_params.EntitlementStaticCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
171
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
172
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
173
|
+
extra_headers: Headers | None = None,
|
|
174
|
+
extra_query: Query | None = None,
|
|
175
|
+
extra_body: Body | None = None,
|
|
176
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
177
|
+
) -> Entitlement:
|
|
178
|
+
"""OpenMeter has three types of entitlements: metered, boolean, and static.
|
|
179
|
+
|
|
180
|
+
The
|
|
181
|
+
type property determines the type of entitlement. The underlying feature has to
|
|
182
|
+
be compatible with the entitlement type specified in the request (e.g., a
|
|
183
|
+
metered entitlement needs a feature associated with a meter).
|
|
184
|
+
|
|
185
|
+
- Boolean entitlements define static feature access, e.g. "Can use SSO
|
|
186
|
+
authentication".
|
|
187
|
+
- Static entitlements let you pass along a configuration while granting access,
|
|
188
|
+
e.g. "Using this feature with X Y settings" (passed in the config).
|
|
189
|
+
- Metered entitlements have many use cases, from setting up usage-based access
|
|
190
|
+
to implementing complex credit systems. Example: The customer can use 10000 AI
|
|
191
|
+
tokens during the usage period of the entitlement.
|
|
192
|
+
|
|
193
|
+
A given subject can only have one active (non-deleted) entitlement per
|
|
194
|
+
featureKey. If you try to create a new entitlement for a featureKey that already
|
|
195
|
+
has an active entitlement, the request will fail with a 409 error.
|
|
196
|
+
|
|
197
|
+
Once an entitlement is created you cannot modify it, only delete it.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
config: The JSON parsable config of the entitlement. This value is also returned when
|
|
201
|
+
checking entitlement access and it is useful for configuring fine-grained access
|
|
202
|
+
settings to the feature, implemented in your own system. Has to be an object.
|
|
203
|
+
|
|
204
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
205
|
+
required.
|
|
206
|
+
|
|
207
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
208
|
+
required.
|
|
209
|
+
|
|
210
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
211
|
+
about a resource.
|
|
212
|
+
|
|
213
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
214
|
+
|
|
215
|
+
extra_headers: Send extra headers
|
|
216
|
+
|
|
217
|
+
extra_query: Add additional query parameters to the request
|
|
218
|
+
|
|
219
|
+
extra_body: Add additional JSON properties to the request
|
|
220
|
+
|
|
221
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
222
|
+
"""
|
|
223
|
+
...
|
|
224
|
+
|
|
225
|
+
@overload
|
|
226
|
+
def create(
|
|
227
|
+
self,
|
|
228
|
+
subject_id_or_key: str,
|
|
229
|
+
*,
|
|
230
|
+
type: Literal["boolean"],
|
|
231
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
232
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
233
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
234
|
+
usage_period: entitlement_create_params.EntitlementBooleanCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
235
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
236
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
237
|
+
extra_headers: Headers | None = None,
|
|
238
|
+
extra_query: Query | None = None,
|
|
239
|
+
extra_body: Body | None = None,
|
|
240
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
241
|
+
) -> Entitlement:
|
|
242
|
+
"""OpenMeter has three types of entitlements: metered, boolean, and static.
|
|
243
|
+
|
|
244
|
+
The
|
|
245
|
+
type property determines the type of entitlement. The underlying feature has to
|
|
246
|
+
be compatible with the entitlement type specified in the request (e.g., a
|
|
247
|
+
metered entitlement needs a feature associated with a meter).
|
|
248
|
+
|
|
249
|
+
- Boolean entitlements define static feature access, e.g. "Can use SSO
|
|
250
|
+
authentication".
|
|
251
|
+
- Static entitlements let you pass along a configuration while granting access,
|
|
252
|
+
e.g. "Using this feature with X Y settings" (passed in the config).
|
|
253
|
+
- Metered entitlements have many use cases, from setting up usage-based access
|
|
254
|
+
to implementing complex credit systems. Example: The customer can use 10000 AI
|
|
255
|
+
tokens during the usage period of the entitlement.
|
|
256
|
+
|
|
257
|
+
A given subject can only have one active (non-deleted) entitlement per
|
|
258
|
+
featureKey. If you try to create a new entitlement for a featureKey that already
|
|
259
|
+
has an active entitlement, the request will fail with a 409 error.
|
|
260
|
+
|
|
261
|
+
Once an entitlement is created you cannot modify it, only delete it.
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
265
|
+
required.
|
|
266
|
+
|
|
267
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
268
|
+
required.
|
|
269
|
+
|
|
270
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
271
|
+
about a resource.
|
|
272
|
+
|
|
273
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
274
|
+
|
|
275
|
+
extra_headers: Send extra headers
|
|
276
|
+
|
|
277
|
+
extra_query: Add additional query parameters to the request
|
|
278
|
+
|
|
279
|
+
extra_body: Add additional JSON properties to the request
|
|
280
|
+
|
|
281
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
282
|
+
"""
|
|
283
|
+
...
|
|
284
|
+
|
|
285
|
+
@required_args(["type", "usage_period"], ["config", "type"], ["type"])
|
|
286
|
+
def create(
|
|
287
|
+
self,
|
|
288
|
+
subject_id_or_key: str,
|
|
289
|
+
*,
|
|
290
|
+
type: Literal["metered"] | Literal["static"] | Literal["boolean"],
|
|
291
|
+
usage_period: entitlement_create_params.EntitlementMeteredCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
292
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
293
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
294
|
+
is_soft_limit: bool | NotGiven = NOT_GIVEN,
|
|
295
|
+
issue_after_reset: float | NotGiven = NOT_GIVEN,
|
|
296
|
+
issue_after_reset_priority: int | NotGiven = NOT_GIVEN,
|
|
297
|
+
is_unlimited: bool | NotGiven = NOT_GIVEN,
|
|
298
|
+
measure_usage_from: Union[Literal["CURRENT_PERIOD_START", "NOW"], Union[str, datetime]] | NotGiven = NOT_GIVEN,
|
|
299
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
300
|
+
preserve_overage_at_reset: bool | NotGiven = NOT_GIVEN,
|
|
301
|
+
config: str | NotGiven = NOT_GIVEN,
|
|
302
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
303
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
304
|
+
extra_headers: Headers | None = None,
|
|
305
|
+
extra_query: Query | None = None,
|
|
306
|
+
extra_body: Body | None = None,
|
|
307
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
308
|
+
) -> Entitlement:
|
|
309
|
+
if not subject_id_or_key:
|
|
310
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
311
|
+
return cast(
|
|
312
|
+
Entitlement,
|
|
313
|
+
self._post(
|
|
314
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements",
|
|
315
|
+
body=maybe_transform(
|
|
316
|
+
{
|
|
317
|
+
"type": type,
|
|
318
|
+
"usage_period": usage_period,
|
|
319
|
+
"feature_id": feature_id,
|
|
320
|
+
"feature_key": feature_key,
|
|
321
|
+
"is_soft_limit": is_soft_limit,
|
|
322
|
+
"issue_after_reset": issue_after_reset,
|
|
323
|
+
"issue_after_reset_priority": issue_after_reset_priority,
|
|
324
|
+
"is_unlimited": is_unlimited,
|
|
325
|
+
"measure_usage_from": measure_usage_from,
|
|
326
|
+
"metadata": metadata,
|
|
327
|
+
"preserve_overage_at_reset": preserve_overage_at_reset,
|
|
328
|
+
"config": config,
|
|
329
|
+
},
|
|
330
|
+
entitlement_create_params.EntitlementCreateParams,
|
|
331
|
+
),
|
|
332
|
+
options=make_request_options(
|
|
333
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
334
|
+
),
|
|
335
|
+
cast_to=cast(Any, Entitlement), # Union types cannot be passed in as arguments in the type system
|
|
336
|
+
),
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
def retrieve(
|
|
340
|
+
self,
|
|
341
|
+
entitlement_id: str,
|
|
342
|
+
*,
|
|
343
|
+
subject_id_or_key: str,
|
|
344
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
345
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
346
|
+
extra_headers: Headers | None = None,
|
|
347
|
+
extra_query: Query | None = None,
|
|
348
|
+
extra_body: Body | None = None,
|
|
349
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
350
|
+
) -> Entitlement:
|
|
351
|
+
"""Get entitlement by id.
|
|
352
|
+
|
|
353
|
+
For checking entitlement access, use the /value endpoint
|
|
354
|
+
instead.
|
|
355
|
+
|
|
356
|
+
Args:
|
|
357
|
+
extra_headers: Send extra headers
|
|
358
|
+
|
|
359
|
+
extra_query: Add additional query parameters to the request
|
|
360
|
+
|
|
361
|
+
extra_body: Add additional JSON properties to the request
|
|
362
|
+
|
|
363
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
364
|
+
"""
|
|
365
|
+
if not subject_id_or_key:
|
|
366
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
367
|
+
if not entitlement_id:
|
|
368
|
+
raise ValueError(f"Expected a non-empty value for `entitlement_id` but received {entitlement_id!r}")
|
|
369
|
+
return cast(
|
|
370
|
+
Entitlement,
|
|
371
|
+
self._get(
|
|
372
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id}",
|
|
373
|
+
options=make_request_options(
|
|
374
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
375
|
+
),
|
|
376
|
+
cast_to=cast(Any, Entitlement), # Union types cannot be passed in as arguments in the type system
|
|
377
|
+
),
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
def list(
|
|
381
|
+
self,
|
|
382
|
+
subject_id_or_key: str,
|
|
383
|
+
*,
|
|
384
|
+
include_deleted: bool | NotGiven = NOT_GIVEN,
|
|
385
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
386
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
387
|
+
extra_headers: Headers | None = None,
|
|
388
|
+
extra_query: Query | None = None,
|
|
389
|
+
extra_body: Body | None = None,
|
|
390
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
391
|
+
) -> EntitlementListResponse:
|
|
392
|
+
"""List all entitlements for a subject.
|
|
393
|
+
|
|
394
|
+
For checking entitlement access, use the
|
|
395
|
+
/value endpoint instead.
|
|
396
|
+
|
|
397
|
+
Args:
|
|
398
|
+
extra_headers: Send extra headers
|
|
399
|
+
|
|
400
|
+
extra_query: Add additional query parameters to the request
|
|
401
|
+
|
|
402
|
+
extra_body: Add additional JSON properties to the request
|
|
403
|
+
|
|
404
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
405
|
+
"""
|
|
406
|
+
if not subject_id_or_key:
|
|
407
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
408
|
+
return self._get(
|
|
409
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements",
|
|
410
|
+
options=make_request_options(
|
|
411
|
+
extra_headers=extra_headers,
|
|
412
|
+
extra_query=extra_query,
|
|
413
|
+
extra_body=extra_body,
|
|
414
|
+
timeout=timeout,
|
|
415
|
+
query=maybe_transform(
|
|
416
|
+
{"include_deleted": include_deleted}, entitlement_list_params.EntitlementListParams
|
|
417
|
+
),
|
|
418
|
+
),
|
|
419
|
+
cast_to=EntitlementListResponse,
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
def delete(
|
|
423
|
+
self,
|
|
424
|
+
entitlement_id: str,
|
|
425
|
+
*,
|
|
426
|
+
subject_id_or_key: str,
|
|
427
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
428
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
429
|
+
extra_headers: Headers | None = None,
|
|
430
|
+
extra_query: Query | None = None,
|
|
431
|
+
extra_body: Body | None = None,
|
|
432
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
433
|
+
) -> None:
|
|
434
|
+
"""Deleting an entitlement revokes access to the associated feature.
|
|
435
|
+
|
|
436
|
+
As a single
|
|
437
|
+
subject can only have one entitlement per featureKey, when "migrating" features
|
|
438
|
+
you have to delete the old entitlements as well. As access and status checks can
|
|
439
|
+
be historical queries, deleting an entitlement populates the deletedAt
|
|
440
|
+
timestamp. When queried for a time before that, the entitlement is still
|
|
441
|
+
considered active, you cannot have retroactive changes to access, which is
|
|
442
|
+
important for, among other things, auditing.
|
|
443
|
+
|
|
444
|
+
Args:
|
|
445
|
+
extra_headers: Send extra headers
|
|
446
|
+
|
|
447
|
+
extra_query: Add additional query parameters to the request
|
|
448
|
+
|
|
449
|
+
extra_body: Add additional JSON properties to the request
|
|
450
|
+
|
|
451
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
452
|
+
"""
|
|
453
|
+
if not subject_id_or_key:
|
|
454
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
455
|
+
if not entitlement_id:
|
|
456
|
+
raise ValueError(f"Expected a non-empty value for `entitlement_id` but received {entitlement_id!r}")
|
|
457
|
+
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
|
|
458
|
+
return self._delete(
|
|
459
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id}",
|
|
460
|
+
options=make_request_options(
|
|
461
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
462
|
+
),
|
|
463
|
+
cast_to=NoneType,
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
def history(
|
|
467
|
+
self,
|
|
468
|
+
entitlement_id: str,
|
|
469
|
+
*,
|
|
470
|
+
subject_id_or_key: str,
|
|
471
|
+
window_size: Literal["MINUTE", "HOUR", "DAY"],
|
|
472
|
+
from_: Union[str, datetime] | NotGiven = NOT_GIVEN,
|
|
473
|
+
to: Union[str, datetime] | NotGiven = NOT_GIVEN,
|
|
474
|
+
window_time_zone: str | NotGiven = NOT_GIVEN,
|
|
475
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
476
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
477
|
+
extra_headers: Headers | None = None,
|
|
478
|
+
extra_query: Query | None = None,
|
|
479
|
+
extra_body: Body | None = None,
|
|
480
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
481
|
+
) -> EntitlementHistoryResponse:
|
|
482
|
+
"""Returns historical balance and usage data for the entitlement.
|
|
483
|
+
|
|
484
|
+
The queried
|
|
485
|
+
history can span accross multiple reset events.
|
|
486
|
+
|
|
487
|
+
BurndownHistory returns a continous history of segments, where the segments are
|
|
488
|
+
seperated by events that changed either the grant burndown priority or the usage
|
|
489
|
+
period.
|
|
490
|
+
|
|
491
|
+
WindowedHistory returns windowed usage data for the period enriched with balance
|
|
492
|
+
information and the list of grants that were being burnt down in that window.
|
|
493
|
+
|
|
494
|
+
Args:
|
|
495
|
+
window_size: Windowsize
|
|
496
|
+
|
|
497
|
+
from_: Start of time range to query entitlement: date-time in RFC 3339 format. Defaults
|
|
498
|
+
to the last reset. Gets truncated to the granularity of the underlying meter.
|
|
499
|
+
|
|
500
|
+
to: End of time range to query entitlement: date-time in RFC 3339 format. Defaults
|
|
501
|
+
to now. If not now then gets truncated to the granularity of the underlying
|
|
502
|
+
meter.
|
|
503
|
+
|
|
504
|
+
window_time_zone: The timezone used when calculating the windows.
|
|
505
|
+
|
|
506
|
+
extra_headers: Send extra headers
|
|
507
|
+
|
|
508
|
+
extra_query: Add additional query parameters to the request
|
|
509
|
+
|
|
510
|
+
extra_body: Add additional JSON properties to the request
|
|
511
|
+
|
|
512
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
513
|
+
"""
|
|
514
|
+
if not subject_id_or_key:
|
|
515
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
516
|
+
if not entitlement_id:
|
|
517
|
+
raise ValueError(f"Expected a non-empty value for `entitlement_id` but received {entitlement_id!r}")
|
|
518
|
+
return self._get(
|
|
519
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id}/history",
|
|
520
|
+
options=make_request_options(
|
|
521
|
+
extra_headers=extra_headers,
|
|
522
|
+
extra_query=extra_query,
|
|
523
|
+
extra_body=extra_body,
|
|
524
|
+
timeout=timeout,
|
|
525
|
+
query=maybe_transform(
|
|
526
|
+
{
|
|
527
|
+
"window_size": window_size,
|
|
528
|
+
"from_": from_,
|
|
529
|
+
"to": to,
|
|
530
|
+
"window_time_zone": window_time_zone,
|
|
531
|
+
},
|
|
532
|
+
entitlement_history_params.EntitlementHistoryParams,
|
|
533
|
+
),
|
|
534
|
+
),
|
|
535
|
+
cast_to=EntitlementHistoryResponse,
|
|
536
|
+
)
|
|
537
|
+
|
|
538
|
+
@overload
|
|
539
|
+
def override(
|
|
540
|
+
self,
|
|
541
|
+
entitlement_id_or_feature_key: str,
|
|
542
|
+
*,
|
|
543
|
+
subject_id_or_key: str,
|
|
544
|
+
type: Literal["metered"],
|
|
545
|
+
usage_period: entitlement_override_params.EntitlementMeteredCreateInputsUsagePeriod,
|
|
546
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
547
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
548
|
+
is_soft_limit: bool | NotGiven = NOT_GIVEN,
|
|
549
|
+
issue_after_reset: float | NotGiven = NOT_GIVEN,
|
|
550
|
+
issue_after_reset_priority: int | NotGiven = NOT_GIVEN,
|
|
551
|
+
is_unlimited: bool | NotGiven = NOT_GIVEN,
|
|
552
|
+
measure_usage_from: Union[Literal["CURRENT_PERIOD_START", "NOW"], Union[str, datetime]] | NotGiven = NOT_GIVEN,
|
|
553
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
554
|
+
preserve_overage_at_reset: bool | NotGiven = NOT_GIVEN,
|
|
555
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
556
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
557
|
+
extra_headers: Headers | None = None,
|
|
558
|
+
extra_query: Query | None = None,
|
|
559
|
+
extra_body: Body | None = None,
|
|
560
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
561
|
+
) -> Entitlement:
|
|
562
|
+
"""
|
|
563
|
+
Overriding an entitlement creates a new entitlement from the provided inputs and
|
|
564
|
+
soft deletes the previous entitlement for the provided subject-feature pair. If
|
|
565
|
+
the previous entitlement is already deleted or otherwise doesnt exist, the
|
|
566
|
+
override will fail.
|
|
567
|
+
|
|
568
|
+
This endpoint is useful for upgrades, downgrades, or other changes to
|
|
569
|
+
entitlements that require a new entitlement to be created with zero downtime.
|
|
570
|
+
|
|
571
|
+
Args:
|
|
572
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
573
|
+
|
|
574
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
575
|
+
required.
|
|
576
|
+
|
|
577
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
578
|
+
required.
|
|
579
|
+
|
|
580
|
+
is_soft_limit: If softLimit=true the subject can use the feature even if the entitlement is
|
|
581
|
+
exhausted, hasAccess will always be true.
|
|
582
|
+
|
|
583
|
+
issue_after_reset: You can grant usage automatically alongside the entitlement, the example
|
|
584
|
+
scenario would be creating a starting balance. If an amount is specified here, a
|
|
585
|
+
grant will be created alongside the entitlement with the specified amount. That
|
|
586
|
+
grant will have it's rollover settings configured in a way that after each reset
|
|
587
|
+
operation, the balance will return the original amount specified here. Manually
|
|
588
|
+
creating such a grant would mean having the "amount", "minRolloverAmount", and
|
|
589
|
+
"maxRolloverAmount" fields all be the same.
|
|
590
|
+
|
|
591
|
+
issue_after_reset_priority: Defines the grant priority for the default grant.
|
|
592
|
+
|
|
593
|
+
is_unlimited: Deprecated, ignored by the backend. Please use isSoftLimit instead; this field
|
|
594
|
+
will be removed in the future.
|
|
595
|
+
|
|
596
|
+
measure_usage_from: Measure usage from
|
|
597
|
+
|
|
598
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
599
|
+
about a resource.
|
|
600
|
+
|
|
601
|
+
preserve_overage_at_reset: If true, the overage is preserved at reset. If false, the usage is reset to 0.
|
|
602
|
+
|
|
603
|
+
extra_headers: Send extra headers
|
|
604
|
+
|
|
605
|
+
extra_query: Add additional query parameters to the request
|
|
606
|
+
|
|
607
|
+
extra_body: Add additional JSON properties to the request
|
|
608
|
+
|
|
609
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
610
|
+
"""
|
|
611
|
+
...
|
|
612
|
+
|
|
613
|
+
@overload
|
|
614
|
+
def override(
|
|
615
|
+
self,
|
|
616
|
+
entitlement_id_or_feature_key: str,
|
|
617
|
+
*,
|
|
618
|
+
subject_id_or_key: str,
|
|
619
|
+
config: str,
|
|
620
|
+
type: Literal["static"],
|
|
621
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
622
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
623
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
624
|
+
usage_period: entitlement_override_params.EntitlementStaticCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
625
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
626
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
627
|
+
extra_headers: Headers | None = None,
|
|
628
|
+
extra_query: Query | None = None,
|
|
629
|
+
extra_body: Body | None = None,
|
|
630
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
631
|
+
) -> Entitlement:
|
|
632
|
+
"""
|
|
633
|
+
Overriding an entitlement creates a new entitlement from the provided inputs and
|
|
634
|
+
soft deletes the previous entitlement for the provided subject-feature pair. If
|
|
635
|
+
the previous entitlement is already deleted or otherwise doesnt exist, the
|
|
636
|
+
override will fail.
|
|
637
|
+
|
|
638
|
+
This endpoint is useful for upgrades, downgrades, or other changes to
|
|
639
|
+
entitlements that require a new entitlement to be created with zero downtime.
|
|
640
|
+
|
|
641
|
+
Args:
|
|
642
|
+
config: The JSON parsable config of the entitlement. This value is also returned when
|
|
643
|
+
checking entitlement access and it is useful for configuring fine-grained access
|
|
644
|
+
settings to the feature, implemented in your own system. Has to be an object.
|
|
645
|
+
|
|
646
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
647
|
+
required.
|
|
648
|
+
|
|
649
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
650
|
+
required.
|
|
651
|
+
|
|
652
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
653
|
+
about a resource.
|
|
654
|
+
|
|
655
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
656
|
+
|
|
657
|
+
extra_headers: Send extra headers
|
|
658
|
+
|
|
659
|
+
extra_query: Add additional query parameters to the request
|
|
660
|
+
|
|
661
|
+
extra_body: Add additional JSON properties to the request
|
|
662
|
+
|
|
663
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
664
|
+
"""
|
|
665
|
+
...
|
|
666
|
+
|
|
667
|
+
@overload
|
|
668
|
+
def override(
|
|
669
|
+
self,
|
|
670
|
+
entitlement_id_or_feature_key: str,
|
|
671
|
+
*,
|
|
672
|
+
subject_id_or_key: str,
|
|
673
|
+
type: Literal["boolean"],
|
|
674
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
675
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
676
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
677
|
+
usage_period: entitlement_override_params.EntitlementBooleanCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
678
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
679
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
680
|
+
extra_headers: Headers | None = None,
|
|
681
|
+
extra_query: Query | None = None,
|
|
682
|
+
extra_body: Body | None = None,
|
|
683
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
684
|
+
) -> Entitlement:
|
|
685
|
+
"""
|
|
686
|
+
Overriding an entitlement creates a new entitlement from the provided inputs and
|
|
687
|
+
soft deletes the previous entitlement for the provided subject-feature pair. If
|
|
688
|
+
the previous entitlement is already deleted or otherwise doesnt exist, the
|
|
689
|
+
override will fail.
|
|
690
|
+
|
|
691
|
+
This endpoint is useful for upgrades, downgrades, or other changes to
|
|
692
|
+
entitlements that require a new entitlement to be created with zero downtime.
|
|
693
|
+
|
|
694
|
+
Args:
|
|
695
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
696
|
+
required.
|
|
697
|
+
|
|
698
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
699
|
+
required.
|
|
700
|
+
|
|
701
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
702
|
+
about a resource.
|
|
703
|
+
|
|
704
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
705
|
+
|
|
706
|
+
extra_headers: Send extra headers
|
|
707
|
+
|
|
708
|
+
extra_query: Add additional query parameters to the request
|
|
709
|
+
|
|
710
|
+
extra_body: Add additional JSON properties to the request
|
|
711
|
+
|
|
712
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
713
|
+
"""
|
|
714
|
+
...
|
|
715
|
+
|
|
716
|
+
@required_args(
|
|
717
|
+
["subject_id_or_key", "type", "usage_period"],
|
|
718
|
+
["subject_id_or_key", "config", "type"],
|
|
719
|
+
["subject_id_or_key", "type"],
|
|
720
|
+
)
|
|
721
|
+
def override(
|
|
722
|
+
self,
|
|
723
|
+
entitlement_id_or_feature_key: str,
|
|
724
|
+
*,
|
|
725
|
+
subject_id_or_key: str,
|
|
726
|
+
type: Literal["metered"] | Literal["static"] | Literal["boolean"],
|
|
727
|
+
usage_period: entitlement_override_params.EntitlementMeteredCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
728
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
729
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
730
|
+
is_soft_limit: bool | NotGiven = NOT_GIVEN,
|
|
731
|
+
issue_after_reset: float | NotGiven = NOT_GIVEN,
|
|
732
|
+
issue_after_reset_priority: int | NotGiven = NOT_GIVEN,
|
|
733
|
+
is_unlimited: bool | NotGiven = NOT_GIVEN,
|
|
734
|
+
measure_usage_from: Union[Literal["CURRENT_PERIOD_START", "NOW"], Union[str, datetime]] | NotGiven = NOT_GIVEN,
|
|
735
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
736
|
+
preserve_overage_at_reset: bool | NotGiven = NOT_GIVEN,
|
|
737
|
+
config: str | NotGiven = NOT_GIVEN,
|
|
738
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
739
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
740
|
+
extra_headers: Headers | None = None,
|
|
741
|
+
extra_query: Query | None = None,
|
|
742
|
+
extra_body: Body | None = None,
|
|
743
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
744
|
+
) -> Entitlement:
|
|
745
|
+
if not subject_id_or_key:
|
|
746
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
747
|
+
if not entitlement_id_or_feature_key:
|
|
748
|
+
raise ValueError(
|
|
749
|
+
f"Expected a non-empty value for `entitlement_id_or_feature_key` but received {entitlement_id_or_feature_key!r}"
|
|
750
|
+
)
|
|
751
|
+
return cast(
|
|
752
|
+
Entitlement,
|
|
753
|
+
self._put(
|
|
754
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id_or_feature_key}/override",
|
|
755
|
+
body=maybe_transform(
|
|
756
|
+
{
|
|
757
|
+
"type": type,
|
|
758
|
+
"usage_period": usage_period,
|
|
759
|
+
"feature_id": feature_id,
|
|
760
|
+
"feature_key": feature_key,
|
|
761
|
+
"is_soft_limit": is_soft_limit,
|
|
762
|
+
"issue_after_reset": issue_after_reset,
|
|
763
|
+
"issue_after_reset_priority": issue_after_reset_priority,
|
|
764
|
+
"is_unlimited": is_unlimited,
|
|
765
|
+
"measure_usage_from": measure_usage_from,
|
|
766
|
+
"metadata": metadata,
|
|
767
|
+
"preserve_overage_at_reset": preserve_overage_at_reset,
|
|
768
|
+
"config": config,
|
|
769
|
+
},
|
|
770
|
+
entitlement_override_params.EntitlementOverrideParams,
|
|
771
|
+
),
|
|
772
|
+
options=make_request_options(
|
|
773
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
774
|
+
),
|
|
775
|
+
cast_to=cast(Any, Entitlement), # Union types cannot be passed in as arguments in the type system
|
|
776
|
+
),
|
|
777
|
+
)
|
|
778
|
+
|
|
779
|
+
def reset(
|
|
780
|
+
self,
|
|
781
|
+
entitlement_id: str,
|
|
782
|
+
*,
|
|
783
|
+
subject_id_or_key: str,
|
|
784
|
+
effective_at: Union[str, datetime] | NotGiven = NOT_GIVEN,
|
|
785
|
+
preserve_overage: bool | NotGiven = NOT_GIVEN,
|
|
786
|
+
retain_anchor: bool | NotGiven = NOT_GIVEN,
|
|
787
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
788
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
789
|
+
extra_headers: Headers | None = None,
|
|
790
|
+
extra_query: Query | None = None,
|
|
791
|
+
extra_body: Body | None = None,
|
|
792
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
793
|
+
) -> None:
|
|
794
|
+
"""
|
|
795
|
+
Reset marks the start of a new usage period for the entitlement and initiates
|
|
796
|
+
grant rollover. At the start of a period usage is zerod out and grants are
|
|
797
|
+
rolled over based on their rollover settings. It would typically be synced with
|
|
798
|
+
the subjects billing period to enforce usage based on their subscription.
|
|
799
|
+
|
|
800
|
+
Usage is automatically reset for metered entitlements based on their usage
|
|
801
|
+
period, but this endpoint allows to manually reset it at any time. When doing so
|
|
802
|
+
the period anchor of the entitlement can be changed if needed.
|
|
803
|
+
|
|
804
|
+
Args:
|
|
805
|
+
effective_at: The time at which the reset takes effect, defaults to now. The reset cannot be
|
|
806
|
+
in the future. The provided value is truncated to the minute due to how
|
|
807
|
+
historical meter data is stored.
|
|
808
|
+
|
|
809
|
+
preserve_overage: Determines whether the overage is preserved or forgiven, overriding the
|
|
810
|
+
entitlement's default behavior.
|
|
811
|
+
|
|
812
|
+
- If true, the overage is preserved.
|
|
813
|
+
- If false, the overage is forgiven.
|
|
814
|
+
|
|
815
|
+
retain_anchor: Determines whether the usage period anchor is retained or reset to the
|
|
816
|
+
effectiveAt time.
|
|
817
|
+
|
|
818
|
+
- If true, the usage period anchor is retained.
|
|
819
|
+
- If false, the usage period anchor is reset to the effectiveAt time.
|
|
820
|
+
|
|
821
|
+
extra_headers: Send extra headers
|
|
822
|
+
|
|
823
|
+
extra_query: Add additional query parameters to the request
|
|
824
|
+
|
|
825
|
+
extra_body: Add additional JSON properties to the request
|
|
826
|
+
|
|
827
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
828
|
+
"""
|
|
829
|
+
if not subject_id_or_key:
|
|
830
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
831
|
+
if not entitlement_id:
|
|
832
|
+
raise ValueError(f"Expected a non-empty value for `entitlement_id` but received {entitlement_id!r}")
|
|
833
|
+
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
|
|
834
|
+
return self._post(
|
|
835
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id}/reset",
|
|
836
|
+
body=maybe_transform(
|
|
837
|
+
{
|
|
838
|
+
"effective_at": effective_at,
|
|
839
|
+
"preserve_overage": preserve_overage,
|
|
840
|
+
"retain_anchor": retain_anchor,
|
|
841
|
+
},
|
|
842
|
+
entitlement_reset_params.EntitlementResetParams,
|
|
843
|
+
),
|
|
844
|
+
options=make_request_options(
|
|
845
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
846
|
+
),
|
|
847
|
+
cast_to=NoneType,
|
|
848
|
+
)
|
|
849
|
+
|
|
850
|
+
def value(
|
|
851
|
+
self,
|
|
852
|
+
entitlement_id_or_feature_key: str,
|
|
853
|
+
*,
|
|
854
|
+
subject_id_or_key: str,
|
|
855
|
+
time: Union[str, datetime] | NotGiven = NOT_GIVEN,
|
|
856
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
857
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
858
|
+
extra_headers: Headers | None = None,
|
|
859
|
+
extra_query: Query | None = None,
|
|
860
|
+
extra_body: Body | None = None,
|
|
861
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
862
|
+
) -> EntitlementValue:
|
|
863
|
+
"""This endpoint should be used for access checks and enforcement.
|
|
864
|
+
|
|
865
|
+
All entitlement
|
|
866
|
+
types share the hasAccess property in their value response, but multiple other
|
|
867
|
+
properties are returned based on the entitlement type.
|
|
868
|
+
|
|
869
|
+
For convenience reasons, /value works with both entitlementId and featureKey.
|
|
870
|
+
|
|
871
|
+
Args:
|
|
872
|
+
extra_headers: Send extra headers
|
|
873
|
+
|
|
874
|
+
extra_query: Add additional query parameters to the request
|
|
875
|
+
|
|
876
|
+
extra_body: Add additional JSON properties to the request
|
|
877
|
+
|
|
878
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
879
|
+
"""
|
|
880
|
+
if not subject_id_or_key:
|
|
881
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
882
|
+
if not entitlement_id_or_feature_key:
|
|
883
|
+
raise ValueError(
|
|
884
|
+
f"Expected a non-empty value for `entitlement_id_or_feature_key` but received {entitlement_id_or_feature_key!r}"
|
|
885
|
+
)
|
|
886
|
+
return self._get(
|
|
887
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id_or_feature_key}/value",
|
|
888
|
+
options=make_request_options(
|
|
889
|
+
extra_headers=extra_headers,
|
|
890
|
+
extra_query=extra_query,
|
|
891
|
+
extra_body=extra_body,
|
|
892
|
+
timeout=timeout,
|
|
893
|
+
query=maybe_transform({"time": time}, entitlement_value_params.EntitlementValueParams),
|
|
894
|
+
),
|
|
895
|
+
cast_to=EntitlementValue,
|
|
896
|
+
)
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
class AsyncEntitlementsResource(AsyncAPIResource):
|
|
900
|
+
@cached_property
|
|
901
|
+
def grants(self) -> AsyncGrantsResource:
|
|
902
|
+
return AsyncGrantsResource(self._client)
|
|
903
|
+
|
|
904
|
+
@cached_property
|
|
905
|
+
def with_raw_response(self) -> AsyncEntitlementsResourceWithRawResponse:
|
|
906
|
+
"""
|
|
907
|
+
This property can be used as a prefix for any HTTP method call to return the
|
|
908
|
+
the raw response object instead of the parsed content.
|
|
909
|
+
|
|
910
|
+
For more information, see https://www.github.com/openmeterio/openmeter-python#accessing-raw-response-data-eg-headers
|
|
911
|
+
"""
|
|
912
|
+
return AsyncEntitlementsResourceWithRawResponse(self)
|
|
913
|
+
|
|
914
|
+
@cached_property
|
|
915
|
+
def with_streaming_response(self) -> AsyncEntitlementsResourceWithStreamingResponse:
|
|
916
|
+
"""
|
|
917
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
918
|
+
|
|
919
|
+
For more information, see https://www.github.com/openmeterio/openmeter-python#with_streaming_response
|
|
920
|
+
"""
|
|
921
|
+
return AsyncEntitlementsResourceWithStreamingResponse(self)
|
|
922
|
+
|
|
923
|
+
@overload
|
|
924
|
+
async def create(
|
|
925
|
+
self,
|
|
926
|
+
subject_id_or_key: str,
|
|
927
|
+
*,
|
|
928
|
+
type: Literal["metered"],
|
|
929
|
+
usage_period: entitlement_create_params.EntitlementMeteredCreateInputsUsagePeriod,
|
|
930
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
931
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
932
|
+
is_soft_limit: bool | NotGiven = NOT_GIVEN,
|
|
933
|
+
issue_after_reset: float | NotGiven = NOT_GIVEN,
|
|
934
|
+
issue_after_reset_priority: int | NotGiven = NOT_GIVEN,
|
|
935
|
+
is_unlimited: bool | NotGiven = NOT_GIVEN,
|
|
936
|
+
measure_usage_from: Union[Literal["CURRENT_PERIOD_START", "NOW"], Union[str, datetime]] | NotGiven = NOT_GIVEN,
|
|
937
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
938
|
+
preserve_overage_at_reset: bool | NotGiven = NOT_GIVEN,
|
|
939
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
940
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
941
|
+
extra_headers: Headers | None = None,
|
|
942
|
+
extra_query: Query | None = None,
|
|
943
|
+
extra_body: Body | None = None,
|
|
944
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
945
|
+
) -> Entitlement:
|
|
946
|
+
"""OpenMeter has three types of entitlements: metered, boolean, and static.
|
|
947
|
+
|
|
948
|
+
The
|
|
949
|
+
type property determines the type of entitlement. The underlying feature has to
|
|
950
|
+
be compatible with the entitlement type specified in the request (e.g., a
|
|
951
|
+
metered entitlement needs a feature associated with a meter).
|
|
952
|
+
|
|
953
|
+
- Boolean entitlements define static feature access, e.g. "Can use SSO
|
|
954
|
+
authentication".
|
|
955
|
+
- Static entitlements let you pass along a configuration while granting access,
|
|
956
|
+
e.g. "Using this feature with X Y settings" (passed in the config).
|
|
957
|
+
- Metered entitlements have many use cases, from setting up usage-based access
|
|
958
|
+
to implementing complex credit systems. Example: The customer can use 10000 AI
|
|
959
|
+
tokens during the usage period of the entitlement.
|
|
960
|
+
|
|
961
|
+
A given subject can only have one active (non-deleted) entitlement per
|
|
962
|
+
featureKey. If you try to create a new entitlement for a featureKey that already
|
|
963
|
+
has an active entitlement, the request will fail with a 409 error.
|
|
964
|
+
|
|
965
|
+
Once an entitlement is created you cannot modify it, only delete it.
|
|
966
|
+
|
|
967
|
+
Args:
|
|
968
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
969
|
+
|
|
970
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
971
|
+
required.
|
|
972
|
+
|
|
973
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
974
|
+
required.
|
|
975
|
+
|
|
976
|
+
is_soft_limit: If softLimit=true the subject can use the feature even if the entitlement is
|
|
977
|
+
exhausted, hasAccess will always be true.
|
|
978
|
+
|
|
979
|
+
issue_after_reset: You can grant usage automatically alongside the entitlement, the example
|
|
980
|
+
scenario would be creating a starting balance. If an amount is specified here, a
|
|
981
|
+
grant will be created alongside the entitlement with the specified amount. That
|
|
982
|
+
grant will have it's rollover settings configured in a way that after each reset
|
|
983
|
+
operation, the balance will return the original amount specified here. Manually
|
|
984
|
+
creating such a grant would mean having the "amount", "minRolloverAmount", and
|
|
985
|
+
"maxRolloverAmount" fields all be the same.
|
|
986
|
+
|
|
987
|
+
issue_after_reset_priority: Defines the grant priority for the default grant.
|
|
988
|
+
|
|
989
|
+
is_unlimited: Deprecated, ignored by the backend. Please use isSoftLimit instead; this field
|
|
990
|
+
will be removed in the future.
|
|
991
|
+
|
|
992
|
+
measure_usage_from: Measure usage from
|
|
993
|
+
|
|
994
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
995
|
+
about a resource.
|
|
996
|
+
|
|
997
|
+
preserve_overage_at_reset: If true, the overage is preserved at reset. If false, the usage is reset to 0.
|
|
998
|
+
|
|
999
|
+
extra_headers: Send extra headers
|
|
1000
|
+
|
|
1001
|
+
extra_query: Add additional query parameters to the request
|
|
1002
|
+
|
|
1003
|
+
extra_body: Add additional JSON properties to the request
|
|
1004
|
+
|
|
1005
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1006
|
+
"""
|
|
1007
|
+
...
|
|
1008
|
+
|
|
1009
|
+
@overload
|
|
1010
|
+
async def create(
|
|
1011
|
+
self,
|
|
1012
|
+
subject_id_or_key: str,
|
|
1013
|
+
*,
|
|
1014
|
+
config: str,
|
|
1015
|
+
type: Literal["static"],
|
|
1016
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
1017
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
1018
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
1019
|
+
usage_period: entitlement_create_params.EntitlementStaticCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
1020
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1021
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1022
|
+
extra_headers: Headers | None = None,
|
|
1023
|
+
extra_query: Query | None = None,
|
|
1024
|
+
extra_body: Body | None = None,
|
|
1025
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1026
|
+
) -> Entitlement:
|
|
1027
|
+
"""OpenMeter has three types of entitlements: metered, boolean, and static.
|
|
1028
|
+
|
|
1029
|
+
The
|
|
1030
|
+
type property determines the type of entitlement. The underlying feature has to
|
|
1031
|
+
be compatible with the entitlement type specified in the request (e.g., a
|
|
1032
|
+
metered entitlement needs a feature associated with a meter).
|
|
1033
|
+
|
|
1034
|
+
- Boolean entitlements define static feature access, e.g. "Can use SSO
|
|
1035
|
+
authentication".
|
|
1036
|
+
- Static entitlements let you pass along a configuration while granting access,
|
|
1037
|
+
e.g. "Using this feature with X Y settings" (passed in the config).
|
|
1038
|
+
- Metered entitlements have many use cases, from setting up usage-based access
|
|
1039
|
+
to implementing complex credit systems. Example: The customer can use 10000 AI
|
|
1040
|
+
tokens during the usage period of the entitlement.
|
|
1041
|
+
|
|
1042
|
+
A given subject can only have one active (non-deleted) entitlement per
|
|
1043
|
+
featureKey. If you try to create a new entitlement for a featureKey that already
|
|
1044
|
+
has an active entitlement, the request will fail with a 409 error.
|
|
1045
|
+
|
|
1046
|
+
Once an entitlement is created you cannot modify it, only delete it.
|
|
1047
|
+
|
|
1048
|
+
Args:
|
|
1049
|
+
config: The JSON parsable config of the entitlement. This value is also returned when
|
|
1050
|
+
checking entitlement access and it is useful for configuring fine-grained access
|
|
1051
|
+
settings to the feature, implemented in your own system. Has to be an object.
|
|
1052
|
+
|
|
1053
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
1054
|
+
required.
|
|
1055
|
+
|
|
1056
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
1057
|
+
required.
|
|
1058
|
+
|
|
1059
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
1060
|
+
about a resource.
|
|
1061
|
+
|
|
1062
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
1063
|
+
|
|
1064
|
+
extra_headers: Send extra headers
|
|
1065
|
+
|
|
1066
|
+
extra_query: Add additional query parameters to the request
|
|
1067
|
+
|
|
1068
|
+
extra_body: Add additional JSON properties to the request
|
|
1069
|
+
|
|
1070
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1071
|
+
"""
|
|
1072
|
+
...
|
|
1073
|
+
|
|
1074
|
+
@overload
|
|
1075
|
+
async def create(
|
|
1076
|
+
self,
|
|
1077
|
+
subject_id_or_key: str,
|
|
1078
|
+
*,
|
|
1079
|
+
type: Literal["boolean"],
|
|
1080
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
1081
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
1082
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
1083
|
+
usage_period: entitlement_create_params.EntitlementBooleanCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
1084
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1085
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1086
|
+
extra_headers: Headers | None = None,
|
|
1087
|
+
extra_query: Query | None = None,
|
|
1088
|
+
extra_body: Body | None = None,
|
|
1089
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1090
|
+
) -> Entitlement:
|
|
1091
|
+
"""OpenMeter has three types of entitlements: metered, boolean, and static.
|
|
1092
|
+
|
|
1093
|
+
The
|
|
1094
|
+
type property determines the type of entitlement. The underlying feature has to
|
|
1095
|
+
be compatible with the entitlement type specified in the request (e.g., a
|
|
1096
|
+
metered entitlement needs a feature associated with a meter).
|
|
1097
|
+
|
|
1098
|
+
- Boolean entitlements define static feature access, e.g. "Can use SSO
|
|
1099
|
+
authentication".
|
|
1100
|
+
- Static entitlements let you pass along a configuration while granting access,
|
|
1101
|
+
e.g. "Using this feature with X Y settings" (passed in the config).
|
|
1102
|
+
- Metered entitlements have many use cases, from setting up usage-based access
|
|
1103
|
+
to implementing complex credit systems. Example: The customer can use 10000 AI
|
|
1104
|
+
tokens during the usage period of the entitlement.
|
|
1105
|
+
|
|
1106
|
+
A given subject can only have one active (non-deleted) entitlement per
|
|
1107
|
+
featureKey. If you try to create a new entitlement for a featureKey that already
|
|
1108
|
+
has an active entitlement, the request will fail with a 409 error.
|
|
1109
|
+
|
|
1110
|
+
Once an entitlement is created you cannot modify it, only delete it.
|
|
1111
|
+
|
|
1112
|
+
Args:
|
|
1113
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
1114
|
+
required.
|
|
1115
|
+
|
|
1116
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
1117
|
+
required.
|
|
1118
|
+
|
|
1119
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
1120
|
+
about a resource.
|
|
1121
|
+
|
|
1122
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
1123
|
+
|
|
1124
|
+
extra_headers: Send extra headers
|
|
1125
|
+
|
|
1126
|
+
extra_query: Add additional query parameters to the request
|
|
1127
|
+
|
|
1128
|
+
extra_body: Add additional JSON properties to the request
|
|
1129
|
+
|
|
1130
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1131
|
+
"""
|
|
1132
|
+
...
|
|
1133
|
+
|
|
1134
|
+
@required_args(["type", "usage_period"], ["config", "type"], ["type"])
|
|
1135
|
+
async def create(
|
|
1136
|
+
self,
|
|
1137
|
+
subject_id_or_key: str,
|
|
1138
|
+
*,
|
|
1139
|
+
type: Literal["metered"] | Literal["static"] | Literal["boolean"],
|
|
1140
|
+
usage_period: entitlement_create_params.EntitlementMeteredCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
1141
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
1142
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
1143
|
+
is_soft_limit: bool | NotGiven = NOT_GIVEN,
|
|
1144
|
+
issue_after_reset: float | NotGiven = NOT_GIVEN,
|
|
1145
|
+
issue_after_reset_priority: int | NotGiven = NOT_GIVEN,
|
|
1146
|
+
is_unlimited: bool | NotGiven = NOT_GIVEN,
|
|
1147
|
+
measure_usage_from: Union[Literal["CURRENT_PERIOD_START", "NOW"], Union[str, datetime]] | NotGiven = NOT_GIVEN,
|
|
1148
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
1149
|
+
preserve_overage_at_reset: bool | NotGiven = NOT_GIVEN,
|
|
1150
|
+
config: str | NotGiven = NOT_GIVEN,
|
|
1151
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1152
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1153
|
+
extra_headers: Headers | None = None,
|
|
1154
|
+
extra_query: Query | None = None,
|
|
1155
|
+
extra_body: Body | None = None,
|
|
1156
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1157
|
+
) -> Entitlement:
|
|
1158
|
+
if not subject_id_or_key:
|
|
1159
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
1160
|
+
return cast(
|
|
1161
|
+
Entitlement,
|
|
1162
|
+
await self._post(
|
|
1163
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements",
|
|
1164
|
+
body=await async_maybe_transform(
|
|
1165
|
+
{
|
|
1166
|
+
"type": type,
|
|
1167
|
+
"usage_period": usage_period,
|
|
1168
|
+
"feature_id": feature_id,
|
|
1169
|
+
"feature_key": feature_key,
|
|
1170
|
+
"is_soft_limit": is_soft_limit,
|
|
1171
|
+
"issue_after_reset": issue_after_reset,
|
|
1172
|
+
"issue_after_reset_priority": issue_after_reset_priority,
|
|
1173
|
+
"is_unlimited": is_unlimited,
|
|
1174
|
+
"measure_usage_from": measure_usage_from,
|
|
1175
|
+
"metadata": metadata,
|
|
1176
|
+
"preserve_overage_at_reset": preserve_overage_at_reset,
|
|
1177
|
+
"config": config,
|
|
1178
|
+
},
|
|
1179
|
+
entitlement_create_params.EntitlementCreateParams,
|
|
1180
|
+
),
|
|
1181
|
+
options=make_request_options(
|
|
1182
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
1183
|
+
),
|
|
1184
|
+
cast_to=cast(Any, Entitlement), # Union types cannot be passed in as arguments in the type system
|
|
1185
|
+
),
|
|
1186
|
+
)
|
|
1187
|
+
|
|
1188
|
+
async def retrieve(
|
|
1189
|
+
self,
|
|
1190
|
+
entitlement_id: str,
|
|
1191
|
+
*,
|
|
1192
|
+
subject_id_or_key: str,
|
|
1193
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1194
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1195
|
+
extra_headers: Headers | None = None,
|
|
1196
|
+
extra_query: Query | None = None,
|
|
1197
|
+
extra_body: Body | None = None,
|
|
1198
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1199
|
+
) -> Entitlement:
|
|
1200
|
+
"""Get entitlement by id.
|
|
1201
|
+
|
|
1202
|
+
For checking entitlement access, use the /value endpoint
|
|
1203
|
+
instead.
|
|
1204
|
+
|
|
1205
|
+
Args:
|
|
1206
|
+
extra_headers: Send extra headers
|
|
1207
|
+
|
|
1208
|
+
extra_query: Add additional query parameters to the request
|
|
1209
|
+
|
|
1210
|
+
extra_body: Add additional JSON properties to the request
|
|
1211
|
+
|
|
1212
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1213
|
+
"""
|
|
1214
|
+
if not subject_id_or_key:
|
|
1215
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
1216
|
+
if not entitlement_id:
|
|
1217
|
+
raise ValueError(f"Expected a non-empty value for `entitlement_id` but received {entitlement_id!r}")
|
|
1218
|
+
return cast(
|
|
1219
|
+
Entitlement,
|
|
1220
|
+
await self._get(
|
|
1221
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id}",
|
|
1222
|
+
options=make_request_options(
|
|
1223
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
1224
|
+
),
|
|
1225
|
+
cast_to=cast(Any, Entitlement), # Union types cannot be passed in as arguments in the type system
|
|
1226
|
+
),
|
|
1227
|
+
)
|
|
1228
|
+
|
|
1229
|
+
async def list(
|
|
1230
|
+
self,
|
|
1231
|
+
subject_id_or_key: str,
|
|
1232
|
+
*,
|
|
1233
|
+
include_deleted: bool | NotGiven = NOT_GIVEN,
|
|
1234
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1235
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1236
|
+
extra_headers: Headers | None = None,
|
|
1237
|
+
extra_query: Query | None = None,
|
|
1238
|
+
extra_body: Body | None = None,
|
|
1239
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1240
|
+
) -> EntitlementListResponse:
|
|
1241
|
+
"""List all entitlements for a subject.
|
|
1242
|
+
|
|
1243
|
+
For checking entitlement access, use the
|
|
1244
|
+
/value endpoint instead.
|
|
1245
|
+
|
|
1246
|
+
Args:
|
|
1247
|
+
extra_headers: Send extra headers
|
|
1248
|
+
|
|
1249
|
+
extra_query: Add additional query parameters to the request
|
|
1250
|
+
|
|
1251
|
+
extra_body: Add additional JSON properties to the request
|
|
1252
|
+
|
|
1253
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1254
|
+
"""
|
|
1255
|
+
if not subject_id_or_key:
|
|
1256
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
1257
|
+
return await self._get(
|
|
1258
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements",
|
|
1259
|
+
options=make_request_options(
|
|
1260
|
+
extra_headers=extra_headers,
|
|
1261
|
+
extra_query=extra_query,
|
|
1262
|
+
extra_body=extra_body,
|
|
1263
|
+
timeout=timeout,
|
|
1264
|
+
query=await async_maybe_transform(
|
|
1265
|
+
{"include_deleted": include_deleted}, entitlement_list_params.EntitlementListParams
|
|
1266
|
+
),
|
|
1267
|
+
),
|
|
1268
|
+
cast_to=EntitlementListResponse,
|
|
1269
|
+
)
|
|
1270
|
+
|
|
1271
|
+
async def delete(
|
|
1272
|
+
self,
|
|
1273
|
+
entitlement_id: str,
|
|
1274
|
+
*,
|
|
1275
|
+
subject_id_or_key: str,
|
|
1276
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1277
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1278
|
+
extra_headers: Headers | None = None,
|
|
1279
|
+
extra_query: Query | None = None,
|
|
1280
|
+
extra_body: Body | None = None,
|
|
1281
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1282
|
+
) -> None:
|
|
1283
|
+
"""Deleting an entitlement revokes access to the associated feature.
|
|
1284
|
+
|
|
1285
|
+
As a single
|
|
1286
|
+
subject can only have one entitlement per featureKey, when "migrating" features
|
|
1287
|
+
you have to delete the old entitlements as well. As access and status checks can
|
|
1288
|
+
be historical queries, deleting an entitlement populates the deletedAt
|
|
1289
|
+
timestamp. When queried for a time before that, the entitlement is still
|
|
1290
|
+
considered active, you cannot have retroactive changes to access, which is
|
|
1291
|
+
important for, among other things, auditing.
|
|
1292
|
+
|
|
1293
|
+
Args:
|
|
1294
|
+
extra_headers: Send extra headers
|
|
1295
|
+
|
|
1296
|
+
extra_query: Add additional query parameters to the request
|
|
1297
|
+
|
|
1298
|
+
extra_body: Add additional JSON properties to the request
|
|
1299
|
+
|
|
1300
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1301
|
+
"""
|
|
1302
|
+
if not subject_id_or_key:
|
|
1303
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
1304
|
+
if not entitlement_id:
|
|
1305
|
+
raise ValueError(f"Expected a non-empty value for `entitlement_id` but received {entitlement_id!r}")
|
|
1306
|
+
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
|
|
1307
|
+
return await self._delete(
|
|
1308
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id}",
|
|
1309
|
+
options=make_request_options(
|
|
1310
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
1311
|
+
),
|
|
1312
|
+
cast_to=NoneType,
|
|
1313
|
+
)
|
|
1314
|
+
|
|
1315
|
+
async def history(
|
|
1316
|
+
self,
|
|
1317
|
+
entitlement_id: str,
|
|
1318
|
+
*,
|
|
1319
|
+
subject_id_or_key: str,
|
|
1320
|
+
window_size: Literal["MINUTE", "HOUR", "DAY"],
|
|
1321
|
+
from_: Union[str, datetime] | NotGiven = NOT_GIVEN,
|
|
1322
|
+
to: Union[str, datetime] | NotGiven = NOT_GIVEN,
|
|
1323
|
+
window_time_zone: str | NotGiven = NOT_GIVEN,
|
|
1324
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1325
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1326
|
+
extra_headers: Headers | None = None,
|
|
1327
|
+
extra_query: Query | None = None,
|
|
1328
|
+
extra_body: Body | None = None,
|
|
1329
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1330
|
+
) -> EntitlementHistoryResponse:
|
|
1331
|
+
"""Returns historical balance and usage data for the entitlement.
|
|
1332
|
+
|
|
1333
|
+
The queried
|
|
1334
|
+
history can span accross multiple reset events.
|
|
1335
|
+
|
|
1336
|
+
BurndownHistory returns a continous history of segments, where the segments are
|
|
1337
|
+
seperated by events that changed either the grant burndown priority or the usage
|
|
1338
|
+
period.
|
|
1339
|
+
|
|
1340
|
+
WindowedHistory returns windowed usage data for the period enriched with balance
|
|
1341
|
+
information and the list of grants that were being burnt down in that window.
|
|
1342
|
+
|
|
1343
|
+
Args:
|
|
1344
|
+
window_size: Windowsize
|
|
1345
|
+
|
|
1346
|
+
from_: Start of time range to query entitlement: date-time in RFC 3339 format. Defaults
|
|
1347
|
+
to the last reset. Gets truncated to the granularity of the underlying meter.
|
|
1348
|
+
|
|
1349
|
+
to: End of time range to query entitlement: date-time in RFC 3339 format. Defaults
|
|
1350
|
+
to now. If not now then gets truncated to the granularity of the underlying
|
|
1351
|
+
meter.
|
|
1352
|
+
|
|
1353
|
+
window_time_zone: The timezone used when calculating the windows.
|
|
1354
|
+
|
|
1355
|
+
extra_headers: Send extra headers
|
|
1356
|
+
|
|
1357
|
+
extra_query: Add additional query parameters to the request
|
|
1358
|
+
|
|
1359
|
+
extra_body: Add additional JSON properties to the request
|
|
1360
|
+
|
|
1361
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1362
|
+
"""
|
|
1363
|
+
if not subject_id_or_key:
|
|
1364
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
1365
|
+
if not entitlement_id:
|
|
1366
|
+
raise ValueError(f"Expected a non-empty value for `entitlement_id` but received {entitlement_id!r}")
|
|
1367
|
+
return await self._get(
|
|
1368
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id}/history",
|
|
1369
|
+
options=make_request_options(
|
|
1370
|
+
extra_headers=extra_headers,
|
|
1371
|
+
extra_query=extra_query,
|
|
1372
|
+
extra_body=extra_body,
|
|
1373
|
+
timeout=timeout,
|
|
1374
|
+
query=await async_maybe_transform(
|
|
1375
|
+
{
|
|
1376
|
+
"window_size": window_size,
|
|
1377
|
+
"from_": from_,
|
|
1378
|
+
"to": to,
|
|
1379
|
+
"window_time_zone": window_time_zone,
|
|
1380
|
+
},
|
|
1381
|
+
entitlement_history_params.EntitlementHistoryParams,
|
|
1382
|
+
),
|
|
1383
|
+
),
|
|
1384
|
+
cast_to=EntitlementHistoryResponse,
|
|
1385
|
+
)
|
|
1386
|
+
|
|
1387
|
+
@overload
|
|
1388
|
+
async def override(
|
|
1389
|
+
self,
|
|
1390
|
+
entitlement_id_or_feature_key: str,
|
|
1391
|
+
*,
|
|
1392
|
+
subject_id_or_key: str,
|
|
1393
|
+
type: Literal["metered"],
|
|
1394
|
+
usage_period: entitlement_override_params.EntitlementMeteredCreateInputsUsagePeriod,
|
|
1395
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
1396
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
1397
|
+
is_soft_limit: bool | NotGiven = NOT_GIVEN,
|
|
1398
|
+
issue_after_reset: float | NotGiven = NOT_GIVEN,
|
|
1399
|
+
issue_after_reset_priority: int | NotGiven = NOT_GIVEN,
|
|
1400
|
+
is_unlimited: bool | NotGiven = NOT_GIVEN,
|
|
1401
|
+
measure_usage_from: Union[Literal["CURRENT_PERIOD_START", "NOW"], Union[str, datetime]] | NotGiven = NOT_GIVEN,
|
|
1402
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
1403
|
+
preserve_overage_at_reset: bool | NotGiven = NOT_GIVEN,
|
|
1404
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1405
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1406
|
+
extra_headers: Headers | None = None,
|
|
1407
|
+
extra_query: Query | None = None,
|
|
1408
|
+
extra_body: Body | None = None,
|
|
1409
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1410
|
+
) -> Entitlement:
|
|
1411
|
+
"""
|
|
1412
|
+
Overriding an entitlement creates a new entitlement from the provided inputs and
|
|
1413
|
+
soft deletes the previous entitlement for the provided subject-feature pair. If
|
|
1414
|
+
the previous entitlement is already deleted or otherwise doesnt exist, the
|
|
1415
|
+
override will fail.
|
|
1416
|
+
|
|
1417
|
+
This endpoint is useful for upgrades, downgrades, or other changes to
|
|
1418
|
+
entitlements that require a new entitlement to be created with zero downtime.
|
|
1419
|
+
|
|
1420
|
+
Args:
|
|
1421
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
1422
|
+
|
|
1423
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
1424
|
+
required.
|
|
1425
|
+
|
|
1426
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
1427
|
+
required.
|
|
1428
|
+
|
|
1429
|
+
is_soft_limit: If softLimit=true the subject can use the feature even if the entitlement is
|
|
1430
|
+
exhausted, hasAccess will always be true.
|
|
1431
|
+
|
|
1432
|
+
issue_after_reset: You can grant usage automatically alongside the entitlement, the example
|
|
1433
|
+
scenario would be creating a starting balance. If an amount is specified here, a
|
|
1434
|
+
grant will be created alongside the entitlement with the specified amount. That
|
|
1435
|
+
grant will have it's rollover settings configured in a way that after each reset
|
|
1436
|
+
operation, the balance will return the original amount specified here. Manually
|
|
1437
|
+
creating such a grant would mean having the "amount", "minRolloverAmount", and
|
|
1438
|
+
"maxRolloverAmount" fields all be the same.
|
|
1439
|
+
|
|
1440
|
+
issue_after_reset_priority: Defines the grant priority for the default grant.
|
|
1441
|
+
|
|
1442
|
+
is_unlimited: Deprecated, ignored by the backend. Please use isSoftLimit instead; this field
|
|
1443
|
+
will be removed in the future.
|
|
1444
|
+
|
|
1445
|
+
measure_usage_from: Measure usage from
|
|
1446
|
+
|
|
1447
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
1448
|
+
about a resource.
|
|
1449
|
+
|
|
1450
|
+
preserve_overage_at_reset: If true, the overage is preserved at reset. If false, the usage is reset to 0.
|
|
1451
|
+
|
|
1452
|
+
extra_headers: Send extra headers
|
|
1453
|
+
|
|
1454
|
+
extra_query: Add additional query parameters to the request
|
|
1455
|
+
|
|
1456
|
+
extra_body: Add additional JSON properties to the request
|
|
1457
|
+
|
|
1458
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1459
|
+
"""
|
|
1460
|
+
...
|
|
1461
|
+
|
|
1462
|
+
@overload
|
|
1463
|
+
async def override(
|
|
1464
|
+
self,
|
|
1465
|
+
entitlement_id_or_feature_key: str,
|
|
1466
|
+
*,
|
|
1467
|
+
subject_id_or_key: str,
|
|
1468
|
+
config: str,
|
|
1469
|
+
type: Literal["static"],
|
|
1470
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
1471
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
1472
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
1473
|
+
usage_period: entitlement_override_params.EntitlementStaticCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
1474
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1475
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1476
|
+
extra_headers: Headers | None = None,
|
|
1477
|
+
extra_query: Query | None = None,
|
|
1478
|
+
extra_body: Body | None = None,
|
|
1479
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1480
|
+
) -> Entitlement:
|
|
1481
|
+
"""
|
|
1482
|
+
Overriding an entitlement creates a new entitlement from the provided inputs and
|
|
1483
|
+
soft deletes the previous entitlement for the provided subject-feature pair. If
|
|
1484
|
+
the previous entitlement is already deleted or otherwise doesnt exist, the
|
|
1485
|
+
override will fail.
|
|
1486
|
+
|
|
1487
|
+
This endpoint is useful for upgrades, downgrades, or other changes to
|
|
1488
|
+
entitlements that require a new entitlement to be created with zero downtime.
|
|
1489
|
+
|
|
1490
|
+
Args:
|
|
1491
|
+
config: The JSON parsable config of the entitlement. This value is also returned when
|
|
1492
|
+
checking entitlement access and it is useful for configuring fine-grained access
|
|
1493
|
+
settings to the feature, implemented in your own system. Has to be an object.
|
|
1494
|
+
|
|
1495
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
1496
|
+
required.
|
|
1497
|
+
|
|
1498
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
1499
|
+
required.
|
|
1500
|
+
|
|
1501
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
1502
|
+
about a resource.
|
|
1503
|
+
|
|
1504
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
1505
|
+
|
|
1506
|
+
extra_headers: Send extra headers
|
|
1507
|
+
|
|
1508
|
+
extra_query: Add additional query parameters to the request
|
|
1509
|
+
|
|
1510
|
+
extra_body: Add additional JSON properties to the request
|
|
1511
|
+
|
|
1512
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1513
|
+
"""
|
|
1514
|
+
...
|
|
1515
|
+
|
|
1516
|
+
@overload
|
|
1517
|
+
async def override(
|
|
1518
|
+
self,
|
|
1519
|
+
entitlement_id_or_feature_key: str,
|
|
1520
|
+
*,
|
|
1521
|
+
subject_id_or_key: str,
|
|
1522
|
+
type: Literal["boolean"],
|
|
1523
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
1524
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
1525
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
1526
|
+
usage_period: entitlement_override_params.EntitlementBooleanCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
1527
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1528
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1529
|
+
extra_headers: Headers | None = None,
|
|
1530
|
+
extra_query: Query | None = None,
|
|
1531
|
+
extra_body: Body | None = None,
|
|
1532
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1533
|
+
) -> Entitlement:
|
|
1534
|
+
"""
|
|
1535
|
+
Overriding an entitlement creates a new entitlement from the provided inputs and
|
|
1536
|
+
soft deletes the previous entitlement for the provided subject-feature pair. If
|
|
1537
|
+
the previous entitlement is already deleted or otherwise doesnt exist, the
|
|
1538
|
+
override will fail.
|
|
1539
|
+
|
|
1540
|
+
This endpoint is useful for upgrades, downgrades, or other changes to
|
|
1541
|
+
entitlements that require a new entitlement to be created with zero downtime.
|
|
1542
|
+
|
|
1543
|
+
Args:
|
|
1544
|
+
feature_id: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
1545
|
+
required.
|
|
1546
|
+
|
|
1547
|
+
feature_key: The feature the subject is entitled to use. Either featureKey or featureId is
|
|
1548
|
+
required.
|
|
1549
|
+
|
|
1550
|
+
metadata: Set of key-value pairs. Metadata can be used to store additional information
|
|
1551
|
+
about a resource.
|
|
1552
|
+
|
|
1553
|
+
usage_period: Recurring period with an interval and an anchor.
|
|
1554
|
+
|
|
1555
|
+
extra_headers: Send extra headers
|
|
1556
|
+
|
|
1557
|
+
extra_query: Add additional query parameters to the request
|
|
1558
|
+
|
|
1559
|
+
extra_body: Add additional JSON properties to the request
|
|
1560
|
+
|
|
1561
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1562
|
+
"""
|
|
1563
|
+
...
|
|
1564
|
+
|
|
1565
|
+
@required_args(
|
|
1566
|
+
["subject_id_or_key", "type", "usage_period"],
|
|
1567
|
+
["subject_id_or_key", "config", "type"],
|
|
1568
|
+
["subject_id_or_key", "type"],
|
|
1569
|
+
)
|
|
1570
|
+
async def override(
|
|
1571
|
+
self,
|
|
1572
|
+
entitlement_id_or_feature_key: str,
|
|
1573
|
+
*,
|
|
1574
|
+
subject_id_or_key: str,
|
|
1575
|
+
type: Literal["metered"] | Literal["static"] | Literal["boolean"],
|
|
1576
|
+
usage_period: entitlement_override_params.EntitlementMeteredCreateInputsUsagePeriod | NotGiven = NOT_GIVEN,
|
|
1577
|
+
feature_id: str | NotGiven = NOT_GIVEN,
|
|
1578
|
+
feature_key: str | NotGiven = NOT_GIVEN,
|
|
1579
|
+
is_soft_limit: bool | NotGiven = NOT_GIVEN,
|
|
1580
|
+
issue_after_reset: float | NotGiven = NOT_GIVEN,
|
|
1581
|
+
issue_after_reset_priority: int | NotGiven = NOT_GIVEN,
|
|
1582
|
+
is_unlimited: bool | NotGiven = NOT_GIVEN,
|
|
1583
|
+
measure_usage_from: Union[Literal["CURRENT_PERIOD_START", "NOW"], Union[str, datetime]] | NotGiven = NOT_GIVEN,
|
|
1584
|
+
metadata: Dict[str, str] | NotGiven = NOT_GIVEN,
|
|
1585
|
+
preserve_overage_at_reset: bool | NotGiven = NOT_GIVEN,
|
|
1586
|
+
config: str | NotGiven = NOT_GIVEN,
|
|
1587
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1588
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1589
|
+
extra_headers: Headers | None = None,
|
|
1590
|
+
extra_query: Query | None = None,
|
|
1591
|
+
extra_body: Body | None = None,
|
|
1592
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1593
|
+
) -> Entitlement:
|
|
1594
|
+
if not subject_id_or_key:
|
|
1595
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
1596
|
+
if not entitlement_id_or_feature_key:
|
|
1597
|
+
raise ValueError(
|
|
1598
|
+
f"Expected a non-empty value for `entitlement_id_or_feature_key` but received {entitlement_id_or_feature_key!r}"
|
|
1599
|
+
)
|
|
1600
|
+
return cast(
|
|
1601
|
+
Entitlement,
|
|
1602
|
+
await self._put(
|
|
1603
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id_or_feature_key}/override",
|
|
1604
|
+
body=await async_maybe_transform(
|
|
1605
|
+
{
|
|
1606
|
+
"type": type,
|
|
1607
|
+
"usage_period": usage_period,
|
|
1608
|
+
"feature_id": feature_id,
|
|
1609
|
+
"feature_key": feature_key,
|
|
1610
|
+
"is_soft_limit": is_soft_limit,
|
|
1611
|
+
"issue_after_reset": issue_after_reset,
|
|
1612
|
+
"issue_after_reset_priority": issue_after_reset_priority,
|
|
1613
|
+
"is_unlimited": is_unlimited,
|
|
1614
|
+
"measure_usage_from": measure_usage_from,
|
|
1615
|
+
"metadata": metadata,
|
|
1616
|
+
"preserve_overage_at_reset": preserve_overage_at_reset,
|
|
1617
|
+
"config": config,
|
|
1618
|
+
},
|
|
1619
|
+
entitlement_override_params.EntitlementOverrideParams,
|
|
1620
|
+
),
|
|
1621
|
+
options=make_request_options(
|
|
1622
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
1623
|
+
),
|
|
1624
|
+
cast_to=cast(Any, Entitlement), # Union types cannot be passed in as arguments in the type system
|
|
1625
|
+
),
|
|
1626
|
+
)
|
|
1627
|
+
|
|
1628
|
+
async def reset(
|
|
1629
|
+
self,
|
|
1630
|
+
entitlement_id: str,
|
|
1631
|
+
*,
|
|
1632
|
+
subject_id_or_key: str,
|
|
1633
|
+
effective_at: Union[str, datetime] | NotGiven = NOT_GIVEN,
|
|
1634
|
+
preserve_overage: bool | NotGiven = NOT_GIVEN,
|
|
1635
|
+
retain_anchor: bool | NotGiven = NOT_GIVEN,
|
|
1636
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1637
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1638
|
+
extra_headers: Headers | None = None,
|
|
1639
|
+
extra_query: Query | None = None,
|
|
1640
|
+
extra_body: Body | None = None,
|
|
1641
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1642
|
+
) -> None:
|
|
1643
|
+
"""
|
|
1644
|
+
Reset marks the start of a new usage period for the entitlement and initiates
|
|
1645
|
+
grant rollover. At the start of a period usage is zerod out and grants are
|
|
1646
|
+
rolled over based on their rollover settings. It would typically be synced with
|
|
1647
|
+
the subjects billing period to enforce usage based on their subscription.
|
|
1648
|
+
|
|
1649
|
+
Usage is automatically reset for metered entitlements based on their usage
|
|
1650
|
+
period, but this endpoint allows to manually reset it at any time. When doing so
|
|
1651
|
+
the period anchor of the entitlement can be changed if needed.
|
|
1652
|
+
|
|
1653
|
+
Args:
|
|
1654
|
+
effective_at: The time at which the reset takes effect, defaults to now. The reset cannot be
|
|
1655
|
+
in the future. The provided value is truncated to the minute due to how
|
|
1656
|
+
historical meter data is stored.
|
|
1657
|
+
|
|
1658
|
+
preserve_overage: Determines whether the overage is preserved or forgiven, overriding the
|
|
1659
|
+
entitlement's default behavior.
|
|
1660
|
+
|
|
1661
|
+
- If true, the overage is preserved.
|
|
1662
|
+
- If false, the overage is forgiven.
|
|
1663
|
+
|
|
1664
|
+
retain_anchor: Determines whether the usage period anchor is retained or reset to the
|
|
1665
|
+
effectiveAt time.
|
|
1666
|
+
|
|
1667
|
+
- If true, the usage period anchor is retained.
|
|
1668
|
+
- If false, the usage period anchor is reset to the effectiveAt time.
|
|
1669
|
+
|
|
1670
|
+
extra_headers: Send extra headers
|
|
1671
|
+
|
|
1672
|
+
extra_query: Add additional query parameters to the request
|
|
1673
|
+
|
|
1674
|
+
extra_body: Add additional JSON properties to the request
|
|
1675
|
+
|
|
1676
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1677
|
+
"""
|
|
1678
|
+
if not subject_id_or_key:
|
|
1679
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
1680
|
+
if not entitlement_id:
|
|
1681
|
+
raise ValueError(f"Expected a non-empty value for `entitlement_id` but received {entitlement_id!r}")
|
|
1682
|
+
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
|
|
1683
|
+
return await self._post(
|
|
1684
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id}/reset",
|
|
1685
|
+
body=await async_maybe_transform(
|
|
1686
|
+
{
|
|
1687
|
+
"effective_at": effective_at,
|
|
1688
|
+
"preserve_overage": preserve_overage,
|
|
1689
|
+
"retain_anchor": retain_anchor,
|
|
1690
|
+
},
|
|
1691
|
+
entitlement_reset_params.EntitlementResetParams,
|
|
1692
|
+
),
|
|
1693
|
+
options=make_request_options(
|
|
1694
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
1695
|
+
),
|
|
1696
|
+
cast_to=NoneType,
|
|
1697
|
+
)
|
|
1698
|
+
|
|
1699
|
+
async def value(
|
|
1700
|
+
self,
|
|
1701
|
+
entitlement_id_or_feature_key: str,
|
|
1702
|
+
*,
|
|
1703
|
+
subject_id_or_key: str,
|
|
1704
|
+
time: Union[str, datetime] | NotGiven = NOT_GIVEN,
|
|
1705
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
1706
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
1707
|
+
extra_headers: Headers | None = None,
|
|
1708
|
+
extra_query: Query | None = None,
|
|
1709
|
+
extra_body: Body | None = None,
|
|
1710
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
1711
|
+
) -> EntitlementValue:
|
|
1712
|
+
"""This endpoint should be used for access checks and enforcement.
|
|
1713
|
+
|
|
1714
|
+
All entitlement
|
|
1715
|
+
types share the hasAccess property in their value response, but multiple other
|
|
1716
|
+
properties are returned based on the entitlement type.
|
|
1717
|
+
|
|
1718
|
+
For convenience reasons, /value works with both entitlementId and featureKey.
|
|
1719
|
+
|
|
1720
|
+
Args:
|
|
1721
|
+
extra_headers: Send extra headers
|
|
1722
|
+
|
|
1723
|
+
extra_query: Add additional query parameters to the request
|
|
1724
|
+
|
|
1725
|
+
extra_body: Add additional JSON properties to the request
|
|
1726
|
+
|
|
1727
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
1728
|
+
"""
|
|
1729
|
+
if not subject_id_or_key:
|
|
1730
|
+
raise ValueError(f"Expected a non-empty value for `subject_id_or_key` but received {subject_id_or_key!r}")
|
|
1731
|
+
if not entitlement_id_or_feature_key:
|
|
1732
|
+
raise ValueError(
|
|
1733
|
+
f"Expected a non-empty value for `entitlement_id_or_feature_key` but received {entitlement_id_or_feature_key!r}"
|
|
1734
|
+
)
|
|
1735
|
+
return await self._get(
|
|
1736
|
+
f"/api/v1/subjects/{subject_id_or_key}/entitlements/{entitlement_id_or_feature_key}/value",
|
|
1737
|
+
options=make_request_options(
|
|
1738
|
+
extra_headers=extra_headers,
|
|
1739
|
+
extra_query=extra_query,
|
|
1740
|
+
extra_body=extra_body,
|
|
1741
|
+
timeout=timeout,
|
|
1742
|
+
query=await async_maybe_transform({"time": time}, entitlement_value_params.EntitlementValueParams),
|
|
1743
|
+
),
|
|
1744
|
+
cast_to=EntitlementValue,
|
|
1745
|
+
)
|
|
1746
|
+
|
|
1747
|
+
|
|
1748
|
+
class EntitlementsResourceWithRawResponse:
|
|
1749
|
+
def __init__(self, entitlements: EntitlementsResource) -> None:
|
|
1750
|
+
self._entitlements = entitlements
|
|
1751
|
+
|
|
1752
|
+
self.create = to_raw_response_wrapper(
|
|
1753
|
+
entitlements.create,
|
|
1754
|
+
)
|
|
1755
|
+
self.retrieve = to_raw_response_wrapper(
|
|
1756
|
+
entitlements.retrieve,
|
|
1757
|
+
)
|
|
1758
|
+
self.list = to_raw_response_wrapper(
|
|
1759
|
+
entitlements.list,
|
|
1760
|
+
)
|
|
1761
|
+
self.delete = to_raw_response_wrapper(
|
|
1762
|
+
entitlements.delete,
|
|
1763
|
+
)
|
|
1764
|
+
self.history = to_raw_response_wrapper(
|
|
1765
|
+
entitlements.history,
|
|
1766
|
+
)
|
|
1767
|
+
self.override = to_raw_response_wrapper(
|
|
1768
|
+
entitlements.override,
|
|
1769
|
+
)
|
|
1770
|
+
self.reset = to_raw_response_wrapper(
|
|
1771
|
+
entitlements.reset,
|
|
1772
|
+
)
|
|
1773
|
+
self.value = to_raw_response_wrapper(
|
|
1774
|
+
entitlements.value,
|
|
1775
|
+
)
|
|
1776
|
+
|
|
1777
|
+
@cached_property
|
|
1778
|
+
def grants(self) -> GrantsResourceWithRawResponse:
|
|
1779
|
+
return GrantsResourceWithRawResponse(self._entitlements.grants)
|
|
1780
|
+
|
|
1781
|
+
|
|
1782
|
+
class AsyncEntitlementsResourceWithRawResponse:
|
|
1783
|
+
def __init__(self, entitlements: AsyncEntitlementsResource) -> None:
|
|
1784
|
+
self._entitlements = entitlements
|
|
1785
|
+
|
|
1786
|
+
self.create = async_to_raw_response_wrapper(
|
|
1787
|
+
entitlements.create,
|
|
1788
|
+
)
|
|
1789
|
+
self.retrieve = async_to_raw_response_wrapper(
|
|
1790
|
+
entitlements.retrieve,
|
|
1791
|
+
)
|
|
1792
|
+
self.list = async_to_raw_response_wrapper(
|
|
1793
|
+
entitlements.list,
|
|
1794
|
+
)
|
|
1795
|
+
self.delete = async_to_raw_response_wrapper(
|
|
1796
|
+
entitlements.delete,
|
|
1797
|
+
)
|
|
1798
|
+
self.history = async_to_raw_response_wrapper(
|
|
1799
|
+
entitlements.history,
|
|
1800
|
+
)
|
|
1801
|
+
self.override = async_to_raw_response_wrapper(
|
|
1802
|
+
entitlements.override,
|
|
1803
|
+
)
|
|
1804
|
+
self.reset = async_to_raw_response_wrapper(
|
|
1805
|
+
entitlements.reset,
|
|
1806
|
+
)
|
|
1807
|
+
self.value = async_to_raw_response_wrapper(
|
|
1808
|
+
entitlements.value,
|
|
1809
|
+
)
|
|
1810
|
+
|
|
1811
|
+
@cached_property
|
|
1812
|
+
def grants(self) -> AsyncGrantsResourceWithRawResponse:
|
|
1813
|
+
return AsyncGrantsResourceWithRawResponse(self._entitlements.grants)
|
|
1814
|
+
|
|
1815
|
+
|
|
1816
|
+
class EntitlementsResourceWithStreamingResponse:
|
|
1817
|
+
def __init__(self, entitlements: EntitlementsResource) -> None:
|
|
1818
|
+
self._entitlements = entitlements
|
|
1819
|
+
|
|
1820
|
+
self.create = to_streamed_response_wrapper(
|
|
1821
|
+
entitlements.create,
|
|
1822
|
+
)
|
|
1823
|
+
self.retrieve = to_streamed_response_wrapper(
|
|
1824
|
+
entitlements.retrieve,
|
|
1825
|
+
)
|
|
1826
|
+
self.list = to_streamed_response_wrapper(
|
|
1827
|
+
entitlements.list,
|
|
1828
|
+
)
|
|
1829
|
+
self.delete = to_streamed_response_wrapper(
|
|
1830
|
+
entitlements.delete,
|
|
1831
|
+
)
|
|
1832
|
+
self.history = to_streamed_response_wrapper(
|
|
1833
|
+
entitlements.history,
|
|
1834
|
+
)
|
|
1835
|
+
self.override = to_streamed_response_wrapper(
|
|
1836
|
+
entitlements.override,
|
|
1837
|
+
)
|
|
1838
|
+
self.reset = to_streamed_response_wrapper(
|
|
1839
|
+
entitlements.reset,
|
|
1840
|
+
)
|
|
1841
|
+
self.value = to_streamed_response_wrapper(
|
|
1842
|
+
entitlements.value,
|
|
1843
|
+
)
|
|
1844
|
+
|
|
1845
|
+
@cached_property
|
|
1846
|
+
def grants(self) -> GrantsResourceWithStreamingResponse:
|
|
1847
|
+
return GrantsResourceWithStreamingResponse(self._entitlements.grants)
|
|
1848
|
+
|
|
1849
|
+
|
|
1850
|
+
class AsyncEntitlementsResourceWithStreamingResponse:
|
|
1851
|
+
def __init__(self, entitlements: AsyncEntitlementsResource) -> None:
|
|
1852
|
+
self._entitlements = entitlements
|
|
1853
|
+
|
|
1854
|
+
self.create = async_to_streamed_response_wrapper(
|
|
1855
|
+
entitlements.create,
|
|
1856
|
+
)
|
|
1857
|
+
self.retrieve = async_to_streamed_response_wrapper(
|
|
1858
|
+
entitlements.retrieve,
|
|
1859
|
+
)
|
|
1860
|
+
self.list = async_to_streamed_response_wrapper(
|
|
1861
|
+
entitlements.list,
|
|
1862
|
+
)
|
|
1863
|
+
self.delete = async_to_streamed_response_wrapper(
|
|
1864
|
+
entitlements.delete,
|
|
1865
|
+
)
|
|
1866
|
+
self.history = async_to_streamed_response_wrapper(
|
|
1867
|
+
entitlements.history,
|
|
1868
|
+
)
|
|
1869
|
+
self.override = async_to_streamed_response_wrapper(
|
|
1870
|
+
entitlements.override,
|
|
1871
|
+
)
|
|
1872
|
+
self.reset = async_to_streamed_response_wrapper(
|
|
1873
|
+
entitlements.reset,
|
|
1874
|
+
)
|
|
1875
|
+
self.value = async_to_streamed_response_wrapper(
|
|
1876
|
+
entitlements.value,
|
|
1877
|
+
)
|
|
1878
|
+
|
|
1879
|
+
@cached_property
|
|
1880
|
+
def grants(self) -> AsyncGrantsResourceWithStreamingResponse:
|
|
1881
|
+
return AsyncGrantsResourceWithStreamingResponse(self._entitlements.grants)
|