forge
Clone
https://git.tahinli.com/Tahinli/forge.git
0 watching0 forksRustAGPL-3.07.1 MiB490f099Tahinli7 hours ago322 commits
| 1 | //! Package registry rules of the web layer: who may read or publish a package, publishing a |
| 2 | //! `.crate`, yanking a version, and the index and config files cargo reads. The protocol |
| 3 | //! rules (names, index lines, publish bodies) live in `forge_core::cargo`; the HTTP routes in |
| 4 | //! `api::packages` and the pages translate these results. Bytes go to the blob store under |
| 5 | //! `packages/<version id>`, and each change is announced on the owner's live signal. |
| 6 | |
| 7 | use ; |
| 8 | use cargo; |
| 9 | use User; |
| 10 | use ; |
| 11 | use OrgMemberRole; |
| 12 | use ; |
| 13 | use ; |
| 14 | use ; |
| 15 | |
| 16 | use crateBlobRead; |
| 17 | use crateAppState; |
| 18 | |
| 19 | /// Largest `.crate` accepted, in bytes. The limit crates.io uses. |
| 20 | pub const MAX_CRATE_BYTES: u64 = 10 * 1024 * 1024; |
| 21 | /// Largest publish body accepted: the crate plus its JSON metadata. |
| 22 | pub const MAX_PUBLISH_BYTES: usize = 16 * 1024 * 1024; |
| 23 | /// Bytes handed to the blob writer at a time. |
| 24 | const PUSH_CHUNK: usize = 1024 * 1024; |
| 25 | |
| 26 | /// Why a registry request failed. The API maps each to a status and a cargo error body. |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | /// The user or org a registry path names. `None` when no such account exists. |
| 49 | pub async |
| 50 | |
| 51 | |
| 52 | |
| 53 | /// True when `actor` may read the repo a package is linked to. A link to a missing repo counts |
| 54 | /// as unreadable, so a dangling link never exposes the package. |
| 55 | async |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | /// True when `actor` may read `package`. A public package is readable by anyone, unless it is |
| 77 | /// linked to a repo the actor may not read. A private one is readable by the instance admin, the |
| 78 | /// owner and the owner's org members. |
| 79 | pub async |
| 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 | /// True when `actor` may publish, yank or unyank in `owner`'s registry: the owner themselves, |
| 106 | /// an org owner, or the instance admin. |
| 107 | pub async |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | /// The package `name` of `owner` as the actor may see it. A missing package and a private one |
| 123 | /// the actor may not read are the same `NotFound`. |
| 124 | pub async |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | /// A container image of `owner` that the viewer may read. The name is the image path below the |
| 143 | /// owner, as the registry stores it. |
| 144 | pub async |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | /// The `config.json` of an owner's registry. `auth-required` is set when the owner has a private |
| 162 | /// package, since cargo then needs a token for every request to that registry. |
| 163 | pub async |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | /// The index file of a package: one JSON line per version, oldest first, each with the current |
| 174 | /// yank state. A package with no versions has no index. |
| 175 | pub async |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | /// Publishes a `.crate` from a publish body. The version row is written first, so a repeated |
| 190 | /// version is a `Conflict` before any bytes are stored. A failed byte write removes the row. |
| 191 | pub async |
| 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 | /// Wakes the repo that `package_id` is linked to, if any: its home page shows the package's newest |
| 261 | /// version. A failed lookup skips the wake only, since the write has already happened. |
| 262 | pub async |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | /// Sets the yank state of a version. Yanked versions stay in the index and stay downloadable, |
| 271 | /// marked as yanked, so existing lockfiles keep working. |
| 272 | pub async |
| 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 | /// The `.crate` bytes of a version, for a download. Yanked versions still download. |
| 302 | pub async |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | /// The blob key of a version's `.crate` file. |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | /// Points the package at the repo its `repository` field names, when that repo belongs to the |
| 328 | /// same owner. A repo of another owner is never linked, so nobody can claim it. |
| 329 | async |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | /// Streams `bytes` into the blob store under `key`, returning the sha256 the store computed. |
| 353 | async |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 |