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

@@ -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' => {} } } },
},