Skip to content

Commit

Permalink
move the pull token determination logic before running 'skopeo inspec…
Browse files Browse the repository at this point in the history
…t' so it can be used there as well
  • Loading branch information
k-rister committed Dec 6, 2024
1 parent bc2f660 commit 57b7690
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions workshop.pl
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,52 @@ sub delete_proto {
push(@checksums, $config_json->{'sha256'});
}

my $tls_verify = $args{'reg-tls-verify'};
my $authfile_arg = "";
if ($userenv_json->{'userenv'}{'origin'}{'requires-pull-token'} eq "true") {
logger('info', "Checking registries JSON for a pull token...\n");

my $found_pull_token = 0;

if (exists($registries_json->{'engines'}{'private'})) {
if ($registries_json->{'engines'}{'private'}{'url'} eq $userenv_json->{'userenv'}{'origin'}{'image'}) {
$found_pull_token = 1;
logger('info', "found " . $registries_json->{'engines'}{'private'}{'tokens'}{'pull'} . " for " . $registries_json->{'engines'}{'private'}{'url'} . " private engines repository\n", 1);

$authfile_arg = "--authfile=" . $registries_json->{'engines'}{'private'}{'tokens'}{'pull'};

if (exists($registries_json->{'engines'}{'private'}{'tls-verify'})) {
$tls_verify = $registries_json->{'engines'}{'private'}{'tls-verify'};
}
} else {
logger('debug', "does not match " . $registries_json->{'engines'}{'private'}{'url'} . "\n", 1);
}
}

if (($found_pull_token == 0) && exists($registries_json->{'userenvs'})) {
foreach my $userenv (@{$registries_json->{'userenvs'}}) {
if ($userenv->{'url'} eq $userenv_json->{'userenv'}{'origin'}{'image'}) {
$found_pull_token = 1;
logger('info', "found " . $userenv->{'pull-token'} . " for " . $userenv->{'url'} . "\n", 1);

$authfile_arg = "--authfile=" . $userenv->{'pull-token'};

if (exists($userenv->{'tls-verify'})) {
$tls_verify = $userenv->{'tls-verify'};
}
} else {
logger('debug', "does not match " . $userenv->{'url'} . "\n", 1);
}
}
}

if ($found_pull_token == 0) {
logger('info', "not found\n", 1);
logger('error', "Failed to locate a pull token for a userenv that requires one!\n");
exit(get_exit_code('pull_token_not_found'));
}
}

if ($args{'dump-config'} eq 'true') {
my %config_dump = ();

Expand Down Expand Up @@ -990,7 +1036,7 @@ sub delete_proto {
$skopeo_url = "docker://" . $image_id;
}
logger('info', "Querying for origin image digest...\n", 1);
($command, $command_output, $rc) = run_command("skopeo inspect --no-tags " . $skopeo_url);
($command, $command_output, $rc) = run_command("skopeo inspect --no-tags " . $authfile_arg . " " . $skopeo_url);
if ($rc == 0) {
logger('info', "succeeded\n", 2);
command_logger('verbose', $command, $rc, $command_output);
Expand Down Expand Up @@ -1047,52 +1093,6 @@ sub delete_proto {
my $container_mount_point;
my $origin_image_id;

my $tls_verify = $args{'reg-tls-verify'};
my $authfile_arg = "";
if ($userenv_json->{'userenv'}{'origin'}{'requires-pull-token'} eq "true") {
logger('info', "Checking registries JSON for a pull token...\n");

my $found_pull_token = 0;

if (exists($registries_json->{'engines'}{'private'})) {
if ($registries_json->{'engines'}{'private'}{'url'} eq $userenv_json->{'userenv'}{'origin'}{'image'}) {
$found_pull_token = 1;
logger('info', "found " . $registries_json->{'engines'}{'private'}{'tokens'}{'pull'} . " for " . $registries_json->{'engines'}{'private'}{'url'} . " private engines repository\n", 1);

$authfile_arg = "--authfile=" . $registries_json->{'engines'}{'private'}{'tokens'}{'pull'};

if (exists($registries_json->{'engines'}{'private'}{'tls-verify'})) {
$tls_verify = $registries_json->{'engines'}{'private'}{'tls-verify'};
}
} else {
logger('debug', "does not match " . $registries_json->{'engines'}{'private'}{'url'} . "\n", 1);
}
}

if (($found_pull_token == 0) && exists($registries_json->{'userenvs'})) {
foreach my $userenv (@{$registries_json->{'userenvs'}}) {
if ($userenv->{'url'} eq $userenv_json->{'userenv'}{'origin'}{'image'}) {
$found_pull_token = 1;
logger('info', "found " . $userenv->{'pull-token'} . " for " . $userenv->{'url'} . "\n", 1);

$authfile_arg = "--authfile=" . $userenv->{'pull-token'};

if (exists($userenv->{'tls-verify'})) {
$tls_verify = $userenv->{'tls-verify'};
}
} else {
logger('debug', "does not match " . $userenv->{'url'} . "\n", 1);
}
}
}

if ($found_pull_token == 0) {
logger('info', "not found\n", 1);
logger('error', "Failed to locate a pull token for a userenv that requires one!\n");
exit(get_exit_code('pull_token_not_found'));
}
}

# acquire the userenv from the origin
logger('info', "Attempting to download the latest version of $userenv_json->{'userenv'}{'origin'}{'image'}:$userenv_json->{'userenv'}{'origin'}{'tag'}...\n");
($command, $command_output, $rc) = run_command("buildah pull --quiet --policy=ifnewer --tls-verify=$tls_verify $authfile_arg $userenv_json->{'userenv'}{'origin'}{'image'}:$userenv_json->{'userenv'}{'origin'}{'tag'}");
Expand Down

0 comments on commit 57b7690

Please sign in to comment.