lightweb-adapter-sdk 0.1.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.
- LICENSE +197 -0
- README.md +106 -0
- lightweb_adapter_sdk/__init__.py +0 -0
- lightweb_adapter_sdk/adapter/__init__.py +133 -0
- lightweb_adapter_sdk/conformance/__init__.py +94 -0
- lightweb_adapter_sdk/conformance/fault_control.py +54 -0
- lightweb_adapter_sdk/conformance/test_apply.py +140 -0
- lightweb_adapter_sdk/conformance/test_capabilities.py +40 -0
- lightweb_adapter_sdk/conformance/test_disable.py +115 -0
- lightweb_adapter_sdk/conformance/test_event_consumer.py +135 -0
- lightweb_adapter_sdk/conformance/test_health.py +52 -0
- lightweb_adapter_sdk/conformance/test_identity_mapping.py +75 -0
- lightweb_adapter_sdk/conformance/test_list_accounts.py +114 -0
- lightweb_adapter_sdk/conformance/test_reconcile.py +148 -0
- lightweb_adapter_sdk/event_consumer/__init__.py +19 -0
- lightweb_adapter_sdk/event_consumer/dedup.py +77 -0
- lightweb_adapter_sdk/event_consumer/jetstream.py +262 -0
- lightweb_adapter_sdk/event_consumer/parser.py +94 -0
- lightweb_adapter_sdk/event_consumer/protocol.py +48 -0
- lightweb_adapter_sdk/py.typed +0 -0
- lightweb_adapter_sdk/reference/__init__.py +330 -0
- lightweb_adapter_sdk/reference/event_consumer.py +50 -0
- lightweb_adapter_sdk/reference/fake_server.py +147 -0
- lightweb_adapter_sdk/reference/fault_control.py +36 -0
- lightweb_adapter_sdk/testkit/__init__.py +35 -0
- lightweb_adapter_sdk/testkit/fake_entitlements.py +115 -0
- lightweb_adapter_sdk/testkit/fake_event_source.py +132 -0
- lightweb_adapter_sdk/testkit/structural.py +64 -0
- lightweb_adapter_sdk/types/__init__.py +416 -0
- lightweb_adapter_sdk-0.1.0.dist-info/METADATA +138 -0
- lightweb_adapter_sdk-0.1.0.dist-info/RECORD +33 -0
- lightweb_adapter_sdk-0.1.0.dist-info/WHEEL +4 -0
- lightweb_adapter_sdk-0.1.0.dist-info/licenses/LICENSE +197 -0
LICENSE
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions to
|
|
50
|
+
that Work or Derivative Works thereof, that is intentionally submitted
|
|
51
|
+
to Licensor for inclusion in the Work by the copyright owner or by an
|
|
52
|
+
individual or Legal Entity authorized to submit on behalf of the
|
|
53
|
+
copyright owner. For the purposes of this definition, "submitted" means
|
|
54
|
+
any form of electronic, verbal, or written communication sent to the
|
|
55
|
+
Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the Work
|
|
71
|
+
and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
74
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
75
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated
|
|
76
|
+
in this section) patent license to make, have made, use, offer to sell,
|
|
77
|
+
sell, import, and otherwise transfer the Work, where such license
|
|
78
|
+
applies only to those patent claims licensable by such Contributor that
|
|
79
|
+
are necessarily infringed by their Contribution(s) alone or by
|
|
80
|
+
combination of their Contribution(s) with the Work to which such
|
|
81
|
+
Contribution(s) was submitted. If You institute patent litigation
|
|
82
|
+
against any entity (including a cross-claim or counterclaim in a
|
|
83
|
+
lawsuit) alleging that the Work or a Contribution incorporated within
|
|
84
|
+
the Work constitutes direct or contributory patent infringement, then
|
|
85
|
+
any patent licenses granted to You under this License for that Work
|
|
86
|
+
shall terminate as of the date such litigation is filed.
|
|
87
|
+
|
|
88
|
+
4. Redistribution. You may reproduce and distribute copies of the Work
|
|
89
|
+
or Derivative Works thereof in any medium, with or without
|
|
90
|
+
modifications, and in Source or Object form, provided that You meet the
|
|
91
|
+
following conditions:
|
|
92
|
+
|
|
93
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
94
|
+
Works a copy of this License; and
|
|
95
|
+
|
|
96
|
+
(b) You must cause any modified files to carry prominent notices
|
|
97
|
+
stating that You changed the files; and
|
|
98
|
+
|
|
99
|
+
(c) You must retain, in the Source form of any Derivative Works that
|
|
100
|
+
You distribute, all copyright, patent, trademark, and attribution
|
|
101
|
+
notices from the Source form of the Work, excluding those notices
|
|
102
|
+
that do not pertain to any part of the Derivative Works; and
|
|
103
|
+
|
|
104
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
105
|
+
distribution, then any Derivative Works that You distribute must
|
|
106
|
+
include a readable copy of the attribution notices contained within
|
|
107
|
+
such NOTICE file, excluding those notices that do not pertain to any
|
|
108
|
+
part of the Derivative Works, in at least one of the following
|
|
109
|
+
places: within a NOTICE text file distributed as part of the
|
|
110
|
+
Derivative Works; within the Source form or documentation, if
|
|
111
|
+
provided along with the Derivative Works; or, within a display
|
|
112
|
+
generated by the Derivative Works, if and wherever such third-party
|
|
113
|
+
notices normally appear. The contents of the NOTICE file are for
|
|
114
|
+
informational purposes only and do not modify the License. You may
|
|
115
|
+
add Your own attribution notices within Derivative Works that You
|
|
116
|
+
distribute, alongside or as an addendum to the NOTICE text from the
|
|
117
|
+
Work, provided that such additional attribution notices cannot be
|
|
118
|
+
construed as modifying the License.
|
|
119
|
+
|
|
120
|
+
You may add Your own copyright statement to Your modifications and may
|
|
121
|
+
provide additional or different license terms and conditions for use,
|
|
122
|
+
reproduction, or distribution of Your modifications, or for any such
|
|
123
|
+
Derivative Works as a whole, provided Your use, reproduction, and
|
|
124
|
+
distribution of the Work otherwise complies with the conditions stated
|
|
125
|
+
in this License.
|
|
126
|
+
|
|
127
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
128
|
+
any Contribution intentionally submitted for inclusion in the Work by
|
|
129
|
+
You to the Licensor shall be under the terms and conditions of this
|
|
130
|
+
License, without any additional terms or conditions. Notwithstanding the
|
|
131
|
+
above, nothing herein shall supersede or modify the terms of any
|
|
132
|
+
separate license agreement you may have executed with the Licensor
|
|
133
|
+
regarding such Contributions.
|
|
134
|
+
|
|
135
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
136
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
137
|
+
except as required for reasonable and customary use in describing the
|
|
138
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
139
|
+
|
|
140
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
141
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
142
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
143
|
+
CONDITIONS OF ANY KIND, either express or implied, including, without
|
|
144
|
+
limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
|
|
145
|
+
MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
|
|
146
|
+
responsible for determining the appropriateness of using or
|
|
147
|
+
redistributing the Work and assume any risks associated with Your
|
|
148
|
+
exercise of permissions under this License.
|
|
149
|
+
|
|
150
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
151
|
+
whether in tort (including negligence), contract, or otherwise, unless
|
|
152
|
+
required by applicable law (such as deliberate and grossly negligent
|
|
153
|
+
acts) or agreed to in writing, shall any Contributor be liable to You
|
|
154
|
+
for damages, including any direct, indirect, special, incidental, or
|
|
155
|
+
consequential damages of any character arising as a result of this
|
|
156
|
+
License or out of the use or inability to use the Work (including but
|
|
157
|
+
not limited to damages for loss of goodwill, work stoppage, computer
|
|
158
|
+
failure or malfunction, or any and all other commercial damages or
|
|
159
|
+
losses), even if such Contributor has been advised of the possibility
|
|
160
|
+
of such damages.
|
|
161
|
+
|
|
162
|
+
9. Accepting Warranty or Additional Liability. While redistributing the
|
|
163
|
+
Work or Derivative Works thereof, You may choose to offer, and charge a
|
|
164
|
+
fee for, acceptance of support, warranty, indemnity, or other liability
|
|
165
|
+
obligations and/or rights consistent with this License. However, in
|
|
166
|
+
accepting such obligations, You may act only on Your own behalf and on
|
|
167
|
+
Your sole responsibility, not on behalf of any other Contributor, and
|
|
168
|
+
only if You agree to indemnify, defend, and hold each Contributor
|
|
169
|
+
harmless for any liability incurred by, or claims asserted against, such
|
|
170
|
+
Contributor by reason of your accepting any such warranty or additional
|
|
171
|
+
liability.
|
|
172
|
+
|
|
173
|
+
END OF TERMS AND CONDITIONS
|
|
174
|
+
|
|
175
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
176
|
+
|
|
177
|
+
To apply the Apache License to your work, attach the following
|
|
178
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
179
|
+
replaced with your own identifying information. (Don't include the
|
|
180
|
+
brackets!) The text should be enclosed in the appropriate comment
|
|
181
|
+
syntax for the file format. We also recommend that a file or class name
|
|
182
|
+
and description of purpose be included on the same "printed page" as the
|
|
183
|
+
copyright notice for easier identification within third-party archives.
|
|
184
|
+
|
|
185
|
+
Copyright 2025 Lightweb
|
|
186
|
+
|
|
187
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
188
|
+
you may not use this file except in compliance with the License.
|
|
189
|
+
You may obtain a copy of the License at
|
|
190
|
+
|
|
191
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
192
|
+
|
|
193
|
+
Unless required by applicable law or agreed to in writing, software
|
|
194
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
195
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
196
|
+
See the License for the specific language governing permissions and
|
|
197
|
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Lightweb adapter SDK
|
|
2
|
+
|
|
3
|
+
The published Python SDK for the Lightweb adapter contract.
|
|
4
|
+
|
|
5
|
+
> **Status: pre-1.0, under active development.** The SDK is not yet released to PyPI. The first 0.1.0 release will follow once initial implementation rounds are complete. See [`CHANGELOG.md`](CHANGELOG.md) for release history.
|
|
6
|
+
|
|
7
|
+
## What this is
|
|
8
|
+
|
|
9
|
+
[Lightweb](https://github.com/lightweb/platform) is a community-owned, deployable platform template for hosting self-hosted alternatives to common web services — files, chat, code, meetings. The platform separates *what a member is entitled to* (the entitlements service, source of truth) from *how those entitlements are provisioned into specific apps* (one adapter per app: NextCloud, Matrix, Gitea, Jitsi, and others).
|
|
10
|
+
|
|
11
|
+
This SDK publishes the contract those adapters implement. It's six methods, a handful of shared types, an event envelope, and a conformance suite that every adapter is expected to pass.
|
|
12
|
+
|
|
13
|
+
If you want to build an adapter for a new app, this is the library you depend on. If you want to understand how the platform's adapter layer works without writing one, [`docs/contract.md`](docs/contract.md) is the canonical specification.
|
|
14
|
+
|
|
15
|
+
## The contract, briefly
|
|
16
|
+
|
|
17
|
+
Every adapter implements six methods:
|
|
18
|
+
|
|
19
|
+
- `capabilities()` — declares which feature keys this adapter handles and what enforcement it offers.
|
|
20
|
+
- `apply(member, entitlements)` — idempotent; makes the target app's state match the desired entitlements.
|
|
21
|
+
- `disable(member)` — soft-disable; blocks access while preserving data.
|
|
22
|
+
- `reconcile(member, entitlements)` — read-only; returns a drift report comparing app state to desired state.
|
|
23
|
+
- `health()` — the adapter and its target app are reachable.
|
|
24
|
+
- `list_accounts(cursor)` — optional; pages through every account in the app for whole-system reconciliation.
|
|
25
|
+
|
|
26
|
+
There is no `delete`. Deletion is destructive, asymmetric, and out of the contract by design; it's handled separately as a gated, human-approved workflow in the platform's reconciler.
|
|
27
|
+
|
|
28
|
+
The full specification is in [`docs/contract.md`](docs/contract.md).
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
Install:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install lightweb-adapter-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
A minimal adapter:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from lightweb_adapter_sdk.adapter import Adapter
|
|
42
|
+
from lightweb_adapter_sdk.types import (
|
|
43
|
+
Member, Entitlement, AppAccount, DriftReport,
|
|
44
|
+
Capabilities, HealthStatus, AccountListPage,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class MyAdapter:
|
|
49
|
+
"""Adapter for MyApp."""
|
|
50
|
+
|
|
51
|
+
def capabilities(self) -> Capabilities:
|
|
52
|
+
...
|
|
53
|
+
|
|
54
|
+
def apply(self, member: Member, entitlements: list[Entitlement]) -> AppAccount:
|
|
55
|
+
...
|
|
56
|
+
|
|
57
|
+
def disable(self, member: Member) -> None:
|
|
58
|
+
...
|
|
59
|
+
|
|
60
|
+
def reconcile(self, member: Member) -> DriftReport:
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
def health(self) -> HealthStatus:
|
|
64
|
+
...
|
|
65
|
+
|
|
66
|
+
def list_accounts(self, cursor: str | None = None) -> AccountListPage:
|
|
67
|
+
...
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# Verify the adapter satisfies the contract structurally:
|
|
71
|
+
adapter: Adapter = MyAdapter()
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The `Adapter` is a `typing.Protocol`; your class doesn't have to inherit from it. If it has the right method signatures, it satisfies the contract.
|
|
75
|
+
|
|
76
|
+
The conformance suite verifies your adapter meets the contract's *behavioral* requirements (not just its structural ones). See [`docs/conformance.md`](docs/conformance.md) for how to run it against your adapter.
|
|
77
|
+
|
|
78
|
+
## Documentation
|
|
79
|
+
|
|
80
|
+
- [`docs/contract.md`](docs/contract.md) — the canonical contract specification. The authority on what an adapter must do.
|
|
81
|
+
- [`docs/conformance.md`](docs/conformance.md) — how to wire the conformance suite into your adapter's CI.
|
|
82
|
+
- [`docs/event-consumer.md`](docs/event-consumer.md) — JetStream event consumer conventions.
|
|
83
|
+
- [`docs/testkit.md`](docs/testkit.md) — the testkit for adapter authors.
|
|
84
|
+
- [`ARCHITECTURE.md`](ARCHITECTURE.md) — repository orientation; what's where and why.
|
|
85
|
+
|
|
86
|
+
For the broader architectural context — *why* the adapter contract exists in this shape — see the Lightweb HLD in the platform monorepo at `lightweb/platform`'s `docs/hld.md`, especially §4.
|
|
87
|
+
|
|
88
|
+
## Status
|
|
89
|
+
|
|
90
|
+
The SDK is pre-1.0. The current implementation is structured as a sequence of rounds, with Round 5 targeting the first 0.1.0 release. 1.0 follows once the contract has been validated by at least one production adapter.
|
|
91
|
+
|
|
92
|
+
## Relationship to the Lightweb platform
|
|
93
|
+
|
|
94
|
+
The platform monorepo (`lightweb/platform`) is AGPLv3 and contains the bespoke spine services and first-party adapters that ship with Lightweb. The platform's first-party adapters consume this SDK the same way third-party adapters do — as a pinned PyPI dependency, not as a source-level inclusion.
|
|
95
|
+
|
|
96
|
+
This SDK is Apache 2.0. The license boundary is structural: the SDK is the *contract* third parties implement against, and a permissive license is appropriate for a contract definition.
|
|
97
|
+
|
|
98
|
+
The SDK has no code-level dependency on the platform monorepo. It does mirror some platform-side artifacts (event envelope schemas, the entitlements service's API shape), but those are vendored as generated bindings, not pulled dynamically.
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
Apache License 2.0. See [`LICENSE`](LICENSE) for the full text.
|
|
103
|
+
|
|
104
|
+
## Code of conduct
|
|
105
|
+
|
|
106
|
+
Project participants are expected to follow the [Contributor Covenant](https://www.contributor-covenant.org/).
|
|
File without changes
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""The adapter contract as a structural Protocol.
|
|
2
|
+
|
|
3
|
+
Every adapter must implement the six methods declared here.
|
|
4
|
+
See docs/contract.md for the prose specification.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Protocol, runtime_checkable
|
|
8
|
+
|
|
9
|
+
from lightweb_adapter_sdk.types import (
|
|
10
|
+
AccountListPage,
|
|
11
|
+
AppAccount,
|
|
12
|
+
Capabilities,
|
|
13
|
+
DriftReport,
|
|
14
|
+
Entitlement,
|
|
15
|
+
HealthStatus,
|
|
16
|
+
Member,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@runtime_checkable
|
|
21
|
+
class Adapter(Protocol):
|
|
22
|
+
"""Protocol defining the six-method adapter contract.
|
|
23
|
+
|
|
24
|
+
This is a structural Protocol, not a base class. Adapter authors
|
|
25
|
+
are not required to inherit from this class; any class that
|
|
26
|
+
implements the six methods with matching signatures satisfies
|
|
27
|
+
the contract.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def capabilities(self) -> Capabilities:
|
|
31
|
+
"""Declare which feature keys this adapter handles and its limits.
|
|
32
|
+
|
|
33
|
+
Returns static metadata describing the adapter's scope: the app
|
|
34
|
+
it targets, the feature keys it enforces, and any operational
|
|
35
|
+
constraints (e.g. maximum concurrent applies). Called once at
|
|
36
|
+
adapter registration.
|
|
37
|
+
|
|
38
|
+
Idempotent: repeated calls with no intervening configuration
|
|
39
|
+
changes return an equivalent result.
|
|
40
|
+
|
|
41
|
+
Error modes: should not raise. All required information is
|
|
42
|
+
static configuration available at adapter startup.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def apply(self, member: Member, entitlements: list[Entitlement]) -> AppAccount:
|
|
46
|
+
"""Idempotently make the target app's state match the desired entitlements.
|
|
47
|
+
|
|
48
|
+
Creates accounts that should exist; updates quotas that have
|
|
49
|
+
changed; adjusts feature flags. Returns the resulting
|
|
50
|
+
``AppAccount`` data (``external_id`` and current state) so the
|
|
51
|
+
entitlements service can record the provisioned reality.
|
|
52
|
+
|
|
53
|
+
When called with an empty ``entitlements`` list, ensures the
|
|
54
|
+
account exists with status ``"active"`` and ``current_state``
|
|
55
|
+
reflecting no entitlements. (Distinct from ``disable`` which
|
|
56
|
+
sets status to ``"disabled"``.)
|
|
57
|
+
|
|
58
|
+
Error modes: should raise on target-app unreachable or
|
|
59
|
+
authentication failure. Partial application is acceptable only
|
|
60
|
+
if the adapter's internal state remains consistent for a retry.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def disable(self, member: Member) -> None:
|
|
64
|
+
"""Soft-disable a member's access while preserving data.
|
|
65
|
+
|
|
66
|
+
Blocks the member from using the target app without destroying
|
|
67
|
+
the account or its data. Reversible by a subsequent ``apply``.
|
|
68
|
+
|
|
69
|
+
Idempotent: calling disable multiple times has the same effect
|
|
70
|
+
as calling it once. A no-op if the member is already disabled
|
|
71
|
+
or has no account in this app.
|
|
72
|
+
|
|
73
|
+
Error modes: should raise on target-app unreachable. Should
|
|
74
|
+
NOT raise when the member has no account.
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
def reconcile(self, member: Member, entitlements: list[Entitlement]) -> DriftReport:
|
|
78
|
+
"""Read-only drift detection: compare app state to desired state.
|
|
79
|
+
|
|
80
|
+
Compares the target app's current state for ``member`` against
|
|
81
|
+
the desired state described by ``entitlements``. Returns a
|
|
82
|
+
structured ``DriftReport`` enumerating each discrepancy as a
|
|
83
|
+
``DriftFinding``. An empty ``findings`` list means no drift.
|
|
84
|
+
Never mutates the target app.
|
|
85
|
+
|
|
86
|
+
The ``entitlements`` argument is the same shape passed to
|
|
87
|
+
``apply`` — current desired state, not deltas. The reconciler
|
|
88
|
+
passes the entitlements it currently knows for the member; the
|
|
89
|
+
adapter does not fetch them on its own.
|
|
90
|
+
|
|
91
|
+
Four cases by (account-presence x entitlements-presence):
|
|
92
|
+
account-exists & entitlements-non-empty is the expected case
|
|
93
|
+
(compare and report mismatches); account-exists & entitlements-empty
|
|
94
|
+
means correct no-entitlements state (no drift); account-absent &
|
|
95
|
+
entitlements-non-empty produces a ``missing_in_app`` finding;
|
|
96
|
+
account-absent & entitlements-empty is correct no-account state
|
|
97
|
+
(no drift).
|
|
98
|
+
|
|
99
|
+
A return with empty findings means the adapter was able to
|
|
100
|
+
contact the target app and found no drift; it is not a fallback
|
|
101
|
+
for unreachability. When the target app is unreachable, raises
|
|
102
|
+
an adapter-specific exception rather than returning a
|
|
103
|
+
misleadingly empty report.
|
|
104
|
+
|
|
105
|
+
Idempotent: repeated calls with unchanged inputs return the
|
|
106
|
+
same report (modulo clock drift in ``reconciled_at``).
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
def health(self) -> HealthStatus:
|
|
110
|
+
"""Report adapter and target-app reachability.
|
|
111
|
+
|
|
112
|
+
Returns a ``HealthStatus`` with two boolean signals:
|
|
113
|
+
- ``healthy``: ``True`` only when the adapter is responding AND
|
|
114
|
+
``app_reachable`` is ``True`` (strict conjunction).
|
|
115
|
+
- ``app_reachable``: the target app's API responded.
|
|
116
|
+
|
|
117
|
+
The method itself must not raise. If the adapter cannot perform
|
|
118
|
+
the health check, return ``healthy=False`` with
|
|
119
|
+
``app_reachable=False`` and use ``details`` to explain.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
def list_accounts(self, cursor: str | None = None) -> AccountListPage:
|
|
123
|
+
"""Page through every account in the target app.
|
|
124
|
+
|
|
125
|
+
Used by the reconciler for whole-system drift detection.
|
|
126
|
+
Returns a window of accounts and a ``next_cursor`` for
|
|
127
|
+
pagination (``None`` when no more pages).
|
|
128
|
+
|
|
129
|
+
An expired or invalid cursor returns an empty page with
|
|
130
|
+
``next_cursor=None`` rather than raising.
|
|
131
|
+
|
|
132
|
+
Error modes: should raise on target-app unreachable.
|
|
133
|
+
"""
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Conformance test suite for the Lightweb adapter contract.
|
|
2
|
+
|
|
3
|
+
Every adapter must pass these tests to be considered conformant.
|
|
4
|
+
The suite is the mechanical expression of ``docs/contract.md``.
|
|
5
|
+
|
|
6
|
+
Adapter authors import these test functions in their own
|
|
7
|
+
``tests/test_conformance.py`` and provide the required fixtures
|
|
8
|
+
in their ``conftest.py``. See ``docs/conformance.md`` for usage
|
|
9
|
+
instructions.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from lightweb_adapter_sdk.conformance.test_apply import (
|
|
13
|
+
test_apply_creates_account_on_first_call,
|
|
14
|
+
test_apply_empty_entitlements_creates_active_account,
|
|
15
|
+
test_apply_idempotent,
|
|
16
|
+
test_apply_replaces_state_rather_than_merging,
|
|
17
|
+
test_apply_raises_when_unreachable,
|
|
18
|
+
)
|
|
19
|
+
from lightweb_adapter_sdk.conformance.test_capabilities import (
|
|
20
|
+
test_capabilities_idempotent,
|
|
21
|
+
test_capabilities_schema_version_declared,
|
|
22
|
+
)
|
|
23
|
+
from lightweb_adapter_sdk.conformance.test_disable import (
|
|
24
|
+
test_disable_idempotent,
|
|
25
|
+
test_disable_noop_for_missing_account,
|
|
26
|
+
test_disable_sets_status_disabled,
|
|
27
|
+
)
|
|
28
|
+
from lightweb_adapter_sdk.conformance.test_health import (
|
|
29
|
+
test_health_never_raises,
|
|
30
|
+
test_health_strict_conjunction_when_app_reachable,
|
|
31
|
+
test_health_strict_conjunction_when_app_unreachable,
|
|
32
|
+
)
|
|
33
|
+
from lightweb_adapter_sdk.conformance.test_identity_mapping import (
|
|
34
|
+
test_external_id_immutable_across_apply,
|
|
35
|
+
test_external_id_immutable_across_reconcile,
|
|
36
|
+
)
|
|
37
|
+
from lightweb_adapter_sdk.conformance.test_list_accounts import (
|
|
38
|
+
test_list_accounts_invalid_cursor_returns_empty,
|
|
39
|
+
test_list_accounts_paginates,
|
|
40
|
+
test_list_accounts_preserves_member_id,
|
|
41
|
+
test_list_accounts_raises_when_unreachable,
|
|
42
|
+
)
|
|
43
|
+
from lightweb_adapter_sdk.conformance.test_reconcile import (
|
|
44
|
+
test_reconcile_account_absent_entitlements_empty,
|
|
45
|
+
test_reconcile_account_absent_entitlements_non_empty,
|
|
46
|
+
test_reconcile_account_exists_entitlements_differ,
|
|
47
|
+
test_reconcile_account_exists_entitlements_match,
|
|
48
|
+
test_reconcile_raises_when_unreachable_not_vacuous_empty,
|
|
49
|
+
)
|
|
50
|
+
from lightweb_adapter_sdk.conformance.test_event_consumer import (
|
|
51
|
+
test_consumer_satisfies_protocol,
|
|
52
|
+
test_consume_invokes_apply_for_change_events,
|
|
53
|
+
test_consume_is_idempotent_at_event_level,
|
|
54
|
+
test_consume_handles_non_change_events_gracefully,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
__all__ = [
|
|
58
|
+
# capabilities
|
|
59
|
+
"test_capabilities_idempotent",
|
|
60
|
+
"test_capabilities_schema_version_declared",
|
|
61
|
+
# apply
|
|
62
|
+
"test_apply_creates_account_on_first_call",
|
|
63
|
+
"test_apply_empty_entitlements_creates_active_account",
|
|
64
|
+
"test_apply_idempotent",
|
|
65
|
+
"test_apply_replaces_state_rather_than_merging",
|
|
66
|
+
"test_apply_raises_when_unreachable",
|
|
67
|
+
# disable
|
|
68
|
+
"test_disable_idempotent",
|
|
69
|
+
"test_disable_noop_for_missing_account",
|
|
70
|
+
"test_disable_sets_status_disabled",
|
|
71
|
+
# reconcile
|
|
72
|
+
"test_reconcile_account_exists_entitlements_match",
|
|
73
|
+
"test_reconcile_account_exists_entitlements_differ",
|
|
74
|
+
"test_reconcile_account_absent_entitlements_non_empty",
|
|
75
|
+
"test_reconcile_account_absent_entitlements_empty",
|
|
76
|
+
"test_reconcile_raises_when_unreachable_not_vacuous_empty",
|
|
77
|
+
# health
|
|
78
|
+
"test_health_never_raises",
|
|
79
|
+
"test_health_strict_conjunction_when_app_reachable",
|
|
80
|
+
"test_health_strict_conjunction_when_app_unreachable",
|
|
81
|
+
# list_accounts
|
|
82
|
+
"test_list_accounts_paginates",
|
|
83
|
+
"test_list_accounts_invalid_cursor_returns_empty",
|
|
84
|
+
"test_list_accounts_preserves_member_id",
|
|
85
|
+
"test_list_accounts_raises_when_unreachable",
|
|
86
|
+
# identity_mapping
|
|
87
|
+
"test_external_id_immutable_across_apply",
|
|
88
|
+
"test_external_id_immutable_across_reconcile",
|
|
89
|
+
# event_consumer
|
|
90
|
+
"test_consumer_satisfies_protocol",
|
|
91
|
+
"test_consume_invokes_apply_for_change_events",
|
|
92
|
+
"test_consume_is_idempotent_at_event_level",
|
|
93
|
+
"test_consume_handles_non_change_events_gracefully",
|
|
94
|
+
]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Fault injection abstraction for the conformance suite.
|
|
2
|
+
|
|
3
|
+
Adapter authors provide an implementation of this Protocol via the
|
|
4
|
+
``adapter_fault_control`` conftest fixture, scoped to a single test's
|
|
5
|
+
lifetime. Conformance tests call methods on this fixture to inject
|
|
6
|
+
fault conditions; each adapter author decides which fault modes their
|
|
7
|
+
fake server supports.
|
|
8
|
+
|
|
9
|
+
Methods declare named fault modes. Implementations either inject the
|
|
10
|
+
fault (returning normally) or raise ``NotImplementedError`` if the
|
|
11
|
+
fault mode is not supported. Conformance tests that require a fault
|
|
12
|
+
mode the adapter doesn't support should skip via a helper.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Protocol, runtime_checkable
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@runtime_checkable
|
|
21
|
+
class FaultControl(Protocol):
|
|
22
|
+
"""Adapter authors provide an implementation via the
|
|
23
|
+
``adapter_fault_control`` conftest fixture, scoped to a single
|
|
24
|
+
test's lifetime.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def inject_unreachable(self) -> None:
|
|
28
|
+
"""Inject a fault condition where the target app is unreachable.
|
|
29
|
+
|
|
30
|
+
Subsequent calls to adapter methods that make HTTP requests
|
|
31
|
+
should raise the adapter's unreachable exception (see
|
|
32
|
+
``lightweb_adapter_sdk.types.AdapterUnreachable``).
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def inject_rate_limit(self) -> None:
|
|
36
|
+
"""Inject a fault condition where the target app returns 429.
|
|
37
|
+
|
|
38
|
+
Subsequent calls to adapter methods should raise the adapter's
|
|
39
|
+
rate-limit exception.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def inject_auth_failure(self) -> None:
|
|
43
|
+
"""Inject a fault condition where the target app returns 401/403.
|
|
44
|
+
|
|
45
|
+
Subsequent calls to adapter methods should raise the adapter's
|
|
46
|
+
authentication-failure exception.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
def reset(self) -> None:
|
|
50
|
+
"""Reset the adapter's fake server to normal operating mode.
|
|
51
|
+
|
|
52
|
+
Called automatically in fixture teardown so individual tests
|
|
53
|
+
don't need to.
|
|
54
|
+
"""
|