3232import java .util .Map ;
3333import land .oras .auth .AuthProvider ;
3434import land .oras .auth .AuthStoreAuthenticationProvider ;
35+ import land .oras .auth .HttpClient ;
3536import land .oras .auth .NoAuthProvider ;
37+ import land .oras .auth .Scopes ;
3638import land .oras .auth .UsernamePasswordProvider ;
3739import land .oras .exception .OrasException ;
3840import land .oras .utils .ArchiveUtils ;
3941import land .oras .utils .Const ;
40- import land .oras .utils .HttpClient ;
4142import land .oras .utils .JsonUtils ;
4243import land .oras .utils .SupportedAlgorithm ;
4344import org .jspecify .annotations .NullMarked ;
@@ -151,8 +152,11 @@ public String getScheme() {
151152 public Tags getTags (ContainerRef containerRef ) {
152153 URI uri = URI .create (
153154 "%s://%s" .formatted (getScheme (), containerRef .forRegistry (this ).getTagsPath (this )));
154- HttpClient .ResponseWrapper <String > response =
155- client .get (uri , Map .of (Const .ACCEPT_HEADER , Const .DEFAULT_JSON_MEDIA_TYPE ), containerRef , authProvider );
155+ HttpClient .ResponseWrapper <String > response = client .get (
156+ uri ,
157+ Map .of (Const .ACCEPT_HEADER , Const .DEFAULT_JSON_MEDIA_TYPE ),
158+ Scopes .of (this , containerRef ),
159+ authProvider );
156160 handleError (response );
157161 return JsonUtils .fromJson (response .response (), Tags .class );
158162 }
@@ -165,7 +169,10 @@ public Referrers getReferrers(ContainerRef containerRef, @Nullable ArtifactType
165169 URI uri = URI .create (
166170 "%s://%s" .formatted (getScheme (), containerRef .forRegistry (this ).getReferrersPath (this , artifactType )));
167171 HttpClient .ResponseWrapper <String > response = client .get (
168- uri , Map .of (Const .ACCEPT_HEADER , Const .DEFAULT_INDEX_MEDIA_TYPE ), containerRef , authProvider );
172+ uri ,
173+ Map .of (Const .ACCEPT_HEADER , Const .DEFAULT_INDEX_MEDIA_TYPE ),
174+ Scopes .of (this , containerRef ),
175+ authProvider );
169176 handleError (response );
170177 return JsonUtils .fromJson (response .response (), Referrers .class );
171178 }
@@ -177,7 +184,8 @@ public Referrers getReferrers(ContainerRef containerRef, @Nullable ArtifactType
177184 public void deleteManifest (ContainerRef containerRef ) {
178185 URI uri = URI .create (
179186 "%s://%s" .formatted (getScheme (), containerRef .forRegistry (this ).getManifestsPath (this )));
180- HttpClient .ResponseWrapper <String > response = client .delete (uri , Map .of (), containerRef , authProvider );
187+ HttpClient .ResponseWrapper <String > response =
188+ client .delete (uri , Map .of (), Scopes .of (this , containerRef ), authProvider );
181189 logResponse (response );
182190 handleError (response );
183191 }
@@ -201,7 +209,7 @@ public Manifest pushManifest(ContainerRef containerRef, Manifest manifest) {
201209 uri ,
202210 manifestData ,
203211 Map .of (Const .CONTENT_TYPE_HEADER , Const .DEFAULT_MANIFEST_MEDIA_TYPE ),
204- containerRef ,
212+ Scopes . of ( this , containerRef ) ,
205213 authProvider );
206214 logResponse (response );
207215 handleError (response );
@@ -225,7 +233,7 @@ public Index pushIndex(ContainerRef containerRef, Index index) {
225233 uri ,
226234 indexData ,
227235 Map .of (Const .CONTENT_TYPE_HEADER , Const .DEFAULT_INDEX_MEDIA_TYPE ),
228- containerRef ,
236+ Scopes . of ( this , containerRef ) ,
229237 authProvider );
230238 logResponse (response );
231239 handleError (response );
@@ -239,7 +247,8 @@ public Index pushIndex(ContainerRef containerRef, Index index) {
239247 public void deleteBlob (ContainerRef containerRef ) {
240248 URI uri = URI .create (
241249 "%s://%s" .formatted (getScheme (), containerRef .forRegistry (this ).getBlobsPath (this )));
242- HttpClient .ResponseWrapper <String > response = client .delete (uri , Map .of (), containerRef , authProvider );
250+ HttpClient .ResponseWrapper <String > response =
251+ client .delete (uri , Map .of (), Scopes .of (this , containerRef ), authProvider );
243252 logResponse (response );
244253 handleError (response );
245254 }
@@ -344,7 +353,7 @@ public Layer pushBlob(ContainerRef containerRef, Path blob, Map<String, String>
344353 uri ,
345354 Map .of (Const .CONTENT_TYPE_HEADER , Const .APPLICATION_OCTET_STREAM_HEADER_VALUE ),
346355 blob ,
347- containerRef ,
356+ Scopes . of ( this , containerRef ) ,
348357 authProvider );
349358 logResponse (response );
350359
@@ -367,7 +376,7 @@ public Layer pushBlob(ContainerRef containerRef, Path blob, Map<String, String>
367376 URI .create ("%s&digest=%s" .formatted (location , digest )),
368377 Map .of (Const .CONTENT_TYPE_HEADER , Const .APPLICATION_OCTET_STREAM_HEADER_VALUE ),
369378 blob ,
370- containerRef ,
379+ Scopes . of ( this , containerRef ) ,
371380 authProvider );
372381 if (response .statusCode () == 201 ) {
373382 LOG .debug ("Successful push: {}" , response .response ());
@@ -398,7 +407,7 @@ public Layer pushBlob(ContainerRef containerRef, byte[] data) {
398407 uri ,
399408 data ,
400409 Map .of (Const .CONTENT_TYPE_HEADER , Const .APPLICATION_OCTET_STREAM_HEADER_VALUE ),
401- containerRef ,
410+ Scopes . of ( this , containerRef ) ,
402411 authProvider );
403412 logResponse (response );
404413
@@ -420,7 +429,7 @@ public Layer pushBlob(ContainerRef containerRef, byte[] data) {
420429 URI .create ("%s&digest=%s" .formatted (location , digest )),
421430 data ,
422431 Map .of (Const .CONTENT_TYPE_HEADER , Const .APPLICATION_OCTET_STREAM_HEADER_VALUE ),
423- containerRef ,
432+ Scopes . of ( this , containerRef ) ,
424433 authProvider );
425434 if (response .statusCode () == 201 ) {
426435 LOG .debug ("Successful push: {}" , response .response ());
@@ -449,7 +458,7 @@ private HttpClient.ResponseWrapper<String> headBlob(ContainerRef containerRef) {
449458 HttpClient .ResponseWrapper <String > response = client .head (
450459 uri ,
451460 Map .of (Const .ACCEPT_HEADER , Const .APPLICATION_OCTET_STREAM_HEADER_VALUE ),
452- containerRef ,
461+ Scopes . of ( this , containerRef ) ,
453462 authProvider );
454463 logResponse (response );
455464 return response ;
@@ -480,7 +489,7 @@ public void fetchBlob(ContainerRef containerRef, Path path) {
480489 uri ,
481490 Map .of (Const .ACCEPT_HEADER , Const .APPLICATION_OCTET_STREAM_HEADER_VALUE ),
482491 path ,
483- containerRef ,
492+ Scopes . of ( this , containerRef ) ,
484493 authProvider );
485494 logResponse (response );
486495 handleError (response );
@@ -496,7 +505,7 @@ public InputStream fetchBlob(ContainerRef containerRef) {
496505 HttpClient .ResponseWrapper <InputStream > response = client .download (
497506 uri ,
498507 Map .of (Const .ACCEPT_HEADER , Const .APPLICATION_OCTET_STREAM_HEADER_VALUE ),
499- containerRef ,
508+ Scopes . of ( this , containerRef ) ,
500509 authProvider );
501510 logResponse (response );
502511 handleError (response );
@@ -561,11 +570,15 @@ public Descriptor probeDescriptor(ContainerRef ref) {
561570 private HttpClient .ResponseWrapper <String > getManifestResponse (ContainerRef containerRef ) {
562571 URI uri = URI .create (
563572 "%s://%s" .formatted (getScheme (), containerRef .forRegistry (this ).getManifestsPath (this )));
564- HttpClient .ResponseWrapper <String > response =
565- client .head (uri , Map .of (Const .ACCEPT_HEADER , Const .MANIFEST_ACCEPT_TYPE ), containerRef , authProvider );
573+ HttpClient .ResponseWrapper <String > response = client .head (
574+ uri ,
575+ Map .of (Const .ACCEPT_HEADER , Const .MANIFEST_ACCEPT_TYPE ),
576+ Scopes .of (this , containerRef ),
577+ authProvider );
566578 logResponse (response );
567579 handleError (response );
568- return client .get (uri , Map .of ("Accept" , Const .MANIFEST_ACCEPT_TYPE ), containerRef , authProvider );
580+ return client .get (
581+ uri , Map .of ("Accept" , Const .MANIFEST_ACCEPT_TYPE ), Scopes .of (this , containerRef ), authProvider );
569582 }
570583
571584 private byte [] ensureDigest (ContainerRef ref , byte [] data ) {
@@ -635,8 +648,11 @@ String getContentType(ContainerRef containerRef) {
635648 Map <String , String > getHeaders (ContainerRef containerRef ) {
636649 URI uri = URI .create (
637650 "%s://%s" .formatted (getScheme (), containerRef .forRegistry (this ).getManifestsPath (this )));
638- HttpClient .ResponseWrapper <String > response =
639- client .head (uri , Map .of (Const .ACCEPT_HEADER , Const .MANIFEST_ACCEPT_TYPE ), containerRef , authProvider );
651+ HttpClient .ResponseWrapper <String > response = client .head (
652+ uri ,
653+ Map .of (Const .ACCEPT_HEADER , Const .MANIFEST_ACCEPT_TYPE ),
654+ Scopes .of (this , containerRef ),
655+ authProvider );
640656 logResponse (response );
641657 handleError (response );
642658 return response .headers ();
0 commit comments