@trustify-da/trustify-da-javascript-client 0.2.4-ea-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +482 -0
- package/config/config.properties +1 -0
- package/dist/package.json +110 -0
- package/dist/src/analysis.d.ts +43 -0
- package/dist/src/analysis.js +252 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +102 -0
- package/dist/src/cyclone_dx_sbom.d.ts +77 -0
- package/dist/src/cyclone_dx_sbom.js +244 -0
- package/dist/src/index.d.ts +82 -0
- package/dist/src/index.js +194 -0
- package/dist/src/oci_image/images.d.ts +99 -0
- package/dist/src/oci_image/images.js +263 -0
- package/dist/src/oci_image/platform.d.ts +59 -0
- package/dist/src/oci_image/platform.js +138 -0
- package/dist/src/oci_image/utils.d.ts +42 -0
- package/dist/src/oci_image/utils.js +496 -0
- package/dist/src/provider.d.ts +29 -0
- package/dist/src/provider.js +47 -0
- package/dist/src/providers/base_java.d.ts +85 -0
- package/dist/src/providers/base_java.js +191 -0
- package/dist/src/providers/base_javascript.d.ts +127 -0
- package/dist/src/providers/base_javascript.js +350 -0
- package/dist/src/providers/golang_gomodules.d.ts +42 -0
- package/dist/src/providers/golang_gomodules.js +403 -0
- package/dist/src/providers/java_gradle.d.ts +35 -0
- package/dist/src/providers/java_gradle.js +399 -0
- package/dist/src/providers/java_gradle_groovy.d.ts +7 -0
- package/dist/src/providers/java_gradle_groovy.js +19 -0
- package/dist/src/providers/java_gradle_kotlin.d.ts +11 -0
- package/dist/src/providers/java_gradle_kotlin.js +23 -0
- package/dist/src/providers/java_maven.d.ts +52 -0
- package/dist/src/providers/java_maven.js +263 -0
- package/dist/src/providers/javascript_npm.d.ts +4 -0
- package/dist/src/providers/javascript_npm.js +15 -0
- package/dist/src/providers/javascript_pnpm.d.ts +5 -0
- package/dist/src/providers/javascript_pnpm.js +22 -0
- package/dist/src/providers/javascript_yarn.d.ts +11 -0
- package/dist/src/providers/javascript_yarn.js +39 -0
- package/dist/src/providers/manifest.d.ts +11 -0
- package/dist/src/providers/manifest.js +48 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +41 -0
- package/dist/src/providers/processors/yarn_berry_processor.js +130 -0
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +37 -0
- package/dist/src/providers/processors/yarn_classic_processor.js +109 -0
- package/dist/src/providers/processors/yarn_processor.d.ts +9 -0
- package/dist/src/providers/processors/yarn_processor.js +20 -0
- package/dist/src/providers/python_controller.d.ts +31 -0
- package/dist/src/providers/python_controller.js +406 -0
- package/dist/src/providers/python_pip.d.ts +35 -0
- package/dist/src/providers/python_pip.js +227 -0
- package/dist/src/sbom.d.ts +59 -0
- package/dist/src/sbom.js +84 -0
- package/dist/src/tools.d.ts +74 -0
- package/dist/src/tools.js +159 -0
- package/package.json +110 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { PackageURL } from "packageurl-js";
|
|
2
|
+
import { Platform } from "./platform.js";
|
|
3
|
+
import { getImageDigests, getImagePlatform } from "./utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for parsing docker repository/image names:
|
|
6
|
+
*
|
|
7
|
+
* - If the first part before the slash contains a "." or a ":" it is considered to be a registry URL
|
|
8
|
+
* - A last part starting with a ":" is considered to be a tag
|
|
9
|
+
* - The rest is considered the repository name (which might be separated via slashes)
|
|
10
|
+
*
|
|
11
|
+
* Example of valid names:
|
|
12
|
+
*
|
|
13
|
+
* - consol/tomcat-8.0
|
|
14
|
+
* - consol/tomcat-8.0:8.0.9
|
|
15
|
+
* - docker.consol.de:5000/tomcat-8.0
|
|
16
|
+
* - docker.consol.de:5000/jolokia/tomcat-8.0:8.0.9
|
|
17
|
+
*/
|
|
18
|
+
export class Image {
|
|
19
|
+
static NAME_COMPONENT_REGEXP = '[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?';
|
|
20
|
+
static DOMAIN_COMPONENT_REGEXP = '(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])';
|
|
21
|
+
static NAME_COMP_REGEXP = new RegExp(this.NAME_COMPONENT_REGEXP);
|
|
22
|
+
static IMAGE_NAME_REGEXP = new RegExp(this.NAME_COMPONENT_REGEXP + '(?:(?:/' + this.NAME_COMPONENT_REGEXP + ')+)?');
|
|
23
|
+
static DOMAIN_REGEXP = new RegExp('^' + this.DOMAIN_COMPONENT_REGEXP + '(?:\\.' + this.DOMAIN_COMPONENT_REGEXP + ')*(?::[0-9]+)?$');
|
|
24
|
+
static TAG_REGEXP = new RegExp('^[\\w][\\w.-]{0,127}$');
|
|
25
|
+
static DIGEST_REGEXP = new RegExp('^sha256:[a-z0-9]{32,}$');
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param {string} fullName
|
|
29
|
+
* @param {string} [givenTag]
|
|
30
|
+
*/
|
|
31
|
+
constructor(fullName, givenTag) {
|
|
32
|
+
this.repository = '';
|
|
33
|
+
this.registry = '';
|
|
34
|
+
this.tag = '';
|
|
35
|
+
this.digest = '';
|
|
36
|
+
this.user = '';
|
|
37
|
+
if (fullName == null) {
|
|
38
|
+
throw new Error('Image name must not be null');
|
|
39
|
+
}
|
|
40
|
+
// Set digest to null as default
|
|
41
|
+
this.digest = null;
|
|
42
|
+
// Check if digest is part of fullName
|
|
43
|
+
if (fullName.includes('@sha256')) {
|
|
44
|
+
const digestParts = fullName.split('@');
|
|
45
|
+
this.digest = digestParts[1];
|
|
46
|
+
fullName = digestParts[0];
|
|
47
|
+
}
|
|
48
|
+
// Check for tag
|
|
49
|
+
const tagPattern = /^(.+?)(?::([^:/]+))?$/;
|
|
50
|
+
const matcher = fullName.match(tagPattern);
|
|
51
|
+
if (!matcher) {
|
|
52
|
+
throw new Error(fullName + ' is not a proper image name ([registry/][repo][:port]');
|
|
53
|
+
}
|
|
54
|
+
this.tag = givenTag != null ? givenTag : matcher[2];
|
|
55
|
+
const rest = matcher[1];
|
|
56
|
+
this.parseComponentsBeforeTag(rest);
|
|
57
|
+
if (this.tag == null && this.digest == null) {
|
|
58
|
+
this.tag = 'latest';
|
|
59
|
+
}
|
|
60
|
+
this.doValidate();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @param {string[]} parts
|
|
64
|
+
* @returns {string}
|
|
65
|
+
*/
|
|
66
|
+
joinTail(parts) {
|
|
67
|
+
let builder = '';
|
|
68
|
+
for (let i = 1; i < parts.length; i++) {
|
|
69
|
+
builder += parts[i];
|
|
70
|
+
if (i < parts.length - 1) {
|
|
71
|
+
builder += '/';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return builder;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @param {string} part
|
|
78
|
+
* @returns {boolean}
|
|
79
|
+
*/
|
|
80
|
+
isRegistry(part) {
|
|
81
|
+
return part.includes('.') || part.includes(':');
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* @param {string} [optionalRegistry]
|
|
85
|
+
* @returns {string}
|
|
86
|
+
*/
|
|
87
|
+
getNameWithoutTag(optionalRegistry) {
|
|
88
|
+
let ret = '';
|
|
89
|
+
if (this.registry != null || optionalRegistry != null) {
|
|
90
|
+
ret += (this.registry != null ? this.registry : optionalRegistry) + '/';
|
|
91
|
+
}
|
|
92
|
+
ret += this.repository;
|
|
93
|
+
return ret;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @param {string} [optionalRegistry]
|
|
97
|
+
* @returns {string}
|
|
98
|
+
*/
|
|
99
|
+
getFullName(optionalRegistry) {
|
|
100
|
+
let fullName = this.getNameWithoutTag(optionalRegistry);
|
|
101
|
+
if (this.tag != null) {
|
|
102
|
+
fullName = fullName + ':' + this.tag;
|
|
103
|
+
}
|
|
104
|
+
if (this.digest != null) {
|
|
105
|
+
fullName = fullName + '@' + this.digest;
|
|
106
|
+
}
|
|
107
|
+
return fullName;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @returns {string}
|
|
111
|
+
*/
|
|
112
|
+
getSimpleName() {
|
|
113
|
+
const prefix = this.user + '/';
|
|
114
|
+
return this.repository.startsWith(prefix) ? this.repository.substring(prefix.length) : this.repository;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @param {string} optionalRepository
|
|
118
|
+
* @returns {string}
|
|
119
|
+
*/
|
|
120
|
+
getNameWithOptionalRepository(optionalRepository) {
|
|
121
|
+
if (optionalRepository != null) {
|
|
122
|
+
const simpleName = this.getFullName();
|
|
123
|
+
const simpleNameParts = simpleName.split('/');
|
|
124
|
+
if (simpleNameParts.length > 0) {
|
|
125
|
+
return optionalRepository + '/' + simpleNameParts[simpleNameParts.length - 1];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return this.getFullName();
|
|
129
|
+
}
|
|
130
|
+
doValidate() {
|
|
131
|
+
const errors = [];
|
|
132
|
+
const image = this.user != null ? this.repository.substring(this.user.length + 1) : this.repository;
|
|
133
|
+
/** @type {[[string, RegExp, string]]} */
|
|
134
|
+
const checks = [
|
|
135
|
+
['registry', Image.DOMAIN_REGEXP, this.registry],
|
|
136
|
+
['image', Image.IMAGE_NAME_REGEXP, image],
|
|
137
|
+
['user', Image.NAME_COMP_REGEXP, this.user],
|
|
138
|
+
['tag', Image.TAG_REGEXP, this.tag],
|
|
139
|
+
['digest', Image.DIGEST_REGEXP, this.digest]
|
|
140
|
+
];
|
|
141
|
+
for (const [name, pattern, value] of checks) {
|
|
142
|
+
if (value != null && !pattern.test(value)) {
|
|
143
|
+
errors.push(`${name} part '${value}' doesn't match allowed pattern '${pattern.source}'`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (errors.length > 0) {
|
|
147
|
+
const message = `Given Docker name '${this.getFullName()}' is invalid:\n` +
|
|
148
|
+
errors.map(error => ` * ${error}`).join('\n') +
|
|
149
|
+
'\nSee http://bit.ly/docker_image_fmt for more details';
|
|
150
|
+
throw new Error(message);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @param {string} rest
|
|
155
|
+
*/
|
|
156
|
+
parseComponentsBeforeTag(rest) {
|
|
157
|
+
const parts = rest.split(/\s*\/\s*/);
|
|
158
|
+
if (parts.length === 1) {
|
|
159
|
+
this.registry = null;
|
|
160
|
+
this.user = null;
|
|
161
|
+
this.repository = parts[0];
|
|
162
|
+
}
|
|
163
|
+
else if (parts.length >= 2) {
|
|
164
|
+
if (this.isRegistry(parts[0])) {
|
|
165
|
+
this.registry = parts[0];
|
|
166
|
+
if (parts.length > 2) {
|
|
167
|
+
this.user = parts[1];
|
|
168
|
+
this.repository = this.joinTail(parts);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.user = null;
|
|
172
|
+
this.repository = parts[1];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this.registry = null;
|
|
177
|
+
this.user = parts[0];
|
|
178
|
+
this.repository = rest;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export class ImageRef {
|
|
184
|
+
static OCI_TYPE = "oci";
|
|
185
|
+
static REPOSITORY_QUALIFIER = "repository_url";
|
|
186
|
+
static TAG_QUALIFIER = "tag";
|
|
187
|
+
static ARCH_QUALIFIER = "arch";
|
|
188
|
+
static OS_QUALIFIER = "os";
|
|
189
|
+
static VARIANT_QUALIFIER = "variant";
|
|
190
|
+
/** @type {Image} */
|
|
191
|
+
image;
|
|
192
|
+
/** @type {Platform} */
|
|
193
|
+
platform;
|
|
194
|
+
/**
|
|
195
|
+
* @param {string} image
|
|
196
|
+
* @param {string} [platform]
|
|
197
|
+
* @param {import("index.js").Options} [opts={}]
|
|
198
|
+
*/
|
|
199
|
+
constructor(image, platform, opts) {
|
|
200
|
+
this.image = new Image(image);
|
|
201
|
+
if (platform != null) {
|
|
202
|
+
this.platform = Platform.fromString(platform);
|
|
203
|
+
}
|
|
204
|
+
this.checkImageDigest(opts);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* @private
|
|
208
|
+
*/
|
|
209
|
+
checkImageDigest(opts) {
|
|
210
|
+
if (this.image.digest == null) {
|
|
211
|
+
try {
|
|
212
|
+
const digests = getImageDigests(this, opts);
|
|
213
|
+
if (digests.size === 0) {
|
|
214
|
+
throw new Error("Failed to get any image digest");
|
|
215
|
+
}
|
|
216
|
+
if (digests.size === 1 && digests[Platform.EMPTY.toString()]) {
|
|
217
|
+
this.image.digest = digests[Platform.EMPTY.toString()];
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
if (this.platform == null) {
|
|
221
|
+
this.platform = getImagePlatform(opts);
|
|
222
|
+
}
|
|
223
|
+
if (this.platform == null) {
|
|
224
|
+
throw new Error(`Failed to get image platform for image digest`);
|
|
225
|
+
}
|
|
226
|
+
if (!digests[this.platform.toString()]) {
|
|
227
|
+
throw new Error(`Failed to get image digest for platform ${this.platform}`);
|
|
228
|
+
}
|
|
229
|
+
this.image.digest = digests[this.platform.toString()];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
catch (ex) {
|
|
233
|
+
throw new Error("Failed to get image digest", { cause: ex });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* @returns {PackageURL}
|
|
239
|
+
* @throws {Error}
|
|
240
|
+
* @see https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#oci
|
|
241
|
+
*/
|
|
242
|
+
getPackageURL() {
|
|
243
|
+
/** @type {Object.<string, string>} */
|
|
244
|
+
const qualifiers = {};
|
|
245
|
+
const repositoryUrl = this.image.getNameWithoutTag();
|
|
246
|
+
const simpleName = this.image.getSimpleName();
|
|
247
|
+
if (repositoryUrl != null && repositoryUrl.toLowerCase() !== simpleName.toLowerCase()) {
|
|
248
|
+
qualifiers[ImageRef.REPOSITORY_QUALIFIER] = repositoryUrl.toLowerCase();
|
|
249
|
+
}
|
|
250
|
+
if (this.platform != null) {
|
|
251
|
+
qualifiers[ImageRef.ARCH_QUALIFIER] = this.platform.architecture.toLowerCase();
|
|
252
|
+
qualifiers[ImageRef.OS_QUALIFIER] = this.platform.os.toLowerCase();
|
|
253
|
+
if (this.platform.variant != null) {
|
|
254
|
+
qualifiers[ImageRef.VARIANT_QUALIFIER] = this.platform.variant.toLowerCase();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const tag = this.image.tag;
|
|
258
|
+
if (tag != null) {
|
|
259
|
+
qualifiers[ImageRef.TAG_QUALIFIER] = tag;
|
|
260
|
+
}
|
|
261
|
+
return new PackageURL(ImageRef.OCI_TYPE, null, this.image.getSimpleName().toLowerCase(), this.image.digest.toLowerCase(), qualifiers, null);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class representing a Platform with OS, architecture, and variant information
|
|
3
|
+
*/
|
|
4
|
+
export class Platform {
|
|
5
|
+
static EMPTY: Platform;
|
|
6
|
+
static SUPPORTED_PLATFORMS: Platform[];
|
|
7
|
+
/**
|
|
8
|
+
* Get the variant for the given OS and architecture
|
|
9
|
+
* @param {string} os - Operating system
|
|
10
|
+
* @param {string} arch - Architecture
|
|
11
|
+
* @returns {string|null} - Variant or null
|
|
12
|
+
*/
|
|
13
|
+
static getVariant(os: string, arch: string): string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a variant is required for the given OS and architecture
|
|
16
|
+
* @param {string} os - Operating system
|
|
17
|
+
* @param {string} arch - Architecture
|
|
18
|
+
* @returns {boolean} - True if variant is required
|
|
19
|
+
*/
|
|
20
|
+
static isVariantRequired(os: string, arch: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Create a platform from a string
|
|
23
|
+
* @param {string} platform - Platform string in format "os/arch" or "os/arch/variant"
|
|
24
|
+
* @returns {Platform} - Platform instance
|
|
25
|
+
* @throws {Error} - If platform string is invalid or not supported
|
|
26
|
+
*/
|
|
27
|
+
static fromString(platform: string): Platform;
|
|
28
|
+
/**
|
|
29
|
+
* Create a platform from individual components
|
|
30
|
+
* @param {string|null} os - Operating system
|
|
31
|
+
* @param {string} arch - Architecture
|
|
32
|
+
* @param {string|null} variant - Architecture variant
|
|
33
|
+
* @returns {Platform} - Platform instance
|
|
34
|
+
* @throws {Error} - If platform is invalid or not supported
|
|
35
|
+
*/
|
|
36
|
+
static fromComponents(os: string | null, arch: string, variant: string | null): Platform;
|
|
37
|
+
/**
|
|
38
|
+
* Check if a platform is supported
|
|
39
|
+
* @param {Platform} platform - Platform to check
|
|
40
|
+
* @returns {boolean} - True if platform is supported
|
|
41
|
+
*/
|
|
42
|
+
static isSupported(platform: Platform): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Create a Platform instance
|
|
45
|
+
* @param {string|null} os - Operating system
|
|
46
|
+
* @param {string|null} architecture - Architecture
|
|
47
|
+
* @param {string|null} [variant] - Architecture variant
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
private constructor();
|
|
51
|
+
os: string | null;
|
|
52
|
+
architecture: string | null;
|
|
53
|
+
variant: string | null | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Convert a platform to a string
|
|
56
|
+
* @returns {string} - String representation of platform
|
|
57
|
+
*/
|
|
58
|
+
toString(): string;
|
|
59
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class representing a Platform with OS, architecture, and variant information
|
|
3
|
+
*/
|
|
4
|
+
export class Platform {
|
|
5
|
+
static EMPTY = new Platform(null, null, null);
|
|
6
|
+
// $GOOS and $GOARCH
|
|
7
|
+
// https://github.com/docker-library/bashbrew/blob/v0.1.2/architecture/oci-platform.go#L14-L27
|
|
8
|
+
static SUPPORTED_PLATFORMS = [
|
|
9
|
+
new Platform('linux', 'amd64', null),
|
|
10
|
+
new Platform('linux', 'arm', 'v5'),
|
|
11
|
+
new Platform('linux', 'arm', 'v6'),
|
|
12
|
+
new Platform('linux', 'arm', 'v7'),
|
|
13
|
+
new Platform('linux', 'arm64', 'v8'),
|
|
14
|
+
new Platform('linux', '386', null),
|
|
15
|
+
new Platform('linux', 'mips64le', null),
|
|
16
|
+
new Platform('linux', 'ppc64le', null),
|
|
17
|
+
new Platform('linux', 'riscv64', null),
|
|
18
|
+
new Platform('linux', 's390x', null),
|
|
19
|
+
new Platform('windows', 'arm64', null)
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Create a Platform instance
|
|
23
|
+
* @param {string|null} os - Operating system
|
|
24
|
+
* @param {string|null} architecture - Architecture
|
|
25
|
+
* @param {string|null} [variant] - Architecture variant
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
constructor(os, architecture, variant) {
|
|
29
|
+
this.os = os;
|
|
30
|
+
this.architecture = architecture;
|
|
31
|
+
this.variant = variant;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get the variant for the given OS and architecture
|
|
35
|
+
* @param {string} os - Operating system
|
|
36
|
+
* @param {string} arch - Architecture
|
|
37
|
+
* @returns {string|null} - Variant or null
|
|
38
|
+
*/
|
|
39
|
+
static getVariant(os, arch) {
|
|
40
|
+
if (os === 'linux' && arch === 'arm64') { // in case variant "v8" is not specified
|
|
41
|
+
return 'v8';
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a variant is required for the given OS and architecture
|
|
47
|
+
* @param {string} os - Operating system
|
|
48
|
+
* @param {string} arch - Architecture
|
|
49
|
+
* @returns {boolean} - True if variant is required
|
|
50
|
+
*/
|
|
51
|
+
static isVariantRequired(os, arch) {
|
|
52
|
+
return os === 'linux' && arch === 'arm';
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a platform from a string
|
|
56
|
+
* @param {string} platform - Platform string in format "os/arch" or "os/arch/variant"
|
|
57
|
+
* @returns {Platform} - Platform instance
|
|
58
|
+
* @throws {Error} - If platform string is invalid or not supported
|
|
59
|
+
*/
|
|
60
|
+
static fromString(platform) {
|
|
61
|
+
if (platform == null) {
|
|
62
|
+
throw new Error(`Invalid platform: ${platform}`);
|
|
63
|
+
}
|
|
64
|
+
const parts = platform.split('/');
|
|
65
|
+
let os, arch, variant;
|
|
66
|
+
if (parts.length === 1) {
|
|
67
|
+
os = 'linux';
|
|
68
|
+
arch = parts[0];
|
|
69
|
+
}
|
|
70
|
+
else if (parts.length === 2) {
|
|
71
|
+
os = parts[0];
|
|
72
|
+
arch = parts[1];
|
|
73
|
+
variant = Platform.getVariant(os, arch);
|
|
74
|
+
}
|
|
75
|
+
else if (parts.length === 3) {
|
|
76
|
+
os = parts[0];
|
|
77
|
+
arch = parts[1];
|
|
78
|
+
variant = parts[2];
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw new Error(`Invalid platform: ${platform}`);
|
|
82
|
+
}
|
|
83
|
+
const platformObj = new Platform(os, arch, variant);
|
|
84
|
+
if (!Platform.isSupported(platformObj)) {
|
|
85
|
+
throw new Error(`Image platform is not supported: ${platformObj.toString()}`);
|
|
86
|
+
}
|
|
87
|
+
return platformObj;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create a platform from individual components
|
|
91
|
+
* @param {string|null} os - Operating system
|
|
92
|
+
* @param {string} arch - Architecture
|
|
93
|
+
* @param {string|null} variant - Architecture variant
|
|
94
|
+
* @returns {Platform} - Platform instance
|
|
95
|
+
* @throws {Error} - If platform is invalid or not supported
|
|
96
|
+
*/
|
|
97
|
+
static fromComponents(os, arch, variant) {
|
|
98
|
+
if (arch == null) {
|
|
99
|
+
throw new Error(`Invalid platform arch: ${arch}`);
|
|
100
|
+
}
|
|
101
|
+
// Default to linux if OS is not specified
|
|
102
|
+
if (os == null) {
|
|
103
|
+
os = 'linux';
|
|
104
|
+
}
|
|
105
|
+
// Get default variant if not specified
|
|
106
|
+
if (variant == null) {
|
|
107
|
+
variant = Platform.getVariant(os, arch);
|
|
108
|
+
}
|
|
109
|
+
const platformObj = new Platform(os, arch, variant);
|
|
110
|
+
if (!Platform.isSupported(platformObj)) {
|
|
111
|
+
throw new Error(`Image platform is not supported: ${os}/${arch}/${variant}`);
|
|
112
|
+
}
|
|
113
|
+
return platformObj;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Check if a platform is supported
|
|
117
|
+
* @param {Platform} platform - Platform to check
|
|
118
|
+
* @returns {boolean} - True if platform is supported
|
|
119
|
+
*/
|
|
120
|
+
static isSupported(platform) {
|
|
121
|
+
return Platform.SUPPORTED_PLATFORMS.some(p => p.os === platform.os &&
|
|
122
|
+
p.architecture === platform.architecture &&
|
|
123
|
+
// eslint-disable-next-line eqeqeq
|
|
124
|
+
p.variant == platform.variant);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Convert a platform to a string
|
|
128
|
+
* @returns {string} - String representation of platform
|
|
129
|
+
*/
|
|
130
|
+
toString() {
|
|
131
|
+
if (this.variant == null) {
|
|
132
|
+
return `${this.os}/${this.architecture}`;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return `${this.os}/${this.architecture}/${this.variant}`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {import('./images').ImageRef} imageRef
|
|
4
|
+
* @param {import("../index.js").Options} [opts={}] - optional various options to pass along the application
|
|
5
|
+
* @returns {{}}
|
|
6
|
+
*/
|
|
7
|
+
export function generateImageSBOM(imageRef: import('./images').ImageRef, opts?: import("../index.js").Options | undefined): {};
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {string} image
|
|
11
|
+
* @param {import("../index.js").Options} [opts={}] - optional various options to pass along the application
|
|
12
|
+
* @returns {ImageRef}
|
|
13
|
+
*/
|
|
14
|
+
export function parseImageRef(image: string, opts?: import("../index.js").Options | undefined): ImageRef;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the platform information for an image
|
|
17
|
+
* @param {import("../index.js").Options} [opts={}] - optional various options to pass along the application
|
|
18
|
+
* @returns {Platform|null} - The platform information or null
|
|
19
|
+
*/
|
|
20
|
+
export function getImagePlatform(opts?: import("../index.js").Options | undefined): Platform | null;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the digests for an image
|
|
23
|
+
* @param {import('./images').ImageRef} imageRef - The image reference
|
|
24
|
+
* @param {import("../index.js").Options} [opts={}] - optional various options to pass along the application
|
|
25
|
+
* @returns {Object.<string, string>} - The image digests
|
|
26
|
+
* @throws {Error} If the image info is invalid
|
|
27
|
+
*/
|
|
28
|
+
export function getImageDigests(imageRef: import('./images').ImageRef, opts?: import("../index.js").Options | undefined): {
|
|
29
|
+
[x: string]: string;
|
|
30
|
+
};
|
|
31
|
+
export type SyftImageSource = {
|
|
32
|
+
getOs: () => string;
|
|
33
|
+
getArch: () => string;
|
|
34
|
+
getVariant: () => string;
|
|
35
|
+
};
|
|
36
|
+
export type SyftImageSourceType = {
|
|
37
|
+
getOs: (arg0: any) => string;
|
|
38
|
+
getArch: (arg0: any) => string;
|
|
39
|
+
getVariant: (arg0: any) => string;
|
|
40
|
+
};
|
|
41
|
+
import { ImageRef } from './images.js';
|
|
42
|
+
import { Platform } from './platform.js';
|