Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3cba6f6

Browse files
committed
[NF] allow filtering of some IX-F export content
Proof of concept for @yannrobin
1 parent 5be5d13 commit 3cba6f6

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

.env.example

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,14 @@ GRAPHER_BACKEND_MRTG_DBTYPE="rrd"
193193
## IX-F Member Export - see: https://docs.ixpmanager.org/features/ixf-export/
194194

195195

196-
IXP_API_JSONEXPORTSCHEMA_PUBLIC=true
196+
# IXP_API_JSONEXPORTSCHEMA_PUBLIC=true
197+
198+
# Some variables can be excluded is required.
199+
# See: https://docs.ixpmanager.org/features/ixf-export/
200+
#
201+
# IXP_API_JSONEXPORTSCHEMA_EXCLUDE_SWITCH="model|software"
202+
203+
197204

198205

199206
#######################################################################################

app/Utils/Export/JsonSchema.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ public function get( string $version = null, $asArray = false, $detailed = true,
9999
$output['ixp_list'] = $this->getIXPInfo( $version );
100100
$output['member_list'] = $this->getMemberInfo( $version, $detailed, $tags );
101101

102+
// apply filters as some IXs don't want to export all details
103+
$output = $this->filter($output);
104+
102105
if( $asArray ) {
103106
return $output;
104107
}
@@ -511,4 +514,28 @@ private function xlateMemberType( int $ixpmType ) : string
511514
return 'other';
512515
}
513516
}
517+
518+
/**
519+
* Filter details if requested by the config
520+
* @param array $output
521+
* @return array
522+
*/
523+
private function filter( array $output ): array
524+
{
525+
// switch filters
526+
if( $c = config( 'ixp_api.json_export_schema.excludes.switch' ) ) {
527+
foreach( explode( '|', $c ) as $exc ) {
528+
foreach( $output['ixp_list'] as $ixid => $ix ) {
529+
foreach( $ix['switch'] as $sid => $sw ) {
530+
if( isset( $output['ixp_list'][ $ixid ]['switch'][$sid][$exc] ) ) {
531+
unset( $output['ixp_list'][ $ixid ]['switch'][$sid][$exc] );
532+
}
533+
}
534+
}
535+
}
536+
}
537+
538+
return $output;
539+
}
540+
514541
}

config/ixp_api.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838

3939
// or - we can set a static key here if we like:
4040
'access_key' => env( 'IXP_API_JSONEXPORTSCHEMA_ACCESS_KEY', false ),
41+
42+
// some IXs want to exclude some information:
43+
'excludes' => [
44+
'switch' => env( 'IXP_API_JSONEXPORTSCHEMA_EXCLUDE_SWITCH', false ),
45+
],
4146
],
4247

4348
/*

0 commit comments

Comments
 (0)