From a236c597c1bdbd1063bad5ccc364a358b44918c7 Mon Sep 17 00:00:00 2001 From: "o.moresis" Date: Thu, 23 May 2024 16:33:54 +0300 Subject: [PATCH] refractor config --- docker-compose.yml | 4 ++-- src/Config.php | 32 ++++++++++++++++++++++---------- src/Services/GeoserverAPI.php | 23 +++++++++++++++-------- src/Services/WfdAPI.php | 4 ++-- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 401cbef..5449810 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -52,9 +52,9 @@ services: volumes: - geoserver_data:/opt/geoserver/data_dir expose: - - 8081 + - 8080 ports: - - "8081:8081" + - "8080:8080" networks: - internal diff --git a/src/Config.php b/src/Config.php index 6fd87cc..05e882b 100644 --- a/src/Config.php +++ b/src/Config.php @@ -28,9 +28,7 @@ class Config { const LINE_READ_LIMIT = 500; const BYTE_READ_LIMIT = 450000000; const MODE = 1; - // const API_BASE_URL = "https://geoserver.hcmr.gr/geoserver/rest/"; // const API_BASE_URL = getenv("https://geoserver.hcmr.gr/geoserver/rest/"); - const API_CREDENTIALS = ["portal", "@dm!n322"]; /* const REPO_API = "http://msfd-repo.ath.hcmr.gr"; */ const API_URL = array( "REPO" => "http://msfd-repo.ath.hcmr.gr/", @@ -41,13 +39,7 @@ class Config { // Database configuration // Production / Development - const API_CREDS = array( - "REPO" => "", - "GSRV" => "", - "POSD" => "", - "WFD" => "" - ); - + private static $api_creds; // Header translations const HEADER_TRANSLATIONS = [ 'Cruise' => 'cruise', @@ -91,6 +83,11 @@ class Config { return self::ITEM_SEPARATOR; } + public static function getAPIBaseURL($api_name) + { + $url = getenv("{$api_name}_URL"); + return self::API_URL[$api_name]; + } public static function getDatabaseCreds($mode = self::MODE) { @@ -111,7 +108,22 @@ class Config { public static function getAPICredentials($api_name) { - return self::API_CREDENTIALS; + $username = getenv("{$api_name}_USER"); + $password = getenv("{$api_name}_PASS"); + + return array("username" => $username, "password" => $password); } + + // public static function getAPICredentials($api_name) + // { + // self::$api_creds = array( + // "REPO" => getenv("CREDS_REPO"), + // "GSRV" => getenv("CREDS_GSRV"), + // "POSD" => getenv("CREDS_POSD"), + // "WFD" => getenv("CREDS_WFD") + // ); + // + // return self::$api_creds[$api_name]; + // } } diff --git a/src/Services/GeoserverAPI.php b/src/Services/GeoserverAPI.php index 2df19c9..89a260b 100644 --- a/src/Services/GeoserverAPI.php +++ b/src/Services/GeoserverAPI.php @@ -13,19 +13,26 @@ class GeoserverAPI extends API{ private $post_data; private $geoserver_response; private $apiName = 'GSRV'; + private $username; + private $password; + public $isBasicAuth = true; + private $headers = array( + "Content-Type: application/json", + "Accept: application/json" + ); public function __construct() { $url = Config::getAPIbaseURL($this->apiName); - $this->username = 'portal'; - $this->password = '@dm!n322'; - $this->hasFile = FALSE; - $this->isBasicAuth = TRUE; - $this->headers = array( - "Content-Type: application/json", - "Accept: application/json" - ); + $this->username = Config::getAPICredentials($this->apiName)["username"]; + $this->password = Config::getAPICredentials($this->apiName)["password"]; + // $this->hasFile = FALSE; + // $this->isBasicAuth = TRUE; + // $this->headers = array( + // "Content-Type: application/json", + // "Accept: application/json" + // ); parent::__construct($url); } diff --git a/src/Services/WfdAPI.php b/src/Services/WfdAPI.php index 1de931b..b108994 100644 --- a/src/Services/WfdAPI.php +++ b/src/Services/WfdAPI.php @@ -17,8 +17,8 @@ class WfdAPI extends API { $url = Config::getAPIbaseURL($this->apiName); parent::__construct($url); - $this->username = Config::getAPIusername($this->apiName); - $this->password = Config::getAPIpassword($this->apiName); + $this->username = Config::getAPICredentials($this->apiName)->username; + $this->password = Config::getAPICredentials($this->apiName)->password; $this->client_id = Config::getAPIclientID($this->apiName); $this->client_secret = Config::getAPIclientSecret($this->apiName); }