|
14 | 14 | * You should have received a copy of the GNU Affero General Public License
|
15 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 | 16 | */
|
17 |
| -import { Http } from './http'; |
18 |
| -import { isDigit, eventTransfer, ERROR_CAN_NOT_READ_CONTENT_DIGEST } from './utils'; |
| 17 | +import { Http } from './http.js'; |
| 18 | +import { eventTransfer, ERROR_CAN_NOT_READ_CONTENT_DIGEST } from './utils.js'; |
19 | 19 | import observable from '@riotjs/observable';
|
20 | 20 |
|
| 21 | +export const supportListManifest = (response) => { |
| 22 | + if (response.mediaType === 'application/vnd.docker.distribution.manifest.list.v2+json') { |
| 23 | + return true; |
| 24 | + } |
| 25 | + if (response.mediaType === 'application/vnd.oci.image.index.v1+json' && Array.isArray(response.manifests)) { |
| 26 | + return !response.manifests.some(({ mediaType }) => mediaType !== 'application/vnd.oci.image.manifest.v1+json'); |
| 27 | + } |
| 28 | + return false; |
| 29 | +}; |
| 30 | + |
| 31 | +export const filterWrongManifests = (response) => { |
| 32 | + return response.manifests.filter( |
| 33 | + ({ annotations }) => !annotations || annotations['vnd.docker.reference.type'] !== 'attestation-manifest' |
| 34 | + ); |
| 35 | +}; |
| 36 | + |
21 | 37 | export class DockerImage {
|
22 | 38 | constructor(name, tag, { list, registryUrl, onNotify, onAuthentication, useControlCacheHeader }) {
|
23 | 39 | this.name = name;
|
@@ -73,8 +89,8 @@ export class DockerImage {
|
73 | 89 | oReq.addEventListener('loadend', function () {
|
74 | 90 | if (this.status === 200 || this.status === 202) {
|
75 | 91 | const response = JSON.parse(this.responseText);
|
76 |
| - if (response.mediaType === 'application/vnd.docker.distribution.manifest.list.v2+json' && self.opts.list) { |
77 |
| - self.trigger('list', response); |
| 92 | + if (supportListManifest(response) && self.opts.list) { |
| 93 | + self.trigger('list', filterWrongManifests(response)); |
78 | 94 | const manifest = response.manifests[0];
|
79 | 95 | const image = new DockerImage(self.name, manifest.digest, { ...self.opts, list: false });
|
80 | 96 | eventTransfer(image, self);
|
|
0 commit comments