pxa-drm-server 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.
- pxa_drm_server-0.1.0/LICENSE +201 -0
- pxa_drm_server-0.1.0/MANIFEST.in +8 -0
- pxa_drm_server-0.1.0/PKG-INFO +311 -0
- pxa_drm_server-0.1.0/README.md +273 -0
- pxa_drm_server-0.1.0/config/config.yaml +55 -0
- pxa_drm_server-0.1.0/domain_core.py +74 -0
- pxa_drm_server-0.1.0/pxa_drm_server/__init__.py +26 -0
- pxa_drm_server-0.1.0/pxa_drm_server/__main__.py +7 -0
- pxa_drm_server-0.1.0/pxa_drm_server/api/__init__.py +1 -0
- pxa_drm_server-0.1.0/pxa_drm_server/api/v1/__init__.py +4 -0
- pxa_drm_server-0.1.0/pxa_drm_server/api/v1/routes.py +83 -0
- pxa_drm_server-0.1.0/pxa_drm_server/app.py +80 -0
- pxa_drm_server-0.1.0/pxa_drm_server/asgi.py +12 -0
- pxa_drm_server-0.1.0/pxa_drm_server/codes.py +46 -0
- pxa_drm_server-0.1.0/pxa_drm_server/config.py +101 -0
- pxa_drm_server-0.1.0/pxa_drm_server/domain.py +122 -0
- pxa_drm_server-0.1.0/pxa_drm_server/errors.py +94 -0
- pxa_drm_server-0.1.0/pxa_drm_server/main.py +112 -0
- pxa_drm_server-0.1.0/pxa_drm_server/messages/drm.yaml +25 -0
- pxa_drm_server-0.1.0/pxa_drm_server/runtime.py +49 -0
- pxa_drm_server-0.1.0/pxa_drm_server/service.py +169 -0
- pxa_drm_server-0.1.0/pxa_drm_server/sources/__init__.py +14 -0
- pxa_drm_server-0.1.0/pxa_drm_server/sources/base.py +43 -0
- pxa_drm_server-0.1.0/pxa_drm_server/sources/local.py +84 -0
- pxa_drm_server-0.1.0/pxa_drm_server/sources/objectstorage.py +163 -0
- pxa_drm_server-0.1.0/pxa_drm_server/sources/upload.py +79 -0
- pxa_drm_server-0.1.0/pxa_drm_server/templates/__init__.py +8 -0
- pxa_drm_server-0.1.0/pxa_drm_server/templates/config.yaml +55 -0
- pxa_drm_server-0.1.0/pxa_drm_server/templates/domain_core.py +74 -0
- pxa_drm_server-0.1.0/pxa_drm_server/workspace.py +37 -0
- pxa_drm_server-0.1.0/pxa_drm_server.egg-info/PKG-INFO +311 -0
- pxa_drm_server-0.1.0/pxa_drm_server.egg-info/SOURCES.txt +43 -0
- pxa_drm_server-0.1.0/pxa_drm_server.egg-info/dependency_links.txt +1 -0
- pxa_drm_server-0.1.0/pxa_drm_server.egg-info/entry_points.txt +2 -0
- pxa_drm_server-0.1.0/pxa_drm_server.egg-info/requires.txt +10 -0
- pxa_drm_server-0.1.0/pxa_drm_server.egg-info/top_level.txt +1 -0
- pxa_drm_server-0.1.0/pyproject.toml +58 -0
- pxa_drm_server-0.1.0/requirements.txt +6 -0
- pxa_drm_server-0.1.0/setup.cfg +4 -0
- pxa_drm_server-0.1.0/tests/conftest.py +74 -0
- pxa_drm_server-0.1.0/tests/fixtures/odd_domain.py +12 -0
- pxa_drm_server-0.1.0/tests/test_api_local.py +113 -0
- pxa_drm_server-0.1.0/tests/test_api_storage.py +149 -0
- pxa_drm_server-0.1.0/tests/test_api_upload.py +77 -0
- pxa_drm_server-0.1.0/tests/test_packaging.py +68 -0
|
@@ -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.
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pxa-drm-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 파일 암복호화 API 서버 — domain_core 세 함수만 구현하면 되는 FastAPI 기반 DRM 서버 (pxa-common)
|
|
5
|
+
Author: Kwanghyun Daniel Lee
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/asulikeit/pxa-drm-server-py
|
|
8
|
+
Project-URL: Repository, https://github.com/asulikeit/pxa-drm-server-py
|
|
9
|
+
Project-URL: Issues, https://github.com/asulikeit/pxa-drm-server-py/issues
|
|
10
|
+
Keywords: pxa,drm,encryption,decryption,fastapi,s3,api-server
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Web Environment
|
|
13
|
+
Classifier: Framework :: FastAPI
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Natural Language :: Korean
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
23
|
+
Classifier: Topic :: Security :: Cryptography
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: pxa-common==0.1.1
|
|
29
|
+
Requires-Dist: fastapi==0.128.0
|
|
30
|
+
Requires-Dist: uvicorn[standard]>=0.30
|
|
31
|
+
Requires-Dist: python-multipart>=0.0.9
|
|
32
|
+
Requires-Dist: boto3>=1.34
|
|
33
|
+
Requires-Dist: PyYAML>=6.0
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
36
|
+
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# pxa-drm-server
|
|
40
|
+
|
|
41
|
+
파일 **암복호화 API 서버**. `pxa-common==0.1.1` 위에 `fastapi==0.128.0` 으로 만들었다.
|
|
42
|
+
|
|
43
|
+
개발자는 **`domain_core.py` 에 세 함수만 구현**하면 된다.
|
|
44
|
+
REST API, 로깅, 에러 처리, 표준 응답 포맷, 오브젝트 스토리지 입출력,
|
|
45
|
+
첨부파일 처리는 서버가 전부 담당한다.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
# domain_core.py — 개발자가 작성하는 유일한 파일
|
|
49
|
+
def encrypt(filepath: str) -> bool: # 암호화 성공 True / 실패 False
|
|
50
|
+
def decrypt(filepath: str) -> bool: # 복호화 성공 True / 실패 False
|
|
51
|
+
def check(filepath: str) -> bool: # 암호화되어 있으면 True (파일 수정 금지)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 1. 빠르게 실행하기
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install pxa-drm-server
|
|
60
|
+
|
|
61
|
+
pxa-drm-server init # domain_core.py 와 config/config.yaml 을 만든다
|
|
62
|
+
|
|
63
|
+
# domain_core.py 의 세 함수를 실제 DRM 모듈 호출로 바꾼다 (기본은 동작 확인용 샘플)
|
|
64
|
+
|
|
65
|
+
PXA_CONFIG=config/config.yaml pxa-drm-server
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
저장소를 직접 받아서 쓸 때는 `pip install -e ".[dev]"` 로 설치하면
|
|
69
|
+
`domain_core.py` 와 `config/config.yaml` 이 이미 들어 있으므로 `init` 없이 바로 실행된다.
|
|
70
|
+
|
|
71
|
+
실행 방법은 세 가지 모두 같다.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
PXA_CONFIG=config/config.yaml pxa-drm-server
|
|
75
|
+
PXA_CONFIG=config/config.yaml python -m pxa_drm_server
|
|
76
|
+
PXA_CONFIG=config/config.yaml uvicorn pxa_drm_server.asgi:app --host 0.0.0.0 --port 8000
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- Swagger UI: `http://localhost:8000/docs`
|
|
80
|
+
- 상태 확인: `GET /api/v1/health`
|
|
81
|
+
|
|
82
|
+
### CLI
|
|
83
|
+
|
|
84
|
+
| 명령 | 설명 |
|
|
85
|
+
|---|---|
|
|
86
|
+
| `pxa-drm-server` | 서버 실행 (`run` 과 동일) |
|
|
87
|
+
| `pxa-drm-server init [--dir DIR] [--force]` | 시작 템플릿 생성. 이미 있는 파일은 건너뛰고, `--force` 면 덮어쓴다 |
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 2. 기본 제공 API
|
|
92
|
+
|
|
93
|
+
| 대상 | 호출 |
|
|
94
|
+
|---|---|
|
|
95
|
+
| 서버 로컬 경로 | `GET \| POST /api/v1/encrypt?filepath=/download/file.docx` |
|
|
96
|
+
| 서버 로컬 경로 | `GET \| POST /api/v1/decrypt?filepath=/download/file.docx` |
|
|
97
|
+
| 오브젝트 스토리지 | `GET \| POST /api/v1/encrypt?uri=ABC:download/file.docx` |
|
|
98
|
+
| 오브젝트 스토리지 | `GET \| POST /api/v1/decrypt?uri=ABC:download/file.docx` |
|
|
99
|
+
| 첨부파일 | `POST /api/v1/encrypt` (multipart, `file=@file.docx`) |
|
|
100
|
+
| 첨부파일 | `POST /api/v1/decrypt` (multipart, `file=@file.docx`) |
|
|
101
|
+
| 암호화 여부 확인 | `GET \| POST /api/v1/check` (위 세 가지 대상 모두 지원) |
|
|
102
|
+
|
|
103
|
+
`filepath`, `uri`, `file` 중 **정확히 하나**를 지정한다.
|
|
104
|
+
하나도 없으면 `pxa-20002`, 둘 이상이면 `pxa-20001` 로 응답한다.
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# 로컬 경로
|
|
108
|
+
curl "http://localhost:8000/api/v1/encrypt?filepath=/download/file.docx"
|
|
109
|
+
|
|
110
|
+
# 오브젝트 스토리지 (ABC 는 config 에 등록한 버킷 별칭)
|
|
111
|
+
curl "http://localhost:8000/api/v1/decrypt?uri=ABC:download/file.docx"
|
|
112
|
+
|
|
113
|
+
# 첨부파일 -> 처리된 파일을 그대로 내려받는다
|
|
114
|
+
curl -F "file=@file.docx" "http://localhost:8000/api/v1/encrypt" -o encrypted.docx
|
|
115
|
+
|
|
116
|
+
# 첨부파일 -> 파일 대신 JSON 결과만 받고 싶을 때
|
|
117
|
+
curl -F "file=@file.docx" "http://localhost:8000/api/v1/encrypt?response=json"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 응답 포맷
|
|
121
|
+
|
|
122
|
+
pxa-common 규약을 따른다. **HTTP 상태는 항상 200**이고 정상/비정상은 `code` 로 구분한다.
|
|
123
|
+
(첨부파일 요청이 성공했을 때만 예외적으로 결과 파일이 바로 내려간다.)
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"success": true,
|
|
128
|
+
"code": "pxa-10000",
|
|
129
|
+
"message": "'file.docx' 파일을 암호화했습니다.",
|
|
130
|
+
"result": {
|
|
131
|
+
"operation": "encrypt",
|
|
132
|
+
"source": {"type": "local", "location": "/download/file.docx", "filename": "file.docx"},
|
|
133
|
+
"size": 29,
|
|
134
|
+
"elapsed_ms": 1.8
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`check` 는 `result.encrypted` 에 true/false 가 담긴다.
|
|
140
|
+
|
|
141
|
+
### 에러 코드
|
|
142
|
+
|
|
143
|
+
| 코드 | 의미 |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `pxa-20001` | 요청 검증 실패 (대상 중복 지정, `response` 값 오류 등) |
|
|
146
|
+
| `pxa-20002` | `filepath / uri / file` 중 아무것도 없음 |
|
|
147
|
+
| `pxa-21001` | `encrypt()` 가 False 반환 |
|
|
148
|
+
| `pxa-21002` | `decrypt()` 가 False 반환 |
|
|
149
|
+
| `pxa-21003` | 도메인 함수에서 예외 발생 |
|
|
150
|
+
| `pxa-21004` | 도메인 함수 미구현 |
|
|
151
|
+
| `pxa-21005` | 도메인 함수가 True/False 가 아닌 값을 반환 |
|
|
152
|
+
| `pxa-22001` | 대상 파일/오브젝트 없음 |
|
|
153
|
+
| `pxa-22002` | 허용되지 않은 경로 (`local.allowed_roots`) |
|
|
154
|
+
| `pxa-22003` | `uri` 형식 오류 |
|
|
155
|
+
| `pxa-22004` | 설정에 없는 버킷 별칭 |
|
|
156
|
+
| `pxa-22005` | 오브젝트 스토리지 입출력 오류 |
|
|
157
|
+
| `pxa-22006` | 첨부파일 처리 오류 |
|
|
158
|
+
| `pxa-22007` | 첨부파일 크기 초과 |
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## 3. 개발자가 작성하는 코드
|
|
163
|
+
|
|
164
|
+
`domain_core.py` 하나가 전부다.
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
def encrypt(filepath: str) -> bool:
|
|
168
|
+
ok = my_drm.protect(filepath) # 실제 DRM 모듈 호출
|
|
169
|
+
return bool(ok)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
지켜야 할 것
|
|
173
|
+
|
|
174
|
+
1. `filepath` 는 **서버가 준비해 둔 로컬 파일 경로**다. 오브젝트 스토리지든 첨부파일이든
|
|
175
|
+
여기까지 오면 똑같은 로컬 파일이므로 경로만 신경 쓰면 된다.
|
|
176
|
+
2. `encrypt` / `decrypt` 는 **그 경로의 파일을 제자리에서 바꾸면** 된다.
|
|
177
|
+
성공하면 서버가 원래 위치(로컬 경로 / 오브젝트 스토리지 / 응답 파일)로 되돌려 놓는다.
|
|
178
|
+
3. `check` 는 **파일을 수정하면 안 된다**(읽기 전용).
|
|
179
|
+
4. 실패는 `False` 를 반환하거나 예외를 던지면 된다. 서버가 표준 에러 응답으로 바꾸고 로그를 남긴다.
|
|
180
|
+
5. 오래 걸리는 동기 함수여도 된다. 서버가 워커 스레드에서 호출한다. `async def` 도 그대로 동작한다.
|
|
181
|
+
|
|
182
|
+
`check()` 는 선택 사항이다. 없으면 서버는 기동되지만 `/api/v1/check` 는 `pxa-21004` 로 응답한다.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## 4. 설정
|
|
187
|
+
|
|
188
|
+
우선순위는 **환경변수(`PXA_*`) > `config.yaml` > 기본값** 이고, 파일 경로는 `PXA_CONFIG` 로 지정한다
|
|
189
|
+
(pxa-common 설정 기능).
|
|
190
|
+
|
|
191
|
+
```yaml
|
|
192
|
+
app: { name: "pxa-drm-server", debug: false }
|
|
193
|
+
server: { host: "0.0.0.0", port: 8000 }
|
|
194
|
+
logging: { dir: "./logs", level: "INFO", filename: "drm-server.log", backup_count: 14 }
|
|
195
|
+
|
|
196
|
+
drm:
|
|
197
|
+
domain_module: "domain_core" # import 할 모듈명
|
|
198
|
+
# domain_file: "./domain_core.py" # 파일 경로로 직접 지정(우선 적용)
|
|
199
|
+
work_dir: null # 임시 작업 디렉토리(null 이면 OS 임시 디렉토리)
|
|
200
|
+
max_upload_size_mb: 512 # 0 이하면 제한 없음
|
|
201
|
+
upload_response: "file" # 첨부파일 기본 응답: file | json
|
|
202
|
+
|
|
203
|
+
local:
|
|
204
|
+
allowed_roots: [] # 비우면 모든 경로 허용. 예: ["/download", "/data"]
|
|
205
|
+
in_place: false # false 권장 (아래 "안전 처리" 참고)
|
|
206
|
+
|
|
207
|
+
storage:
|
|
208
|
+
buckets:
|
|
209
|
+
ABC: # uri 의 "ABC:download/file.docx" 에서 ABC
|
|
210
|
+
bucket: "abc-bucket"
|
|
211
|
+
endpoint_url: "https://s3.example.com"
|
|
212
|
+
region: "us-east-1"
|
|
213
|
+
addressing_style: "path" # MinIO/Ceph 등 S3 호환 스토리지는 path 권장
|
|
214
|
+
verify_ssl: true
|
|
215
|
+
access_key: "" # 환경변수 주입 권장
|
|
216
|
+
secret_key: ""
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### 접근키는 환경변수로
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
export PXA_STORAGE__BUCKETS__ABC__ACCESS_KEY=...
|
|
223
|
+
export PXA_STORAGE__BUCKETS__ABC__SECRET_KEY=...
|
|
224
|
+
export PXA_SERVER__PORT=9000
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
버킷 별칭은 **대소문자를 구분하지 않는다**. pxa-common 이 환경변수 경로를 소문자로 바꾸기 때문에,
|
|
228
|
+
`config.yaml` 의 `ABC` 와 환경변수의 `abc` 를 서버가 하나로 합쳐 준다.
|
|
229
|
+
`uri` 에는 `ABC:` 든 `abc:` 든 쓸 수 있고, `s3://ABC/download/file.docx` 형식도 받는다.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## 5. 동작 방식
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
요청 -> 대상 해석(filepath/uri/file) -> 로컬 작업 파일 준비
|
|
237
|
+
-> domain_core.encrypt|decrypt|check(filepath)
|
|
238
|
+
-> 성공 시에만 원래 위치로 반영 -> 표준 응답 -> 임시 파일 정리
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**안전 처리**
|
|
242
|
+
|
|
243
|
+
- `local.in_place: false`(기본값)이면 작업본을 만들어 처리하고, 성공했을 때만 원본을
|
|
244
|
+
원자적으로(`os.replace`) 교체한다. 도메인이 실패하거나 예외를 던져도 **원본은 그대로** 남는다.
|
|
245
|
+
- 오브젝트 스토리지는 성공했을 때만 같은 키로 다시 올린다(`ContentType` 유지).
|
|
246
|
+
- `check` 는 읽기 전용이라 큰 파일이어도 복사하지 않고 원본을 그대로 읽는다.
|
|
247
|
+
- 임시 작업 디렉토리는 요청이 끝나면(파일 응답이면 전송 완료 후) 지운다.
|
|
248
|
+
|
|
249
|
+
**보안**
|
|
250
|
+
|
|
251
|
+
- `local.allowed_roots` 를 지정하면 그 디렉토리 하위 경로만 처리한다(경로 정규화 후 검사).
|
|
252
|
+
비워 두면 서버가 접근 가능한 모든 경로를 허용하므로, 외부에 노출되는 환경에서는 지정을 권장한다.
|
|
253
|
+
- 접근키는 config 파일 대신 환경변수로 주입한다.
|
|
254
|
+
|
|
255
|
+
**로깅** — `pxa-common` 의 `setup_logging()` + `RequestLoggingMiddleware`.
|
|
256
|
+
request-id 와 처리시간이 함께 남고, 설정한 디렉토리에 자정마다 회전 저장된다.
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
2026-09-14 21:41:03,815 | INFO | pxa | encrypt 요청: source=local location=/download/file.docx
|
|
260
|
+
2026-09-14 21:41:03,816 | INFO | pxa | encrypt 완료: location=/download/file.docx result=True (1.8ms)
|
|
261
|
+
2026-09-14 21:41:03,816 | INFO | pxa | [4126cfffb094] GET /api/v1/encrypt -> 200 (3.1ms)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## 6. 구조
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
domain_core.py # ★ 개발자가 작성하는 유일한 파일
|
|
270
|
+
config/config.yaml # 설정 (접근키는 환경변수 권장)
|
|
271
|
+
pxa_drm_server/
|
|
272
|
+
app.py # FastAPI 앱 조립 (로깅/예외/미들웨어/라우터)
|
|
273
|
+
asgi.py # ASGI 진입점 (uvicorn 이 잡는 app)
|
|
274
|
+
main.py # CLI 진입점 (run / init)
|
|
275
|
+
api/v1/routes.py # encrypt / decrypt / check / health
|
|
276
|
+
service.py # 공통 처리 흐름
|
|
277
|
+
domain.py # domain_core 로딩 및 호출
|
|
278
|
+
sources/ # 대상별 입출력 (local / objectstorage / upload)
|
|
279
|
+
config.py codes.py errors.py runtime.py workspace.py
|
|
280
|
+
messages/drm.yaml # 메시지 카탈로그
|
|
281
|
+
templates/ # init 이 복사하는 시작 템플릿
|
|
282
|
+
tests/
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## 7. 테스트
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
pip install -e ".[dev]"
|
|
289
|
+
pytest
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## 8. 배포 (PyPI)
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
pip install build twine
|
|
296
|
+
|
|
297
|
+
rm -rf dist build *.egg-info
|
|
298
|
+
python -m build # dist/ 에 sdist + wheel 생성
|
|
299
|
+
twine check dist/*
|
|
300
|
+
|
|
301
|
+
twine upload --repository testpypi dist/* # 먼저 TestPyPI 로 확인
|
|
302
|
+
twine upload dist/* # PyPI 업로드
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
- 버전은 `pyproject.toml` 의 `project.version` 한 곳에서 관리한다.
|
|
306
|
+
`pxa_drm_server.__version__` 은 설치된 패키지 메타데이터에서 읽으므로 따로 고칠 필요가 없다
|
|
307
|
+
(`tests/test_packaging.py` 가 둘이 어긋나지 않는지 검사한다).
|
|
308
|
+
- PyPI 는 같은 버전을 다시 올릴 수 없다. 올린 뒤 고칠 것이 생기면 `0.1.1` 로 올려서 배포한다.
|
|
309
|
+
- 인증은 API 토큰을 쓴다(`~/.pypirc` 또는 `TWINE_USERNAME=__token__`, `TWINE_PASSWORD=pypi-...`).
|
|
310
|
+
- `domain_core.py` 와 `config/config.yaml` 은 패키지에 직접 담기지 않고
|
|
311
|
+
`pxa_drm_server/templates/` 로 들어가 `init` 이 꺼내 준다.
|