fish-edge-gateway-sdk 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.
- fish_edge_gateway_sdk-0.1.0/.gitignore +5 -0
- fish_edge_gateway_sdk-0.1.0/LICENSE-APACHE +202 -0
- fish_edge_gateway_sdk-0.1.0/LICENSE-MIT +21 -0
- fish_edge_gateway_sdk-0.1.0/PKG-INFO +88 -0
- fish_edge_gateway_sdk-0.1.0/README.md +65 -0
- fish_edge_gateway_sdk-0.1.0/examples/omni_asr_demo.py +26 -0
- fish_edge_gateway_sdk-0.1.0/pyproject.toml +47 -0
- fish_edge_gateway_sdk-0.1.0/src/fish_edge_gateway_sdk/__init__.py +85 -0
- fish_edge_gateway_sdk-0.1.0/src/fish_edge_gateway_sdk/auth.py +64 -0
- fish_edge_gateway_sdk-0.1.0/src/fish_edge_gateway_sdk/discovery.py +201 -0
- fish_edge_gateway_sdk-0.1.0/src/fish_edge_gateway_sdk/manifest.py +181 -0
- fish_edge_gateway_sdk-0.1.0/src/fish_edge_gateway_sdk/trace.py +42 -0
- fish_edge_gateway_sdk-0.1.0/src/fish_edge_gateway_sdk/usage.py +109 -0
- fish_edge_gateway_sdk-0.1.0/tests/test_fastapi_integration.py +153 -0
- fish_edge_gateway_sdk-0.1.0/tests/test_manifest.py +172 -0
- fish_edge_gateway_sdk-0.1.0/tests/test_trace.py +18 -0
- fish_edge_gateway_sdk-0.1.0/tests/test_usage.py +64 -0
- fish_edge_gateway_sdk-0.1.0/uv.lock +424 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fish Audio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fish-edge-gateway-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Service-side SDK for apex-edge-gateway: declare a FastAPI service's routes for discovery, report usage in band, verify gateway-origin auth, and join the gateway's trace
|
|
5
|
+
Project-URL: Homepage, https://fish.audio
|
|
6
|
+
Author: Fish Audio
|
|
7
|
+
License-Expression: MIT OR Apache-2.0
|
|
8
|
+
License-File: LICENSE-APACHE
|
|
9
|
+
License-File: LICENSE-MIT
|
|
10
|
+
Keywords: edge,fastapi,fish-audio,gateway,sdk
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Framework :: FastAPI
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Requires-Dist: fastapi>=0.100
|
|
18
|
+
Requires-Dist: pydantic>=2
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# fish-edge-gateway-sdk (Python)
|
|
25
|
+
|
|
26
|
+
接入 apex-edge-gateway 的服务侧 SDK:manifest 声明与暴露、internal auth、trace 透传。协议契约见仓库 `docs/contracts/`。
|
|
27
|
+
|
|
28
|
+
## 安装(不发布 PyPI,直接 git 依赖)
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
# requirements.txt / pyproject dependency(锁 tag 或 commit,不要追 main)
|
|
32
|
+
fish-edge-gateway-sdk @ git+ssh://git@github.com/fishaudio/apex-edge-gateway.git@<tag-or-sha>#subdirectory=sdk-python
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
# 本地开发
|
|
37
|
+
pip install "fish-edge-gateway-sdk @ git+ssh://git@github.com/fishaudio/apex-edge-gateway.git@main#subdirectory=sdk-python"
|
|
38
|
+
|
|
39
|
+
# uv
|
|
40
|
+
uv add "fish-edge-gateway-sdk @ git+ssh://git@github.com/fishaudio/apex-edge-gateway.git@main#subdirectory=sdk-python"
|
|
41
|
+
|
|
42
|
+
# CI / Docker(https + token,避免挂 ssh key)
|
|
43
|
+
pip install "fish-edge-gateway-sdk @ git+https://${GITHUB_TOKEN}@github.com/fishaudio/apex-edge-gateway.git@<sha>#subdirectory=sdk-python"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
版本锁定约定:SDK 变更打 `sdk-python/vX.Y.Z` 形式的 git tag,服务锁 tag 升级;紧急验证可锁 commit sha。
|
|
47
|
+
|
|
48
|
+
## 集成
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from fastapi import Depends, FastAPI
|
|
52
|
+
from fish_edge_gateway_sdk import edge_route, mount_edge, require_gateway
|
|
53
|
+
|
|
54
|
+
app = FastAPI()
|
|
55
|
+
|
|
56
|
+
@app.post("/internal/asr", dependencies=[Depends(require_gateway)])
|
|
57
|
+
@edge_route(auth="internal")
|
|
58
|
+
async def asr(payload: dict) -> dict: ...
|
|
59
|
+
|
|
60
|
+
mount_edge(app, service="omni-asr") # 挂载 GET /.edge/manifest
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
k8s Service 侧标注(manifest 契约 §2.1):
|
|
64
|
+
|
|
65
|
+
```yaml
|
|
66
|
+
metadata:
|
|
67
|
+
annotations:
|
|
68
|
+
fish.audio/edge-discovery: enable
|
|
69
|
+
# 可选:manifest 端点与业务端口分离时
|
|
70
|
+
# fish.audio/edge-discovery-port: "9090"
|
|
71
|
+
# fish.audio/edge-discovery-url: /.edge/manifest
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
gateway 侧无需额外授权:发现 namespace 的成员资格就是信任边界(manifest 契约 §11),被发现的 manifest 其 route 直接编译。
|
|
75
|
+
|
|
76
|
+
## 环境变量
|
|
77
|
+
|
|
78
|
+
| 变量 | 语义 |
|
|
79
|
+
| -- | -- |
|
|
80
|
+
| `FISH_EDGE_GATEWAY_TOKEN` | 期望的 `x-fish-gateway-token`。未设 = 观察模式(只记日志) |
|
|
81
|
+
| `FISH_EDGE_REQUIRE_GATEWAY` | `1` 时强制校验(403 拒绝非 gateway 流量)。P6 gateway 下发 token 后开启 |
|
|
82
|
+
|
|
83
|
+
## 开发
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
pip install -e "sdk-python[dev]"
|
|
87
|
+
pytest sdk-python/tests -q
|
|
88
|
+
```
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# fish-edge-gateway-sdk (Python)
|
|
2
|
+
|
|
3
|
+
接入 apex-edge-gateway 的服务侧 SDK:manifest 声明与暴露、internal auth、trace 透传。协议契约见仓库 `docs/contracts/`。
|
|
4
|
+
|
|
5
|
+
## 安装(不发布 PyPI,直接 git 依赖)
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
# requirements.txt / pyproject dependency(锁 tag 或 commit,不要追 main)
|
|
9
|
+
fish-edge-gateway-sdk @ git+ssh://git@github.com/fishaudio/apex-edge-gateway.git@<tag-or-sha>#subdirectory=sdk-python
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
# 本地开发
|
|
14
|
+
pip install "fish-edge-gateway-sdk @ git+ssh://git@github.com/fishaudio/apex-edge-gateway.git@main#subdirectory=sdk-python"
|
|
15
|
+
|
|
16
|
+
# uv
|
|
17
|
+
uv add "fish-edge-gateway-sdk @ git+ssh://git@github.com/fishaudio/apex-edge-gateway.git@main#subdirectory=sdk-python"
|
|
18
|
+
|
|
19
|
+
# CI / Docker(https + token,避免挂 ssh key)
|
|
20
|
+
pip install "fish-edge-gateway-sdk @ git+https://${GITHUB_TOKEN}@github.com/fishaudio/apex-edge-gateway.git@<sha>#subdirectory=sdk-python"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
版本锁定约定:SDK 变更打 `sdk-python/vX.Y.Z` 形式的 git tag,服务锁 tag 升级;紧急验证可锁 commit sha。
|
|
24
|
+
|
|
25
|
+
## 集成
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from fastapi import Depends, FastAPI
|
|
29
|
+
from fish_edge_gateway_sdk import edge_route, mount_edge, require_gateway
|
|
30
|
+
|
|
31
|
+
app = FastAPI()
|
|
32
|
+
|
|
33
|
+
@app.post("/internal/asr", dependencies=[Depends(require_gateway)])
|
|
34
|
+
@edge_route(auth="internal")
|
|
35
|
+
async def asr(payload: dict) -> dict: ...
|
|
36
|
+
|
|
37
|
+
mount_edge(app, service="omni-asr") # 挂载 GET /.edge/manifest
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
k8s Service 侧标注(manifest 契约 §2.1):
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
metadata:
|
|
44
|
+
annotations:
|
|
45
|
+
fish.audio/edge-discovery: enable
|
|
46
|
+
# 可选:manifest 端点与业务端口分离时
|
|
47
|
+
# fish.audio/edge-discovery-port: "9090"
|
|
48
|
+
# fish.audio/edge-discovery-url: /.edge/manifest
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
gateway 侧无需额外授权:发现 namespace 的成员资格就是信任边界(manifest 契约 §11),被发现的 manifest 其 route 直接编译。
|
|
52
|
+
|
|
53
|
+
## 环境变量
|
|
54
|
+
|
|
55
|
+
| 变量 | 语义 |
|
|
56
|
+
| -- | -- |
|
|
57
|
+
| `FISH_EDGE_GATEWAY_TOKEN` | 期望的 `x-fish-gateway-token`。未设 = 观察模式(只记日志) |
|
|
58
|
+
| `FISH_EDGE_REQUIRE_GATEWAY` | `1` 时强制校验(403 拒绝非 gateway 流量)。P6 gateway 下发 token 后开启 |
|
|
59
|
+
|
|
60
|
+
## 开发
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
pip install -e "sdk-python[dev]"
|
|
64
|
+
pytest sdk-python/tests -q
|
|
65
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Minimal edge-integrated service, used both as documentation and to produce
|
|
2
|
+
the cross-language conformance fixture (docs/contracts/fixtures/manifest/).
|
|
3
|
+
|
|
4
|
+
Run: uvicorn omni_asr_demo:app --port 9000
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from fastapi import Depends, FastAPI
|
|
8
|
+
|
|
9
|
+
from fish_edge_gateway_sdk import edge_route, mount_edge, require_gateway, trace_id
|
|
10
|
+
|
|
11
|
+
app = FastAPI()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@app.post("/internal/asr", dependencies=[Depends(require_gateway)])
|
|
15
|
+
@edge_route(auth="internal", protocol="json")
|
|
16
|
+
async def asr(payload: dict) -> dict:
|
|
17
|
+
return {"ok": True, "len": len(str(payload))}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@app.get("/internal/asr/health")
|
|
21
|
+
@edge_route(auth="internal", protocol="json", concurrency="none")
|
|
22
|
+
async def health() -> dict:
|
|
23
|
+
return {"status": "up"}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
mount_edge(app, service="omni-asr")
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "fish-edge-gateway-sdk"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Service-side SDK for apex-edge-gateway: declare a FastAPI service's routes for discovery, report usage in band, verify gateway-origin auth, and join the gateway's trace"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "MIT OR Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE-MIT", "LICENSE-APACHE"]
|
|
9
|
+
authors = [{ name = "Fish Audio" }]
|
|
10
|
+
keywords = ["fish-audio", "gateway", "fastapi", "sdk", "edge"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
"Framework :: FastAPI",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
17
|
+
]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"fastapi>=0.100",
|
|
20
|
+
"pydantic>=2",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
# No public repository: the gateway is private and a link to it would 404.
|
|
24
|
+
# The README ships in the sdist and wheel, so it is the documentation.
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://fish.audio"
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
dev = [
|
|
30
|
+
"pytest>=8",
|
|
31
|
+
"httpx>=0.27",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["hatchling"]
|
|
36
|
+
build-backend = "hatchling.build"
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.wheel]
|
|
39
|
+
packages = ["src/fish_edge_gateway_sdk"]
|
|
40
|
+
# Bytecode from local runs would otherwise ride along in the wheel.
|
|
41
|
+
exclude = ["**/__pycache__", "**/*.pyc"]
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.sdist]
|
|
44
|
+
exclude = ["**/__pycache__", "**/*.pyc", ".venv"]
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""fish-edge-sdk: manifest discovery, internal auth, and trace propagation for
|
|
2
|
+
services behind apex-edge-gateway (contracts: docs/contracts/ in the
|
|
3
|
+
apex-edge-proxy repository).
|
|
4
|
+
|
|
5
|
+
Minimal integration:
|
|
6
|
+
|
|
7
|
+
from fastapi import Depends, FastAPI
|
|
8
|
+
from fish_edge_gateway_sdk import edge_route, mount_edge, require_gateway
|
|
9
|
+
|
|
10
|
+
app = FastAPI()
|
|
11
|
+
|
|
12
|
+
@app.post("/internal/asr", dependencies=[Depends(require_gateway)])
|
|
13
|
+
@edge_route(auth="internal")
|
|
14
|
+
async def asr(...): ...
|
|
15
|
+
|
|
16
|
+
mount_edge(app, service="omni-asr")
|
|
17
|
+
|
|
18
|
+
Usage reporting helpers (usage contract) arrive together with the gateway's
|
|
19
|
+
P5 billing engine.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from .auth import GATEWAY_TOKEN_HEADER, require_gateway
|
|
23
|
+
from .discovery import MANIFEST_PATH, build_manifest, edge_route, mount_edge
|
|
24
|
+
from .manifest import (
|
|
25
|
+
SCHEMA_VERSION,
|
|
26
|
+
Billing,
|
|
27
|
+
Concurrency,
|
|
28
|
+
Claim,
|
|
29
|
+
Manifest,
|
|
30
|
+
Match,
|
|
31
|
+
PathMatch,
|
|
32
|
+
RouteDecl,
|
|
33
|
+
ClaimsTarget,
|
|
34
|
+
StaticTarget,
|
|
35
|
+
)
|
|
36
|
+
from .trace import TRACEPARENT_HEADER, propagation_headers, trace_id
|
|
37
|
+
from .usage import (
|
|
38
|
+
EVENT_CONCURRENCY,
|
|
39
|
+
USAGE_TOKENS_HEADER,
|
|
40
|
+
usage_header,
|
|
41
|
+
usage_json_field,
|
|
42
|
+
EVENT_CONCURRENCY_REJECTED,
|
|
43
|
+
EVENT_USAGE,
|
|
44
|
+
EVENT_USAGE_FINAL,
|
|
45
|
+
concurrency_event,
|
|
46
|
+
is_protocol_event,
|
|
47
|
+
sse_data,
|
|
48
|
+
usage_event,
|
|
49
|
+
usage_final_event,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
__all__ = [
|
|
53
|
+
"SCHEMA_VERSION",
|
|
54
|
+
"MANIFEST_PATH",
|
|
55
|
+
"GATEWAY_TOKEN_HEADER",
|
|
56
|
+
"TRACEPARENT_HEADER",
|
|
57
|
+
"Manifest",
|
|
58
|
+
"RouteDecl",
|
|
59
|
+
"Match",
|
|
60
|
+
"PathMatch",
|
|
61
|
+
"StaticTarget",
|
|
62
|
+
"ClaimsTarget",
|
|
63
|
+
"Claim",
|
|
64
|
+
"model_header_is",
|
|
65
|
+
"Billing",
|
|
66
|
+
"Concurrency",
|
|
67
|
+
"edge_route",
|
|
68
|
+
"mount_edge",
|
|
69
|
+
"build_manifest",
|
|
70
|
+
"require_gateway",
|
|
71
|
+
"trace_id",
|
|
72
|
+
"propagation_headers",
|
|
73
|
+
"EVENT_USAGE",
|
|
74
|
+
"EVENT_USAGE_FINAL",
|
|
75
|
+
"EVENT_CONCURRENCY",
|
|
76
|
+
"EVENT_CONCURRENCY_REJECTED",
|
|
77
|
+
"usage_event",
|
|
78
|
+
"usage_final_event",
|
|
79
|
+
"USAGE_TOKENS_HEADER",
|
|
80
|
+
"usage_header",
|
|
81
|
+
"usage_json_field",
|
|
82
|
+
"concurrency_event",
|
|
83
|
+
"is_protocol_event",
|
|
84
|
+
"sse_data",
|
|
85
|
+
]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Internal-auth dependency: verify traffic arrived through the gateway.
|
|
2
|
+
|
|
3
|
+
gateway-adaptor contract §2/§4: the gateway attaches `x-fish-gateway-token`
|
|
4
|
+
(P5+) to forwards; a service that should only ever be reached through the
|
|
5
|
+
gateway verifies it. Before the token rollout (and for services also taking
|
|
6
|
+
direct traffic) the check runs in observe mode: it records but does not
|
|
7
|
+
reject.
|
|
8
|
+
|
|
9
|
+
Configuration (env):
|
|
10
|
+
|
|
11
|
+
* `FISH_EDGE_GATEWAY_TOKEN` — the expected token. Unset = observe mode.
|
|
12
|
+
* `FISH_EDGE_REQUIRE_GATEWAY` — "1" to enforce (403 on mismatch). Default
|
|
13
|
+
observe: log-only, so the dependency is safe to adopt before the gateway
|
|
14
|
+
sends tokens.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import hmac
|
|
20
|
+
import logging
|
|
21
|
+
import os
|
|
22
|
+
|
|
23
|
+
from fastapi import HTTPException, Request
|
|
24
|
+
|
|
25
|
+
GATEWAY_TOKEN_HEADER = "x-fish-gateway-token"
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger("fish_edge_gateway_sdk.auth")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _expected_token() -> str | None:
|
|
31
|
+
return os.environ.get("FISH_EDGE_GATEWAY_TOKEN") or None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _enforced() -> bool:
|
|
35
|
+
return os.environ.get("FISH_EDGE_REQUIRE_GATEWAY") == "1"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
async def require_gateway(request: Request) -> None:
|
|
39
|
+
"""FastAPI dependency: `Depends(require_gateway)` on internal routes."""
|
|
40
|
+
expected = _expected_token()
|
|
41
|
+
presented = request.headers.get(GATEWAY_TOKEN_HEADER)
|
|
42
|
+
|
|
43
|
+
if expected is None:
|
|
44
|
+
# Token not rolled out yet: observe only.
|
|
45
|
+
if _enforced():
|
|
46
|
+
logger.error(
|
|
47
|
+
"FISH_EDGE_REQUIRE_GATEWAY=1 but FISH_EDGE_GATEWAY_TOKEN is unset; "
|
|
48
|
+
"refusing request (misconfiguration must fail loudly)"
|
|
49
|
+
)
|
|
50
|
+
raise HTTPException(status_code=503, detail="gateway auth misconfigured")
|
|
51
|
+
return
|
|
52
|
+
|
|
53
|
+
ok = presented is not None and hmac.compare_digest(presented, expected)
|
|
54
|
+
if ok:
|
|
55
|
+
return
|
|
56
|
+
if _enforced():
|
|
57
|
+
raise HTTPException(status_code=403, detail="request did not arrive via the edge gateway")
|
|
58
|
+
logger.warning(
|
|
59
|
+
"request without a valid %s (observe mode; set FISH_EDGE_REQUIRE_GATEWAY=1 to enforce)",
|
|
60
|
+
GATEWAY_TOKEN_HEADER,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
__all__ = ["require_gateway", "GATEWAY_TOKEN_HEADER"]
|