cpkit 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cpkit-0.1.0/LICENSE +201 -0
- cpkit-0.1.0/PKG-INFO +105 -0
- cpkit-0.1.0/README.md +82 -0
- cpkit-0.1.0/cpkit/README.md +82 -0
- cpkit-0.1.0/cpkit/__init__.py +42 -0
- cpkit-0.1.0/cpkit/admin.py +53 -0
- cpkit-0.1.0/cpkit/app.py +130 -0
- cpkit-0.1.0/cpkit/audit/README.md +33 -0
- cpkit-0.1.0/cpkit/audit/__init__.py +44 -0
- cpkit-0.1.0/cpkit/audit/events_service.py +36 -0
- cpkit-0.1.0/cpkit/audit/recorder.py +240 -0
- cpkit-0.1.0/cpkit/audit/repository.py +64 -0
- cpkit-0.1.0/cpkit/audit/router.py +46 -0
- cpkit-0.1.0/cpkit/audit/service.py +34 -0
- cpkit-0.1.0/cpkit/audit/types.py +38 -0
- cpkit-0.1.0/cpkit/auth/README.md +38 -0
- cpkit-0.1.0/cpkit/auth/__init__.py +123 -0
- cpkit-0.1.0/cpkit/auth/api_key_router.py +52 -0
- cpkit-0.1.0/cpkit/auth/api_key_service.py +143 -0
- cpkit-0.1.0/cpkit/auth/api_keys.py +143 -0
- cpkit-0.1.0/cpkit/auth/bundle.py +113 -0
- cpkit-0.1.0/cpkit/auth/claims.py +37 -0
- cpkit-0.1.0/cpkit/auth/config.py +162 -0
- cpkit-0.1.0/cpkit/auth/dependencies.py +155 -0
- cpkit-0.1.0/cpkit/auth/oidc.py +703 -0
- cpkit-0.1.0/cpkit/auth/redirects.py +12 -0
- cpkit-0.1.0/cpkit/auth/repositories.py +181 -0
- cpkit-0.1.0/cpkit/auth/router.py +214 -0
- cpkit-0.1.0/cpkit/auth/secrets.py +78 -0
- cpkit-0.1.0/cpkit/auth/types.py +49 -0
- cpkit-0.1.0/cpkit/bundle.py +252 -0
- cpkit-0.1.0/cpkit/cli/README.md +21 -0
- cpkit-0.1.0/cpkit/cli/__init__.py +14 -0
- cpkit-0.1.0/cpkit/cli/__main__.py +5 -0
- cpkit-0.1.0/cpkit/cli/base.py +200 -0
- cpkit-0.1.0/cpkit/cli/schema.py +30 -0
- cpkit-0.1.0/cpkit/cli/server.py +22 -0
- cpkit-0.1.0/cpkit/config/README.md +13 -0
- cpkit-0.1.0/cpkit/config/__init__.py +9 -0
- cpkit-0.1.0/cpkit/config/env.py +31 -0
- cpkit-0.1.0/cpkit/db/README.md +24 -0
- cpkit-0.1.0/cpkit/db/__init__.py +23 -0
- cpkit-0.1.0/cpkit/db/postgres.py +252 -0
- cpkit-0.1.0/cpkit/dependencies.py +73 -0
- cpkit-0.1.0/cpkit/errors/README.md +22 -0
- cpkit-0.1.0/cpkit/errors/__init__.py +35 -0
- cpkit-0.1.0/cpkit/errors/http.py +45 -0
- cpkit-0.1.0/cpkit/errors/repository.py +32 -0
- cpkit-0.1.0/cpkit/errors/service.py +74 -0
- cpkit-0.1.0/cpkit/jobs/README.md +29 -0
- cpkit-0.1.0/cpkit/jobs/__init__.py +49 -0
- cpkit-0.1.0/cpkit/jobs/maintenance.py +15 -0
- cpkit-0.1.0/cpkit/jobs/repository.py +306 -0
- cpkit-0.1.0/cpkit/jobs/router.py +105 -0
- cpkit-0.1.0/cpkit/jobs/service.py +138 -0
- cpkit-0.1.0/cpkit/jobs/types.py +67 -0
- cpkit-0.1.0/cpkit/jobs/worker.py +200 -0
- cpkit-0.1.0/cpkit/logging/README.md +19 -0
- cpkit-0.1.0/cpkit/logging/__init__.py +13 -0
- cpkit-0.1.0/cpkit/logging/context.py +29 -0
- cpkit-0.1.0/cpkit/logging/middleware.py +55 -0
- cpkit-0.1.0/cpkit/logging/setup.py +81 -0
- cpkit-0.1.0/cpkit/playbooks/README.md +25 -0
- cpkit-0.1.0/cpkit/playbooks/__init__.py +40 -0
- cpkit-0.1.0/cpkit/playbooks/ansible.py +359 -0
- cpkit-0.1.0/cpkit/playbooks/repository.py +95 -0
- cpkit-0.1.0/cpkit/playbooks/router.py +95 -0
- cpkit-0.1.0/cpkit/playbooks/service.py +232 -0
- cpkit-0.1.0/cpkit/playbooks/types.py +43 -0
- cpkit-0.1.0/cpkit/repository.py +63 -0
- cpkit-0.1.0/cpkit/resources/__init__.py +17 -0
- cpkit-0.1.0/cpkit/resources/ddl.sql +150 -0
- cpkit-0.1.0/cpkit/settings/README.md +22 -0
- cpkit-0.1.0/cpkit/settings/__init__.py +18 -0
- cpkit-0.1.0/cpkit/settings/keys.py +30 -0
- cpkit-0.1.0/cpkit/settings/repository.py +108 -0
- cpkit-0.1.0/cpkit/settings/router.py +62 -0
- cpkit-0.1.0/cpkit/settings/service.py +105 -0
- cpkit-0.1.0/cpkit/settings/types.py +25 -0
- cpkit-0.1.0/cpkit/time.py +4 -0
- cpkit-0.1.0/cpkit/webapp/README.md +71 -0
- cpkit-0.1.0/cpkit/webapp/__init__.py +12 -0
- cpkit-0.1.0/cpkit/webapp/index.html +970 -0
- cpkit-0.1.0/cpkit/webapp/script.js +1690 -0
- cpkit-0.1.0/cpkit/webapp/style.css +1561 -0
- cpkit-0.1.0/pyproject.toml +39 -0
- cpkit-0.1.0/resources/README.md +16 -0
- cpkit-0.1.0/resources/repository_maintenance_guide.md +90 -0
- cpkit-0.1.0/resources/webapp_extension_guide.md +706 -0
- cpkit-0.1.0/resources/webapp_extension_template.js +130 -0
cpkit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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, as 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
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the 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
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
cpkit-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cpkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reusable control-plane framework extracted from cp.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: Your Name
|
|
8
|
+
Author-email: you@example.com
|
|
9
|
+
Requires-Python: >=3.14
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Requires-Dist: PyJWT (>=2.10.1,<3.0.0)
|
|
13
|
+
Requires-Dist: ansible-runner (>=2.4.3,<3.0.0)
|
|
14
|
+
Requires-Dist: cryptography (>=46.0.7,<47.0.0)
|
|
15
|
+
Requires-Dist: fastapi[standard] (>=0.135.3,<0.136.0)
|
|
16
|
+
Requires-Dist: psycopg (>=3.3.3,<4.0.0)
|
|
17
|
+
Requires-Dist: psycopg-binary (>=3.3.3,<4.0.0)
|
|
18
|
+
Requires-Dist: psycopg-pool (>=3.3.0,<4.0.0)
|
|
19
|
+
Requires-Dist: pydantic (>=2.12.0,<3.0.0)
|
|
20
|
+
Requires-Dist: systemd-python (>=235,<236) ; sys_platform == "linux"
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# cpkit
|
|
24
|
+
|
|
25
|
+
cpkit is an early-stage framework for building small control-plane applications
|
|
26
|
+
on FastAPI and Postgres-compatible databases.
|
|
27
|
+
|
|
28
|
+
It is meant for applications that need more than CRUD endpoints but should not
|
|
29
|
+
have to rebuild the same operational foundation every time: authentication,
|
|
30
|
+
settings, audit logging, job execution, playbook storage, database wiring, and a
|
|
31
|
+
basic web console.
|
|
32
|
+
|
|
33
|
+
cpkit is still immature, but it is already usable as a foundation for apps that
|
|
34
|
+
want to focus on their domain model while inheriting common control-plane
|
|
35
|
+
capabilities.
|
|
36
|
+
|
|
37
|
+
## Why cpkit?
|
|
38
|
+
|
|
39
|
+
Control-plane apps tend to repeat the same infrastructure:
|
|
40
|
+
|
|
41
|
+
- API key and OIDC authentication
|
|
42
|
+
- role-aware API dependencies
|
|
43
|
+
- durable settings stored in the database
|
|
44
|
+
- audit events and request logging
|
|
45
|
+
- durable job queues and background workers
|
|
46
|
+
- versioned playbooks and Ansible execution
|
|
47
|
+
- consistent service/repository error handling
|
|
48
|
+
- a minimal admin web UI
|
|
49
|
+
|
|
50
|
+
cpkit packages those pieces as framework capabilities. The application provides
|
|
51
|
+
its business routers, services, repositories, models, and job handlers; cpkit
|
|
52
|
+
provides the surrounding platform.
|
|
53
|
+
|
|
54
|
+
## What You Get
|
|
55
|
+
|
|
56
|
+
- FastAPI app bootstrap with cpkit routers mounted under `/api`
|
|
57
|
+
- A repository base class for framework-owned tables
|
|
58
|
+
- Built-in settings, events, jobs, API keys, auth, and playbooks APIs
|
|
59
|
+
- A durable message queue and worker loop for application jobs
|
|
60
|
+
- OIDC sessions and signed API-key authentication
|
|
61
|
+
- Request logging and audit event helpers
|
|
62
|
+
- A packaged template webapp for framework/admin pages
|
|
63
|
+
- A standard CLI with `serve` and `init`
|
|
64
|
+
|
|
65
|
+
## Try The TODO Example
|
|
66
|
+
|
|
67
|
+
The best way to understand cpkit is to run the TODO example:
|
|
68
|
+
|
|
69
|
+
[examples/todo_app](examples/todo_app)
|
|
70
|
+
|
|
71
|
+
The example is intentionally small, but it is not toy scaffolding. It shows a
|
|
72
|
+
real cpkit app with:
|
|
73
|
+
|
|
74
|
+
- its own `todos` table
|
|
75
|
+
- TODO API routes
|
|
76
|
+
- a service layer
|
|
77
|
+
- a repository extending cpkit's repository base
|
|
78
|
+
- a cpkit-managed FastAPI app
|
|
79
|
+
- cpkit settings, events, jobs, API keys, auth, and playbooks
|
|
80
|
+
- an `EXPORT_TODOS` job that writes TODOs to JSON or CSV files
|
|
81
|
+
|
|
82
|
+
Run it:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
cd examples/todo_app
|
|
86
|
+
poetry install
|
|
87
|
+
export CPKIT_DB_URL='postgres://...'
|
|
88
|
+
export CPKIT_MASTER_KEY='base64-encoded-32-byte-key'
|
|
89
|
+
poetry run todo init
|
|
90
|
+
poetry run todo serve --reload
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Then open:
|
|
94
|
+
|
|
95
|
+
- Web console: `http://localhost:8000/`
|
|
96
|
+
- API docs: `http://localhost:8000/api/docs`
|
|
97
|
+
|
|
98
|
+
## Project Status
|
|
99
|
+
|
|
100
|
+
cpkit is independent and evolving. The APIs are not yet stable, and the TODO app
|
|
101
|
+
is the current reference for the recommended application structure.
|
|
102
|
+
|
|
103
|
+
Expect the framework to keep moving toward a clearer extension model: cpkit owns
|
|
104
|
+
the operational platform, while applications plug in business logic.
|
|
105
|
+
|
cpkit-0.1.0/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# cpkit
|
|
2
|
+
|
|
3
|
+
cpkit is an early-stage framework for building small control-plane applications
|
|
4
|
+
on FastAPI and Postgres-compatible databases.
|
|
5
|
+
|
|
6
|
+
It is meant for applications that need more than CRUD endpoints but should not
|
|
7
|
+
have to rebuild the same operational foundation every time: authentication,
|
|
8
|
+
settings, audit logging, job execution, playbook storage, database wiring, and a
|
|
9
|
+
basic web console.
|
|
10
|
+
|
|
11
|
+
cpkit is still immature, but it is already usable as a foundation for apps that
|
|
12
|
+
want to focus on their domain model while inheriting common control-plane
|
|
13
|
+
capabilities.
|
|
14
|
+
|
|
15
|
+
## Why cpkit?
|
|
16
|
+
|
|
17
|
+
Control-plane apps tend to repeat the same infrastructure:
|
|
18
|
+
|
|
19
|
+
- API key and OIDC authentication
|
|
20
|
+
- role-aware API dependencies
|
|
21
|
+
- durable settings stored in the database
|
|
22
|
+
- audit events and request logging
|
|
23
|
+
- durable job queues and background workers
|
|
24
|
+
- versioned playbooks and Ansible execution
|
|
25
|
+
- consistent service/repository error handling
|
|
26
|
+
- a minimal admin web UI
|
|
27
|
+
|
|
28
|
+
cpkit packages those pieces as framework capabilities. The application provides
|
|
29
|
+
its business routers, services, repositories, models, and job handlers; cpkit
|
|
30
|
+
provides the surrounding platform.
|
|
31
|
+
|
|
32
|
+
## What You Get
|
|
33
|
+
|
|
34
|
+
- FastAPI app bootstrap with cpkit routers mounted under `/api`
|
|
35
|
+
- A repository base class for framework-owned tables
|
|
36
|
+
- Built-in settings, events, jobs, API keys, auth, and playbooks APIs
|
|
37
|
+
- A durable message queue and worker loop for application jobs
|
|
38
|
+
- OIDC sessions and signed API-key authentication
|
|
39
|
+
- Request logging and audit event helpers
|
|
40
|
+
- A packaged template webapp for framework/admin pages
|
|
41
|
+
- A standard CLI with `serve` and `init`
|
|
42
|
+
|
|
43
|
+
## Try The TODO Example
|
|
44
|
+
|
|
45
|
+
The best way to understand cpkit is to run the TODO example:
|
|
46
|
+
|
|
47
|
+
[examples/todo_app](examples/todo_app)
|
|
48
|
+
|
|
49
|
+
The example is intentionally small, but it is not toy scaffolding. It shows a
|
|
50
|
+
real cpkit app with:
|
|
51
|
+
|
|
52
|
+
- its own `todos` table
|
|
53
|
+
- TODO API routes
|
|
54
|
+
- a service layer
|
|
55
|
+
- a repository extending cpkit's repository base
|
|
56
|
+
- a cpkit-managed FastAPI app
|
|
57
|
+
- cpkit settings, events, jobs, API keys, auth, and playbooks
|
|
58
|
+
- an `EXPORT_TODOS` job that writes TODOs to JSON or CSV files
|
|
59
|
+
|
|
60
|
+
Run it:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
cd examples/todo_app
|
|
64
|
+
poetry install
|
|
65
|
+
export CPKIT_DB_URL='postgres://...'
|
|
66
|
+
export CPKIT_MASTER_KEY='base64-encoded-32-byte-key'
|
|
67
|
+
poetry run todo init
|
|
68
|
+
poetry run todo serve --reload
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Then open:
|
|
72
|
+
|
|
73
|
+
- Web console: `http://localhost:8000/`
|
|
74
|
+
- API docs: `http://localhost:8000/api/docs`
|
|
75
|
+
|
|
76
|
+
## Project Status
|
|
77
|
+
|
|
78
|
+
cpkit is independent and evolving. The APIs are not yet stable, and the TODO app
|
|
79
|
+
is the current reference for the recommended application structure.
|
|
80
|
+
|
|
81
|
+
Expect the framework to keep moving toward a clearer extension model: cpkit owns
|
|
82
|
+
the operational platform, while applications plug in business logic.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# cpkit Code Map
|
|
2
|
+
|
|
3
|
+
cpkit is an application framework for FastAPI apps that want the same
|
|
4
|
+
operational backbone: authentication, audit events, settings, jobs, playbooks,
|
|
5
|
+
database helpers, and a shared webapp shell.
|
|
6
|
+
|
|
7
|
+
The package is organized by capability. The directories look flat at first
|
|
8
|
+
glance, but most capability packages use the same internal pattern:
|
|
9
|
+
|
|
10
|
+
- `types.py`: Pydantic models, enums, and response shapes.
|
|
11
|
+
- `repository.py` or `repositories.py`: database mixins for framework-owned
|
|
12
|
+
tables.
|
|
13
|
+
- `service.py`: business rules and repository error translation.
|
|
14
|
+
- `router.py`: FastAPI routes and dependency wiring.
|
|
15
|
+
- `__init__.py`: public exports for that capability.
|
|
16
|
+
|
|
17
|
+
The main app flow is:
|
|
18
|
+
|
|
19
|
+
1. An app calls `create_cpkit_bundle()` from `bundle.py` to assemble cpkit
|
|
20
|
+
capabilities.
|
|
21
|
+
2. The app calls `create_cpkit_app()` from `app.py` to create the FastAPI app,
|
|
22
|
+
configure the repository, run startup hooks, mount routers, and launch
|
|
23
|
+
background tasks.
|
|
24
|
+
3. `repository.py` provides `CPKitRepo`, a mix of all framework repository
|
|
25
|
+
capabilities. Apps can subclass it and add their own repository methods.
|
|
26
|
+
4. Capability services use `get_repo()` to work with the configured app repo.
|
|
27
|
+
5. The shared webapp in `webapp/` talks to the framework API routes and can be
|
|
28
|
+
extended by app-owned web assets.
|
|
29
|
+
|
|
30
|
+
## Architecture Review
|
|
31
|
+
|
|
32
|
+
The current flat capability layout is reasonable for cpkit's size. It keeps
|
|
33
|
+
imports readable and makes each framework feature easy to find. A deeper layout
|
|
34
|
+
like `cpkit/core`, `cpkit/capabilities`, and `cpkit/integrations` might become
|
|
35
|
+
useful later, but moving there now would mostly create import churn.
|
|
36
|
+
|
|
37
|
+
The part that made the project feel like a black box was not the package shape;
|
|
38
|
+
it was the lack of an orientation layer. These README files are intended to be
|
|
39
|
+
that layer. They explain the module boundaries without changing runtime code.
|
|
40
|
+
|
|
41
|
+
Good rules of thumb:
|
|
42
|
+
|
|
43
|
+
- Start in `bundle.py` when asking "how does cpkit assemble itself?"
|
|
44
|
+
- Start in `app.py` when asking "how does cpkit become a FastAPI app?"
|
|
45
|
+
- Start in `repository.py` when asking "how do framework services reach the DB?"
|
|
46
|
+
- Start in a capability package when asking about one feature area.
|
|
47
|
+
- Start in `webapp/README.md` for frontend extension behavior.
|
|
48
|
+
|
|
49
|
+
## Top-Level Modules
|
|
50
|
+
|
|
51
|
+
- `app.py`: FastAPI app bootstrap, lifespan management, router mounting, static
|
|
52
|
+
webapp mounting, DB initialization, and background task startup.
|
|
53
|
+
- `bundle.py`: The standard cpkit capability bundle. It wires auth, jobs,
|
|
54
|
+
events, admin routes, settings, playbooks, API keys, audit hooks, and the
|
|
55
|
+
queue worker.
|
|
56
|
+
- `repository.py`: The framework repository composition point. `CPKitRepo`
|
|
57
|
+
combines all cpkit repository mixins; `configure_repository()` tells cpkit how
|
|
58
|
+
to create app repo instances.
|
|
59
|
+
- `resources/`: Packaged framework resources such as `ddl.sql`. Use
|
|
60
|
+
`cpkit_ddl_path()` to locate them from installed wheels.
|
|
61
|
+
- `admin.py`: Composes built-in admin routers under the admin API prefix.
|
|
62
|
+
- `dependencies.py`: Global dependency accessors used by routers after a bundle
|
|
63
|
+
has been configured.
|
|
64
|
+
- `time.py`: Shared timestamp formatting constants.
|
|
65
|
+
|
|
66
|
+
## Capability Packages
|
|
67
|
+
|
|
68
|
+
- `audit/`: audit event records, event reads, audit hooks, and the context used
|
|
69
|
+
to attach request/job identifiers.
|
|
70
|
+
- `auth/`: OIDC login/logout, API key auth, role/group mapping, encrypted
|
|
71
|
+
secrets, and auth dependencies.
|
|
72
|
+
- `cli/`: reusable app CLI for schema initialization, schema checks, and serving.
|
|
73
|
+
- `config/`: small environment/config helpers.
|
|
74
|
+
- `db/`: database pool, query helpers, Cockroach/Postgres compatibility, and
|
|
75
|
+
DB error translation.
|
|
76
|
+
- `errors/`: repository/service/http exception layers.
|
|
77
|
+
- `jobs/`: framework job table, queue table, queue worker, job APIs, and job
|
|
78
|
+
rescheduling.
|
|
79
|
+
- `logging/`: request id context, middleware, and logging setup.
|
|
80
|
+
- `playbooks/`: versioned playbook storage and Ansible runner integration.
|
|
81
|
+
- `settings/`: framework settings table and admin settings API.
|
|
82
|
+
- `webapp/`: static HTML/CSS/JS shell and extension contract for app UIs.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Reusable control-plane framework primitives."""
|
|
2
|
+
|
|
3
|
+
from .admin import create_cpkit_admin_router
|
|
4
|
+
from .app import create_cpkit_app
|
|
5
|
+
from .bundle import CpkitBundle, create_cpkit_bundle
|
|
6
|
+
from .cli import ApplicationCLI
|
|
7
|
+
from .dependencies import (
|
|
8
|
+
configure_cpkit_dependencies,
|
|
9
|
+
get_access_scope,
|
|
10
|
+
get_audit_actor,
|
|
11
|
+
require_admin,
|
|
12
|
+
require_authenticated,
|
|
13
|
+
require_readonly,
|
|
14
|
+
require_user,
|
|
15
|
+
)
|
|
16
|
+
from .repository import CPKitRepo, configure_repository, get_repo
|
|
17
|
+
from .resources import cpkit_ddl_path, cpkit_resources_directory
|
|
18
|
+
from .time import STRFTIME, TS_FORMAT
|
|
19
|
+
from .webapp import template_webapp_directory
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"CPKitRepo",
|
|
23
|
+
"ApplicationCLI",
|
|
24
|
+
"CpkitBundle",
|
|
25
|
+
"STRFTIME",
|
|
26
|
+
"TS_FORMAT",
|
|
27
|
+
"configure_cpkit_dependencies",
|
|
28
|
+
"configure_repository",
|
|
29
|
+
"create_cpkit_bundle",
|
|
30
|
+
"create_cpkit_admin_router",
|
|
31
|
+
"create_cpkit_app",
|
|
32
|
+
"cpkit_ddl_path",
|
|
33
|
+
"cpkit_resources_directory",
|
|
34
|
+
"get_access_scope",
|
|
35
|
+
"get_audit_actor",
|
|
36
|
+
"get_repo",
|
|
37
|
+
"require_admin",
|
|
38
|
+
"require_authenticated",
|
|
39
|
+
"require_readonly",
|
|
40
|
+
"require_user",
|
|
41
|
+
"template_webapp_directory",
|
|
42
|
+
]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Admin router assembly for framework-owned capabilities."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable, Sequence
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from fastapi import APIRouter
|
|
7
|
+
|
|
8
|
+
from .auth import create_api_keys_router
|
|
9
|
+
from .playbooks import create_playbooks_router
|
|
10
|
+
from .settings import create_settings_router
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def create_cpkit_admin_router(
|
|
14
|
+
*,
|
|
15
|
+
get_api_keys_service: Callable[..., Any],
|
|
16
|
+
get_settings_service: Callable[..., Any],
|
|
17
|
+
get_playbooks_service: Callable[..., Any],
|
|
18
|
+
get_audit_actor: Callable[..., Any],
|
|
19
|
+
handle_service_error: Callable[[Exception], None],
|
|
20
|
+
service_error_type: type[Exception] = Exception,
|
|
21
|
+
prefix: str = "/admin",
|
|
22
|
+
dependencies: Sequence[Any] | None = None,
|
|
23
|
+
) -> APIRouter:
|
|
24
|
+
"""Create the standard admin routes provided by cpkit."""
|
|
25
|
+
router = APIRouter(
|
|
26
|
+
prefix=prefix,
|
|
27
|
+
dependencies=list(dependencies or ()),
|
|
28
|
+
)
|
|
29
|
+
router.include_router(
|
|
30
|
+
create_settings_router(
|
|
31
|
+
get_service=get_settings_service,
|
|
32
|
+
get_audit_actor=get_audit_actor,
|
|
33
|
+
handle_service_error=handle_service_error,
|
|
34
|
+
service_error_type=service_error_type,
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
router.include_router(
|
|
38
|
+
create_playbooks_router(
|
|
39
|
+
get_service=get_playbooks_service,
|
|
40
|
+
get_audit_actor=get_audit_actor,
|
|
41
|
+
handle_service_error=handle_service_error,
|
|
42
|
+
service_error_type=service_error_type,
|
|
43
|
+
)
|
|
44
|
+
)
|
|
45
|
+
router.include_router(
|
|
46
|
+
create_api_keys_router(
|
|
47
|
+
get_service=get_api_keys_service,
|
|
48
|
+
get_audit_actor=get_audit_actor,
|
|
49
|
+
handle_service_error=handle_service_error,
|
|
50
|
+
service_error_type=service_error_type,
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
return router
|