From 4baa737d9552a7b5ac3ca15b6dc8b95dc43e2dc7 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Mon, 11 Dec 2023 23:30:39 +0100 Subject: [PATCH] feat: add option to use secrets JSON file instead --- .gitignore | 3 +++ www/mysql_adapter.php | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 57872d0..230fe86 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ /vendor/ + +/www/secrets +sftp.json \ No newline at end of file diff --git a/www/mysql_adapter.php b/www/mysql_adapter.php index a939911..5f663f8 100644 --- a/www/mysql_adapter.php +++ b/www/mysql_adapter.php @@ -7,8 +7,16 @@ class MySQLAdapter { public $data_directory; function __construct() { - $this->raw = mysqli_connect(getenv('MYSQL_HOST'), - getenv('MYSQL_USER'), getenv('MYSQL_PASSWORD'), getenv('MYSQL_DATABASE')); + $db_params = json_decode(file_get_contents('secrets/db.json'), true); + + if(null !== getenv('MYSQL_HOST')) { + $this->raw = mysqli_connect(getenv('MYSQL_HOST'), + getenv('MYSQL_USER'), getenv('MYSQL_PASSWORD'), getenv('MYSQL_DATABASE')); + } + else { + $this->raw = mysqli_connect($db_params['MYSQL_HOST'], + $db_params['MYSQL_USER'], $db_params['MYSQL_PASSWORD'], $db_params['MYSQL_DATABASE']); + } $this->data_directory = 'raw';