Skip to content

Commit

Permalink
[NF] Option to export customer tags with IX-F Member Export
Browse files Browse the repository at this point in the history
Includes CI tests for IX-F export also
  • Loading branch information
barryo committed Jun 19, 2018
1 parent 77b521d commit ae8b3ca
Show file tree
Hide file tree
Showing 9 changed files with 1,448 additions and 22 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ GRAPHER_BACKEND_MRTG_DBTYPE="rrd"
# GRAPHER_BACKEND_SMOKEPING_URL="http://www.example.com/smokeping"


#################################################################################
## IX-F Member Export - see: https://docs.ixpmanager.org/features/ixf-export/


IXP_API_JSONEXPORTSCHEMA_PUBLIC=true


#######################################################################################
### Skinning
#
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Controllers/Api/V4/MemberExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

use Auth;
use Illuminate\Http\Response;
use Illuminate\Http\{Request,Response};

use IXP\Utils\Export\JsonSchema as JsonSchemaExporter;

Expand All @@ -35,17 +35,20 @@ class MemberExportController extends Controller {
/**
* API call to generate DNS ARPA records in a given format
*
* @param Request $r
* @param string $version Version fo schema to export
* @return Response
*/
public function ixf( string $version = JsonSchemaExporter::EUROIX_JSON_LATEST ) {
public function ixf( Request $r, string $version = JsonSchemaExporter::EUROIX_JSON_LATEST ) {

if( !Auth::check() && !config( 'ixp_api.json_export_schema.public', false ) ) {
abort(401, 'Public access not permitted' );
}

$withTags = $r->query('withtags', null) === "1";

$exporter = new JsonSchemaExporter;
return response()->json( $exporter->get( $version, true, Auth::check() ), 200, [], JSON_PRETTY_PRINT )
return response()->json( $exporter->get( $version, true, Auth::check(), $withTags ), 200, [], JSON_PRETTY_PRINT )
->header( "Access-Control-Allow-Origin", "*" );
}

Expand Down
20 changes: 15 additions & 5 deletions app/Utils/Export/JsonSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ class JsonSchema
*
* @param string $version The version to get (or, if null / not present then the latest)
* @param bool $asArray Do not convert to JSON but rather return the PHP array
* @param bool $detailed Create the very detailed version (usualy for logged in users)
* @param bool $detailed Create the very detailed version (usually for logged in users)
* @param bool $tags Include customer tags
* @return string|array
*/
public function get( $version = null, $asArray = false, $detailed = true )
public function get( $version = null, $asArray = false, $detailed = true, $tags = false )
{
if( $version === null ) {
$version = self::EUROIX_JSON_LATEST;
Expand All @@ -84,13 +85,13 @@ public function get( $version = null, $asArray = false, $detailed = true )
$output['timestamp'] = date( 'Y-m-d', time() ) . 'T' . date( 'H:i:s', time() ) . 'Z';

$output['ixp_list'] = $this->getIXPInfo( $version );
$output['member_list'] = $this->getMemberInfo( $version, $detailed );
$output['member_list'] = $this->getMemberInfo( $version, $detailed, $tags );

if( $asArray ) {
return $output;
}

return json_encode( $output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE )."\n";
return json_encode( $output, JSON_PRETTY_PRINT )."\n";
}

/**
Expand Down Expand Up @@ -222,7 +223,7 @@ private function getSwitchInfo( $version, Infrastructure $infra )
* @param string $version The version to collate the detail for
* @return array
*/
private function getMemberInfo( string $version, bool $detailed )
private function getMemberInfo( string $version, bool $detailed, bool $tags )
{
$memberinfo = [];

Expand Down Expand Up @@ -376,6 +377,15 @@ private function getMemberInfo( string $version, bool $detailed )
}


if( $tags ) {
$memberinfo[$cnt]['ixp_manager']['tags'] = [];
foreach( $c->getTags() as $tag ) {
if( !$tag->isInternalOnly() || $detailed ) {
$memberinfo[$cnt]['ixp_manager']['tags'][ $tag->getTag() ] = $tag->getDisplayAs();
}
}
}

$memberinfo[$cnt]['connection_list'] = $connlist;

$cnt++;
Expand Down
Loading

0 comments on commit ae8b3ca

Please sign in to comment.