Add test for the FreeNAS API
- Add a simple API test using the FreeNAS API call to get its version number, which could prove useful in future versions. Closes #17 - Whitespace cleanup
This commit is contained in:
parent
42edb8614e
commit
3f6059e75f
|
|
@ -230,6 +230,7 @@ sub freenas_api_call {
|
||||||
my ($scfg, $method, $path, $data) = @_;
|
my ($scfg, $method, $path, $data) = @_;
|
||||||
my $client = undef;
|
my $client = undef;
|
||||||
my $scheme = $scfg->{freenas_use_ssl} ? "https" : "http";
|
my $scheme = $scfg->{freenas_use_ssl} ? "https" : "http";
|
||||||
|
my $apiping = '/api/v1.0/system/version/';
|
||||||
|
|
||||||
$client = REST::Client->new();
|
$client = REST::Client->new();
|
||||||
$client->setHost($scheme . '://' . $scfg->{portal});
|
$client->setHost($scheme . '://' . $scfg->{portal});
|
||||||
|
|
@ -240,6 +241,12 @@ sub freenas_api_call {
|
||||||
$client->getUseragent()->ssl_opts(verify_hostname => 0);
|
$client->getUseragent()->ssl_opts(verify_hostname => 0);
|
||||||
$client->getUseragent()->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE);
|
$client->getUseragent()->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE);
|
||||||
}
|
}
|
||||||
|
# Check if the API is working via the selected scheme
|
||||||
|
my $code = $client->request('GET', $apiping)->responseCode();
|
||||||
|
if ($code != 200) {
|
||||||
|
freenas_api_log_error($client, "freenas_api_call");
|
||||||
|
die "Unable to connect to the FreeNAS API service at '" . $scfg->{portal} . "' using '" . $scheme . "' protocol";
|
||||||
|
}
|
||||||
if ($method eq 'GET') {
|
if ($method eq 'GET') {
|
||||||
$client->GET($path);
|
$client->GET($path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue