Commit 5a885216 authored by Dietmar Maurer's avatar Dietmar Maurer

API2Client: split out login code

parent e24a91c1
......@@ -41,31 +41,20 @@ sub update_ticket {
$self->{cookie_jar}->set_cookie(0, 'PVEAuthCookie', $ticket, '/', $domain);
}
sub call {
my ($self, $method, $path, $param) = @_;
#print "wrapper called\n";
my $ticket;
my $ua = $self->{useragent};
my $cj = $self->{cookie_jar};
sub login {
my ($self) = @_;
$cj->scan(sub {
my ($version, $key, $val) = @_;
$ticket = $val if $key eq 'PVEAuthCookie';
});
if (!$ticket && $self->{username} && $self->{password}) {
my $uri = URI->new();
$uri->scheme($self->{protocol});
$uri->host($self->{host});
$uri->port($self->{port});
$uri->path('/api2/json/access/ticket');
my $ua = $self->{useragent};
my $response = $ua->post($uri, {
username => $self->{username},
password => $self->{password}});
username => $self->{username} || 'unknown',
password => $self->{password} || ''});
if (!$response->is_success) {
die $response->status_line . "\n";
......@@ -75,6 +64,27 @@ sub call {
$self->update_ticket($data->{data}->{ticket});
$self->{csrftoken} = $data->{data}->{CSRFPreventionToken};
return $data;
}
sub call {
my ($self, $method, $path, $param) = @_;
#print "wrapper called\n";
my $ticket;
my $ua = $self->{useragent};
my $cj = $self->{cookie_jar};
$cj->scan(sub {
my ($version, $key, $val) = @_;
$ticket = $val if $key eq 'PVEAuthCookie';
});
if (!$ticket && $self->{username} && $self->{password}) {
$self->login();
}
my $uri = URI->new();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment