@@ -149,14 +149,35 @@ export class RegistryHTTPClient implements Registry {
149149 }
150150
151151 authBase64 ( ) : string {
152+ const configuration = this . configuration ;
153+ if ( configuration . username === undefined ) {
154+ return "" ;
155+ }
156+
152157 return btoa ( this . configuration . username + ":" + this . password ( ) ) ;
153158 }
154159
155160 password ( ) : string {
156- return ( this . env as unknown as Record < string , string > ) [ this . configuration . password_env ] ?? "" ;
161+ const configuration = this . configuration ;
162+ if ( configuration . username === undefined ) {
163+ return "" ;
164+ }
165+
166+ return ( this . env as unknown as Record < string , string > ) [ configuration . password_env ] ?? "" ;
157167 }
158168
159169 async authenticate ( namespace : string ) : Promise < HTTPContext > {
170+ const emptyAuthentication = {
171+ authContext : {
172+ authType : "none" ,
173+ realm : "" ,
174+ scope : "" ,
175+ service : this . url . host ,
176+ } ,
177+ repository : this . url . pathname ,
178+ accessToken : "" ,
179+ } as const ;
180+
160181 const res = await fetch ( `${ this . url . protocol } //${ this . url . host } /v2/` , {
161182 headers : {
162183 "User-Agent" : "Docker-Client/24.0.5 (linux)" ,
@@ -165,16 +186,7 @@ export class RegistryHTTPClient implements Registry {
165186 } ) ;
166187
167188 if ( res . ok ) {
168- return {
169- authContext : {
170- authType : "none" ,
171- realm : "" ,
172- scope : "" ,
173- service : this . url . host ,
174- } ,
175- repository : this . url . pathname ,
176- accessToken : "" ,
177- } ;
189+ return emptyAuthentication ;
178190 }
179191
180192 if ( res . status !== 401 ) {
@@ -212,11 +224,12 @@ export class RegistryHTTPClient implements Registry {
212224 async authenticateBearerSimple ( ctx : AuthContext , params : URLSearchParams ) : Promise < Response > {
213225 params . delete ( "password" ) ;
214226 console . log ( "sending authentication parameters:" , ctx . realm + "?" + params . toString ( ) ) ;
227+
215228 return await fetch ( ctx . realm + "?" + params . toString ( ) , {
216229 headers : {
217- "Authorization" : "Basic " + this . authBase64 ( ) ,
218230 "Accept" : "application/json" ,
219231 "User-Agent" : "Docker-Client/24.0.5 (linux)" ,
232+ ...( this . configuration . username !== undefined ? { Authorization : "Basic " + this . authBase64 ( ) } : { } ) ,
220233 } ,
221234 } ) ;
222235 }
@@ -227,8 +240,8 @@ export class RegistryHTTPClient implements Registry {
227240 // explicitely include that we don't want an offline_token.
228241 scope : `repository:${ ctx . scope } :pull,push` ,
229242 client_id : "r2registry" ,
230- grant_type : "password" ,
231- password : this . password ( ) ,
243+ grant_type : this . configuration . username === undefined ? "none" : "password" ,
244+ password : this . configuration . username === undefined ? "" : this . password ( ) ,
232245 } ) ;
233246 let response = await fetch ( ctx . realm , {
234247 headers : {
@@ -468,7 +481,7 @@ export class RegistryHTTPClient implements Registry {
468481 _namespace : string ,
469482 _reference : string ,
470483 _readableStream : ReadableStream < any > ,
471- _contentType : string ,
484+ { } : { } ,
472485 ) : Promise < PutManifestResponse | RegistryError > {
473486 throw new Error ( "unimplemented" ) ;
474487 }
0 commit comments