maven-proxy 0.0.1__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.
- maven-proxy-0.0.1/LICENSE +201 -0
- maven-proxy-0.0.1/PKG-INFO +16 -0
- maven-proxy-0.0.1/README.md +1 -0
- maven-proxy-0.0.1/maven_proxy/__init__.py +0 -0
- maven-proxy-0.0.1/maven_proxy/app.py +9 -0
- maven-proxy-0.0.1/maven_proxy/config.py +38 -0
- maven-proxy-0.0.1/maven_proxy/nexus_py.py +278 -0
- maven-proxy-0.0.1/maven_proxy/templates/directory_listing.html +93 -0
- maven-proxy-0.0.1/maven_proxy.egg-info/PKG-INFO +16 -0
- maven-proxy-0.0.1/maven_proxy.egg-info/SOURCES.txt +14 -0
- maven-proxy-0.0.1/maven_proxy.egg-info/dependency_links.txt +1 -0
- maven-proxy-0.0.1/maven_proxy.egg-info/entry_points.txt +3 -0
- maven-proxy-0.0.1/maven_proxy.egg-info/requires.txt +4 -0
- maven-proxy-0.0.1/maven_proxy.egg-info/top_level.txt +1 -0
- maven-proxy-0.0.1/setup.cfg +4 -0
- maven-proxy-0.0.1/setup.py +31 -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,16 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: maven-proxy
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Maven Repository Proxy with caching and authentication
|
|
5
|
+
Home-page: https://github.com/yourusername/maven-proxy
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: your.email@example.com
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Platform: UNKNOWN
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
|
|
14
|
+
maven2 repository by py
|
|
15
|
+
|
|
16
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
maven2 repository by py
|
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding:utf-8 -*-
|
|
3
|
+
# Author: qicongsheng
|
|
4
|
+
import os
|
|
5
|
+
import argparse
|
|
6
|
+
|
|
7
|
+
class Config:
|
|
8
|
+
def __init__(self):
|
|
9
|
+
# 解析命令行参数
|
|
10
|
+
parser = argparse.ArgumentParser(description="Maven Proxy Configuration")
|
|
11
|
+
parser.add_argument("--local-repo-dir", type=str, default=os.getenv("LOCAL_REPO_DIR", os.path.expanduser("~/.m2/repository")))
|
|
12
|
+
parser.add_argument("--remote-repo", type=str, default=os.getenv("REMOTE_REPO", "https://repo1.maven.org/maven2/"))
|
|
13
|
+
parser.add_argument("--remote-repo-username", type=str, default=os.getenv("REMOTE_REPO_USERNAME", None))
|
|
14
|
+
parser.add_argument("--remote-repo-password", type=str, default=os.getenv("REMOTE_REPO_PASSWORD", None))
|
|
15
|
+
parser.add_argument("--auth-user", type=str, default=os.getenv("AUTH_USER", "user"))
|
|
16
|
+
parser.add_argument("--auth-password", type=str, default=os.getenv("AUTH_PASSWORD", "passwd"))
|
|
17
|
+
parser.add_argument("--context-path", type=str, default=os.getenv("CONTEXT_PATH", ""))
|
|
18
|
+
parser.add_argument("--cleanup-interval", type=int, default=int(os.getenv("CLEANUP_INTERVAL", 300)))
|
|
19
|
+
parser.add_argument("--cleanup-age", type=int, default=int(os.getenv("CLEANUP_AGE", 3600)))
|
|
20
|
+
args = parser.parse_args()
|
|
21
|
+
|
|
22
|
+
# 本地仓库路径
|
|
23
|
+
self.REPO_ROOT = args.local_repo_dir
|
|
24
|
+
# 远程Maven仓库
|
|
25
|
+
self.REMOTE_REPO = args.remote_repo
|
|
26
|
+
# 远程Maven仓库 认证(可选)
|
|
27
|
+
self.REMOTE_REPO_USERNAME = args.remote_repo_username
|
|
28
|
+
self.REMOTE_REPO_PASSWORD = args.remote_repo_password
|
|
29
|
+
# 部署用户认证
|
|
30
|
+
self.USERS = {args.auth_user: args.auth_password}
|
|
31
|
+
# 上下文路径(如 /maven2)
|
|
32
|
+
self.CONTEXT_PATH = args.context_path
|
|
33
|
+
# 定时任务配置
|
|
34
|
+
self.CLEANUP_INTERVAL = args.cleanup_interval
|
|
35
|
+
self.CLEANUP_AGE = args.cleanup_age
|
|
36
|
+
|
|
37
|
+
# 创建全局配置对象
|
|
38
|
+
config = Config()
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding:utf-8 -*-
|
|
3
|
+
# Author: qicongsheng
|
|
4
|
+
import hashlib
|
|
5
|
+
import os
|
|
6
|
+
import time
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from xml.etree import ElementTree as ET
|
|
9
|
+
|
|
10
|
+
import requests
|
|
11
|
+
from apscheduler.schedulers.background import BackgroundScheduler
|
|
12
|
+
from flask import Flask, request, send_from_directory, abort, Response, render_template
|
|
13
|
+
from flask_httpauth import HTTPBasicAuth
|
|
14
|
+
|
|
15
|
+
from maven_proxy.config import config
|
|
16
|
+
|
|
17
|
+
app = Flask(__name__)
|
|
18
|
+
auth = HTTPBasicAuth()
|
|
19
|
+
|
|
20
|
+
# 配置
|
|
21
|
+
app.config.from_object(config)
|
|
22
|
+
app.url_map.strict_slashes = False
|
|
23
|
+
context_path = app.config['CONTEXT_PATH']
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# 获取本地路径
|
|
27
|
+
def get_local_path(path):
|
|
28
|
+
return os.path.join(app.config['REPO_ROOT'], path)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# 从远程仓库获取文件
|
|
32
|
+
def fetch_from_remote(path):
|
|
33
|
+
remote_url = app.config['REMOTE_REPO'] + path
|
|
34
|
+
try:
|
|
35
|
+
auth = None
|
|
36
|
+
if app.config['REMOTE_REPO_USERNAME'] and app.config['REMOTE_REPO_PASSWORD']:
|
|
37
|
+
auth = (app.config['REMOTE_REPO_USERNAME'], app.config['REMOTE_REPO_PASSWORD'])
|
|
38
|
+
|
|
39
|
+
resp = requests.get(remote_url, auth=auth, timeout=10)
|
|
40
|
+
if resp.status_code == 200:
|
|
41
|
+
local_path = get_local_path(path)
|
|
42
|
+
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
|
43
|
+
with open(local_path, 'wb') as f:
|
|
44
|
+
f.write(resp.content)
|
|
45
|
+
|
|
46
|
+
return True
|
|
47
|
+
return False
|
|
48
|
+
except Exception as e:
|
|
49
|
+
print(f"Remote fetch failed: {e}")
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# 生成空的 maven-metadata.xml
|
|
54
|
+
def generate_empty_metadata(path):
|
|
55
|
+
metadata = ET.Element("metadata")
|
|
56
|
+
group_id, artifact_id = path.split("/")[-3:-1]
|
|
57
|
+
ET.SubElement(metadata, "groupId").text = group_id
|
|
58
|
+
ET.SubElement(metadata, "artifactId").text = artifact_id
|
|
59
|
+
ET.SubElement(metadata, "versioning")
|
|
60
|
+
return ET.tostring(metadata, encoding="utf-8", xml_declaration=True)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# 生成文件的 SHA1 校验值
|
|
64
|
+
def generate_sha1(content):
|
|
65
|
+
sha1 = hashlib.sha1()
|
|
66
|
+
sha1.update(content)
|
|
67
|
+
return sha1.hexdigest()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# 生成文件的 MD5 校验值
|
|
71
|
+
def generate_md5(content):
|
|
72
|
+
md5 = hashlib.md5()
|
|
73
|
+
md5.update(content)
|
|
74
|
+
return md5.hexdigest()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# 辅助函数:获取文件的最后修改时间
|
|
78
|
+
def get_last_modified(file_path):
|
|
79
|
+
timestamp = os.path.getmtime(file_path)
|
|
80
|
+
return datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# 辅助函数:获取文件大小
|
|
84
|
+
def get_file_size(file_path):
|
|
85
|
+
size = os.path.getsize(file_path)
|
|
86
|
+
if size < 1024:
|
|
87
|
+
return f"{size} B"
|
|
88
|
+
elif size < 1024 * 1024:
|
|
89
|
+
return f"{size / 1024:.2f} KB"
|
|
90
|
+
else:
|
|
91
|
+
return f"{size / (1024 * 1024):.2f} MB"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# 生成文件列表的 HTML 页面(Nginx 风格)
|
|
95
|
+
def generate_directory_listing(path):
|
|
96
|
+
local_path = get_local_path(path)
|
|
97
|
+
if not os.path.exists(local_path):
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
# 获取目录下的文件和子目录
|
|
101
|
+
items = os.listdir(local_path)
|
|
102
|
+
items.sort()
|
|
103
|
+
files = []
|
|
104
|
+
dirs = []
|
|
105
|
+
for item in items:
|
|
106
|
+
item_path = os.path.join(local_path, item)
|
|
107
|
+
if os.path.isdir(item_path):
|
|
108
|
+
dirs.append(item + "/")
|
|
109
|
+
else:
|
|
110
|
+
files.append(item)
|
|
111
|
+
# 计算父路径
|
|
112
|
+
if path == "/":
|
|
113
|
+
parent_path = "/"
|
|
114
|
+
else:
|
|
115
|
+
parent_path = os.path.dirname(path.rstrip("/"))
|
|
116
|
+
if not parent_path:
|
|
117
|
+
parent_path = "/"
|
|
118
|
+
else:
|
|
119
|
+
parent_path = "/" + parent_path + "/"
|
|
120
|
+
|
|
121
|
+
return render_template(
|
|
122
|
+
"directory_listing.html",
|
|
123
|
+
path=path,
|
|
124
|
+
context_path=context_path,
|
|
125
|
+
parent_path=parent_path,
|
|
126
|
+
local_path=local_path,
|
|
127
|
+
dirs=dirs,
|
|
128
|
+
files=files,
|
|
129
|
+
os=os,
|
|
130
|
+
get_last_modified=get_last_modified,
|
|
131
|
+
get_file_size=get_file_size
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
# 处理 maven-metadata.xml 请求
|
|
136
|
+
def handle_metadata(path):
|
|
137
|
+
local_path = get_local_path(path)
|
|
138
|
+
if os.path.isfile(local_path):
|
|
139
|
+
return send_from_directory(
|
|
140
|
+
os.path.dirname(local_path),
|
|
141
|
+
os.path.basename(local_path))
|
|
142
|
+
|
|
143
|
+
if fetch_from_remote(path):
|
|
144
|
+
return send_from_directory(
|
|
145
|
+
os.path.dirname(local_path),
|
|
146
|
+
os.path.basename(local_path))
|
|
147
|
+
|
|
148
|
+
# 如果远程仓库也不存在,生成一个空的 maven-metadata.xml
|
|
149
|
+
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
|
150
|
+
empty_metadata = generate_empty_metadata(path)
|
|
151
|
+
with open(local_path, 'wb') as f:
|
|
152
|
+
f.write(empty_metadata)
|
|
153
|
+
|
|
154
|
+
# 生成 maven-metadata.xml.sha1
|
|
155
|
+
sha1_content = generate_sha1(empty_metadata)
|
|
156
|
+
with open(local_path + ".sha1", 'w') as f:
|
|
157
|
+
f.write(sha1_content)
|
|
158
|
+
|
|
159
|
+
# 生成 maven-metadata.xml.md5
|
|
160
|
+
md5_content = generate_md5(empty_metadata)
|
|
161
|
+
with open(local_path + ".md5", 'w') as f:
|
|
162
|
+
f.write(md5_content)
|
|
163
|
+
|
|
164
|
+
return send_from_directory(
|
|
165
|
+
os.path.dirname(local_path),
|
|
166
|
+
os.path.basename(local_path))
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
# 验证用户
|
|
170
|
+
@auth.verify_password
|
|
171
|
+
def verify_password(username, password):
|
|
172
|
+
if username in app.config['USERS'] and app.config['USERS'][username] == password:
|
|
173
|
+
return username
|
|
174
|
+
return None
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
# 处理根路径请求
|
|
178
|
+
@app.route(f'{context_path}/', methods=['GET'])
|
|
179
|
+
@auth.login_required
|
|
180
|
+
def handle_root():
|
|
181
|
+
return handle_get("")
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
@app.route(f'{context_path}/<path:path>', methods=['GET', 'PUT', 'HEAD'])
|
|
185
|
+
@auth.login_required
|
|
186
|
+
def handle_path(path):
|
|
187
|
+
if request.method == 'GET':
|
|
188
|
+
return handle_get(path)
|
|
189
|
+
elif request.method == 'PUT':
|
|
190
|
+
return handle_put(path)
|
|
191
|
+
elif request.method == 'HEAD':
|
|
192
|
+
return handle_head(path)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
# 处理 GET 请求
|
|
196
|
+
def handle_get(path):
|
|
197
|
+
local_path = get_local_path(path)
|
|
198
|
+
if os.path.isfile(local_path):
|
|
199
|
+
return send_from_directory(os.path.dirname(local_path), os.path.basename(local_path))
|
|
200
|
+
elif os.path.isdir(local_path):
|
|
201
|
+
listing = generate_directory_listing(path)
|
|
202
|
+
if listing:
|
|
203
|
+
return listing
|
|
204
|
+
else:
|
|
205
|
+
abort(404)
|
|
206
|
+
else:
|
|
207
|
+
# 如果是 maven-metadata.xml,特殊处理
|
|
208
|
+
if path.endswith("maven-metadata.xml"):
|
|
209
|
+
return handle_metadata(path)
|
|
210
|
+
# 尝试从远程仓库获取
|
|
211
|
+
if fetch_from_remote(path):
|
|
212
|
+
return send_from_directory(os.path.dirname(local_path), os.path.basename(local_path))
|
|
213
|
+
abort(404)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
# 处理 HEAD 请求
|
|
217
|
+
def handle_head(path):
|
|
218
|
+
local_path = get_local_path(path)
|
|
219
|
+
if os.path.exists(local_path):
|
|
220
|
+
return Response(headers={'Content-Length': os.path.getsize(local_path)})
|
|
221
|
+
abort(404)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
# 处理 PUT 请求(需要认证)
|
|
225
|
+
def handle_put(path):
|
|
226
|
+
local_path = get_local_path(path)
|
|
227
|
+
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
|
228
|
+
try:
|
|
229
|
+
with open(local_path, 'wb') as f:
|
|
230
|
+
f.write(request.data)
|
|
231
|
+
# 如果是 maven-metadata.xml,生成校验文件
|
|
232
|
+
if path.endswith("maven-metadata.xml"):
|
|
233
|
+
sha1_content = generate_sha1(request.data)
|
|
234
|
+
with open(local_path + ".sha1", 'w') as f:
|
|
235
|
+
f.write(sha1_content)
|
|
236
|
+
md5_content = generate_md5(request.data)
|
|
237
|
+
with open(local_path + ".md5", 'w') as f:
|
|
238
|
+
f.write(md5_content)
|
|
239
|
+
return Response("Deployment successful", 201)
|
|
240
|
+
except Exception as e:
|
|
241
|
+
return Response(f"Deployment failed: {str(e)}", 500)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def cleanup_empty_folders():
|
|
245
|
+
print("Starting cleanup of empty folders...")
|
|
246
|
+
cutoff_time = time.time() - app.config['CLEANUP_AGE']
|
|
247
|
+
deleted_folders = []
|
|
248
|
+
# 遍历 REPO_ROOT 目录
|
|
249
|
+
for root, dirs, files in os.walk(app.config['REPO_ROOT'], topdown=False):
|
|
250
|
+
for dir_name in dirs:
|
|
251
|
+
dir_path = os.path.join(root, dir_name)
|
|
252
|
+
try:
|
|
253
|
+
# 检查是否为空文件夹
|
|
254
|
+
if not os.listdir(dir_path):
|
|
255
|
+
dir_mtime = os.path.getmtime(dir_path)
|
|
256
|
+
# 检查是否超过清理时间
|
|
257
|
+
if dir_mtime < cutoff_time:
|
|
258
|
+
os.rmdir(dir_path)
|
|
259
|
+
deleted_folders.append(dir_path)
|
|
260
|
+
print(f"Deleted empty folder: {dir_path}")
|
|
261
|
+
except Exception as e:
|
|
262
|
+
print(f"Failed to delete {dir_path}: {e}")
|
|
263
|
+
# 如果删除了文件夹,记录日志
|
|
264
|
+
if deleted_folders:
|
|
265
|
+
print(f"Deleted {len(deleted_folders)} empty folders.")
|
|
266
|
+
else:
|
|
267
|
+
print("No empty folders to delete.")
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
# 启动服务
|
|
271
|
+
if __name__ == '__main__':
|
|
272
|
+
# 初始化定时任务
|
|
273
|
+
print("Job of cleanup of empty folders job starting...")
|
|
274
|
+
scheduler = BackgroundScheduler()
|
|
275
|
+
scheduler.add_job(cleanup_empty_folders, 'interval', seconds=app.config['CLEANUP_INTERVAL'])
|
|
276
|
+
scheduler.start()
|
|
277
|
+
print("Job of cleanup of empty folders job end...")
|
|
278
|
+
app.run(host='0.0.0.0', port=8081, threaded=True)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Index of {{ path }}</title>
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
|
8
|
+
margin: 20px;
|
|
9
|
+
background-color: #f5f5f5;
|
|
10
|
+
}
|
|
11
|
+
.container {
|
|
12
|
+
max-width: 1200px;
|
|
13
|
+
margin: 0 auto;
|
|
14
|
+
background: white;
|
|
15
|
+
padding: 20px;
|
|
16
|
+
border-radius: 4px;
|
|
17
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.12);
|
|
18
|
+
}
|
|
19
|
+
h1 {
|
|
20
|
+
font-size: 24px;
|
|
21
|
+
color: #333;
|
|
22
|
+
border-bottom: 1px solid #e1e4e8;
|
|
23
|
+
padding-bottom: 10px;
|
|
24
|
+
margin-bottom: 20px;
|
|
25
|
+
}
|
|
26
|
+
table {
|
|
27
|
+
width: 100%;
|
|
28
|
+
border-collapse: collapse;
|
|
29
|
+
font-size: 14px;
|
|
30
|
+
}
|
|
31
|
+
th {
|
|
32
|
+
text-align: left;
|
|
33
|
+
padding: 12px;
|
|
34
|
+
background-color: #f6f8fa;
|
|
35
|
+
border-bottom: 1px solid #e1e4e8;
|
|
36
|
+
}
|
|
37
|
+
td {
|
|
38
|
+
padding: 12px;
|
|
39
|
+
border-bottom: 1px solid #e1e4e8;
|
|
40
|
+
}
|
|
41
|
+
a {
|
|
42
|
+
color: #0366d6;
|
|
43
|
+
text-decoration: none;
|
|
44
|
+
}
|
|
45
|
+
a:hover {
|
|
46
|
+
text-decoration: underline;
|
|
47
|
+
}
|
|
48
|
+
.dir-icon::before {
|
|
49
|
+
content: "📁 ";
|
|
50
|
+
}
|
|
51
|
+
.file-icon::before {
|
|
52
|
+
content: "📄 ";
|
|
53
|
+
}
|
|
54
|
+
</style>
|
|
55
|
+
</head>
|
|
56
|
+
<body>
|
|
57
|
+
<div class="container">
|
|
58
|
+
<h1>Index of {{ path }}</h1>
|
|
59
|
+
<table>
|
|
60
|
+
<thead>
|
|
61
|
+
<tr>
|
|
62
|
+
<th>Name</th>
|
|
63
|
+
<th>Last Modified</th>
|
|
64
|
+
<th>Size</th>
|
|
65
|
+
</tr>
|
|
66
|
+
</thead>
|
|
67
|
+
<tbody>
|
|
68
|
+
{% if path != "" %}
|
|
69
|
+
<tr>
|
|
70
|
+
<td><a href="{{ context_path + '/' + parent_path.rstrip('/') if context_path != '' else parent_path.rstrip('/') if parent_path != '/' else '/'}}" class="dir-icon">../</a></td>
|
|
71
|
+
<td>-</td>
|
|
72
|
+
<td>-</td>
|
|
73
|
+
</tr>
|
|
74
|
+
{% endif %}
|
|
75
|
+
{% for dir in dirs %}
|
|
76
|
+
<tr>
|
|
77
|
+
<td><a href="{{ context_path + '/' + path.rstrip('/') + '/' + dir if path != '' else context_path + '/' + dir }}" class="dir-icon">{{ dir }}</a></td>
|
|
78
|
+
<td>{{ get_last_modified(os.path.join(local_path, dir)) }}</td>
|
|
79
|
+
<td>-</td>
|
|
80
|
+
</tr>
|
|
81
|
+
{% endfor %}
|
|
82
|
+
{% for file in files %}
|
|
83
|
+
<tr>
|
|
84
|
+
<td><a href="{{ context_path + '/' + path.rstrip('/') + '/' + file if path != '' else context_path + '/' + file }}" class="file-icon">{{ file }}</a></td>
|
|
85
|
+
<td>{{ get_last_modified(os.path.join(local_path, file)) }}</td>
|
|
86
|
+
<td>{{ get_file_size(os.path.join(local_path, file)) }}</td>
|
|
87
|
+
</tr>
|
|
88
|
+
{% endfor %}
|
|
89
|
+
</tbody>
|
|
90
|
+
</table>
|
|
91
|
+
</div>
|
|
92
|
+
</body>
|
|
93
|
+
</html>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: maven-proxy
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Maven Repository Proxy with caching and authentication
|
|
5
|
+
Home-page: https://github.com/yourusername/maven-proxy
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: your.email@example.com
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Platform: UNKNOWN
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
|
|
14
|
+
maven2 repository by py
|
|
15
|
+
|
|
16
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
maven_proxy/__init__.py
|
|
5
|
+
maven_proxy/app.py
|
|
6
|
+
maven_proxy/config.py
|
|
7
|
+
maven_proxy/nexus_py.py
|
|
8
|
+
maven_proxy.egg-info/PKG-INFO
|
|
9
|
+
maven_proxy.egg-info/SOURCES.txt
|
|
10
|
+
maven_proxy.egg-info/dependency_links.txt
|
|
11
|
+
maven_proxy.egg-info/entry_points.txt
|
|
12
|
+
maven_proxy.egg-info/requires.txt
|
|
13
|
+
maven_proxy.egg-info/top_level.txt
|
|
14
|
+
maven_proxy/templates/directory_listing.html
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
maven_proxy
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
4
|
+
long_description = fh.read()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name="maven-proxy",
|
|
8
|
+
version="0.0.1",
|
|
9
|
+
author="Your Name",
|
|
10
|
+
author_email="your.email@example.com",
|
|
11
|
+
description="Maven Repository Proxy with caching and authentication",
|
|
12
|
+
long_description=long_description,
|
|
13
|
+
long_description_content_type="text/markdown",
|
|
14
|
+
url="https://github.com/yourusername/maven-proxy",
|
|
15
|
+
packages=find_packages(),
|
|
16
|
+
package_data={
|
|
17
|
+
"maven_proxy": ["templates/*.html"]
|
|
18
|
+
},
|
|
19
|
+
install_requires=[
|
|
20
|
+
"Flask>=2.0.3",
|
|
21
|
+
"requests>=2.26.0",
|
|
22
|
+
"flask-httpauth>=4.5.0",
|
|
23
|
+
"APScheduler>=3.8.1"
|
|
24
|
+
],
|
|
25
|
+
entry_points={
|
|
26
|
+
"console_scripts": [
|
|
27
|
+
"maven-proxy=maven_proxy.app:main"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
python_requires=">=3.7",
|
|
31
|
+
)
|