Ports API: Workaround for ifNames with slashes (#10502)

* Workaround for ifNames with slashes

Basically,

/api/v0/devices/3/ports/0%2f4 -> /api/v0/devices/3/ports/ifName?ifName=0/4
/api/v0/devices/3/ports/0%2f4/port_bits -> /api/v0/devices/3/ports/ifName/port_bits?ifName=0/4

Or you can just use port_id.

* Fix API ports using ifName with slashes
hand parse the path for the ports graph endpoints
this way we can respect the original way of handling slashes (%2F)
This commit is contained in:
Tony Murray
2019-08-12 09:46:36 -05:00
committed by GitHub
parent cec10c1d37
commit f1c67ac5f4
4 changed files with 38 additions and 8 deletions

View File

@@ -455,6 +455,18 @@ function generate_entity_link($type, $entity, $text = null, $graph_type = null)
return ($link);
}//end generate_entity_link()
/**
* Extract type and subtype from a complex graph type, also makes sure variables are file name safe.
* @param string $type
* @return array [type, subtype]
*/
function extract_graph_type($type): array
{
preg_match('/^(?P<type>[A-Za-z0-9]+)_(?P<subtype>.+)/', $type, $graphtype);
$type = basename($graphtype['type']);
$subtype = basename($graphtype['subtype']);
return [$type, $subtype];
}
function generate_port_link($port, $text = null, $type = null, $overlib = 1, $single_graph = 0)
{