@@ -46,13 +46,16 @@ export function compare(e1, e2) {
46
46
}
47
47
48
48
export class DockerImage {
49
- constructor ( name , tag , list , registryUrl , onNotify ) {
49
+ constructor ( name , tag , { list, registryUrl, onNotify, onAuthentication } ) {
50
50
this . name = name ;
51
51
this . tag = tag ;
52
- this . list = list ;
53
- this . registryUrl = registryUrl ;
54
52
this . chars = 0 ;
55
- this . onNotify = onNotify ;
53
+ this . opts = {
54
+ list,
55
+ registryUrl,
56
+ onNotify,
57
+ onAuthentication,
58
+ } ;
56
59
observable ( this ) ;
57
60
this . on ( 'get-size' , function ( ) {
58
61
if ( this . size !== undefined ) {
@@ -90,15 +93,15 @@ export class DockerImage {
90
93
return ;
91
94
}
92
95
this . _fillInfoWaiting = true ;
93
- const oReq = new Http ( ) ;
96
+ const oReq = new Http ( { onAuthentication : this . opts . onAuthentication } ) ;
94
97
const self = this ;
95
98
oReq . addEventListener ( 'loadend' , function ( ) {
96
99
if ( this . status == 200 || this . status == 202 ) {
97
100
const response = JSON . parse ( this . responseText ) ;
98
101
if ( response . mediaType === 'application/vnd.docker.distribution.manifest.list.v2+json' ) {
99
102
self . trigger ( 'list' , response ) ;
100
103
const manifest = response . manifests [ 0 ] ;
101
- const image = new DockerImage ( self . name , manifest . digest , false , self . registryUrl , self . onNotify ) ;
104
+ const image = new DockerImage ( self . name , manifest . digest , { ... self . opts , list : false } ) ;
102
105
eventTransfer ( image , self ) ;
103
106
image . fillInfo ( ) ;
104
107
self . variants = [ image ] ;
@@ -115,26 +118,26 @@ export class DockerImage {
115
118
self . digest = digest ;
116
119
self . trigger ( 'content-digest' , digest ) ;
117
120
if ( ! digest ) {
118
- self . onNotify ( ERROR_CAN_NOT_READ_CONTENT_DIGEST ) ;
121
+ self . opts . onNotify ( ERROR_CAN_NOT_READ_CONTENT_DIGEST ) ;
119
122
}
120
123
} ) ;
121
124
self . getBlobs ( response . config . digest ) ;
122
125
} else if ( this . status == 404 ) {
123
- self . onNotify ( `Manifest for ${ self . name } :${ self . tag } not found` , true ) ;
126
+ self . opts . onNotify ( `Manifest for ${ self . name } :${ self . tag } not found` , true ) ;
124
127
} else {
125
- self . onNotify ( this . responseText ) ;
128
+ self . opts . onNotify ( this . responseText ) ;
126
129
}
127
130
} ) ;
128
- oReq . open ( 'GET' , this . registryUrl + ' /v2/' + self . name + ' /manifests/' + self . tag ) ;
131
+ oReq . open ( 'GET' , ` ${ this . opts . registryUrl } /v2/${ self . name } /manifests/${ self . tag } ` ) ;
129
132
oReq . setRequestHeader (
130
133
'Accept' ,
131
134
'application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json' +
132
- ( self . list ? ', application/vnd.docker.distribution.manifest.list.v2+json' : '' )
135
+ ( self . opts . list ? ', application/vnd.docker.distribution.manifest.list.v2+json' : '' )
133
136
) ;
134
137
oReq . send ( ) ;
135
138
}
136
139
getBlobs ( blob ) {
137
- const oReq = new Http ( ) ;
140
+ const oReq = new Http ( { onAuthentication : this . opts . onAuthentication } ) ;
138
141
const self = this ;
139
142
oReq . addEventListener ( 'loadend' , function ( ) {
140
143
if ( this . status == 200 || this . status == 202 ) {
@@ -153,12 +156,12 @@ export class DockerImage {
153
156
self . trigger ( 'creation-date' , self . creationDate ) ;
154
157
self . trigger ( 'blobs' , self . blobs ) ;
155
158
} else if ( this . status == 404 ) {
156
- self . onNotify ( `Blobs for ${ self . name } :${ self . tag } not found` , true ) ;
159
+ self . opts . onNotify ( `Blobs for ${ self . name } :${ self . tag } not found` , true ) ;
157
160
} else {
158
- self . onNotify ( this . responseText ) ;
161
+ self . opts . onNotify ( this . responseText ) ;
159
162
}
160
163
} ) ;
161
- oReq . open ( 'GET' , this . registryUrl + ' /v2/' + self . name + ' /blobs/' + blob ) ;
164
+ oReq . open ( 'GET' , ` ${ this . opts . registryUrl } /v2/${ self . name } /blobs/${ blob } ` ) ;
162
165
oReq . setRequestHeader (
163
166
'Accept' ,
164
167
'application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json'
0 commit comments