From db0caeb8b7af476a799d825c669b6f0d4657c732 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Fri, 4 Oct 2019 22:52:40 +0000 Subject: [PATCH 1/8] fix: remove GitHub Actions workflow step for vfs-site holobranch --- .github/workflows/holo.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/holo.yml b/.github/workflows/holo.yml index 832fdfa..2cd59f6 100644 --- a/.github/workflows/holo.yml +++ b/.github/workflows/holo.yml @@ -19,12 +19,3 @@ jobs: ref: releases/v2 holobranch: emergence-skeleton commit-to: emergence/skeleton/v2 - - name: 'Update holobranch: emergence/vfs-site/v2' - uses: JarvusInnovations/hologit@actions/projector/v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - HAB_LICENSE: accept - with: - ref: releases/v2 - holobranch: emergence-vfs-site - commit-to: emergence/vfs-site/v2 From fae6558761a00cc0408c7c51fab19ee84a93d705 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sat, 5 Oct 2019 00:12:51 +0000 Subject: [PATCH 2/8] fix: centralize getApiBaseUrl logic and handle array-values for $apiHostname correctly --- html-templates/endpoints/endpointEdit.tpl | 2 +- php-classes/Gatekeeper/Endpoints/Endpoint.php | 8 +------- php-classes/Gatekeeper/Gatekeeper.php | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/html-templates/endpoints/endpointEdit.tpl b/html-templates/endpoints/endpointEdit.tpl index 5f9a251..434e414 100644 --- a/html-templates/endpoints/endpointEdit.tpl +++ b/html-templates/endpoints/endpointEdit.tpl @@ -37,7 +37,7 @@

Routing

{capture assign=pathInputHtml}{strip} - http://{tif Gatekeeper\Gatekeeper::$apiHostname ? Gatekeeper\Gatekeeper::$apiHostname : "$.server.HTTP_HOST/api"}/  + {Gatekeeper\Gatekeeper::getApiBaseUrl()}/  {/strip}{/capture} {labeledField html=$pathInputHtml type=compound label='Public Path' error=$errors.Path required=true} diff --git a/php-classes/Gatekeeper/Endpoints/Endpoint.php b/php-classes/Gatekeeper/Endpoints/Endpoint.php index cb283f9..959d4e4 100644 --- a/php-classes/Gatekeeper/Endpoints/Endpoint.php +++ b/php-classes/Gatekeeper/Endpoints/Endpoint.php @@ -375,13 +375,7 @@ public function applyRewrites($url) public function getExternalUrl() { - $url = 'http://'; - - if (Gatekeeper::$apiHostname) { - $url .= Gatekeeper::$apiHostname; - } else { - $url .= Site::getConfig('primary_hostname') . '/api'; - } + $url = Gatekeeper::getApiBaseUrl(); $url .= '/' . $this->Path; diff --git a/php-classes/Gatekeeper/Gatekeeper.php b/php-classes/Gatekeeper/Gatekeeper.php index 62c69d6..186dcd8 100644 --- a/php-classes/Gatekeeper/Gatekeeper.php +++ b/php-classes/Gatekeeper/Gatekeeper.php @@ -2,6 +2,7 @@ namespace Gatekeeper; +use Site; use JSON; class Gatekeeper @@ -10,6 +11,23 @@ class Gatekeeper public static $portalHostname; public static $authRealm = 'Gatekeeper'; + public static function getApiBaseUrl() + { + $url = Site::getConfig('ssl') ? 'https://' : 'http://'; + + if (static::$apiHostname) { + $url .= is_array(static::$apiHostname) ? static::$apiHostname[0] : static::$apiHostname; + } elseif (!empty($_SERVER['HTTP_HOST'])) { + $url .= $_SERVER['HTTP_HOST']; + $url .= '/api'; + } else { + $url .= Site::getConfig('primary_hostname') ?: 'localhost'; + $url .= '/api'; + } + + return $url; + } + public static function authorizeTestApiAccess() { if ( From 2df0c77b29019042dc6f306631b4359667d4ce59 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sat, 5 Oct 2019 00:13:45 +0000 Subject: [PATCH 3/8] chore: add xdebug and sqltools to recommended vscode extensions --- .vscode/extensions.json | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 89b5f1b..8b79ed3 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,10 +1,15 @@ { - // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. - // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp - // List of extensions which should be recommended for users of this workspace. - "recommendations": [ - "bmewburn.vscode-intelephense-client", - "imperez.smarty" - ] + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "bmewburn.vscode-intelephense-client", + "imperez.smarty", + "felixfbecker.php-debug", + "mtxr.sqltools" + ], + "unwantedRecommendations": [ + "ms-mssql.mssql" + ] } \ No newline at end of file From af65873b1a0b2dfa87e9a476c1e50a028bf06058 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sat, 5 Oct 2019 00:14:05 +0000 Subject: [PATCH 4/8] chore: add vscode debug launcher config --- .vscode/launch.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..585eaa5 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Listen for XDebug", + "type": "php", + "request": "launch", + "port": 7089, + "pathMappings": { + "/hab/svc/php-runtime/var/site/php-classes/Emergence": "${workspaceFolder:emergence-skeleton-v1}/php-classes/Emergence", + "/hab/svc/php-runtime/var/site": "${workspaceFolder:gatekeeper}", + "/src/emergence-php-core": "${workspaceFolder:emergence-php-core}" + }, + "ignore": [ + "**/vendor/**/*" + ] + } + ] +} \ No newline at end of file From f931d05212863e9d00a70868ef6dfda517eee6e8 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sat, 5 Oct 2019 00:41:22 +0000 Subject: [PATCH 5/8] fix: evaluate ping frequency in minutes --- php-classes/Gatekeeper/Endpoints/Pinger.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php-classes/Gatekeeper/Endpoints/Pinger.php b/php-classes/Gatekeeper/Endpoints/Pinger.php index 919ab0f..50fbf3e 100644 --- a/php-classes/Gatekeeper/Endpoints/Pinger.php +++ b/php-classes/Gatekeeper/Endpoints/Pinger.php @@ -21,7 +21,7 @@ public static function pingOverdueEndpoints($verbose = false) if ( $lastPing === false - || $Endpoint->PingFrequency < time()-$lastPing['time'] // * 60 + || $Endpoint->PingFrequency*60 < time()-$lastPing['time'] ) { static::pingEndpoint($Endpoint, $verbose); } @@ -107,7 +107,7 @@ public static function pingEndpoint(Endpoint $Endpoint, $verbose = false) Cache::store("endpoints/{$Endpoint->ID}/last-ping", [ 'time' => time(), 'testPassed' => $testPassed - ], ($Endpoint->PingFrequency+5)); // * 60 + ], ($Endpoint->PingFrequency+5)*60); return $testPassed; } From 3ce8ba0ca5183f4ece80148d462f91aa61c1da17 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sat, 5 Oct 2019 02:54:35 +0000 Subject: [PATCH 6/8] fix: force GET method for ping tests --- php-classes/Gatekeeper/Endpoints/Pinger.php | 1 + 1 file changed, 1 insertion(+) diff --git a/php-classes/Gatekeeper/Endpoints/Pinger.php b/php-classes/Gatekeeper/Endpoints/Pinger.php index 50fbf3e..3618ce8 100644 --- a/php-classes/Gatekeeper/Endpoints/Pinger.php +++ b/php-classes/Gatekeeper/Endpoints/Pinger.php @@ -38,6 +38,7 @@ public static function pingEndpoint(Endpoint $Endpoint, $verbose = false) $response = HttpProxy::relayRequest([ 'autoAppend' => false, 'autoQuery' => false, + 'method' => 'GET', 'url' => rtrim($Endpoint->InternalEndpoint, '/') . '/' . ltrim($Endpoint->PingURI, '/'), 'interface' => ApiRequestHandler::$sourceInterface, 'timeout' => 15, From 4aecb4cb49463c26da50373fd374246f84eb6249 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sat, 5 Oct 2019 02:55:00 +0000 Subject: [PATCH 7/8] fix: force normalized headers for ping tests --- php-classes/Gatekeeper/Endpoints/Pinger.php | 11 +++++++++-- site-root/health/endpoint-tests.php | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/php-classes/Gatekeeper/Endpoints/Pinger.php b/php-classes/Gatekeeper/Endpoints/Pinger.php index 3618ce8..a7a76fa 100644 --- a/php-classes/Gatekeeper/Endpoints/Pinger.php +++ b/php-classes/Gatekeeper/Endpoints/Pinger.php @@ -2,6 +2,7 @@ namespace Gatekeeper\Endpoints; +use Site; use Cache; use HttpProxy; @@ -43,7 +44,13 @@ public static function pingEndpoint(Endpoint $Endpoint, $verbose = false) 'interface' => ApiRequestHandler::$sourceInterface, 'timeout' => 15, 'timeoutConnect' => 5, - 'returnResponse' => true + 'returnResponse' => true, + 'forwardHeaders' => [], + 'headers' => [ + 'Accept: */*', + 'Accept-Language: *', + 'User-Agent: ' . (ApiRequestHandler::$poweredByHeader ?: Site::$title) + ] ]); @@ -112,4 +119,4 @@ public static function pingEndpoint(Endpoint $Endpoint, $verbose = false) return $testPassed; } -} \ No newline at end of file +} diff --git a/site-root/health/endpoint-tests.php b/site-root/health/endpoint-tests.php index 7ebd839..9ea7d26 100644 --- a/site-root/health/endpoint-tests.php +++ b/site-root/health/endpoint-tests.php @@ -56,7 +56,13 @@ 'interface' => ApiRequestHandler::$sourceInterface, 'timeout' => 15, 'timeoutConnect' => 5, - 'returnResponse' => true + 'returnResponse' => true, + 'forwardHeaders' => [], + 'headers' => [ + 'Accept: */*', + 'Accept-Language: *', + 'User-Agent: ' . (ApiRequestHandler::$poweredByHeader ?: Site::$title) + ] ]); // evaluate success From f4206b3a67e139cbde70bce1c387d612f60b7417 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sat, 5 Oct 2019 02:55:18 +0000 Subject: [PATCH 8/8] fix: display complete request URL in endpoint-tests report --- site-root/health/endpoint-tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-root/health/endpoint-tests.php b/site-root/health/endpoint-tests.php index 9ea7d26..6fd1eb7 100644 --- a/site-root/health/endpoint-tests.php +++ b/site-root/health/endpoint-tests.php @@ -83,7 +83,7 @@ Path?> PingURI?> PingTestPattern?> - +