| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed by the Apache v2.0 license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """CIPD-specific code is concentrated here.""" | 5 """CIPD-specific code is concentrated here.""" |
| 6 | 6 |
| 7 import re | 7 import re |
| 8 | 8 |
| 9 # Regular expressions below are copied from | 9 # Regular expressions below are copied from |
| 10 # https://chromium.googlesource.com/infra/infra/+/468bb43/appengine/chrome_infra
_packages/cipd/impl.py | 10 # https://chromium.googlesource.com/infra/infra/+/468bb43/appengine/chrome_infra
_packages/cipd/impl.py |
| 11 # https://chromium.googlesource.com/infra/infra/+/468bb43/appengine/chrome_infra
_packages/cas/impl.py | 11 # https://chromium.googlesource.com/infra/infra/+/468bb43/appengine/chrome_infra
_packages/cas/impl.py |
| 12 | 12 |
| 13 PACKAGE_NAME_RE = re.compile(r'^([a-z0-9_\-]+/)*[a-z0-9_\-]+$') | 13 PACKAGE_NAME_RE = re.compile(r'^([a-z0-9_\-]+/)*[a-z0-9_\-]+$') |
| 14 INSTANCE_ID_RE = re.compile(r'^[0-9a-f]{40}$') | 14 INSTANCE_ID_RE = re.compile(r'^[0-9a-f]{40}$') |
| 15 TAG_KEY_RE = re.compile(r'^[a-z0-9_\-]$') | 15 TAG_KEY_RE = re.compile(r'^[a-z0-9_\-]+$') |
| 16 REF_RE = re.compile(r'^[a-z0-9_\-]{1,100}$') | 16 REF_RE = re.compile(r'^[a-z0-9_\-]{1,100}$') |
| 17 TAG_MAX_LEN = 400 | 17 TAG_MAX_LEN = 400 |
| 18 | 18 |
| 19 | 19 |
| 20 # CIPD package name template parameters allow a user to reference different |
| 21 # packages for different enviroments. Inspired by |
| 22 # https://chromium.googlesource.com/infra/infra/+/f1072a132c68532b548458392c5444
f04386d684/build/README.md |
| 23 # The values of the parameters are computed on the bot. |
| 24 # |
| 25 # Platform parameter value is "<os>-<arch>" string, where |
| 26 # os can be "linux", "mac" or "windows" and arch can be "386", "amd64" or "arm". |
| 27 PARAM_PLATFORM = '${platform}' |
| 28 # OS version parameter defines major and minor version of the OS distribution. |
| 29 # It is useful if package depends on .dll/.so libraries provided by the OS. |
| 30 # Example values: "ubuntu14_04", "mac10_9", "win6_1". |
| 31 PARAM_OS_VER = '${os_ver}' |
| 32 ALL_PARAMS = (PARAM_PLATFORM, PARAM_OS_VER) |
| 33 |
| 34 |
| 20 def is_valid_package_name(package_name): | 35 def is_valid_package_name(package_name): |
| 21 """Returns True if |package_name| is a valid CIPD package name.""" | 36 """Returns True if |package_name| is a valid CIPD package name.""" |
| 22 return bool(PACKAGE_NAME_RE.match(package_name)) | 37 return bool(PACKAGE_NAME_RE.match(package_name)) |
| 23 | 38 |
| 24 | 39 |
| 40 def is_valid_package_name_template(template): |
| 41 """Returns True if |package_name| is a valid CIPD package name template.""" |
| 42 # Render known parameters first. |
| 43 for p in ALL_PARAMS: |
| 44 template = template.replace(p, 'x') |
| 45 return is_valid_package_name(template) |
| 46 |
| 47 |
| 25 def is_valid_version(version): | 48 def is_valid_version(version): |
| 26 """Returns True if |version| is a valid CIPD package version.""" | 49 """Returns True if |version| is a valid CIPD package version.""" |
| 27 return bool( | 50 return bool( |
| 28 INSTANCE_ID_RE.match(version) or | 51 INSTANCE_ID_RE.match(version) or |
| 29 is_valid_tag(version) or | 52 is_valid_tag(version) or |
| 30 REF_RE.match(version) | 53 REF_RE.match(version) |
| 31 ) | 54 ) |
| 32 | 55 |
| 56 |
| 33 def is_valid_tag(tag): | 57 def is_valid_tag(tag): |
| 34 """True if string looks like a valid package instance tag.""" | 58 """True if string looks like a valid package instance tag.""" |
| 35 if not tag or ':' not in tag or len(tag) > TAG_MAX_LEN: | 59 if not tag or ':' not in tag or len(tag) > TAG_MAX_LEN: |
| 36 return False | 60 return False |
| 37 # Care only about the key. Value can be anything (including empty string). | 61 # Care only about the key. Value can be anything (including empty string). |
| 38 return bool(TAG_KEY_RE.match(tag.split(':', 1)[0])) | 62 return bool(TAG_KEY_RE.match(tag.split(':', 1)[0])) |
| 39 | 63 |
| 40 | 64 |
| 41 def is_pinned_version(version): | 65 def is_pinned_version(version): |
| 42 """Returns True if |version| is pinned.""" | 66 """Returns True if |version| is pinned.""" |
| 43 return bool(INSTANCE_ID_RE.match(version) or TAG_KEY_RE.match(version)) | 67 return bool(INSTANCE_ID_RE.match(version)) or is_valid_tag(version) |
| OLD | NEW |