a bunch of logic changes to allow tests to run standalone

This commit is contained in:
Oliver Gorwits
2021-08-12 10:58:55 +01:00
parent f1224b087c
commit d206b9ccbf
5 changed files with 23 additions and 17 deletions

View File

@@ -709,8 +709,8 @@ sub delete {
{ ip => { '-in' => $devices->as_query } },
)->delete;
Dancer::Logger::debug sprintf ' [%s] db/device - removed %d %s from %s',
$ip, $gone, _plural($gone), $set if defined Dancer::Logger::logger();
Dancer::Logger::debug( sprintf( ' [%s] db/device - removed %d %s from %s',
$ip, $gone, _plural($gone), $set ) ) if defined Dancer::Logger::logger();
}
foreach my $set (qw/
@@ -729,8 +729,8 @@ sub delete {
],
})->delete;
Dancer::Logger::debug sprintf ' [%s] db/device - removed %d manual topology %s',
$ip, $gone, _plural($gone) if defined Dancer::Logger::logger();
Dancer::Logger::debug( sprintf( ' [%s] db/device - removed %d manual topology %s',
$ip, $gone, _plural($gone) ) ) if defined Dancer::Logger::logger();
$schema->resultset('DevicePort')->search(
{ ip => { '-in' => $devices->as_query } },

View File

@@ -262,8 +262,8 @@ sub delete {
{ ip => { '-in' => $ports->as_query }},
)->delete;
Dancer::Logger::debug sprintf ' [%s] db/ports - removed %d port %s from %s',
$ip, $gone, _plural($gone), $set if defined Dancer::Logger::logger();
Dancer::Logger::debug( sprintf( ' [%s] db/ports - removed %d port %s from %s',
$ip, $gone, _plural($gone), $set ) ) if defined Dancer::Logger::logger();
}
$schema->resultset('Node')->search(

View File

@@ -2,9 +2,14 @@ package App::Netdisco::JobQueue;
use Dancer qw/:moose :syntax :script/;
BEGIN {
$ENV{ND_QUEUE_ENGINE} ||=
setting('workers') ? setting('workers')->{queue} : 'PostgreSQL';
}
use Module::Load ();
Module::Load::load
'App::Netdisco::JobQueue::' . setting('workers')->{queue} => ':all';
'App::Netdisco::JobQueue::' . $ENV{ND_QUEUE_ENGINE} => ':all';
use base 'Exporter';
our @EXPORT = ();

View File

@@ -9,7 +9,7 @@ use Try::Tiny;
swagger_path {
tags => ['Objects'],
path => setting('api_base').'/object/device/{ip}',
path => (setting('api_base') || '').'/object/device/{ip}',
description => 'Returns a row from the device table',
parameters => [
ip => {
@@ -28,7 +28,7 @@ swagger_path {
foreach my $rel (qw/device_ips vlans ports modules port_vlans wireless_ports ssids powered_ports/) {
swagger_path {
tags => ['Objects'],
path => setting('api_base')."/object/device/{ip}/$rel",
path => (setting('api_base') || '')."/object/device/{ip}/$rel",
description => "Returns $rel rows for a given device",
parameters => [
ip => {
@@ -49,7 +49,7 @@ foreach my $rel (qw/nodes active_nodes nodes_with_age active_nodes_with_age vlan
swagger_path {
tags => ['Objects'],
description => "Returns $rel rows for a given port",
path => setting('api_base')."/object/device/{ip}/port/{port}/$rel",
path => (setting('api_base') || '')."/object/device/{ip}/port/{port}/$rel",
parameters => [
ip => {
description => 'Canonical IP of the Device. Use Search methods to find this.',
@@ -76,7 +76,7 @@ foreach my $rel (qw/power properties ssid wireless agg_master neighbor last_node
swagger_path {
tags => ['Objects'],
description => "Returns the related $rel table entry for a given port",
path => setting('api_base')."/object/device/{ip}/port/{port}/$rel",
path => (setting('api_base') || '')."/object/device/{ip}/port/{port}/$rel",
parameters => [
ip => {
description => 'Canonical IP of the Device. Use Search methods to find this.',
@@ -103,7 +103,7 @@ foreach my $rel (qw/power properties ssid wireless agg_master neighbor last_node
swagger_path {
tags => ['Objects'],
description => 'Returns a row from the device_port table',
path => setting('api_base').'/object/device/{ip}/port/{port}',
path => (setting('api_base') || '').'/object/device/{ip}/port/{port}',
parameters => [
ip => {
description => 'Canonical IP of the Device. Use Search methods to find this.',
@@ -127,7 +127,7 @@ swagger_path {
swagger_path {
tags => ['Objects'],
path => setting('api_base').'/object/device/{ip}/nodes',
path => (setting('api_base') || '').'/object/device/{ip}/nodes',
description => "Returns the nodes found on a given Device",
parameters => [
ip => {
@@ -153,7 +153,7 @@ swagger_path {
swagger_path {
tags => ['Objects'],
path => setting('api_base').'/object/vlan/{vlan}/nodes',
path => (setting('api_base') || '').'/object/vlan/{vlan}/nodes',
description => "Returns the nodes found in a given VLAN",
parameters => [
vlan => {

View File

@@ -5,6 +5,7 @@ use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;
use Dancer::Plugin::Swagger;
use App::Netdisco; # a safe noop but needed for standalone testing
use App::Netdisco::Util::Web 'request_is_api';
use MIME::Base64;
@@ -85,7 +86,7 @@ hook 'before' => sub {
swagger_path {
description => 'Obtain an API Key',
tags => ['General'],
path => setting('url_base')->with('/login')->path,
path => (setting('url_base') ? setting('url_base')->with('/login')->path : '/login'),
parameters => [],
responses => { default => { examples => {
'application/json' => { api_key => 'cc9d5c02d8898e5728b7d7a0339c0785' } } },
@@ -159,14 +160,14 @@ post '/login' => sub {
# ugh, *puke*, but D::P::Swagger has no way to set this with swagger_path
# must be after the path is declared, above.
Dancer::Plugin::Swagger->instance->doc
->{paths}->{ setting('url_base')->with('/login')->path }
->{paths}->{ (setting('url_base') ? setting('url_base')->with('/login')->path : '/login') }
->{post}->{security}->[0]->{BasicAuth} = [];
# we override the default login_handler, so logout has to be handled as well
swagger_path {
description => 'Destroy user API Key and session cookie',
tags => ['General'],
path => setting('url_base')->with('/logout')->path,
path => (setting('url_base') ? setting('url_base')->with('/logout')->path : '/logout'),
parameters => [],
responses => { default => { examples => { 'application/json' => {} } } },
},