Adjust "Docker Hub" URL references to use a shared variable

(This makes testing against Hub's staging environment more straightforward.)
This commit is contained in:
Tianon Gravi 2023-05-12 10:29:29 -07:00
parent 6614bce4c1
commit 0ad17f594a
1 changed files with 6 additions and 4 deletions

10
push.pl
View File

@ -43,8 +43,10 @@ unless (defined $password) {
$password = $term->get_reply(prompt => 'Hub Password'); # TODO hide the input? O:)
}
my $login = $ua->post('https://hub.docker.com/v2/users/login/' => {} => json => { username => $username, password => $password });
die 'login failed' unless $login->res->is_success;
my $dockerHub = 'https://hub.docker.com';
my $login = $ua->post($dockerHub . '/v2/users/login/' => {} => json => { username => $username, password => $password });
die 'login failed: ' . $login->res->error->{message} unless $login->res->is_success;
my $token = $login->res->json->{token};
@ -57,7 +59,7 @@ for my $cookie (@{ $login->res->cookies }) {
}
die 'missing CSRF token' unless defined $csrf;
my $attemptLogin = $ua->post('https://hub.docker.com/attempt-login/' => {} => json => { jwt => $token });
my $attemptLogin = $ua->post($dockerHub . '/attempt-login/' => {} => json => { jwt => $token });
die 'attempt-login failed' unless $attemptLogin->res->is_success;
my $authorizationHeader = {
@ -171,7 +173,7 @@ while (my $repo = shift) { # 'library/hylang', 'tianon/perl', etc
my $repoName = $repo;
$repoName =~ s!^.*/!!; # 'hylang', 'perl', etc
my $repoUrl = 'https://hub.docker.com/v2/repositories/' . $repo . '/';
my $repoUrl = $dockerHub . '/v2/repositories/' . $repo . '/';
if ($logos && $repo =~ m{ ^ library/ }x) {
# the "library" org images include a logo which is displayed in the Hub UI