Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 22 additions & 37 deletions src/main/java/io/github/guacsec/trustifyda/image/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,47 +467,32 @@ static Operations.ProcessExecOutput execSkopeoInspect(ImageRef imageRef, boolean
var configPath = Environment.get(TRUSTIFY_DA_SKOPEO_CONFIG_PATH, "");
var daemonHost = Environment.get(TRUSTIFY_DA_IMAGE_SERVICE_ENDPOINT, "");

String[] cmd;
var cmdList = new java.util.ArrayList<String>();
cmdList.add(skopeo);
cmdList.add("inspect");

if (!configPath.isEmpty()) {
cmdList.add("--authfile");
cmdList.add(configPath);
}

if (!daemonHost.isEmpty()) {
cmdList.add("--daemon-host");
cmdList.add(daemonHost);
}

if (raw) {
cmdList.add("--raw");
}

if (daemonHost.isEmpty()) {
cmd =
configPath.isEmpty()
? new String[] {
skopeo,
"inspect",
raw ? "--raw" : "",
String.format("docker://%s", imageRef.getImage().getFullName())
}
: new String[] {
skopeo,
"inspect",
"--authfile",
configPath,
raw ? "--raw" : "",
String.format("docker://%s", imageRef.getImage().getFullName())
};
cmdList.add(String.format("docker://%s", imageRef.getImage().getFullName()));
} else {
cmd =
configPath.isEmpty()
? new String[] {
skopeo,
"inspect",
"--daemon-host",
daemonHost,
raw ? "--raw" : "",
String.format("docker-daemon:%s", imageRef.getImage().getFullName())
}
: new String[] {
skopeo,
"inspect",
"--authfile",
configPath,
"--daemon-host",
daemonHost,
raw ? "--raw" : "",
String.format("docker-daemon:%s", imageRef.getImage().getFullName())
};
cmdList.add(String.format("docker-daemon:%s", imageRef.getImage().getFullName()));
}

String[] cmd = cmdList.toArray(new String[0]);

return Operations.runProcessGetFullOutput(null, cmd, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ void test_get_image_digests_single() throws IOException {
new String[] {
"skopeo",
"inspect",
"",
String.format("docker://%s", mockImageRef.getImage().getFullName())
}),
isNull()))
Expand Down Expand Up @@ -866,7 +865,6 @@ void test_exec_skopeo_inspect() {
mockSkopeoConfig,
"--daemon-host",
mockSkopeoDaemon,
"",
String.format("docker-daemon:%s", mockImageRef.getImage().getFullName())
}),
isNull()))
Expand Down Expand Up @@ -898,7 +896,6 @@ void test_exec_skopeo_inspect_no_config() {
"inspect",
"--daemon-host",
mockSkopeoDaemon,
"",
String.format("docker-daemon:%s", mockImageRef.getImage().getFullName())
}),
isNull()))
Expand Down Expand Up @@ -930,7 +927,6 @@ void test_exec_skopeo_inspect_no_daemon() {
"inspect",
"--authfile",
mockSkopeoConfig,
"",
String.format("docker://%s", mockImageRef.getImage().getFullName())
}),
isNull()))
Expand Down Expand Up @@ -960,7 +956,6 @@ void test_exec_skopeo_inspect_no_config_no_daemon() {
new String[] {
"skopeo",
"inspect",
"",
String.format("docker://%s", mockImageRef.getImage().getFullName())
}),
isNull()))
Expand Down Expand Up @@ -1062,7 +1057,6 @@ void test_get_single_image_digest() throws IOException {
new String[] {
"skopeo",
"inspect",
"",
String.format("docker://%s", mockImageRef.getImage().getFullName())
}),
isNull()))
Expand Down Expand Up @@ -1097,7 +1091,6 @@ void test_get_single_image_digest_empty() throws JsonProcessingException {
new String[] {
"skopeo",
"inspect",
"",
String.format("docker://%s", mockImageRef.getImage().getFullName())
}),
isNull()))
Expand Down
Loading