allow swagger_path installed routes to be relocated
This commit is contained in:
1
Build.PL
1
Build.PL
@@ -89,6 +89,7 @@ Module::Build->new(
|
|||||||
'Term::UI' => '0',
|
'Term::UI' => '0',
|
||||||
'Try::Tiny' => '0',
|
'Try::Tiny' => '0',
|
||||||
'URI' => '0',
|
'URI' => '0',
|
||||||
|
'URI::Based' => '0',
|
||||||
'URL::Encode' => '0.03',
|
'URL::Encode' => '0.03',
|
||||||
'URL::Encode::XS' => '0',
|
'URL::Encode::XS' => '0',
|
||||||
'YAML' => '0.84',
|
'YAML' => '0.84',
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use Dancer ':script';
|
|||||||
use Path::Class 'dir';
|
use Path::Class 'dir';
|
||||||
use Net::Domain 'hostdomain';
|
use Net::Domain 'hostdomain';
|
||||||
use File::ShareDir 'dist_dir';
|
use File::ShareDir 'dist_dir';
|
||||||
|
use URI::Based;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
if (setting('include_paths') and ref [] eq ref setting('include_paths')) {
|
if (setting('include_paths') and ref [] eq ref setting('include_paths')) {
|
||||||
@@ -224,4 +225,11 @@ config->{'reports'} = [ @{setting('system_reports')}, @{setting('reports')} ];
|
|||||||
#config->{plugins}->{Swagger}->{ui_dir} =
|
#config->{plugins}->{Swagger}->{ui_dir} =
|
||||||
#dir(dist_dir('App-Netdisco'), 'share', 'public', 'swagger-ui')->absolute;
|
#dir(dist_dir('App-Netdisco'), 'share', 'public', 'swagger-ui')->absolute;
|
||||||
|
|
||||||
|
# setup helpers for when request->uri_for() isn't available
|
||||||
|
# (for example when inside swagger_path())
|
||||||
|
config->{url_base}
|
||||||
|
= URI::Based->new((config->{path} eq '/') ? '' : config->{path});
|
||||||
|
config->{api_base}
|
||||||
|
= config->{url_base}->with('/api/v1')->path;
|
||||||
|
|
||||||
true;
|
true;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ BEGIN {
|
|||||||
$response->status($status || 302);
|
$response->status($status || 302);
|
||||||
$response->headers('Location' => $destination);
|
$response->headers('Location' => $destination);
|
||||||
};
|
};
|
||||||
|
|
||||||
# neater than using Dancer::Plugin::Res to handle JSON differently
|
# neater than using Dancer::Plugin::Res to handle JSON differently
|
||||||
*Dancer::send_error = sub {
|
*Dancer::send_error = sub {
|
||||||
my ($body, $status) = @_;
|
my ($body, $status) = @_;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use Try::Tiny;
|
|||||||
|
|
||||||
swagger_path {
|
swagger_path {
|
||||||
tags => ['Objects'],
|
tags => ['Objects'],
|
||||||
|
path => setting('api_base').'/object/device/{ip}',
|
||||||
description => 'Returns a row from the device table',
|
description => 'Returns a row from the device table',
|
||||||
parameters => [
|
parameters => [
|
||||||
ip => {
|
ip => {
|
||||||
@@ -27,6 +28,7 @@ swagger_path {
|
|||||||
foreach my $rel (qw/device_ips vlans ports modules port_vlans wireless_ports ssids powered_ports/) {
|
foreach my $rel (qw/device_ips vlans ports modules port_vlans wireless_ports ssids powered_ports/) {
|
||||||
swagger_path {
|
swagger_path {
|
||||||
tags => ['Objects'],
|
tags => ['Objects'],
|
||||||
|
path => setting('api_base')."/object/device/{ip}/$rel",
|
||||||
description => "Returns $rel rows for a given device",
|
description => "Returns $rel rows for a given device",
|
||||||
parameters => [
|
parameters => [
|
||||||
ip => {
|
ip => {
|
||||||
@@ -46,7 +48,7 @@ foreach my $rel (qw/device_ips vlans ports modules port_vlans wireless_ports ssi
|
|||||||
swagger_path {
|
swagger_path {
|
||||||
tags => ['Objects'],
|
tags => ['Objects'],
|
||||||
description => 'Returns a row from the device_port table',
|
description => 'Returns a row from the device_port table',
|
||||||
path => '/api/v1/object/device/{ip}/port/{port}',
|
path => setting('api_base').'/object/device/{ip}/port/{port}',
|
||||||
parameters => [
|
parameters => [
|
||||||
ip => {
|
ip => {
|
||||||
description => 'Canonical IP of the Device. Use Search methods to find this.',
|
description => 'Canonical IP of the Device. Use Search methods to find this.',
|
||||||
@@ -72,7 +74,7 @@ foreach my $rel (qw/nodes active_nodes nodes_with_age active_nodes_with_age vlan
|
|||||||
swagger_path {
|
swagger_path {
|
||||||
tags => ['Objects'],
|
tags => ['Objects'],
|
||||||
description => "Returns $rel rows for a given port",
|
description => "Returns $rel rows for a given port",
|
||||||
path => "/api/v1/object/device/{ip}/port/{port}/$rel",
|
path => setting('api_base')."/object/device/{ip}/port/{port}/$rel",
|
||||||
parameters => [
|
parameters => [
|
||||||
ip => {
|
ip => {
|
||||||
description => 'Canonical IP of the Device. Use Search methods to find this.',
|
description => 'Canonical IP of the Device. Use Search methods to find this.',
|
||||||
@@ -99,7 +101,7 @@ foreach my $rel (qw/power properties ssid wireless agg_master neighbor last_node
|
|||||||
swagger_path {
|
swagger_path {
|
||||||
tags => ['Objects'],
|
tags => ['Objects'],
|
||||||
description => "Returns the related $rel table entry for a given port",
|
description => "Returns the related $rel table entry for a given port",
|
||||||
path => "/api/v1/object/device/{ip}/port/{port}/$rel",
|
path => setting('api_base')."/object/device/{ip}/port/{port}/$rel",
|
||||||
parameters => [
|
parameters => [
|
||||||
ip => {
|
ip => {
|
||||||
description => 'Canonical IP of the Device. Use Search methods to find this.',
|
description => 'Canonical IP of the Device. Use Search methods to find this.',
|
||||||
@@ -124,6 +126,7 @@ foreach my $rel (qw/power properties ssid wireless agg_master neighbor last_node
|
|||||||
|
|
||||||
swagger_path {
|
swagger_path {
|
||||||
tags => ['Objects'],
|
tags => ['Objects'],
|
||||||
|
path => setting('api_base').'/object/device/{ip}/nodes',
|
||||||
description => "Returns the nodes found on a given Device",
|
description => "Returns the nodes found on a given Device",
|
||||||
parameters => [
|
parameters => [
|
||||||
ip => {
|
ip => {
|
||||||
@@ -149,6 +152,7 @@ swagger_path {
|
|||||||
|
|
||||||
swagger_path {
|
swagger_path {
|
||||||
tags => ['Objects'],
|
tags => ['Objects'],
|
||||||
|
path => setting('api_base').'/object/vlan/{vlan}/nodes',
|
||||||
description => "Returns the nodes found in a given VLAN",
|
description => "Returns the nodes found in a given VLAN",
|
||||||
parameters => [
|
parameters => [
|
||||||
vlan => {
|
vlan => {
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ hook 'before' => sub {
|
|||||||
swagger_path {
|
swagger_path {
|
||||||
description => 'Obtain an API Key',
|
description => 'Obtain an API Key',
|
||||||
tags => ['General'],
|
tags => ['General'],
|
||||||
|
path => setting('url_base')->with('/login')->path,
|
||||||
parameters => [],
|
parameters => [],
|
||||||
responses => { default => { examples => {
|
responses => { default => { examples => {
|
||||||
'application/json' => { api_key => 'cc9d5c02d8898e5728b7d7a0339c0785' } } },
|
'application/json' => { api_key => 'cc9d5c02d8898e5728b7d7a0339c0785' } } },
|
||||||
@@ -157,13 +158,15 @@ post '/login' => sub {
|
|||||||
|
|
||||||
# ugh, *puke*, but D::P::Swagger has no way to set this with swagger_path
|
# ugh, *puke*, but D::P::Swagger has no way to set this with swagger_path
|
||||||
# must be after the path is declared, above.
|
# must be after the path is declared, above.
|
||||||
Dancer::Plugin::Swagger->instance->doc->{paths}->{'/login'}
|
Dancer::Plugin::Swagger->instance->doc
|
||||||
|
->{paths}->{ setting('url_base')->with('/login')->path }
|
||||||
->{post}->{security}->[0]->{BasicAuth} = [];
|
->{post}->{security}->[0]->{BasicAuth} = [];
|
||||||
|
|
||||||
# we override the default login_handler, so logout has to be handled as well
|
# we override the default login_handler, so logout has to be handled as well
|
||||||
swagger_path {
|
swagger_path {
|
||||||
description => 'Destroy user API Key and session cookie',
|
description => 'Destroy user API Key and session cookie',
|
||||||
tags => ['General'],
|
tags => ['General'],
|
||||||
|
path => setting('url_base')->with('/logout')->path,
|
||||||
parameters => [],
|
parameters => [],
|
||||||
responses => { default => { examples => { 'application/json' => {} } } },
|
responses => { default => { examples => { 'application/json' => {} } } },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ register 'register_search_tab' => sub {
|
|||||||
my $tag = $config->{tag};
|
my $tag = $config->{tag};
|
||||||
swagger_path {
|
swagger_path {
|
||||||
tags => ['Search'],
|
tags => ['Search'],
|
||||||
|
path => setting('api_base')."/search/$tag",
|
||||||
description => $config->{label} .' Search',
|
description => $config->{label} .' Search',
|
||||||
parameters => $config->{api_parameters},
|
parameters => $config->{api_parameters},
|
||||||
responses =>
|
responses =>
|
||||||
@@ -197,6 +198,7 @@ register 'register_report' => sub {
|
|||||||
(my $category_path = lc $config->{category}) =~ s/ /-/g;
|
(my $category_path = lc $config->{category}) =~ s/ /-/g;
|
||||||
swagger_path {
|
swagger_path {
|
||||||
tags => ['Reports'],
|
tags => ['Reports'],
|
||||||
|
path => setting('api_base')."/report/$category_path/$tag",
|
||||||
description => $config->{label} .' Report',
|
description => $config->{label} .' Report',
|
||||||
parameters =>
|
parameters =>
|
||||||
($config->{api_parameters} ||
|
($config->{api_parameters} ||
|
||||||
|
|||||||
Reference in New Issue
Block a user