release-drift 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,4 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """release-drift: what a package release adds before you install it."""
3
+
4
+ __version__ = "0.1.0"
@@ -0,0 +1,6 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ import sys
3
+
4
+ from .cli import main
5
+
6
+ sys.exit(main())
@@ -0,0 +1,188 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Read a package artifact into memory without extracting it.
3
+
4
+ Every artifact is treated as hostile: member names are checked before use,
5
+ sizes are capped while reading (header sizes are not trusted), and nothing is
6
+ written to disk.
7
+ """
8
+
9
+ import posixpath
10
+ import tarfile
11
+ import zipfile
12
+ import zlib
13
+
14
+ try:
15
+ import lzma
16
+ _DECOMPRESS_ERRORS = (zlib.error, lzma.LZMAError)
17
+ except ImportError: # Python built without lzma
18
+ _DECOMPRESS_ERRORS = (zlib.error,)
19
+
20
+ MAX_MEMBERS = 50000
21
+ MAX_MEMBER_BYTES = 64 * 1024 * 1024
22
+ MAX_TOTAL_BYTES = 512 * 1024 * 1024
23
+
24
+ WHEEL = "wheel"
25
+ SDIST = "sdist"
26
+ NPM = "npm"
27
+
28
+
29
+ class ArtifactError(Exception):
30
+ """The artifact cannot be read safely; the message names the reason."""
31
+
32
+
33
+ class Artifact:
34
+ """files maps each member path (top directory removed for sdists and npm
35
+ tarballs) to its bytes; links maps link members to their targets."""
36
+
37
+ def __init__(self, path, kind, files, links):
38
+ self.path = path
39
+ self.kind = kind
40
+ self.files = files
41
+ self.links = links
42
+
43
+
44
+ def check_name(name):
45
+ """Return the member name as a relative POSIX path, or raise ArtifactError."""
46
+ if not name or "\x00" in name or "\\" in name:
47
+ raise ArtifactError("unsafe member name %r" % name)
48
+ if name.startswith("/") or (len(name) > 1 and name[1] == ":"):
49
+ raise ArtifactError("absolute member name %r" % name)
50
+ parts = [p for p in name.split("/") if p not in ("", ".")]
51
+ if not parts or ".." in parts:
52
+ raise ArtifactError("unsafe member name %r" % name)
53
+ return "/".join(parts)
54
+
55
+
56
+ def _link_target_ok(name, target):
57
+ """A link must stay inside the artifact: relative, and never above its root."""
58
+ if not target or target.startswith("/") or "\\" in target or "\x00" in target:
59
+ return False
60
+ if len(target) > 1 and target[1] == ":":
61
+ return False
62
+ depth = name.count("/") # directories the link sits in
63
+ for part in target.split("/"):
64
+ if part == "..":
65
+ depth -= 1
66
+ if depth < 0:
67
+ return False
68
+ elif part not in ("", "."):
69
+ depth += 1
70
+ return True
71
+
72
+
73
+ class _Reader:
74
+ def __init__(self, limits):
75
+ self.max_members, self.max_member, self.max_total = limits
76
+ self.total = 0
77
+ self.count = 0
78
+ self.files = {}
79
+ self.links = {}
80
+
81
+ def add(self, name, read):
82
+ self.count += 1
83
+ if self.count > self.max_members:
84
+ raise ArtifactError("more than %d members" % self.max_members)
85
+ name = check_name(name)
86
+ if name in self.files or name in self.links:
87
+ raise ArtifactError("duplicate member %r" % name)
88
+ data = read(self.max_member + 1)
89
+ if len(data) > self.max_member:
90
+ raise ArtifactError("member %r is larger than %d bytes" % (name, self.max_member))
91
+ self.total += len(data)
92
+ if self.total > self.max_total:
93
+ raise ArtifactError("artifact is larger than %d bytes uncompressed" % self.max_total)
94
+ self.files[name] = data
95
+
96
+ def add_link(self, name, target):
97
+ self.count += 1
98
+ if self.count > self.max_members:
99
+ raise ArtifactError("more than %d members" % self.max_members)
100
+ name = check_name(name)
101
+ if name in self.files or name in self.links:
102
+ raise ArtifactError("duplicate member %r" % name)
103
+ if not _link_target_ok(name, target):
104
+ raise ArtifactError("link %r points outside the artifact (%r)" % (name, target))
105
+ self.links[name] = target
106
+
107
+
108
+ def _read_zip(path, reader):
109
+ with zipfile.ZipFile(path) as zf:
110
+ for info in zf.infolist():
111
+ # orig_filename is the name as stored: zipfile cuts .filename at a NUL
112
+ # and, on Windows, turns "\\" into "/", which would hide both from check_name.
113
+ name = info.orig_filename
114
+ if info.is_dir():
115
+ check_name(name)
116
+ continue
117
+ mode = (info.external_attr >> 16) & 0o170000
118
+ if info.create_system == 3 and mode == 0o120000: # Unix symlink
119
+ with zf.open(info) as fh:
120
+ target = fh.read(4097)
121
+ reader.add_link(name, target.decode("utf-8", "surrogateescape"))
122
+ continue
123
+ with zf.open(info) as fh:
124
+ reader.add(name, fh.read)
125
+
126
+
127
+ def _read_tar(path, reader):
128
+ with tarfile.open(path, "r:*") as tf:
129
+ while True:
130
+ member = tf.next()
131
+ if member is None:
132
+ break
133
+ if member.isdir():
134
+ check_name(member.name)
135
+ elif member.isfile():
136
+ fh = tf.extractfile(member)
137
+ reader.add(member.name, fh.read)
138
+ elif member.issym():
139
+ reader.add_link(member.name, member.linkname)
140
+ elif member.islnk():
141
+ # A hard link names another member by its full path in the archive.
142
+ target = check_name(member.linkname)
143
+ name = check_name(member.name)
144
+ rel = posixpath.relpath(target, posixpath.dirname(name) or ".")
145
+ reader.add_link(member.name, rel)
146
+ else:
147
+ raise ArtifactError("member %r is a device, FIFO or other special file" % member.name)
148
+
149
+
150
+ def _strip_top(names_files, names_links):
151
+ """sdists and npm tarballs keep everything under one top directory."""
152
+ tops = {n.split("/", 1)[0] for n in list(names_files) + list(names_links)}
153
+ if len(tops) != 1:
154
+ raise ArtifactError("expected one top-level directory, found %d" % len(tops))
155
+ if any("/" not in n for n in list(names_files) + list(names_links)):
156
+ raise ArtifactError("expected one top-level directory, found a top-level file")
157
+ files = {n.split("/", 1)[1]: d for n, d in names_files.items()}
158
+ links = {n.split("/", 1)[1]: t for n, t in names_links.items()}
159
+ return files, links
160
+
161
+
162
+ def read_artifact(path, limits=(MAX_MEMBERS, MAX_MEMBER_BYTES, MAX_TOTAL_BYTES)):
163
+ """Read a .whl, .zip, .tar.gz, .tgz (or other tar) artifact into an Artifact."""
164
+ reader = _Reader(limits)
165
+ lower = path.lower()
166
+ try:
167
+ if lower.endswith((".whl", ".zip")):
168
+ _read_zip(path, reader)
169
+ elif tarfile.is_tarfile(path):
170
+ _read_tar(path, reader)
171
+ else:
172
+ raise ArtifactError("not a wheel, zip or tar archive")
173
+ except (OSError, EOFError, zipfile.BadZipFile, tarfile.TarError, RuntimeError) + _DECOMPRESS_ERRORS as exc:
174
+ # zipfile raises RuntimeError for encrypted members; corrupt compressed
175
+ # data raises the decompressor's own error.
176
+ raise ArtifactError(str(exc) or exc.__class__.__name__)
177
+ if lower.endswith(".whl"):
178
+ return Artifact(path, WHEEL, reader.files, reader.links)
179
+ files, links = _strip_top(reader.files, reader.links)
180
+ if lower.endswith(".tgz") and "package.json" in files:
181
+ kind = NPM
182
+ elif "PKG-INFO" in files or "setup.py" in files or "pyproject.toml" in files:
183
+ kind = SDIST
184
+ elif "package.json" in files:
185
+ kind = NPM
186
+ else:
187
+ kind = SDIST
188
+ return Artifact(path, kind, files, links)
release_drift/cli.py ADDED
@@ -0,0 +1,89 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Command line: release-drift diff | source | fetch."""
3
+
4
+ import argparse
5
+ import json
6
+ import sys
7
+
8
+ from . import __version__
9
+ from .archive import ArtifactError, read_artifact
10
+ from .compare import CompareError, diff, is_finding, source
11
+ from .fetch import FetchError, fetch
12
+
13
+ _ESCAPES = {"\\": "\\\\", "\t": "\\t", "\n": "\\n", "\r": "\\r"}
14
+
15
+
16
+ def escape(text):
17
+ """Make a field safe for one TAB-separated line."""
18
+ out = []
19
+ for ch in text:
20
+ if ch in _ESCAPES:
21
+ out.append(_ESCAPES[ch])
22
+ elif ord(ch) < 0x20 or ord(ch) == 0x7F:
23
+ out.append("\\x%02x" % ord(ch))
24
+ else:
25
+ out.append(ch)
26
+ return "".join(out)
27
+
28
+
29
+ def render(records, as_json):
30
+ """Bytes to print: sorted, the same for the same records."""
31
+ if as_json:
32
+ rows = [dict(zip(("category", "status", "path", "detail"), r)) for r in sorted(records)]
33
+ text = json.dumps(rows, indent=1, sort_keys=True, ensure_ascii=True) + "\n"
34
+ return text.encode("ascii")
35
+ lines = ["\t".join(escape(f) for f in r).encode("utf-8", "surrogateescape") for r in records]
36
+ return b"".join(line + b"\n" for line in sorted(lines))
37
+
38
+
39
+ def _parser():
40
+ p = argparse.ArgumentParser(
41
+ prog="release-drift",
42
+ description="Report what changed between two releases of a package, what new code "
43
+ "runs at install or startup, and which files are not in the tagged source.")
44
+ p.add_argument("--version", action="version", version="release-drift " + __version__)
45
+ sub = p.add_subparsers(dest="command", metavar="COMMAND")
46
+ sub.required = True
47
+
48
+ d = sub.add_parser("diff", help="compare two artifacts of a package")
49
+ d.add_argument("old", metavar="OLD")
50
+ d.add_argument("new", metavar="NEW")
51
+
52
+ s = sub.add_parser("source", help="files of an artifact that are not in git at a ref")
53
+ s.add_argument("artifact", metavar="ARTIFACT")
54
+ s.add_argument("--repo", required=True, metavar="DIR")
55
+ s.add_argument("--ref", required=True, metavar="REF")
56
+ s.add_argument("--prefix", metavar="PATH",
57
+ help="directory of the repository the artifact's root maps to")
58
+
59
+ for cmd in (d, s):
60
+ cmd.add_argument("--json", action="store_true", help="print a JSON array")
61
+
62
+ f = sub.add_parser("fetch", help="download one version from PyPI or npm (no install)")
63
+ f.add_argument("registry", choices=("pypi", "npm"))
64
+ f.add_argument("name", metavar="NAME")
65
+ f.add_argument("version", metavar="VERSION")
66
+ f.add_argument("directory", metavar="DIR")
67
+ f.add_argument("--type", choices=("sdist", "wheel", "all"), dest="kind", default="sdist",
68
+ help="PyPI only: the sdist (default), the wheels, or every file")
69
+ return p
70
+
71
+
72
+ def main(argv=None):
73
+ args = _parser().parse_args(argv)
74
+ out = sys.stdout.buffer
75
+ try:
76
+ if args.command == "fetch":
77
+ for path in fetch(args.registry, args.name, args.version, args.directory, args.kind):
78
+ out.write(escape(path).encode("utf-8", "surrogateescape") + b"\n")
79
+ return 0
80
+ if args.command == "diff":
81
+ records = diff(read_artifact(args.old), read_artifact(args.new))
82
+ else:
83
+ records = source(read_artifact(args.artifact), args.repo, args.ref, args.prefix)
84
+ except (ArtifactError, CompareError, FetchError, OSError) as exc:
85
+ sys.stderr.write("release-drift: error: %s\n" % exc)
86
+ return 2
87
+ out.write(render(records, args.json))
88
+ out.flush()
89
+ return 1 if any(is_finding(args.command, r) for r in records) else 0
@@ -0,0 +1,274 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """The two comparisons: release against release, and release against git."""
3
+
4
+ import configparser
5
+ import hashlib
6
+ import json
7
+ import posixpath
8
+ import re
9
+ import subprocess
10
+
11
+ from .archive import NPM, SDIST, WHEEL
12
+ from .scan import strings, surfaces
13
+
14
+ _VERSIONED_DIR = re.compile(r"^(.+?)-[^-/]+\.(dist-info|data)$")
15
+
16
+ WHEEL_GENERATED = frozenset((
17
+ "METADATA", "RECORD", "WHEEL", "entry_points.txt", "top_level.txt",
18
+ "zip-safe", "namespace_packages.txt", "dependency_links.txt",
19
+ ))
20
+ EGG_INFO_GENERATED = frozenset((
21
+ "PKG-INFO", "SOURCES.txt", "dependency_links.txt", "requires.txt", "top_level.txt",
22
+ "entry_points.txt", "not-zip-safe", "zip-safe", "namespace_packages.txt",
23
+ ))
24
+ LICENSE_PREFIXES = ("LICENSE", "LICENCE", "COPYING", "NOTICE", "AUTHORS")
25
+
26
+
27
+ class CompareError(Exception):
28
+ pass
29
+
30
+
31
+ def normalize(path):
32
+ """Drop the version from a wheel's NAME-VERSION.dist-info and .data directories,
33
+ so the same file lines up across two versions."""
34
+ top, sep, rest = path.partition("/")
35
+ match = _VERSIONED_DIR.match(top)
36
+ if match:
37
+ top = "%s.%s" % (match.group(1), match.group(2))
38
+ return top + sep + rest
39
+
40
+
41
+ def _keyed(artifact):
42
+ return {normalize(p): p for p in artifact.files}, {normalize(p): p for p in artifact.links}
43
+
44
+
45
+ def diff(old, new):
46
+ """Records (category, status, path, detail) describing what NEW adds over OLD."""
47
+ records = []
48
+ old_files, old_links = _keyed(old)
49
+ new_files, new_links = _keyed(new)
50
+ old_content = {k: old.files[p] for k, p in old_files.items()}
51
+ old_content.update({k: old.links[p] for k, p in old_links.items()})
52
+ new_content = {k: new.files[p] for k, p in new_files.items()}
53
+ new_content.update({k: new.links[p] for k, p in new_links.items()})
54
+ new_paths = dict(new_files, **new_links)
55
+ old_paths = dict(old_files, **old_links)
56
+
57
+ for key, path in new_paths.items():
58
+ if key not in old_content:
59
+ records.append(("file", "added", path, "-"))
60
+ elif old_content[key] != new_content[key]:
61
+ records.append(("file", "changed", path, "-"))
62
+ for key, path in old_paths.items():
63
+ if key not in new_content:
64
+ records.append(("file", "removed", path, "-"))
65
+
66
+ old_surfaces = {(cat, normalize(path), detail) for cat, path, detail, _ in surfaces(old)}
67
+ for cat, path, detail, content_sensitive in surfaces(new):
68
+ key = normalize(path)
69
+ if (cat, key, detail) not in old_surfaces:
70
+ records.append((cat, "added", path, detail))
71
+ elif content_sensitive and old_content.get(key) != new_content.get(key):
72
+ records.append((cat, "changed", path, detail))
73
+
74
+ old_strings = {(cat, detail) for cat, _, detail in strings(old)}
75
+ for cat, path, detail in strings(new):
76
+ if (cat, detail) not in old_strings:
77
+ records.append((cat, "added", path, detail))
78
+ return sorted(set(records))
79
+
80
+
81
+ def is_finding(command, record):
82
+ """A finding sets exit status 1. For diff, every record except a plain file
83
+ record; for source, every record, since each names a file not in the tag."""
84
+ return command == "source" or record[0] != "file"
85
+
86
+
87
+ # --- release against git ---------------------------------------------------
88
+
89
+ def _git(repo, *args):
90
+ try:
91
+ proc = subprocess.run(["git", "-C", repo] + list(args), stdout=subprocess.PIPE,
92
+ stderr=subprocess.PIPE)
93
+ except OSError as exc:
94
+ raise CompareError("cannot run git: %s" % exc)
95
+ if proc.returncode != 0:
96
+ msg = proc.stderr.decode("utf-8", "replace").strip()
97
+ raise CompareError("git %s failed: %s" % (args[0], msg))
98
+ return proc.stdout
99
+
100
+
101
+ def read_tree(repo, ref):
102
+ """Map each path in the tree of REF to (mode, object id), and return the
103
+ hash function git uses for object ids."""
104
+ if not ref or ref.startswith("-"):
105
+ raise CompareError("invalid ref %r" % ref)
106
+ _git(repo, "rev-parse", "--verify", "--quiet", ref + "^{tree}")
107
+ try:
108
+ fmt = _git(repo, "rev-parse", "--show-object-format").decode().strip()
109
+ except CompareError:
110
+ fmt = "sha1"
111
+ if fmt not in ("sha1", "sha256"):
112
+ raise CompareError("unknown git object format %r" % fmt)
113
+ out = _git(repo, "ls-tree", "-r", "-z", "--full-tree", ref + "^{tree}")
114
+ tree = {}
115
+ for entry in out.split(b"\x00"):
116
+ if not entry:
117
+ continue
118
+ meta, path = entry.split(b"\t", 1)
119
+ mode, _type, oid = meta.decode().split(" ")
120
+ tree[path.decode("utf-8", "surrogateescape")] = (mode, oid)
121
+ return tree, fmt
122
+
123
+
124
+ def blob_id(data, fmt):
125
+ h = hashlib.new(fmt)
126
+ h.update(b"blob %d\x00" % len(data))
127
+ h.update(data)
128
+ return h.hexdigest()
129
+
130
+
131
+ def _blob(repo, oid):
132
+ return _git(repo, "cat-file", "blob", oid)
133
+
134
+
135
+ def generated(kind, path):
136
+ """True for a file the packaging tool writes and git never holds."""
137
+ parts = path.split("/")
138
+ if kind == WHEEL:
139
+ return len(parts) == 2 and parts[0].endswith(".dist-info") and parts[1] in WHEEL_GENERATED
140
+ if kind == SDIST:
141
+ if path == "PKG-INFO":
142
+ return True
143
+ return len(parts) >= 2 and parts[-2].endswith(".egg-info") and parts[-1] in EGG_INFO_GENERATED
144
+ return False
145
+
146
+
147
+ def _license_copy(kind, path):
148
+ """A licence file copied into a wheel's .dist-info directory."""
149
+ parts = path.split("/")
150
+ if kind != WHEEL or not parts[0].endswith(".dist-info") or len(parts) < 2:
151
+ return False
152
+ return parts[1] == "licenses" or parts[1].upper().startswith(LICENSE_PREFIXES)
153
+
154
+
155
+ def setup_cfg(data):
156
+ """setup.cfg as {section: {key: value}}, without the [egg_info] section.
157
+ setuptools rewrites setup.cfg in the sdist with configparser: it adds
158
+ [egg_info] and respaces 'key=value' lines, and drops comments."""
159
+ parser = configparser.RawConfigParser(strict=True)
160
+ parser.optionxform = str
161
+ try:
162
+ parser.read_string(data.decode("utf-8"))
163
+ except (UnicodeDecodeError, configparser.Error):
164
+ return None
165
+ return {name: dict(parser.items(name)) for name in parser.sections() if name != "egg_info"}
166
+
167
+
168
+ def npm_manifest(data):
169
+ """package.json with the fields npm adds or drops at publish removed."""
170
+ try:
171
+ obj = json.loads(data.decode("utf-8"))
172
+ except ValueError:
173
+ return None
174
+ if not isinstance(obj, dict):
175
+ return None
176
+ return {k: v for k, v in obj.items() if k != "gitHead" and not k.startswith("_")}
177
+
178
+
179
+ def _same_after_normalising(repo, kind, path, data, entry):
180
+ """path is relative to the artifact; entry is the tree entry it maps to."""
181
+ if entry is None:
182
+ return kind == SDIST and path == "setup.cfg" and setup_cfg(data) == {}
183
+ if kind == SDIST and path == "setup.cfg":
184
+ mine = setup_cfg(data)
185
+ return mine is not None and mine == setup_cfg(_blob(repo, entry[1]))
186
+ if kind == NPM and path == "package.json":
187
+ mine = npm_manifest(data)
188
+ return mine is not None and mine == npm_manifest(_blob(repo, entry[1]))
189
+ return False
190
+
191
+
192
+ MAX_LINK_HOPS = 40
193
+
194
+
195
+ def _lookup(repo, tree, path):
196
+ """The tree entry for path, following directory symlinks in the tree the
197
+ way a checkout would (a build copies the files through them). Links that
198
+ leave the repository are not followed."""
199
+ for _ in range(MAX_LINK_HOPS):
200
+ entry = tree.get(path)
201
+ if entry is not None:
202
+ return entry
203
+ parts = path.split("/")
204
+ for i in range(1, len(parts)):
205
+ head = "/".join(parts[:i])
206
+ link = tree.get(head)
207
+ if link is not None and link[0] == "120000":
208
+ target = _blob(repo, link[1]).decode("utf-8", "surrogateescape")
209
+ resolved = posixpath.normpath(posixpath.join(posixpath.dirname(head), target))
210
+ if target.startswith("/") or resolved == ".." or resolved.startswith("../"):
211
+ return None
212
+ path = resolved + "/" + "/".join(parts[i:])
213
+ break
214
+ else:
215
+ return None
216
+ return None
217
+
218
+
219
+ def _status(repo, tree, fmt, prefix, path, data, is_link):
220
+ entry = _lookup(repo, tree, prefix + path)
221
+ if entry is None:
222
+ return "not-in-tag", None
223
+ if (entry[0] == "120000") != is_link:
224
+ return "differs", entry
225
+ if blob_id(data, fmt) != entry[1]:
226
+ return "differs", entry
227
+ return None, entry
228
+
229
+
230
+ def pick_prefix(artifact, tree, fmt):
231
+ """For a wheel, the directory of the repository its paths start in: the
232
+ root or src/, whichever holds more identical files (the root on a tie)."""
233
+ if artifact.kind != WHEEL:
234
+ return ""
235
+ best, best_count = "", -1
236
+ for prefix in ("", "src/"):
237
+ count = sum(1 for p, d in artifact.files.items()
238
+ if tree.get(prefix + p, ("", ""))[1] == blob_id(d, fmt))
239
+ if count > best_count:
240
+ best, best_count = prefix, count
241
+ return best
242
+
243
+
244
+ def source(artifact, repo, ref, prefix=None):
245
+ """Records for files of the artifact that are not, as they are, in REF."""
246
+ tree, fmt = read_tree(repo, ref)
247
+ if prefix is None:
248
+ prefix = pick_prefix(artifact, tree, fmt)
249
+ elif prefix and not prefix.endswith("/"):
250
+ prefix += "/"
251
+ tree_blobs = {oid for mode, oid in tree.values() if mode != "160000"}
252
+ flagged = {}
253
+ items = [(p, d, False) for p, d in artifact.files.items()]
254
+ items += [(p, t.encode("utf-8", "surrogateescape"), True) for p, t in artifact.links.items()]
255
+ for path, data, is_link in items:
256
+ if not is_link and generated(artifact.kind, path):
257
+ continue
258
+ if not is_link and _license_copy(artifact.kind, path) and blob_id(data, fmt) in tree_blobs:
259
+ continue
260
+ status, entry = _status(repo, tree, fmt, prefix, path, data, is_link)
261
+ if status is None:
262
+ continue
263
+ if not is_link and _same_after_normalising(repo, artifact.kind, path, data, entry):
264
+ continue
265
+ flagged[path] = status
266
+
267
+ records = [("file", status, path, "-") for path, status in flagged.items()]
268
+ for cat, path, detail, _ in surfaces(artifact):
269
+ if path in flagged:
270
+ records.append((cat, flagged[path], path, detail))
271
+ for cat, path, detail in strings(artifact):
272
+ if path in flagged:
273
+ records.append((cat, flagged[path], path, detail))
274
+ return sorted(set(records))
release_drift/fetch.py ADDED
@@ -0,0 +1,135 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Download one published version from PyPI or npm. Downloads only: nothing is
3
+ installed, unpacked or run."""
4
+
5
+ import base64
6
+ import hashlib
7
+ import json
8
+ import os
9
+ import re
10
+ import tempfile
11
+ import urllib.parse
12
+ import urllib.request
13
+
14
+ PYPI = "https://pypi.org/pypi/%s/%s/json"
15
+ NPM = "https://registry.npmjs.org/%s/%s"
16
+ MAX_DOWNLOAD = 512 * 1024 * 1024
17
+ MAX_METADATA = 32 * 1024 * 1024
18
+ TIMEOUT = 60
19
+
20
+ _PYPI_NAME = re.compile(r"^[A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?$")
21
+ _NPM_NAME = re.compile(r"^(@[a-z0-9][a-z0-9._~-]*/)?[a-z0-9][a-z0-9._~-]*$")
22
+ _VERSION = re.compile(r"^[A-Za-z0-9][A-Za-z0-9.+!_-]*$")
23
+ _FILENAME = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._+-]*$")
24
+
25
+
26
+ class FetchError(Exception):
27
+ pass
28
+
29
+
30
+ class _HttpsOnly(urllib.request.HTTPRedirectHandler):
31
+ def redirect_request(self, req, fp, code, msg, headers, newurl):
32
+ if urllib.parse.urlsplit(newurl).scheme != "https":
33
+ raise FetchError("refusing redirect to non-https URL %s" % newurl)
34
+ return super().redirect_request(req, fp, code, msg, headers, newurl)
35
+
36
+
37
+ def _opener():
38
+ return urllib.request.build_opener(_HttpsOnly())
39
+
40
+
41
+ def _get(url, limit):
42
+ if urllib.parse.urlsplit(url).scheme != "https":
43
+ raise FetchError("refusing non-https URL %s" % url)
44
+ req = urllib.request.Request(url, headers={"User-Agent": "release-drift"})
45
+ try:
46
+ with _opener().open(req, timeout=TIMEOUT) as resp:
47
+ data = resp.read(limit + 1)
48
+ except OSError as exc: # URLError and HTTPError are OSErrors
49
+ raise FetchError("%s: %s" % (url, exc))
50
+ if len(data) > limit:
51
+ raise FetchError("%s is larger than %d bytes" % (url, limit))
52
+ return data
53
+
54
+
55
+ def check_digest(data, algorithm, expected):
56
+ """expected is a hex digest, or for sha512 an SRI base64 digest."""
57
+ digest = hashlib.new(algorithm, data)
58
+ if algorithm == "sha512":
59
+ ok = base64.b64encode(digest.digest()).decode() == expected
60
+ else:
61
+ ok = digest.hexdigest() == expected.lower()
62
+ if not ok:
63
+ raise FetchError("%s digest does not match the registry's" % algorithm)
64
+
65
+
66
+ def pypi_files(name, version):
67
+ """(filename, url, algorithm, digest, packagetype) for each file of a PyPI version."""
68
+ if not _PYPI_NAME.match(name) or not _VERSION.match(version):
69
+ raise FetchError("invalid PyPI name or version")
70
+ meta = json.loads(_get(PYPI % (name, version), MAX_METADATA).decode("utf-8"))
71
+ out = []
72
+ for entry in meta.get("urls", []):
73
+ sha = (entry.get("digests") or {}).get("sha256")
74
+ if not sha:
75
+ raise FetchError("%s has no sha256 digest" % entry.get("filename"))
76
+ out.append((entry["filename"], entry["url"], "sha256", sha, entry.get("packagetype", "")))
77
+ if not out:
78
+ raise FetchError("%s %s has no files" % (name, version))
79
+ return out
80
+
81
+
82
+ def npm_files(name, version):
83
+ if not _NPM_NAME.match(name) or not _VERSION.match(version):
84
+ raise FetchError("invalid npm name or version")
85
+ quoted = urllib.parse.quote(name, safe="@")
86
+ meta = json.loads(_get(NPM % (quoted, version), MAX_METADATA).decode("utf-8"))
87
+ dist = meta.get("dist") or {}
88
+ integrity = dist.get("integrity", "")
89
+ sri = [i for i in integrity.split() if i.startswith("sha512-")]
90
+ if not sri:
91
+ raise FetchError("%s@%s has no sha512 integrity digest" % (name, version))
92
+ url = dist.get("tarball", "")
93
+ filename = urllib.parse.urlsplit(url).path.rsplit("/", 1)[-1]
94
+ if name.startswith("@"):
95
+ filename = name[1:].replace("/", "-") + "-" + version + ".tgz"
96
+ return [(filename, url, "sha512", sri[0][len("sha512-"):], "npm")]
97
+
98
+
99
+ PYPI_TYPES = {"sdist": ("sdist",), "wheel": ("bdist_wheel",), "all": None}
100
+
101
+
102
+ def fetch(registry, name, version, directory, kind="sdist"):
103
+ """Download the version's files into directory and return their paths. For
104
+ PyPI, kind picks the sdist (default), the wheels or all files; npm has one."""
105
+ if registry == "pypi":
106
+ files = pypi_files(name, version)
107
+ wanted = PYPI_TYPES[kind]
108
+ if wanted:
109
+ files = [f for f in files if f[4] in wanted]
110
+ if not files:
111
+ raise FetchError("%s %s has no %s on PyPI; choose another with --type (sdist, wheel, all)"
112
+ % (name, version, kind))
113
+ else:
114
+ files = npm_files(name, version)
115
+ if not os.path.isdir(directory):
116
+ raise FetchError("%s is not a directory" % directory)
117
+ saved = []
118
+ for filename, url, algorithm, digest, _ in files:
119
+ if not _FILENAME.match(filename):
120
+ raise FetchError("refusing file name %r" % filename)
121
+ target = os.path.join(directory, filename)
122
+ data = _get(url, MAX_DOWNLOAD)
123
+ check_digest(data, algorithm, digest)
124
+ if os.path.exists(target):
125
+ with open(target, "rb") as fh:
126
+ if fh.read() != data:
127
+ raise FetchError("%s exists with different content" % target)
128
+ else:
129
+ fd, tmp = tempfile.mkstemp(dir=directory, prefix=".release-drift-")
130
+ with os.fdopen(fd, "wb") as fh:
131
+ fh.write(data)
132
+ os.chmod(tmp, 0o644)
133
+ os.replace(tmp, target)
134
+ saved.append(target)
135
+ return sorted(saved)
release_drift/scan.py ADDED
@@ -0,0 +1,169 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Find execution surfaces and notable strings in an artifact's files.
3
+
4
+ Each finding is a tuple (category, path, detail, content_sensitive). A
5
+ content-sensitive finding is reported as "changed" by `diff` when the file it
6
+ sits in changes; the others are compared by their detail only.
7
+ """
8
+
9
+ import hashlib
10
+ import json
11
+ import re
12
+
13
+ from .archive import NPM, SDIST
14
+
15
+ NPM_INSTALL_SCRIPTS = ("preinstall", "install", "postinstall", "prepare")
16
+ STARTUP_MODULES = ("sitecustomize.py", "usercustomize.py")
17
+ BUILD_SCRIPTS = ("setup.py", "hatch_build.py")
18
+ BLOB_MIN = 200
19
+
20
+ _URL = re.compile(rb"(?i)\b(?:https?|wss?|ftp)://([a-z0-9._~%-]+(?::[0-9]{1,5})?)")
21
+ _BLOB = re.compile(rb"[A-Za-z0-9+/_-]{%d,}={0,2}" % BLOB_MIN)
22
+ _HEX = re.compile(rb"[0-9A-Fa-f]+")
23
+
24
+
25
+ def native_format(data):
26
+ """Name the executable format the bytes start with, or None."""
27
+ head = data[:8]
28
+ if head.startswith(b"\x7fELF"):
29
+ return "ELF"
30
+ if head[:4] in (b"\xfe\xed\xfa\xce", b"\xfe\xed\xfa\xcf", b"\xce\xfa\xed\xfe", b"\xcf\xfa\xed\xfe"):
31
+ return "Mach-O"
32
+ if head[:4] == b"\xca\xfe\xba\xbe" and len(head) == 8:
33
+ # Java class files share this magic; their version number is 45 or more,
34
+ # a universal Mach-O's architecture count is small.
35
+ if int.from_bytes(head[4:8], "big") < 45:
36
+ return "Mach-O"
37
+ return None
38
+ if head[:2] == b"MZ" and len(data) >= 0x40:
39
+ offset = int.from_bytes(data[0x3C:0x40], "little")
40
+ if data[offset:offset + 4] == b"PE\x00\x00":
41
+ return "PE"
42
+ if head[:4] == b"\x00asm":
43
+ return "WebAssembly"
44
+ return None
45
+
46
+
47
+ def pth_detail(data):
48
+ """site.py executes the lines of a .pth file that start with 'import'."""
49
+ for line in data.splitlines():
50
+ if line.startswith((b"import ", b"import\t")):
51
+ return "import"
52
+ return "paths"
53
+
54
+
55
+ def _section_lines(text, header):
56
+ """Lines of one TOML table, matched textually (no TOML parser before Python 3.11)."""
57
+ out = []
58
+ inside = False
59
+ for line in text.splitlines():
60
+ stripped = line.strip()
61
+ if stripped.startswith("["):
62
+ inside = stripped == header or stripped.startswith(header[:-1] + ".")
63
+ if inside and stripped != header:
64
+ out.append(stripped)
65
+ continue
66
+ if inside and stripped and not stripped.startswith("#"):
67
+ out.append(stripped)
68
+ return out
69
+
70
+
71
+ def pyproject_findings(data):
72
+ """Build settings in pyproject.toml that decide which code runs at build time."""
73
+ text = data.decode("utf-8", "replace")
74
+ details = []
75
+ for line in _section_lines(text, "[build-system]"):
76
+ key = line.split("=", 1)[0].strip()
77
+ if key in ("build-backend", "backend-path"):
78
+ details.append(" ".join(line.split()))
79
+ for header in ("[tool.hatch.build]", "[tool.poetry.build]", "[tool.pdm.build]"):
80
+ for line in _section_lines(text, header):
81
+ if line.startswith("[") and "hooks" in line:
82
+ details.append(line)
83
+ elif line.split("=", 1)[0].strip() in ("script", "setup-script", "build"):
84
+ details.append(header[1:-1] + ": " + " ".join(line.split()))
85
+ return details
86
+
87
+
88
+ def npm_script_findings(data):
89
+ try:
90
+ manifest = json.loads(data.decode("utf-8"))
91
+ except ValueError:
92
+ return ["package.json does not parse"]
93
+ if not isinstance(manifest, dict):
94
+ return ["package.json is not an object"]
95
+ scripts = manifest.get("scripts")
96
+ if not isinstance(scripts, dict):
97
+ return []
98
+ out = []
99
+ for name in NPM_INSTALL_SCRIPTS:
100
+ if name in scripts:
101
+ out.append("%s=%s" % (name, scripts[name]))
102
+ return out
103
+
104
+
105
+ def _is_manifest_to_scan(path):
106
+ """The root package.json, and those of bundled dependencies."""
107
+ if path == "package.json":
108
+ return True
109
+ parts = path.split("/")
110
+ if parts[-1] != "package.json" or len(parts) < 3:
111
+ return False
112
+ if parts[-3] == "node_modules":
113
+ return True
114
+ return len(parts) >= 4 and parts[-4] == "node_modules" and parts[-3].startswith("@")
115
+
116
+
117
+ def _pyc_source(path):
118
+ parts = path.split("/")
119
+ name = parts[-1]
120
+ if len(parts) >= 2 and parts[-2] == "__pycache__":
121
+ return "/".join(parts[:-2] + [name.split(".", 1)[0] + ".py"])
122
+ return path[:-1]
123
+
124
+
125
+ def surfaces(artifact):
126
+ """Execution surfaces of an artifact: what can run at install, build or startup."""
127
+ out = []
128
+ files = artifact.files
129
+ for path in sorted(files):
130
+ data = files[path]
131
+ base = path.rsplit("/", 1)[-1]
132
+ if base.endswith(".pth"):
133
+ out.append(("pth", path, pth_detail(data), True))
134
+ if base in STARTUP_MODULES:
135
+ out.append(("startup", path, base, True))
136
+ if artifact.kind == SDIST and path in BUILD_SCRIPTS:
137
+ out.append(("build", path, path, True))
138
+ if artifact.kind == SDIST and path == "pyproject.toml":
139
+ for detail in pyproject_findings(data):
140
+ out.append(("build", path, detail, False))
141
+ if artifact.kind == NPM and _is_manifest_to_scan(path):
142
+ for detail in npm_script_findings(data):
143
+ out.append(("npm-script", path, detail, False))
144
+ if artifact.kind == NPM and base == "binding.gyp" and "/" not in path:
145
+ out.append(("npm-script", path, "install=node-gyp rebuild (implicit)", False))
146
+ if base.endswith(".pyc") and _pyc_source(path) not in files:
147
+ out.append(("pyc-only", path, "no .py source", True))
148
+ fmt = native_format(data)
149
+ if fmt:
150
+ out.append(("native", path, fmt, True))
151
+ for path in sorted(artifact.links):
152
+ out.append(("link", path, artifact.links[path], False))
153
+ return out
154
+
155
+
156
+ def strings(artifact):
157
+ """URL hosts and long encoded blobs, as (category, path, detail) tuples."""
158
+ out = set()
159
+ for path, data in artifact.files.items():
160
+ for match in _URL.finditer(data):
161
+ host = match.group(1).decode("ascii").lower()
162
+ out.add(("url-host", path, host))
163
+ for match in _BLOB.finditer(data):
164
+ blob = match.group(0)
165
+ kind = "hex" if _HEX.fullmatch(blob) else "base64"
166
+ digest = hashlib.sha256(blob).hexdigest()[:16]
167
+ out.add(("blob", path, "%s len=%d sha256=%s" % (kind, len(blob), digest)))
168
+ return sorted(out)
169
+
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.4
2
+ Name: release-drift
3
+ Version: 0.1.0
4
+ Summary: Report what a package release adds: changed files, new install and startup code, files not in the tagged source.
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/jacob-adm/release-drift
7
+ Project-URL: Documentation, https://github.com/jacob-adm/release-drift/tree/main/docs
8
+ Project-URL: Source, https://github.com/jacob-adm/release-drift
9
+ Project-URL: Issues, https://github.com/jacob-adm/release-drift/issues
10
+ Keywords: supply-chain,security,pypi,npm,wheel,sdist,cli
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Security
17
+ Classifier: Topic :: Software Development :: Build Tools
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Dynamic: license-file
22
+
23
+ # release-drift
24
+
25
+ release-drift compares two releases of a package, and a release with the git tag it was built
26
+ from, before you install it. It reports which files changed, which new code runs at install or
27
+ interpreter start-up, and which files of the release are not in the project's tagged source.
28
+
29
+ Recent supply-chain attacks used these places: a `.pth` file in a PyPI wheel that Python runs at
30
+ every start, an npm release published from a stolen account instead of the project's CI, and
31
+ npm `preinstall` scripts. A new `.pth` file or install script is a record in release-drift's
32
+ output, and so is a file in a release that is not in the project's tag.
33
+
34
+ release-drift only reports. It does not decide whether a package is malicious, and it does not
35
+ block or quarantine anything; what to do with a record is up to you, for example a required
36
+ check in CI. There is no AI and no scoring: the same inputs always give byte-identical output.
37
+
38
+ ## Requirements
39
+
40
+ - Python 3.9 or later, standard library only.
41
+ - git, for `release-drift source`.
42
+ - No platform-specific code; tested on macOS.
43
+ - Network access only for the optional `fetch` command.
44
+
45
+ ## Install
46
+
47
+ From a clone:
48
+
49
+ ```
50
+ git clone https://github.com/jacob-adm/release-drift
51
+ cd release-drift
52
+ pip install .
53
+ ```
54
+
55
+ pip installs `release-drift` as a console script. Without installing, it runs from a clone as
56
+ `python3 -m release_drift`.
57
+
58
+ ## How it works
59
+
60
+ 1. **Get the artifacts.** Download the wheel, sdist or npm tarball of each version, or let
61
+ `release-drift fetch` download them from PyPI or npm and check them against the registry's
62
+ digests.
63
+ 2. **Read them without unpacking.** Each artifact is read into memory. Absolute paths, `..`,
64
+ links leading outside the archive, device files and oversized members are refused; nothing
65
+ from the artifact is written to disk and nothing is run.
66
+ 3. **Find the execution surfaces.** `.pth` files, `sitecustomize.py`, `setup.py` and build
67
+ backends, npm `preinstall`, `install`, `postinstall` and `prepare` scripts, `.pyc` files
68
+ without source, native binaries (ELF, Mach-O, PE, WebAssembly) and links; also URL hosts and
69
+ long base64 or hex strings.
70
+ 4. **Compare.** `diff` lists the files added, removed or changed between two releases, and the
71
+ surfaces, hosts and strings that are new. `source` lists the files of a release that are not,
72
+ as they are, in git at a tag, apart from a documented list of files packaging tools generate.
73
+ 5. **Act on the result.** release-drift exits 1 when it finds something, 0 when it finds nothing
74
+ and 2 on an error, like `grep`. A finding is a new or changed execution surface, a new URL host
75
+ or encoded string, or, for `source`, a file not in the tag. Files that merely changed between
76
+ two releases are listed but are not findings.
77
+
78
+ ## Commands
79
+
80
+ ```
81
+ release-drift diff OLD NEW [--json] compare two artifacts
82
+ release-drift source ARTIFACT --repo DIR --ref REF files not in git at REF
83
+ [--prefix PATH] [--json]
84
+ release-drift fetch {pypi,npm} NAME VERSION DIR download one version; no install
85
+ [--type {sdist,wheel,all}]
86
+ ```
87
+
88
+ Output is one TAB-separated record per line: `CATEGORY`, `STATUS`, `PATH`, `DETAIL`, sorted.
89
+ `--json` prints a JSON array instead. `fetch` downloads only the sdist from PyPI unless `--type`
90
+ says otherwise.
91
+
92
+ ## Quick start
93
+
94
+ Compare two releases of `six`:
95
+
96
+ ```sh
97
+ mkdir old new
98
+ release-drift fetch pypi six 1.16.0 old
99
+ release-drift fetch pypi six 1.17.0 new
100
+ release-drift diff old/six-1.16.0.tar.gz new/six-1.17.0.tar.gz
101
+ echo $?
102
+ ```
103
+
104
+ ```text
105
+ build changed setup.py setup.py
106
+ file changed CHANGES -
107
+ file changed LICENSE -
108
+ file changed PKG-INFO -
109
+ file changed README.rst -
110
+ file changed documentation/conf.py -
111
+ file changed documentation/index.rst -
112
+ file changed setup.cfg -
113
+ file changed setup.py -
114
+ file changed six.egg-info/PKG-INFO -
115
+ file changed six.py -
116
+ file changed test_six.py -
117
+ 1
118
+ ```
119
+
120
+ `fetch` downloads the sdist and prints the path it saves. In the diff, no file was added and no new
121
+ start-up hook, install script, binary or URL host appeared. The exit status is 1 because
122
+ `setup.py`, which runs when the sdist is built, changed: `build changed setup.py` is a finding.
123
+ The `file changed` records are listed but are not findings; the two wheels of the same versions,
124
+ in which no build script runs, give exit 0. Then check the release against its tag:
125
+
126
+ ```sh
127
+ git clone https://github.com/benjaminp/six
128
+ release-drift source new/six-1.17.0.tar.gz --repo six --ref 1.17.0
129
+ echo $?
130
+ ```
131
+
132
+ ```text
133
+ 0
134
+ ```
135
+
136
+ Every file of the sdist is in the tag `1.17.0`, apart from the files setuptools generates.
137
+
138
+ ## Documentation
139
+
140
+ - [Commands](https://github.com/jacob-adm/release-drift/blob/main/docs/commands.md): each command's input, records, options and exit status.
141
+ - [Source comparison](https://github.com/jacob-adm/release-drift/blob/main/docs/source-comparison.md): which generated files `source` accepts, and why.
142
+ - [Limitations and security](https://github.com/jacob-adm/release-drift/blob/main/docs/limitations-and-security.md): what release-drift reads, refuses
143
+ and does not detect.
144
+ - [Using it with other tools](https://github.com/jacob-adm/release-drift/blob/main/docs/other-tools.md): tested stacks for releases
145
+ and dependency bumps, and GuardDog and Socket, and what release-drift adds.
146
+ - [Contributing](https://github.com/jacob-adm/release-drift/blob/main/CONTRIBUTING.md): running the tests and contributing a change.
147
+ - [Reporting a vulnerability](https://github.com/jacob-adm/release-drift/blob/main/SECURITY.md)
148
+
149
+ ## License
150
+
151
+ Apache License 2.0; see [LICENSE](https://github.com/jacob-adm/release-drift/blob/main/LICENSE).
@@ -0,0 +1,13 @@
1
+ release_drift/__init__.py,sha256=yM94kzgiABFLPa6rbTlnXSgylOt5JCqbAboXtMxqUJ8,133
2
+ release_drift/__main__.py,sha256=Qta3EQNyvTurFmOBO41GuNjy2zx6zUQDxXliqM2ER_0,90
3
+ release_drift/archive.py,sha256=mSJ1Rlbbrp6OkbhZNPD4Nv7di4_Tv_3Hh5DCBhJlMI4,7191
4
+ release_drift/cli.py,sha256=G4MM6qyWhbtVmEjPF93BCn5i-7J8p5fmRRYdtynblZQ,3605
5
+ release_drift/compare.py,sha256=PdYZJm_BgnbRvISpIOhYBgbMCV5jvDGzTBruClAILh8,10372
6
+ release_drift/fetch.py,sha256=5MTOOQuABI3lMf-EEGVmrfCKNKy77FjHRopsJcj4nuo,5253
7
+ release_drift/scan.py,sha256=c7aOa_nj4p2srSv2CpRRyJadwdDSfvu0GqTLFOMoCiY,6400
8
+ release_drift-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
9
+ release_drift-0.1.0.dist-info/METADATA,sha256=wuHalRF4cSMUI3QzMNpAcV5Lxh15urSBInhvTdy6YUM,6640
10
+ release_drift-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
11
+ release_drift-0.1.0.dist-info/entry_points.txt,sha256=kpZu6tV_YQnyGM9RlLIILgKIkzhnnTI8o6EbStbdsNQ,57
12
+ release_drift-0.1.0.dist-info/top_level.txt,sha256=mZMZgKTbo_qoHdsX8WdIpROEyHUAeSafAq1o5SOkhjE,14
13
+ release_drift-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ release-drift = release_drift.cli:main
@@ -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 @@
1
+ release_drift