-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathlicense_notice.py
308 lines (276 loc) · 10.5 KB
/
license_notice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import dataclasses
import glob
import flask
import json_response
@dataclasses.dataclass
class LicenseMetadata:
name: str
homepage_url: str
# The license_glob_pattern and license_url properties are mutually
# exclusive.
# Glob pattern that points to the license file on the local system.
license_glob_pattern: str = ''
# URL of license file if it's not available on the local system.
license_url: str = ''
# For code where the source or license is on the local device, prefer linking to
# the locally-available copy instead of the remote URL so that the license ties
# tightly to the version we're using. When that's not possible, look for
# permalink versions of the license that match the version of the software we're
# using.
# pylint: disable=line-too-long
_LICENSE_METADATA = [
LicenseMetadata(name='TinyPilot',
license_glob_pattern='./LICENSE',
homepage_url='https://tinypilotkvm.com'),
LicenseMetadata(
name='uStreamer',
license_url=
'https://raw.githubusercontent.com/tiny-pilot/ustreamer/v4.13/LICENSE',
homepage_url='https://github.com/pikvm/ustreamer'),
LicenseMetadata(name='Python',
homepage_url='https://python.org',
license_glob_pattern='/usr/lib/python3.*/LICENSE.txt'),
LicenseMetadata(name='nginx',
license_url='https://nginx.org/LICENSE',
homepage_url='https://nginx.org'),
LicenseMetadata(
name='Janus',
homepage_url='https://janus.conf.meetecho.com',
license_url=
'https://raw.githubusercontent.com/tiny-pilot/janus-gateway/v1.0.0/COPYING'
),
# JavaScript dependencies.
LicenseMetadata(
name='janus.js',
homepage_url='https://janus.conf.meetecho.com',
license_glob_pattern='./app/static/third-party/janus-gateway/*/janus.js',
),
LicenseMetadata(
name='webrtc-adapter',
homepage_url='https://github.com/webrtcHacks/adapter',
license_url=
'https://github.com/webrtcHacks/adapter/blob/18a8b4127cbc1376320cac5742d817b5b7dd0085/LICENSE.md',
),
LicenseMetadata(
name='socket.io',
homepage_url='https://socket.io',
license_url='https://github.com/socketio/socket.io/blob/4.7.1/LICENSE',
),
# Python dependencies, from requirements.txt.
LicenseMetadata(
name='eventlet',
homepage_url='https://eventlet.net',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/eventlet-*.dist-info/licenses/LICENSE*',
),
LicenseMetadata(
name='Flask',
homepage_url='https://flask.palletsprojects.com',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/Flask-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='Flask-SocketIO',
homepage_url='https://flask-socketio.readthedocs.io',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/Flask_SocketIO-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='Flask-WTF',
homepage_url='https://flask-wtf.readthedocs.io',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/Flask_WTF-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='pyyaml',
homepage_url='https://pyyaml.org',
license_url=
'https://raw.githubusercontent.com/yaml/pyyaml/6.0.1/LICENSE',
),
LicenseMetadata(
name='bidict',
homepage_url='https://bidict.readthedocs.io/en/main',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/bidict-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='blinker',
homepage_url='https://blinker.readthedocs.io/',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/blinker-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='click',
homepage_url='https://palletsprojects.com/p/click',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/click-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='dnspython',
homepage_url='https://www.dnspython.org',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/dnspython-*.dist-info/licenses/LICENSE*',
),
LicenseMetadata(
name='greenlet',
homepage_url='https://greenlet.readthedocs.io',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/greenlet-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='importlib-metadata',
homepage_url='https://importlib-metadata.readthedocs.io/',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/importlib_metadata-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='itsdangerous',
homepage_url='https://palletsprojects.com/p/itsdangerous/',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/itsdangerous-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='Jinja2',
homepage_url='https://palletsprojects.com/p/jinja/',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/jinja2-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='MarkupSafe',
homepage_url='https://palletsprojects.com/p/markupsafe/',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/MarkupSafe-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='python-engineio',
homepage_url='https://github.com/miguelgrinberg/python-engineio',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/python_engineio-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='python-socketio',
homepage_url='https://github.com/miguelgrinberg/python-socketio',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/python_socketio-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='six',
homepage_url='https://github.com/benjaminp/six',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/six-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='Werkzeug',
homepage_url='https://palletsprojects.com/p/werkzeug/',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/werkzeug-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='WTForms',
homepage_url='https://wtforms.readthedocs.io',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/WTForms-*.dist-info/LICENSE*',
),
LicenseMetadata(
name='zipp',
homepage_url='https://github.com/jaraco/zipp',
license_glob_pattern=
'./venv/lib/python3.*/site-packages/zipp-*.dist-info/LICENSE*',
),
# Indirect dependencies through Janus.
LicenseMetadata(
name='libnice',
homepage_url='https://gitlab.freedesktop.org/libnice/libnice',
license_url=
'https://gitlab.freedesktop.org/libnice/libnice/-/blob/0.1.18/COPYING',
),
LicenseMetadata(
name='libsrtp',
homepage_url='https://github.com/cisco/libsrtp',
license_url='https://github.com/cisco/libsrtp/blob/v2.2.0/LICENSE',
),
LicenseMetadata(
name='libwebsockets',
homepage_url='https://libwebsockets.org',
# In the past, we used to link to the license that was hosted on the
# git mirror at libwebsockets.org/git. We repeatedly experienced
# outages of their website, however, so for reliability reasons, we now
# link to Github instead.
# (See https://github.com/tiny-pilot/tinypilot/pull/1727)
license_url=
'https://github.com/warmcat/libwebsockets/blob/v3.2.2/LICENSE',
),
# Fonts.
LicenseMetadata(
name='Overpass',
homepage_url='https://overpassfont.org/',
license_glob_pattern=
'./app/static/third-party/fonts/Overpass-License.txt',
),
]
blueprint = flask.Blueprint('licensing', __name__, url_prefix='/licensing')
@blueprint.route('', methods=['GET'])
def all_licensing_get():
"""Retrieves licensing metadata for TinyPilot and its dependencies.
Returns:
A JSON-formatted list of licensing information about TinyPilot and its
third-party dependencies.
Example:
[
{
"name": "TinyPilot",
"homepageUrl": "https://tinypilotkvm.com",
"licenseUrl": "/licensing/TinyPilot/license"
},
{
"name": "uStreamer",
"homepageUrl": "https://github.com/pikvm/ustreamer",
"licenseUrl": "/licensing/uStreamer/license"
},
...
]
"""
response = []
for license_data in _LICENSE_METADATA:
response.append({
'name': license_data.name,
'licenseUrl': f'/licensing/{license_data.name}/license',
'homepageUrl': license_data.homepage_url,
})
return json_response.success(response)
@blueprint.route('/<project>/license', methods=['GET'])
def project_license_get(project):
"""Retrieves the license for a given project.
Args:
project: The name of the project's license to retrieve.
Returns:
A plaintext response with the license in plaintext if the license is
available locally, or a redirect to a public URL if the license is not
available locally.
"""
project_metadata = _get_project_metadata(project)
if not project_metadata:
return flask.make_response('Unknown project', 404)
if project_metadata.license_url:
return _make_redirect_response(project_metadata.license_url)
matches = glob.glob(project_metadata.license_glob_pattern)
if not matches:
return flask.make_response('Project license not found', 404)
license_path = matches[0]
return _make_plaintext_response(_read_file(license_path))
def _get_project_metadata(project_name):
for license_data in _LICENSE_METADATA:
if license_data.name == project_name:
return license_data
return None
def _make_plaintext_response(response_body):
response = flask.make_response(response_body, 200)
response.mimetype = 'text/plain'
return response
def _read_file(license_path):
with open(license_path, encoding='utf-8') as license_file:
return license_file.read()
def _make_redirect_response(license_url):
# We intentionally use a 302 temporary redirect, as the license URL will
# change when software versions change.
return flask.redirect(license_url, code=302)