forked from os-autoinst/openQA
OpenQA::Client
Ettore Di Giacinto edited this page May 23, 2017
·
3 revisions
OpenQA::Client - special version of Mojo::UserAgent that handles authentication
use OpenQA::Client;
# create new UserAgent that is meant to talk to localhost. Reads key
# and secret from config section [localhost]
my $ua = OpenQA::Client->new(api => 'localhost');
# specify key and secret manually
my $ua = OpenQA::Client->new(apikey => 'foo', apisecret => 'bar');
OpenQA::Client inherits from Mojo::UserAgent. It automatically sets the correct authentication headers if API key and secret are available.
API key and secret can either be set manually in the constructor, via attributes or read from a config file. OpenQA::Client tries to find a config file in $OPENQA_CONFIG, ~/.config/openqa/client.conf or /etc/openqa/client.conf and reads whatever comes first.
See Mojo::UserAgent for more.
OpenQA::Client implmements the following attributes.
my $apikey = $ua->apikey;
$ua = $ua->apikey('foo');
The API public key
my $apisecret = $ua->apisecret;
$ua = $ua->apisecret('bar');
The API secret key
my $ua = OpenQA::Client->new(api => 'localhost');
my $ua = OpenQA::Client->new(apikey => 'foo', apisecret => 'bar');
Generate the OpenQA::Client object.
The config file is in ini format. The sections are the host name of the api.
[openqa.example.com]
key = foo
secret = bar