mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
Refactor config with constant instead of strings
This commit is contained in:
parent
2836ba6d4b
commit
ba40e13677
10 changed files with 39 additions and 26 deletions
|
@ -85,13 +85,13 @@ class DeveloperActions extends Actions
|
|||
Session::set(Session::KEY_DEVELOPER_RETURN_URL_SUCCESS, Request::getPostParam('returnUrl'));
|
||||
}
|
||||
|
||||
if (!Config::get('github_developer_credits_client_id'))
|
||||
if (!Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_ID))
|
||||
{
|
||||
throw new Exception('no github client id');
|
||||
}
|
||||
|
||||
$gitHubParams = [
|
||||
'client_id' => Config::get('github_developer_credits_client_id'),
|
||||
'client_id' => Config::get(Config::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('github_developer_credits_client_id'),
|
||||
'client_secret' => Config::get('github_developer_credits_client_secret')
|
||||
'client_id' => Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_ID),
|
||||
'client_secret' => Config::get(Config::GITHUB_DEVELOPER_CREDITS_CLIENT_SECRET)
|
||||
], [
|
||||
'headers' => ['Accept: application/json'],
|
||||
'json_response' => true
|
||||
|
|
|
@ -40,7 +40,7 @@ class OpsActions extends Actions
|
|||
}
|
||||
|
||||
$rawPost = file_get_contents('php://input');
|
||||
$secret = Config::get('github_key');
|
||||
$secret = Config::get(Config::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('aws_log_access_key');
|
||||
$awsSecret = Config::get('aws_log_secret_key');
|
||||
$awsKey = Config::get(Config::AWS_LOG_ACCESS_KEY);
|
||||
$awsSecret = Config::get(Config::AWS_LOG_SECRET_KEY);
|
||||
|
||||
if (!$log || !$name)
|
||||
{
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
<?php
|
||||
$config = [];
|
||||
|
||||
// $config['github_key'] = '';
|
||||
// $config['github_developer_credits_client_id'] = '';
|
||||
// $config['github_developer_credits_client_secret'] = '';
|
||||
// $config['lbry_api_server'] = '';
|
||||
// $config['mailchimp_key'] = '';
|
||||
// $config['asana_key'] = '';
|
||||
// $config['aws_log_access_key'] = '';
|
||||
// $config['aws_log_secret_key'] = '';
|
||||
|
||||
// $config[Config::GITHUB_KEY] = '';
|
||||
// $config[Config::GITHUB_DEVELOPER_CREDITS_CLIENT_ID] = '';
|
||||
// $config[Config::GITHUB_DEVELOPER_CREDITS_CLIENT_SECRET] = '';
|
||||
// $config[Config::LBRY_API_SERVER] = '';
|
||||
// $config[Config::MAILCHIMP_KEY] = '';
|
||||
// $config[Config::ASANA_KEY] = '';
|
||||
// $config[Config::AWS_LOG_ACCESS_KEY] = '';
|
||||
// $config[Config::AWS_LOG_SECRET_KEY] = '';
|
||||
return $config;
|
||||
|
|
2
lib/thirdparty/Asana.class.php
vendored
2
lib/thirdparty/Asana.class.php
vendored
|
@ -80,7 +80,7 @@ class Asana
|
|||
|
||||
protected static function get($endpoint, array $data = [], $cache = true)
|
||||
{
|
||||
$apiKey = Config::get('asana_key');
|
||||
$apiKey = Config::get(Config::ASANA_KEY);
|
||||
|
||||
$options = [
|
||||
'headers' => ['Authorization: Bearer ' . $apiKey],
|
||||
|
|
4
lib/thirdparty/LBRY.class.php
vendored
4
lib/thirdparty/LBRY.class.php
vendored
|
@ -5,7 +5,7 @@ class LBRY
|
|||
{
|
||||
public static function getApiUrl($endpoint)
|
||||
{
|
||||
return Config::get('lbry_api_server') . $endpoint;
|
||||
return Config::get(Config::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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
lib/thirdparty/Mailgun.class.php
vendored
2
lib/thirdparty/Mailgun.class.php
vendored
|
@ -51,7 +51,7 @@ class Mailgun
|
|||
{
|
||||
return Curl::doCurl($method, self::BASE_URL . $endpoint, $data, [
|
||||
'headers' => [
|
||||
'Authorization: Basic ' . base64_encode('api:' . Config::get('mailgun_api_key'))
|
||||
'Authorization: Basic ' . base64_encode('api:' . Config::get(Config::MAILGUN_API_KEY))
|
||||
],
|
||||
'retry' => 3,
|
||||
]);
|
||||
|
|
4
lib/thirdparty/Salesforce.class.php
vendored
4
lib/thirdparty/Salesforce.class.php
vendored
|
@ -45,7 +45,7 @@ class Salesforce
|
|||
|
||||
protected static function getApiUserPassword()
|
||||
{
|
||||
$userpw = Config::get('salesforce_key') . ':' . Config::get('salesforce_secret');
|
||||
$userpw = Config::get(Config::SALESFORCE_KEY) . ':' . Config::get(Config::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
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
2
lib/thirdparty/Slack.class.php
vendored
2
lib/thirdparty/Slack.class.php
vendored
|
@ -10,7 +10,7 @@ class Slack
|
|||
$e = Debug::exceptionToString($e);
|
||||
}
|
||||
|
||||
$slackErrorNotificationUrl = Config::get('slack_error_notification_url');
|
||||
$slackErrorNotificationUrl = Config::get(Config::SLACK_ERROR_NOTIFICATION_URL);
|
||||
if ($slackErrorNotificationUrl)
|
||||
{
|
||||
Curl::post($slackErrorNotificationUrl, ['text' => ($alert ? '<!channel> ' : '') . Request::getRelativeUri() . "\n" . $e], ['json_data' => true]);
|
||||
|
|
|
@ -4,6 +4,22 @@ 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 = [];
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ if (php_sapi_name() === 'cli-server' && is_file(__DIR__.preg_replace('#(\?.*)$#'
|
|||
|
||||
include __DIR__ . '/../bootstrap.php';
|
||||
|
||||
define('IS_PRODUCTION', Config::get('is_prod') === "yes");
|
||||
define('IS_PRODUCTION', Config::get(Config::IS_PROD) === true);
|
||||
|
||||
ini_set('display_errors', IS_PRODUCTION ? 'off' : 'on');
|
||||
error_reporting(IS_PRODUCTION ? 0 : (E_ALL | E_STRICT));
|
||||
|
|
Loading…
Add table
Reference in a new issue