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: @@ -52,9 +52,9 @@ services:
volumes:
- geoserver_data:/opt/geoserver/data_dir
expose:
- 8081
- 8080
ports:
- "8081:8081"
- "8080:8080"
networks:
- internal

32
src/Config.php

@ -28,9 +28,7 @@ class Config { @@ -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 { @@ -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 { @@ -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 { @@ -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];
// }
}

23
src/Services/GeoserverAPI.php

@ -13,19 +13,26 @@ class GeoserverAPI extends API{ @@ -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);
}

4
src/Services/WfdAPI.php

@ -17,8 +17,8 @@ class WfdAPI extends API { @@ -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);
}

Loading…
Cancel
Save