API implementation (#712)
* initial v0 creator * working json api for generic reports * add require login * move report swagger into plugin, and set new default layout of noop * require proper role and also use new util func * start to tidy authn * some work on cleaning up web authn * clean up the authN checks * fix bug * fix the auth for api * fixes to json handling * set swagger sort order * enable most reports for api endpoints * fix doc * add paramters to reports * add missed report * allow api_parameters in reports config * reorganise api * add vlan search * add port search * make sure to enable layout processing * add device search * add v1 to api paths * add Node Search * support api_responses * add device object search; fix spurious ports field in device result class * handle some plugins just returning undef if search fails * errors from api seamlessley * fix error in date range default * more sensible default for prefix * change order of endpoints in swagger-ui * all db row classes can now TO_JSON * add device_port api endpoint * add device ports endpoint * do not expand docs * add swagger ui json tree formatter * add all relations from Device table * add port relations * add nodes retrieve on device or vlan * rename to GetAPIKey * update config for previous commit
This commit is contained in:
@@ -2,6 +2,8 @@ package App::Netdisco::Web::Plugin;
|
||||
|
||||
use Dancer ':syntax';
|
||||
use Dancer::Plugin;
|
||||
use Dancer::Plugin::Swagger;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use Path::Class 'dir';
|
||||
|
||||
@@ -150,6 +152,19 @@ sub _register_tab {
|
||||
register 'register_search_tab' => sub {
|
||||
my ($self, $config) = plugin_args(@_);
|
||||
_register_tab('search', $config);
|
||||
|
||||
if ($config->{api_endpoint}) {
|
||||
my $tag = $config->{tag};
|
||||
swagger_path {
|
||||
tags => ['Search'],
|
||||
description => $config->{label} .' Search',
|
||||
parameters => $config->{api_parameters},
|
||||
responses =>
|
||||
($config->{api_responses} || { default => {} }),
|
||||
}, get "/api/v1/search/$tag" => require_role api => sub {
|
||||
forward "/ajax/content/search/$tag";
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
register 'register_device_tab' => sub {
|
||||
@@ -178,6 +193,21 @@ register 'register_report' => sub {
|
||||
if ($config->{tag} eq $tag) {
|
||||
setting('_reports')->{$tag} = $config;
|
||||
|
||||
if ($config->{api_endpoint}) {
|
||||
(my $category_path = lc $config->{category}) =~ s/ /-/g;
|
||||
swagger_path {
|
||||
tags => ['Reports'],
|
||||
description => $config->{label} .' Report',
|
||||
parameters =>
|
||||
($config->{api_parameters} ||
|
||||
($config->{bind_params} ? [map { $_ => {} } @{ $config->{bind_params} }] : [])),
|
||||
responses =>
|
||||
($config->{api_responses} || { default => {} }),
|
||||
}, get "/api/v1/report/$category_path/$tag" => require_role api => sub {
|
||||
forward "/ajax/content/report/$tag";
|
||||
};
|
||||
}
|
||||
|
||||
foreach my $rconfig (@{setting('reports')}) {
|
||||
if ($rconfig->{tag} eq $tag) {
|
||||
setting('_reports')->{$tag}->{'rconfig'} = $rconfig;
|
||||
|
||||
Reference in New Issue
Block a user