|
| 1 | +from gettext import gettext as _ |
| 2 | + |
| 3 | +from pulpcore.plugin.exceptions import PulpException |
| 4 | + |
| 5 | + |
| 6 | +class ProvenanceVerificationError(PulpException): |
| 7 | + """ |
| 8 | + Raised when provenance verification fails. |
| 9 | + """ |
| 10 | + |
| 11 | + error_code = "PYT0001" |
| 12 | + |
| 13 | + def __init__(self, message): |
| 14 | + super().__init__() |
| 15 | + """ |
| 16 | + :param message: Description of the provenance verification error |
| 17 | + :type message: str |
| 18 | + """ |
| 19 | + self.message = message |
| 20 | + |
| 21 | + def __str__(self): |
| 22 | + return f"[{self.error_code}] " + _("Provenance verification failed: {message}").format( |
| 23 | + message=self.message |
| 24 | + ) |
| 25 | + |
| 26 | + |
| 27 | +class AttestationVerificationError(PulpException): |
| 28 | + """ |
| 29 | + Raised when attestation verification fails. |
| 30 | + """ |
| 31 | + |
| 32 | + error_code = "PYT0002" |
| 33 | + |
| 34 | + def __init__(self, message): |
| 35 | + super().__init__() |
| 36 | + """ |
| 37 | + :param message: Description of the attestation verification error |
| 38 | + :type message: str |
| 39 | + """ |
| 40 | + self.message = message |
| 41 | + |
| 42 | + def __str__(self): |
| 43 | + return f"[{self.error_code}] " + _("Attestation verification failed: {message}").format( |
| 44 | + message=self.message |
| 45 | + ) |
| 46 | + |
| 47 | + |
| 48 | +class PackageSubstitutionError(PulpException): |
| 49 | + """ |
| 50 | + Raised when packages with the same filename but different checksums are being added. |
| 51 | + """ |
| 52 | + |
| 53 | + error_code = "PYT0003" |
| 54 | + |
| 55 | + def __init__(self, duplicates): |
| 56 | + super().__init__() |
| 57 | + """ |
| 58 | + :param duplicates: Description of duplicate packages |
| 59 | + :type duplicates: str |
| 60 | + """ |
| 61 | + self.duplicates = duplicates |
| 62 | + |
| 63 | + def __str__(self): |
| 64 | + return f"[{self.error_code}] " + _( |
| 65 | + "Found duplicate packages being added with the same filename but different " |
| 66 | + "checksums. To allow this, set 'allow_package_substitution' to True on the " |
| 67 | + "repository. Conflicting packages: {duplicates}" |
| 68 | + ).format(duplicates=self.duplicates) |
| 69 | + |
| 70 | + |
| 71 | +class UnsupportedProtocolError(PulpException): |
| 72 | + """ |
| 73 | + Raised when an unsupported protocol is used for syncing. |
| 74 | + """ |
| 75 | + |
| 76 | + error_code = "PYT0004" |
| 77 | + |
| 78 | + def __init__(self, protocol): |
| 79 | + super().__init__() |
| 80 | + self.protocol = protocol |
| 81 | + |
| 82 | + def __str__(self): |
| 83 | + return f"[{self.error_code}] " + _( |
| 84 | + "Only HTTP(S) is supported for python syncing, got: {protocol}" |
| 85 | + ).format(protocol=self.protocol) |
| 86 | + |
| 87 | + |
| 88 | +class MissingRelativePathError(PulpException): |
| 89 | + """ |
| 90 | + Raised when relative_path field is missing during package upload. |
| 91 | + """ |
| 92 | + |
| 93 | + error_code = "PYT0005" |
| 94 | + |
| 95 | + def __str__(self): |
| 96 | + return f"[{self.error_code}] " + _("This field is required: relative_path") |
| 97 | + |
| 98 | + |
| 99 | +class InvalidPythonExtensionError(PulpException): |
| 100 | + """ |
| 101 | + Raised when a file has an invalid Python package extension. |
| 102 | + """ |
| 103 | + |
| 104 | + error_code = "PYT0006" |
| 105 | + |
| 106 | + def __init__(self, filename): |
| 107 | + super().__init__() |
| 108 | + """ |
| 109 | + :param filename: The filename with invalid extension |
| 110 | + :type filename: str |
| 111 | + """ |
| 112 | + self.filename = filename |
| 113 | + |
| 114 | + def __str__(self): |
| 115 | + return f"[{self.error_code}] " + _( |
| 116 | + "Extension on {filename} is not a valid python extension " |
| 117 | + "(.whl, .exe, .egg, .tar.gz, .tar.bz2, .zip)" |
| 118 | + ).format(filename=self.filename) |
| 119 | + |
| 120 | + |
| 121 | +class InvalidProvenanceError(PulpException): |
| 122 | + """ |
| 123 | + Raised when uploaded provenance data is invalid. |
| 124 | + """ |
| 125 | + |
| 126 | + error_code = "PYT0007" |
| 127 | + |
| 128 | + def __init__(self, message): |
| 129 | + super().__init__() |
| 130 | + """ |
| 131 | + :param message: Description of the provenance validation error |
| 132 | + :type message: str |
| 133 | + """ |
| 134 | + self.message = message |
| 135 | + |
| 136 | + def __str__(self): |
| 137 | + return f"[{self.error_code}] " + _( |
| 138 | + "The uploaded provenance is not valid: {message}" |
| 139 | + ).format(message=self.message) |
| 140 | + |
| 141 | + |
| 142 | +class RemoteFetchError(PulpException): |
| 143 | + """ |
| 144 | + Raised when fetching metadata from all remotes fails. |
| 145 | + """ |
| 146 | + |
| 147 | + error_code = "PYT0008" |
| 148 | + |
| 149 | + def __init__(self, url): |
| 150 | + super().__init__() |
| 151 | + self.url = url |
| 152 | + |
| 153 | + def __str__(self): |
| 154 | + return f"[{self.error_code}] " + _("Failed to fetch {url} from any remote.").format( |
| 155 | + url=self.url |
| 156 | + ) |
| 157 | + |
| 158 | + |
| 159 | +class InvalidAttestationsError(PulpException): |
| 160 | + """ |
| 161 | + Raised when attestation data cannot be validated. |
| 162 | + """ |
| 163 | + |
| 164 | + error_code = "PYT0009" |
| 165 | + |
| 166 | + def __init__(self, message): |
| 167 | + super().__init__() |
| 168 | + self.message = message |
| 169 | + |
| 170 | + def __str__(self): |
| 171 | + return f"[{self.error_code}] " + _("Invalid attestations: {message}").format( |
| 172 | + message=self.message |
| 173 | + ) |
| 174 | + |
| 175 | + |
| 176 | +class BlocklistedPackageError(PulpException): |
| 177 | + """ |
| 178 | + Raised when packages matching a blocklist entry are added to a repository. |
| 179 | + """ |
| 180 | + |
| 181 | + error_code = "PYT0010" |
| 182 | + |
| 183 | + def __init__(self, blocked): |
| 184 | + super().__init__() |
| 185 | + self.blocked = blocked |
| 186 | + |
| 187 | + def __str__(self): |
| 188 | + return f"[{self.error_code}] " + _( |
| 189 | + "Blocklisted packages cannot be added to this repository: {blocked}" |
| 190 | + ).format(blocked=", ".join(self.blocked)) |
0 commit comments