Browse Source

refractor config

master
o.moresis 7 months ago
parent
commit
a236c597c1
  1. 4
      docker-compose.yml
  2. 32
      src/Config.php
  3. 23
      src/Services/GeoserverAPI.php
  4. 4
      src/Services/WfdAPI.php

4
docker-compose.yml

@ -52,9 +52,9 @@ services:
volumes: volumes:
- geoserver_data:/opt/geoserver/data_dir - geoserver_data:/opt/geoserver/data_dir
expose: expose:
- 8081 - 8080
ports: ports:
- "8081:8081" - "8080:8080"
networks: networks:
- internal - internal

32
src/Config.php

@ -28,9 +28,7 @@ class Config {
const LINE_READ_LIMIT = 500; const LINE_READ_LIMIT = 500;
const BYTE_READ_LIMIT = 450000000; const BYTE_READ_LIMIT = 450000000;
const MODE = 1; 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_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 REPO_API = "http://msfd-repo.ath.hcmr.gr"; */
const API_URL = array( const API_URL = array(
"REPO" => "http://msfd-repo.ath.hcmr.gr/", "REPO" => "http://msfd-repo.ath.hcmr.gr/",
@ -41,13 +39,7 @@ class Config {
// Database configuration // Database configuration
// Production / Development // Production / Development
const API_CREDS = array( private static $api_creds;
"REPO" => "",
"GSRV" => "",
"POSD" => "",
"WFD" => ""
);
// Header translations // Header translations
const HEADER_TRANSLATIONS = [ const HEADER_TRANSLATIONS = [
'Cruise' => 'cruise', 'Cruise' => 'cruise',
@ -91,6 +83,11 @@ class Config {
return self::ITEM_SEPARATOR; 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) public static function getDatabaseCreds($mode = self::MODE)
{ {
@ -111,7 +108,22 @@ class Config {
public static function getAPICredentials($api_name) 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];
// }
} }

23
src/Services/GeoserverAPI.php

@ -13,19 +13,26 @@ class GeoserverAPI extends API{
private $post_data; private $post_data;
private $geoserver_response; private $geoserver_response;
private $apiName = 'GSRV'; private $apiName = 'GSRV';
private $username;
private $password;
public $isBasicAuth = true;
private $headers = array(
"Content-Type: application/json",
"Accept: application/json"
);
public function __construct() public function __construct()
{ {
$url = Config::getAPIbaseURL($this->apiName); $url = Config::getAPIbaseURL($this->apiName);
$this->username = 'portal'; $this->username = Config::getAPICredentials($this->apiName)["username"];
$this->password = '@dm!n322'; $this->password = Config::getAPICredentials($this->apiName)["password"];
$this->hasFile = FALSE; // $this->hasFile = FALSE;
$this->isBasicAuth = TRUE; // $this->isBasicAuth = TRUE;
$this->headers = array( // $this->headers = array(
"Content-Type: application/json", // "Content-Type: application/json",
"Accept: application/json" // "Accept: application/json"
); // );
parent::__construct($url); parent::__construct($url);
} }

4
src/Services/WfdAPI.php

@ -17,8 +17,8 @@ class WfdAPI extends API {
$url = Config::getAPIbaseURL($this->apiName); $url = Config::getAPIbaseURL($this->apiName);
parent::__construct($url); parent::__construct($url);
$this->username = Config::getAPIusername($this->apiName); $this->username = Config::getAPICredentials($this->apiName)->username;
$this->password = Config::getAPIpassword($this->apiName); $this->password = Config::getAPICredentials($this->apiName)->password;
$this->client_id = Config::getAPIclientID($this->apiName); $this->client_id = Config::getAPIclientID($this->apiName);
$this->client_secret = Config::getAPIclientSecret($this->apiName); $this->client_secret = Config::getAPIclientSecret($this->apiName);
} }

Loading…
Cancel
Save