Utils Module
The utils module provides common utility functions and helper methods.
utils
Utility functions for version comparison and other common operations.
This module provides semantic version comparison utilities with custom handling for pre-release versions and wildcard version strings.
Functions:
isVersionBefore(_compare_to_version, _current_version)
Check if the current version is before (older than) the comparison version.
This function performs a modified semantic version comparison where pre-release versions are treated as equal to their base release version. For example, '8.6.0-pre.m1dev86' is normalized to '8.6.0' before comparison. Wildcard versions like '8.6.x' are converted to '8.6.0'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_compare_to_version
|
str
|
The version to compare against (e.g., "8.6.0"). |
required |
_current_version
|
str
|
The current version to check (e.g., "8.5.0" or "8.6.0-pre.m1dev86"). Can be None, in which case False is returned. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if current_version < compare_to_version, False otherwise. Returns False if _current_version is None. |
Note
This differs from strict semantic versioning where pre-release versions are considered less than their base version.
Source code in src/mas/devops/utils.py
isVersionEqualOrAfter(_compare_to_version, _current_version)
Check if the current version is equal to or after (newer than) the comparison version.
This function performs a modified semantic version comparison where pre-release versions are treated as equal to their base release version. For example, '8.6.0-pre.m1dev86' is normalized to '8.6.0' before comparison. Wildcard versions like '8.6.x' are converted to '8.6.0'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_compare_to_version
|
str
|
The version to compare against (e.g., "8.6.0"). |
required |
_current_version
|
str
|
The current version to check (e.g., "8.7.0" or "8.6.0-pre.m1dev86"). Can be None, in which case False is returned. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if current_version >= compare_to_version, False otherwise. Returns False if _current_version is None. |
Note
This differs from strict semantic versioning where pre-release versions are considered less than their base version.
Source code in src/mas/devops/utils.py
validateIBMEntitlementKey(entitlementKey, repository='cp/mas/coreapi', timeout=30)
Validate IBM entitlement key against cp.icr.io registry.
This function validates an IBM entitlement key by attempting to obtain an authentication token from the IBM Container Registry and verifying access to the specified repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entitlementKey
|
str
|
IBM entitlement key to validate. |
required |
repository
|
str
|
Repository to test access against. Defaults to "cp/mas/coreapi". |
'cp/mas/coreapi'
|
timeout
|
int
|
Request timeout in seconds. Defaults to 30. |
30
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if key is valid and grants access to the repository, False otherwise. |
Raises:
| Type | Description |
|---|---|
RequestException
|
If network request fails. |
Source code in src/mas/devops/utils.py
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 | |