cofferdam 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. cofferdam-0.0.0/.gitignore +37 -0
  2. cofferdam-0.0.0/CHANGELOG.md +43 -0
  3. cofferdam-0.0.0/LICENSE +201 -0
  4. cofferdam-0.0.0/PKG-INFO +214 -0
  5. cofferdam-0.0.0/README.md +172 -0
  6. cofferdam-0.0.0/docs/00-ground-rules.md +45 -0
  7. cofferdam-0.0.0/docs/01-overview.md +72 -0
  8. cofferdam-0.0.0/docs/02-conceptual-model.md +51 -0
  9. cofferdam-0.0.0/docs/03-policy-file-format.md +80 -0
  10. cofferdam-0.0.0/docs/04-decision-engine.md +59 -0
  11. cofferdam-0.0.0/docs/05-secret-handling.md +39 -0
  12. cofferdam-0.0.0/docs/06-host-url-handling.md +36 -0
  13. cofferdam-0.0.0/docs/07-email-policy.md +120 -0
  14. cofferdam-0.0.0/docs/08-logging-observability.md +42 -0
  15. cofferdam-0.0.0/docs/09-public-api.md +93 -0
  16. cofferdam-0.0.0/docs/10-cli.md +51 -0
  17. cofferdam-0.0.0/docs/11-frappe-integration.md +30 -0
  18. cofferdam-0.0.0/docs/12-validation.md +43 -0
  19. cofferdam-0.0.0/docs/13-testing.md +54 -0
  20. cofferdam-0.0.0/docs/14-acceptance-criteria.md +27 -0
  21. cofferdam-0.0.0/docs/15-open-questions.md +149 -0
  22. cofferdam-0.0.0/docs/README.md +53 -0
  23. cofferdam-0.0.0/docs/adr/0002-python-library-not-frappe-app.md +33 -0
  24. cofferdam-0.0.0/docs/adr/0003-package-and-cli-name-cofferdam.md +36 -0
  25. cofferdam-0.0.0/docs/adr/0004-toml-policy-format.md +29 -0
  26. cofferdam-0.0.0/docs/adr/0005-fail-closed-by-default.md +32 -0
  27. cofferdam-0.0.0/docs/adr/0006-pydantic-v2-schema-validation.md +34 -0
  28. cofferdam-0.0.0/docs/adr/0007-env-var-credentials.md +32 -0
  29. cofferdam-0.0.0/docs/adr/0008-httpx-optional-http-helper.md +35 -0
  30. cofferdam-0.0.0/docs/adr/0010-frappe-isolation.md +34 -0
  31. cofferdam-0.0.0/docs/adr/0011-frappe-app-first-release.md +65 -0
  32. cofferdam-0.0.0/docs/adr/0012-remove-cofferdam-frappe-module.md +39 -0
  33. cofferdam-0.0.0/docs/adr/README.md +20 -0
  34. cofferdam-0.0.0/pyproject.toml +105 -0
  35. cofferdam-0.0.0/src/cofferdam/__init__.py +45 -0
  36. cofferdam-0.0.0/src/cofferdam/cli.py +138 -0
  37. cofferdam-0.0.0/src/cofferdam/config.py +66 -0
  38. cofferdam-0.0.0/src/cofferdam/credentials.py +51 -0
  39. cofferdam-0.0.0/src/cofferdam/decisions.py +174 -0
  40. cofferdam-0.0.0/src/cofferdam/errors.py +67 -0
  41. cofferdam-0.0.0/src/cofferdam/http.py +139 -0
  42. cofferdam-0.0.0/src/cofferdam/mail.py +177 -0
  43. cofferdam-0.0.0/src/cofferdam/models.py +145 -0
  44. cofferdam-0.0.0/src/cofferdam/py.typed +0 -0
  45. cofferdam-0.0.0/src/cofferdam/validators.py +100 -0
  46. cofferdam-0.0.0/tests/__init__.py +0 -0
  47. cofferdam-0.0.0/tests/conftest.py +21 -0
  48. cofferdam-0.0.0/tests/test_cli.py +69 -0
  49. cofferdam-0.0.0/tests/test_config.py +72 -0
  50. cofferdam-0.0.0/tests/test_credentials.py +51 -0
  51. cofferdam-0.0.0/tests/test_decisions.py +126 -0
  52. cofferdam-0.0.0/tests/test_http.py +269 -0
  53. cofferdam-0.0.0/tests/test_mail.py +335 -0
@@ -0,0 +1,37 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Distribution / packaging
7
+ build/
8
+ dist/
9
+ *.egg-info/
10
+ .eggs/
11
+ make_dist.sh
12
+
13
+ # Virtual environments
14
+ .venv/
15
+ venv/
16
+ env/
17
+
18
+ # Test / coverage artifacts
19
+ .pytest_cache/
20
+ .mypy_cache/
21
+ .ruff_cache/
22
+ .coverage
23
+ .coverage.*
24
+ htmlcov/
25
+ coverage.xml
26
+
27
+ # Editors / OS
28
+ .idea/
29
+ .vscode/
30
+ *.swp
31
+ .DS_Store
32
+
33
+ # cofferdam: never commit real policy files or secrets
34
+ # (example policies under tests/ and examples/ are intentionally safe fixtures)
35
+ environment_policy.toml
36
+ *.secret.toml
37
+ .env
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ All notable changes to `cofferdam` are recorded here. This project follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
5
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ Per the Scribe Coding methodology, this changelog also records **design
8
+ decisions and their rationale**, so that later work can resolve conflicts by
9
+ reading the record rather than re-litigating settled questions. Architecture
10
+ decisions are captured in full under `docs/adr/`.
11
+
12
+ ## [Unreleased]
13
+
14
+ ### Added
15
+
16
+ - Initial project scaffolding: `src/` layout, `docs/`, `tests/`, packaging
17
+ (`pyproject.toml`, `LICENSE`, `.gitignore`).
18
+ - Requirements documentation set under `docs/` with a table of contents and
19
+ business-rule identifiers (`BR-*`).
20
+ - Architecture Decision Records (ADR-0001 … ADR-0010) under `docs/adr/`.
21
+ - Package skeleton: `errors`, `models`, `config`, `validators`, `decisions`,
22
+ `credentials`, `http`, `mail`, `frappe`, `cli`.
23
+
24
+ ### Decided
25
+
26
+ - Project, distribution, import, and CLI name is **`cofferdam`** (ADR-0003),
27
+ superseding the provisional `frappe-outbound-policy` / `outbound_policy`
28
+ names from the source requirements.
29
+ - Ship a **pure Python library, not a Frappe app** (ADR-0002).
30
+ - **TOML** is the policy file format (ADR-0004).
31
+ - The engine is **fail-closed by default** (ADR-0005).
32
+ - Schema is modeled and validated with **Pydantic v2** (ADR-0006).
33
+ - Credentials resolve from **environment variables**; raw `secret_value` in
34
+ TOML is **rejected by default** and only permitted behind an explicit opt-in
35
+ (ADR-0007).
36
+ - The HTTP helper wraps **`httpx`** and is an **optional dependency**
37
+ (`cofferdam[http]`) (ADR-0008).
38
+ - Host matching uses a **structured URL parser** comparing hostnames, never
39
+ substrings (ADR-0009).
40
+ - Frappe-specific behavior is **isolated in `cofferdam.frappe`**; the core
41
+ never imports `frappe` (ADR-0010).
42
+
43
+ [Unreleased]: https://github.com/datahenge/cofferdam/commits/main
@@ -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 2026 Brian Pond / Datahenge LLC
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.
@@ -0,0 +1,214 @@
1
+ Metadata-Version: 2.4
2
+ Name: cofferdam
3
+ Version: 0.0.0
4
+ Summary: Hold back Production outbound side effects from flooding non-Production Frappe/ERPNext environments after a database restore.
5
+ Project-URL: Homepage, https://github.com/datahenge/cofferdam
6
+ Project-URL: Documentation, https://github.com/datahenge/cofferdam/tree/main/docs
7
+ Project-URL: Repository, https://github.com/datahenge/cofferdam
8
+ Project-URL: Changelog, https://github.com/datahenge/cofferdam/blob/main/CHANGELOG.md
9
+ Project-URL: Issues, https://github.com/datahenge/cofferdam/issues
10
+ Author-email: Brian Pond <brian@datahenge.com>
11
+ Maintainer-email: Brian Pond <brian@datahenge.com>
12
+ License-Expression: Apache-2.0
13
+ License-File: LICENSE
14
+ Keywords: devops,erpnext,frappe,outbound,policy,safety,sandbox,staging
15
+ Classifier: Development Status :: 3 - Alpha
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: System Administrators
18
+ Classifier: License :: OSI Approved :: Apache Software License
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Security
26
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
+ Classifier: Topic :: System :: Systems Administration
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.10
30
+ Requires-Dist: pydantic>=2.6
31
+ Requires-Dist: tomli>=2.0; python_version < '3.11'
32
+ Provides-Extra: dev
33
+ Requires-Dist: httpx>=0.27; extra == 'dev'
34
+ Requires-Dist: mypy>=1.10; extra == 'dev'
35
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
36
+ Requires-Dist: pytest>=8.0; extra == 'dev'
37
+ Requires-Dist: ruff>=0.5; extra == 'dev'
38
+ Requires-Dist: twine>=5.0; extra == 'dev'
39
+ Provides-Extra: http
40
+ Requires-Dist: httpx>=0.27; extra == 'http'
41
+ Description-Content-Type: text/markdown
42
+
43
+ # cofferdam
44
+
45
+ > Block outbound side effects — email, API calls, payments, webhooks — from
46
+ > non-production environments.
47
+
48
+ A **cofferdam** is a temporary watertight enclosure pumped dry so work can
49
+ happen on a submerged foundation. This library is the software equivalent: it
50
+ holds back outbound side effects from development, staging, and test
51
+ environments so they cannot reach real customers, payment processors, or live
52
+ vendor APIs.
53
+
54
+ ## The problem
55
+
56
+ When a non-production environment is refreshed from a production database
57
+ backup, the restored data includes live email accounts, API credentials,
58
+ payment configuration, webhook endpoints, and scheduled job settings. Without
59
+ a guard, the non-production environment behaves like production — emailing
60
+ customers, charging cards, and calling live APIs against real data.
61
+
62
+ ## How it works
63
+
64
+ `cofferdam` reads a **local TOML policy file** that lives on the environment's
65
+ filesystem — never in the database, never in a backup. That file is the
66
+ execution authority for every outbound action.
67
+
68
+ > **Restored data owns business intent. Local environment config owns
69
+ > execution authority.**
70
+
71
+ The engine answers one question per outbound action:
72
+
73
+ > *Is this specific side effect permitted **here**?*
74
+
75
+ It **fails closed**: absent, incomplete, or invalid policy denies the action.
76
+
77
+ ## Installation
78
+
79
+ ```console
80
+ $ pip install cofferdam # core library + CLI
81
+ $ pip install "cofferdam[http]" # adds the policy-checked HTTP helper (httpx)
82
+ ```
83
+
84
+ Requires Python 3.10+.
85
+
86
+ ## Quick start
87
+
88
+ ```python
89
+ from cofferdam import load_policy
90
+
91
+ policy = load_policy("environment_policy.toml")
92
+
93
+ # Raise PolicyDeniedError if this side effect is not explicitly permitted here.
94
+ policy.assert_allowed(
95
+ integration="windmill",
96
+ kind="vendor_api",
97
+ operation="write",
98
+ method="POST",
99
+ host="sandbox.windmill.dev",
100
+ credential="windmill_default",
101
+ )
102
+
103
+ # Or inspect the decision without raising.
104
+ decision = policy.decide(integration="stripe", kind="payment", operation="capture")
105
+ if not decision.allowed:
106
+ print(decision.reason_code) # e.g. "operation_not_allowed"
107
+ ```
108
+
109
+ Policy-checked HTTP — host validated against the policy before any bytes leave
110
+ (optional `cofferdam[http]` extra):
111
+
112
+ ```python
113
+ from cofferdam.http import request
114
+
115
+ response = request(
116
+ policy=policy,
117
+ integration="windmill",
118
+ operation="write",
119
+ method="POST",
120
+ url="https://sandbox.windmill.dev/api/jobs/run",
121
+ credential="windmill_default",
122
+ json=payload,
123
+ )
124
+ ```
125
+
126
+ ## Email decoration
127
+
128
+ When an email is sent from a non-production environment, `cofferdam` decorates
129
+ the subject and body so recipients immediately know the source:
130
+
131
+ - **Subject:** `STAGING - Weekly Sales Report`
132
+ - **Body:** a warning banner (HTML) or a notice line (plain text) prepended to
133
+ the original content
134
+
135
+ Decoration is on by default for any non-production environment and can be
136
+ disabled with `decorate = false` under `[mail]`.
137
+
138
+ ## Example policy
139
+
140
+ ```toml
141
+ environment = "staging"
142
+ default_decision = "deny"
143
+
144
+ [mail]
145
+ mode = "sink"
146
+ sink = "dev-inbox@example.internal" # all outbound mail redirected here
147
+
148
+ [integrations.windmill]
149
+ enabled = true
150
+ kind = "vendor_api"
151
+ credential = "windmill_default"
152
+ allowed_hosts = ["sandbox.windmill.dev"]
153
+ allowed_methods = ["GET", "POST"]
154
+ allowed_operations = ["read", "write"]
155
+
156
+ [credentials.windmill_default]
157
+ profile = "staging"
158
+ secret_env = "WINDMILL_API_KEY"
159
+
160
+ [integrations.stripe]
161
+ enabled = true
162
+ kind = "payment"
163
+ credential = "stripe_default"
164
+ allowed_hosts = ["api.stripe.com"]
165
+ allow_authorize = true
166
+ allow_capture = false # never capture money outside Production
167
+
168
+ [credentials.stripe_default]
169
+ profile = "sandbox"
170
+ secret_env = "STRIPE_SANDBOX_SECRET_KEY"
171
+
172
+ [effects.email.customer]
173
+ enabled = false # no customer email in Staging
174
+
175
+ [effects.email.internal]
176
+ enabled = true
177
+ allow_domains = ["example.internal"]
178
+ ```
179
+
180
+ ## CLI
181
+
182
+ ```console
183
+ $ cofferdam validate path/to/environment_policy.toml
184
+ $ cofferdam inspect path/to/environment_policy.toml
185
+ $ cofferdam decide path/to/environment_policy.toml \
186
+ --integration windmill --kind vendor_api --operation write \
187
+ --method POST --url https://sandbox.windmill.dev/api/jobs/run \
188
+ --credential windmill_default
189
+ ```
190
+
191
+ `validate` exits non-zero on invalid policy. `inspect` prints a redacted
192
+ summary — secrets are never shown. `decide` prints allow/deny and a stable
193
+ reason code.
194
+
195
+ ## Frappe / ERPNext
196
+
197
+ `cofferdam` was designed with ERPNext and Frappe Framework in mind — the
198
+ database restore pattern is a daily reality for that ecosystem. The core
199
+ library has no dependency on Frappe and works with any Python application.
200
+
201
+ For full Frappe/ERPNext integration — automatic policy discovery by bench
202
+ site, interception of `frappe.sendmail`, and webhook delivery gating — see
203
+ **[cofferdam-app](https://github.com/Datahenge/cofferdam-app)**, a companion
204
+ Frappe app that installs into a bench alongside your ERPNext site.
205
+
206
+ ## Requirements specification
207
+
208
+ This library is built with a document-driven workflow. See [`docs/`](docs/)
209
+ for the full requirements specification and [`docs/adr/`](docs/adr/) for
210
+ architecture decisions.
211
+
212
+ ## License
213
+
214
+ Apache-2.0 © 2026 Brian Pond / Datahenge LLC
@@ -0,0 +1,172 @@
1
+ # cofferdam
2
+
3
+ > Block outbound side effects — email, API calls, payments, webhooks — from
4
+ > non-production environments.
5
+
6
+ A **cofferdam** is a temporary watertight enclosure pumped dry so work can
7
+ happen on a submerged foundation. This library is the software equivalent: it
8
+ holds back outbound side effects from development, staging, and test
9
+ environments so they cannot reach real customers, payment processors, or live
10
+ vendor APIs.
11
+
12
+ ## The problem
13
+
14
+ When a non-production environment is refreshed from a production database
15
+ backup, the restored data includes live email accounts, API credentials,
16
+ payment configuration, webhook endpoints, and scheduled job settings. Without
17
+ a guard, the non-production environment behaves like production — emailing
18
+ customers, charging cards, and calling live APIs against real data.
19
+
20
+ ## How it works
21
+
22
+ `cofferdam` reads a **local TOML policy file** that lives on the environment's
23
+ filesystem — never in the database, never in a backup. That file is the
24
+ execution authority for every outbound action.
25
+
26
+ > **Restored data owns business intent. Local environment config owns
27
+ > execution authority.**
28
+
29
+ The engine answers one question per outbound action:
30
+
31
+ > *Is this specific side effect permitted **here**?*
32
+
33
+ It **fails closed**: absent, incomplete, or invalid policy denies the action.
34
+
35
+ ## Installation
36
+
37
+ ```console
38
+ $ pip install cofferdam # core library + CLI
39
+ $ pip install "cofferdam[http]" # adds the policy-checked HTTP helper (httpx)
40
+ ```
41
+
42
+ Requires Python 3.10+.
43
+
44
+ ## Quick start
45
+
46
+ ```python
47
+ from cofferdam import load_policy
48
+
49
+ policy = load_policy("environment_policy.toml")
50
+
51
+ # Raise PolicyDeniedError if this side effect is not explicitly permitted here.
52
+ policy.assert_allowed(
53
+ integration="windmill",
54
+ kind="vendor_api",
55
+ operation="write",
56
+ method="POST",
57
+ host="sandbox.windmill.dev",
58
+ credential="windmill_default",
59
+ )
60
+
61
+ # Or inspect the decision without raising.
62
+ decision = policy.decide(integration="stripe", kind="payment", operation="capture")
63
+ if not decision.allowed:
64
+ print(decision.reason_code) # e.g. "operation_not_allowed"
65
+ ```
66
+
67
+ Policy-checked HTTP — host validated against the policy before any bytes leave
68
+ (optional `cofferdam[http]` extra):
69
+
70
+ ```python
71
+ from cofferdam.http import request
72
+
73
+ response = request(
74
+ policy=policy,
75
+ integration="windmill",
76
+ operation="write",
77
+ method="POST",
78
+ url="https://sandbox.windmill.dev/api/jobs/run",
79
+ credential="windmill_default",
80
+ json=payload,
81
+ )
82
+ ```
83
+
84
+ ## Email decoration
85
+
86
+ When an email is sent from a non-production environment, `cofferdam` decorates
87
+ the subject and body so recipients immediately know the source:
88
+
89
+ - **Subject:** `STAGING - Weekly Sales Report`
90
+ - **Body:** a warning banner (HTML) or a notice line (plain text) prepended to
91
+ the original content
92
+
93
+ Decoration is on by default for any non-production environment and can be
94
+ disabled with `decorate = false` under `[mail]`.
95
+
96
+ ## Example policy
97
+
98
+ ```toml
99
+ environment = "staging"
100
+ default_decision = "deny"
101
+
102
+ [mail]
103
+ mode = "sink"
104
+ sink = "dev-inbox@example.internal" # all outbound mail redirected here
105
+
106
+ [integrations.windmill]
107
+ enabled = true
108
+ kind = "vendor_api"
109
+ credential = "windmill_default"
110
+ allowed_hosts = ["sandbox.windmill.dev"]
111
+ allowed_methods = ["GET", "POST"]
112
+ allowed_operations = ["read", "write"]
113
+
114
+ [credentials.windmill_default]
115
+ profile = "staging"
116
+ secret_env = "WINDMILL_API_KEY"
117
+
118
+ [integrations.stripe]
119
+ enabled = true
120
+ kind = "payment"
121
+ credential = "stripe_default"
122
+ allowed_hosts = ["api.stripe.com"]
123
+ allow_authorize = true
124
+ allow_capture = false # never capture money outside Production
125
+
126
+ [credentials.stripe_default]
127
+ profile = "sandbox"
128
+ secret_env = "STRIPE_SANDBOX_SECRET_KEY"
129
+
130
+ [effects.email.customer]
131
+ enabled = false # no customer email in Staging
132
+
133
+ [effects.email.internal]
134
+ enabled = true
135
+ allow_domains = ["example.internal"]
136
+ ```
137
+
138
+ ## CLI
139
+
140
+ ```console
141
+ $ cofferdam validate path/to/environment_policy.toml
142
+ $ cofferdam inspect path/to/environment_policy.toml
143
+ $ cofferdam decide path/to/environment_policy.toml \
144
+ --integration windmill --kind vendor_api --operation write \
145
+ --method POST --url https://sandbox.windmill.dev/api/jobs/run \
146
+ --credential windmill_default
147
+ ```
148
+
149
+ `validate` exits non-zero on invalid policy. `inspect` prints a redacted
150
+ summary — secrets are never shown. `decide` prints allow/deny and a stable
151
+ reason code.
152
+
153
+ ## Frappe / ERPNext
154
+
155
+ `cofferdam` was designed with ERPNext and Frappe Framework in mind — the
156
+ database restore pattern is a daily reality for that ecosystem. The core
157
+ library has no dependency on Frappe and works with any Python application.
158
+
159
+ For full Frappe/ERPNext integration — automatic policy discovery by bench
160
+ site, interception of `frappe.sendmail`, and webhook delivery gating — see
161
+ **[cofferdam-app](https://github.com/Datahenge/cofferdam-app)**, a companion
162
+ Frappe app that installs into a bench alongside your ERPNext site.
163
+
164
+ ## Requirements specification
165
+
166
+ This library is built with a document-driven workflow. See [`docs/`](docs/)
167
+ for the full requirements specification and [`docs/adr/`](docs/adr/) for
168
+ architecture decisions.
169
+
170
+ ## License
171
+
172
+ Apache-2.0 © 2026 Brian Pond / Datahenge LLC