Let's create a mock API endpoint under security.toolforge.org that closely mimics the vendor's API endpoint for product access based upon their current product literature.
Description
Description
Status | Subtype | Assigned | Task | ||
---|---|---|---|---|---|
Declined | None | T290917 New Service Request Security API Gateway | |||
Resolved | Mstyles | T296346 Create Demo Environment for Security API | |||
Resolved | sbassett | T309213 Create a mock vendor API endpoint at toolforge for the Security API service |
Event Timeline
Comment Actions
Ok, this should be done.
Test URL: https://security.toolforge.org/test-vendor/v2/anonymous-residential/
Code (I don't think this is important or lengthy enough to merit inclusion in version control):
.env
VENDOR_ACCESS_TOKEN="xyz" VENDOR_FEED_PRODUCT_PATH="/path/to/file.json"
index.php
<?php /* * Copyright (C) 2022 Wikimedia Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Author: sbassett@wikimedia.org */ /* load .env */ $dotenv = []; $dotenv = file( __DIR__ . "/.env" ); foreach ( $dotenv as $v ) { $kvpairs = preg_split( "/\=/", $v ); if ( sizeof( $kvpairs ) == 2 ) { define( $kvpairs[0], trim( str_replace( '"', "", $kvpairs[1] ) ) ); } } /* check header Token */ if ( ! function_exists( 'apache_request_headers' ) ) { $msg = 'Invalid HTTP Request!'; echo $msg; throw new \UnexpectedValueException( $msg ); } if ( apache_request_headers()['Token'] != VENDOR_ACCESS_TOKEN ) { $msg = 'Invalid Access Token!'; echo $msg; throw new \UnexpectedValueException( $msg ); } /* display protected vendor file data */ if ( is_file( VENDOR_FEED_PRODUCT_PATH ) ) { readfile( VENDOR_FEED_PRODUCT_PATH ); exit; } else { $msg = 'Invalid Vendor File Configuration!'; echo $msg; throw new \UnexpectedValueException( $msg ); }
And the test data file can be generated via this utility script.