@@ -286,32 +286,33 @@ struct RegistryReader {
286
286
}
287
287
288
288
impl RegistryReader {
289
- /// Request registry server with ` authorization` header
289
+ /// Request registry server with authorization workflow, it has two authentication modes:
290
290
///
291
- /// Bearer token authenticate workflow:
291
+ /// # Bearer token authenticate workflow:
292
292
///
293
- /// Request: POST https://my-registry.com/test /repo/blobs/uploads
293
+ /// Request: GET https://my-registry.com/namespace /repo/blobs/sha256:<blob_id>
294
294
/// Response: status: 401 Unauthorized
295
- /// header: www-authenticate: Bearer realm="https://auth.my-registry.com/token",service="my-registry.com",scope="repository:test /repo:pull,push"
295
+ /// header: www-authenticate: Bearer realm="https://auth.my-registry.com/token",service="my-registry.com",scope="repository:namespace /repo:pull,push"
296
296
///
297
297
/// Request: POST https://auth.my-registry.com/token
298
- /// body: "service=my-registry.com&scope=repository:test /repo:pull,push&grant_type=password&username=x&password=x&client_id=nydus-registry-client"
298
+ /// body: "service=my-registry.com&scope=repository:namespace /repo:pull,push&grant_type=password&username=x&password=x&client_id=nydus-registry-client"
299
299
/// Response: status: 200 Ok
300
300
/// body: { "token": "<token>" }
301
301
///
302
- /// Request: POST https://my-registry.com/test /repo/blobs/uploads
302
+ /// Request: GET https://my-registry.com/namespace /repo/blobs/sha256:<blob_id>
303
303
/// header: authorization: Bearer <token>
304
- /// Response: status: 200 Ok
304
+ /// Response: status: 200/301/307
305
+ ///
305
306
///
306
- /// Basic authenticate workflow:
307
+ /// # Basic authenticate workflow:
307
308
///
308
- /// Request: POST https://my-registry.com/test /repo/blobs/uploads
309
+ /// Request: GET https://my-registry.com/namespace /repo/blobs/sha256:<blob_id>
309
310
/// Response: status: 401 Unauthorized
310
311
/// header: www-authenticate: Basic
311
312
///
312
- /// Request: POST https://my-registry.com/test /repo/blobs/uploads
313
+ /// Request: GET https://my-registry.com/namespace /repo/blobs/sha256:<blob_id>
313
314
/// header: authorization: Basic base64(<username:password>)
314
- /// Response: status: 200 Ok
315
+ /// Response: status: 200/301/307
315
316
fn request < R : Read + Send + ' static > (
316
317
& self ,
317
318
method : Method ,
@@ -377,17 +378,16 @@ impl RegistryReader {
377
378
respond ( resp, catch_status) . map_err ( RegistryError :: Request )
378
379
}
379
380
380
- /// Read data from registry server
381
- ///
382
- /// Step:
381
+ /// Read data from registry server, steps:
383
382
///
384
383
/// Request: GET /blobs/sha256:<blob_id>
385
- /// Response: status: 307 Temporary Redirect
384
+ /// Response: status: 301/ 307
386
385
/// header: location: https://raw-blob-storage-host.com/signature=x
387
386
///
388
387
/// Request: GET https://raw-blob-storage-host.com/signature=x
389
- /// Response: status: 200 Ok / 403 Forbidden
390
- /// If responding 403, we need to repeat step one
388
+ /// Response: status: 200/403
389
+ ///
390
+ /// If responding with 403, we need to go authorization workflow
391
391
fn _try_read (
392
392
& self ,
393
393
mut buf : & mut [ u8 ] ,
@@ -748,4 +748,16 @@ mod tests {
748
748
assert_eq ! ( trim( Some ( " te st " . to_owned( ) ) ) , Some ( "te st" . to_owned( ) ) ) ;
749
749
assert_eq ! ( trim( Some ( "te st" . to_owned( ) ) ) , Some ( "te st" . to_owned( ) ) ) ;
750
750
}
751
+
752
+ #[ test]
753
+ fn test_ghcr ( ) {
754
+ let config =
755
+ serde_json:: json!( { "scheme" : "https" , "host" : "ghcr.io" , "repo" : "changweige/python" } ) ;
756
+ let registry = Registry :: new ( config, Some ( "registry" ) ) . unwrap ( ) ;
757
+
758
+ let reader = registry
759
+ . get_reader ( "b91a341ac9a53528c4d96806e1c07c3307a95ede5841f2a13ac4972c7699b067" )
760
+ . unwrap ( ) ;
761
+ let _ = reader. blob_size ( ) . unwrap ( ) ;
762
+ }
751
763
}
0 commit comments