Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move the pull token determination logic before running 'skopeo inspec… #89

Merged
merged 1 commit into from
Dec 7, 2024
Merged
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
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
Loading