From 87160b8e13dfadc242a205825eb20c9a26bc1406 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 15 Feb 2021 22:12:54 +0000 Subject: [PATCH] API port methods do not work with Cisco style Fa1/0/1 port names --- Changes | 6 ++++ lib/App/Netdisco/Web/API/Objects.pm | 55 +++++++++++++++-------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/Changes b/Changes index ec68ab47..292fecaf 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,9 @@ +2.047004 - 2021-02-15 + + [BUG FIXES] + + * API port methods do not work with Cisco style Fa1/0/1 port names + 2.047003 - 2021-02-10 [BUG FIXES] diff --git a/lib/App/Netdisco/Web/API/Objects.pm b/lib/App/Netdisco/Web/API/Objects.pm index 95c7b52e..68eaf9c8 100644 --- a/lib/App/Netdisco/Web/API/Objects.pm +++ b/lib/App/Netdisco/Web/API/Objects.pm @@ -45,31 +45,6 @@ foreach my $rel (qw/device_ips vlans ports modules port_vlans wireless_ports ssi }; } -swagger_path { - tags => ['Objects'], - description => 'Returns a row from the device_port table', - path => setting('api_base').'/object/device/{ip}/port/{port}', - parameters => [ - ip => { - description => 'Canonical IP of the Device. Use Search methods to find this.', - required => 1, - in => 'path', - }, - port => { - description => 'Name of the port. Use the ".../device/{ip}/ports" method to find these.', - required => 1, - in => 'path', - }, - ], - responses => { default => {} }, -}, get qr{/api/v1/object/device/(?[^/]+)/port/(?[^/]+)$} => require_role api => sub { - my $params = captures; - my $port = try { schema('netdisco')->resultset('DevicePort') - ->find( $$params{port}, $$params{ip} ) } - or send_error('Bad Device or Port', 404); - return to_json $port->TO_JSON; -}; - foreach my $rel (qw/nodes active_nodes nodes_with_age active_nodes_with_age vlans logs/) { swagger_path { tags => ['Objects'], @@ -88,7 +63,7 @@ foreach my $rel (qw/nodes active_nodes nodes_with_age active_nodes_with_age vlan }, ], responses => { default => {} }, - }, get qq{/api/v1/object/device/(?[^/]+)/port/(?[^/]+)/$rel} => require_role api => sub { + }, get qr{/api/v1/object/device/(?[^/]+)/port/(?.+)/${rel}$} => require_role api => sub { my $params = captures; my $rows = try { schema('netdisco')->resultset('DevicePort') ->find( $$params{port}, $$params{ip} )->$rel } @@ -115,7 +90,7 @@ foreach my $rel (qw/power properties ssid wireless agg_master neighbor last_node }, ], responses => { default => {} }, - }, get qq{/api/v1/object/device/(?[^/]+)/port/(?[^/]+)/$rel} => require_role api => sub { + }, get qr{/api/v1/object/device/(?[^/]+)/port/(?.+)/${rel}$} => require_role api => sub { my $params = captures; my $row = try { schema('netdisco')->resultset('DevicePort') ->find( $$params{port}, $$params{ip} )->$rel } @@ -124,6 +99,32 @@ foreach my $rel (qw/power properties ssid wireless agg_master neighbor last_node }; } +# must come after the port methods above, so the route matches later +swagger_path { + tags => ['Objects'], + description => 'Returns a row from the device_port table', + path => setting('api_base').'/object/device/{ip}/port/{port}', + parameters => [ + ip => { + description => 'Canonical IP of the Device. Use Search methods to find this.', + required => 1, + in => 'path', + }, + port => { + description => 'Name of the port. Use the ".../device/{ip}/ports" method to find these.', + required => 1, + in => 'path', + }, + ], + responses => { default => {} }, +}, get qr{/api/v1/object/device/(?[^/]+)/port/(?.+)$} => require_role api => sub { + my $params = captures; + my $port = try { schema('netdisco')->resultset('DevicePort') + ->find( $$params{port}, $$params{ip} ) } + or send_error('Bad Device or Port', 404); + return to_json $port->TO_JSON; +}; + swagger_path { tags => ['Objects'], path => setting('api_base').'/object/device/{ip}/nodes',