From 7c6894fcd22f8b8007632cae1d9c2768cda87930 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Fri, 2 Feb 2018 14:11:27 -0800 Subject: [PATCH] Revert "Refactor config with constant instead of strings" --- controller/action/DeveloperActions.class.php | 8 ++++---- controller/action/OpsActions.class.php | 6 +++--- data/config.php.example | 19 +++++++++++-------- lib/thirdparty/Asana.class.php | 2 +- lib/thirdparty/LBRY.class.php | 4 ++-- lib/thirdparty/Mailgun.class.php | 2 +- lib/thirdparty/Salesforce.class.php | 4 ++-- lib/thirdparty/Slack.class.php | 2 +- lib/tools/Config.class.php | 16 ---------------- web/index.php | 2 +- 10 files changed, 26 insertions(+), 39 deletions(-) diff --git a/controller/action/DeveloperActions.class.php b/controller/action/DeveloperActions.class.php index 547c688b..aba841b1 100644 --- a/controller/action/DeveloperActions.class.php +++ b/controller/action/DeveloperActions.class.php @@ -85,13 +85,13 @@ class DeveloperActions extends Actions Session::set(Session::KEY_DEVELOPER_RETURN_URL_SUCCESS, Request::getPostParam('returnUrl')); } - if (!Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_ID)) + if (!Config::get('github_developer_credits_client_id')) { throw new Exception('no github client id'); } $gitHubParams = [ - 'client_id' => Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_ID), + 'client_id' => Config::get('github_developer_credits_client_id'), 'redirect_uri' => Request::getHostAndProto() . '/quickstart/github/callback', 'scope' => 'user:email', 'allow_signup' => false @@ -112,8 +112,8 @@ class DeveloperActions extends Actions { $authResponseData = Curl::post('https://github.com/login/oauth/access_token', [ 'code' => $code, - 'client_id' => Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_ID), - 'client_secret' => Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_SECRET) + 'client_id' => Config::get('github_developer_credits_client_id'), + 'client_secret' => Config::get('github_developer_credits_client_secret') ], [ 'headers' => ['Accept: application/json'], 'json_response' => true diff --git a/controller/action/OpsActions.class.php b/controller/action/OpsActions.class.php index 08e5580f..5214d10e 100644 --- a/controller/action/OpsActions.class.php +++ b/controller/action/OpsActions.class.php @@ -40,7 +40,7 @@ class OpsActions extends Actions } $rawPost = file_get_contents('php://input'); - $secret = Config::get(Config::GITHUB_KEY); + $secret = Config::get('github_key'); if ($hash !== hash_hmac($algo, $rawPost, $secret)) { return NavActions::execute400(['error' => 'Hash does not match.']); @@ -78,8 +78,8 @@ class OpsActions extends Actions return NavActions::execute400(['error' => "Required params: log, name"]); } - $awsKey = Config::get(Config::AWS_LOG_ACCESS_KEY); - $awsSecret = Config::get(Config::AWS_LOG_SECRET_KEY); + $awsKey = Config::get('aws_log_access_key'); + $awsSecret = Config::get('aws_log_secret_key'); if (!$log || !$name) { diff --git a/data/config.php.example b/data/config.php.example index b918085d..9f6987a8 100644 --- a/data/config.php.example +++ b/data/config.php.example @@ -1,10 +1,13 @@ + ['Authorization: Bearer ' . $apiKey], diff --git a/lib/thirdparty/LBRY.class.php b/lib/thirdparty/LBRY.class.php index a3d1325d..6232b092 100644 --- a/lib/thirdparty/LBRY.class.php +++ b/lib/thirdparty/LBRY.class.php @@ -5,7 +5,7 @@ class LBRY { public static function getApiUrl($endpoint) { - return Config::get(Config::LBRY_API_SERVER) . $endpoint; + return Config::get('lbry_api_server') . $endpoint; } public static function getLBCtoUSDRate() @@ -29,4 +29,4 @@ class LBRY { return Curl::post(static::getApiUrl('/list/unsubscribe'), ['email' => $email], ['json_response' => true]); } -} +} \ No newline at end of file diff --git a/lib/thirdparty/Mailgun.class.php b/lib/thirdparty/Mailgun.class.php index cf898cda..1fb79693 100644 --- a/lib/thirdparty/Mailgun.class.php +++ b/lib/thirdparty/Mailgun.class.php @@ -51,7 +51,7 @@ class Mailgun { return Curl::doCurl($method, self::BASE_URL . $endpoint, $data, [ 'headers' => [ - 'Authorization: Basic ' . base64_encode('api:' . Config::get(Config::MAILGUN_API_KEY)) + 'Authorization: Basic ' . base64_encode('api:' . Config::get('mailgun_api_key')) ], 'retry' => 3, ]); diff --git a/lib/thirdparty/Salesforce.class.php b/lib/thirdparty/Salesforce.class.php index fdb5f714..e8ffb0db 100644 --- a/lib/thirdparty/Salesforce.class.php +++ b/lib/thirdparty/Salesforce.class.php @@ -45,7 +45,7 @@ class Salesforce protected static function getApiUserPassword() { - $userpw = Config::get(Config::SALESFORCE_KEY) . ':' . Config::get(Config::SALESFORCE_SECRET); + $userpw = Config::get('salesforce_key') . ':' . Config::get('salesforce_secret'); if ($userpw[0] === ':' || substr($userpw, -1) === ':') { throw new SalesforceException('Salesforce key and/or secret not configured correctly'); @@ -77,4 +77,4 @@ class Salesforce class SalesforceException extends Exception { -} +} \ No newline at end of file diff --git a/lib/thirdparty/Slack.class.php b/lib/thirdparty/Slack.class.php index 616b4983..dd43e56b 100644 --- a/lib/thirdparty/Slack.class.php +++ b/lib/thirdparty/Slack.class.php @@ -10,7 +10,7 @@ class Slack $e = Debug::exceptionToString($e); } - $slackErrorNotificationUrl = Config::get(Config::SLACK_ERROR_NOTIFICATION_URL); + $slackErrorNotificationUrl = Config::get('slack_error_notification_url'); if ($slackErrorNotificationUrl) { Curl::post($slackErrorNotificationUrl, ['text' => ($alert ? ' ' : '') . Request::getRelativeUri() . "\n" . $e], ['json_data' => true]); diff --git a/lib/tools/Config.class.php b/lib/tools/Config.class.php index 32dfed23..76cb6c90 100644 --- a/lib/tools/Config.class.php +++ b/lib/tools/Config.class.php @@ -4,22 +4,6 @@ class Config { const HELP_CONTACT_EMAIL = 'josh@lbry.io'; - //Constant to help with managing strings - const IS_PROD = "is_prod"; - const GITHUB_KEY = "github_key"; - const GITHUB_DEVELOPER_CREDITS_CLIENT_ID = "github_developer_credits_client_id"; - const GITHUB_DEVELOPER_CREDITS_CLIENT_SECRET = "github_developer_credits_client_secret"; - const LBRY_API_SERVER = "lbry_api_server"; - const MAILCHIMP_KEY = "mailchimp_key"; - const ASANA_KEY = "asana_key"; - const AWS_LOG_ACCESS_KEY = "aws_log_access_key"; - const AWS_LOG_SECRET_KEY = "aws_log_secret_key"; - const MAILGUN_API_KEY = "mailgun_api_key"; - const SALESFORCE_KEY = "salesforce_key"; - const SALESFORCE_SECRET = "salesforce_secret"; - const SLACK_ERROR_NOTIFICATION_URL = "slack_error_notification_url"; - - protected static $loaded = false; protected static $data = []; diff --git a/web/index.php b/web/index.php index 118d9395..6212d6ee 100644 --- a/web/index.php +++ b/web/index.php @@ -8,7 +8,7 @@ if (php_sapi_name() === 'cli-server' && is_file(__DIR__.preg_replace('#(\?.*)$#' include __DIR__ . '/../bootstrap.php'; -define('IS_PRODUCTION', Config::get(Config::IS_PROD) === true); +define('IS_PRODUCTION', Config::get('is_prod') === "yes"); ini_set('display_errors', IS_PRODUCTION ? 'off' : 'on'); error_reporting(IS_PRODUCTION ? 0 : (E_ALL | E_STRICT));