Skip to content

Commit

Permalink
Merge pull request #332 from TheBlockCrypto/config-via-env-vars
Browse files Browse the repository at this point in the history
Add support for configuration via environment vars
  • Loading branch information
jacobbednarz authored Feb 11, 2021
2 parents f2d0352 + 0dfcb5f commit bba146a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

// The following constants are available. Add them to wp-config.php to enable.

// To configure Cloudflare credentials via environment vars (defined elsewhere)
// define('CLOUDFLARE_EMAIL', $_ENV['CLOUDFLARE_EMAIL']);
// define('CLOUDFLARE_API_KEY', $_ENV['CLOUDFLARE_API_KEY']);
// define('CLOUDFLARE_DOMAIN_NAME', $_ENV['CLOUDFLARE_DOMAIN_NAME']);

// To enable HTTP/2 Server Push feature:
// define('CLOUDFLARE_HTTP2_SERVER_PUSH_ACTIVE', true);

Expand Down
20 changes: 20 additions & 0 deletions src/WordPress/DataStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function setWordPressWrapper(WordPressWrapper $wordPressWrapper)
*/
public function createUserDataStore($client_api_key, $email, $unique_id, $user_key)
{
if (defined('CLOUDFLARE_API_KEY') && defined('CLOUDFLARE_EMAIL')) {
return true;
}

// Clear options
$this->set(self::API_KEY, '');
$this->set(self::EMAIL, '');
Expand All @@ -63,6 +67,10 @@ public function getHostAPIUserUniqueId()
*/
public function getClientV4APIKey()
{
if (defined('CLOUDFLARE_API_KEY') && CLOUDFLARE_API_KEY !== '') {
return CLOUDFLARE_API_KEY;
}

return $this->get(self::API_KEY);
}

Expand All @@ -79,6 +87,10 @@ public function getHostAPIUserKey()
*/
public function getDomainNameCache()
{
if (defined('CLOUDFLARE_DOMAIN_NAME') && CLOUDFLARE_DOMAIN_NAME !== '') {
return CLOUDFLARE_DOMAIN_NAME;
}

$cachedDomainName = $this->get(self::CACHED_DOMAIN_NAME);
if (empty($cachedDomainName)) {
return;
Expand All @@ -92,6 +104,10 @@ public function getDomainNameCache()
*/
public function setDomainNameCache($domainName)
{
if (defined('CLOUDFLARE_DOMAIN_NAME') && CLOUDFLARE_DOMAIN_NAME !== '') {
return;
}

return $this->set(self::CACHED_DOMAIN_NAME, $domainName);
}

Expand All @@ -100,6 +116,10 @@ public function setDomainNameCache($domainName)
*/
public function getCloudFlareEmail()
{
if (defined('CLOUDFLARE_EMAIL') && CLOUDFLARE_EMAIL !== '') {
return CLOUDFLARE_EMAIL;
}

return $this->get(self::EMAIL);
}

Expand Down

0 comments on commit bba146a

Please sign in to comment.