Skip to content

Commit

Permalink
Merge pull request #21 from pantheon-systems/CMS-1115
Browse files Browse the repository at this point in the history
[CMS-1115] Warn users if an environment is passed in site_id.
  • Loading branch information
kporras07 authored Nov 22, 2022
2 parents c1a6dfd + 7acc008 commit 4223377
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Commands/DeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DeleteCommand extends SecretBaseCommand implements SiteAwareInterface
public function deleteSecret($site_id, string $name, array $options = ['debug' => false])
{
$site = $this->getSite($site_id);
$this->warnIfEnvironmentPresent($site_id);
$this->setupRequest();
if ($this->secretsApi->deleteSecret($site->id, $name, $options['debug'])) {
$this->log()->notice('Success');
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ListCommand extends SecretBaseCommand implements SiteAwareInterface
public function listSecrets($site_id, array $options = ['debug' => false,])
{
$site = $this->getSite($site_id);
$this->warnIfEnvironmentPresent($site_id);
$this->setupRequest();
$secrets = $this->secretsApi->listSecrets($site->id, $options['debug']);
$print_options = [
Expand Down
13 changes: 13 additions & 0 deletions src/Commands/SecretBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,17 @@ protected function setupRequest()
{
$this->secretsApi()->setRequest($this->request());
}

/**
* Warn use if environment is present in site_id.
*
* @param string $site_id
* Site ID.
*/
protected function warnIfEnvironmentPresent(string $site_id)
{
if (preg_match('/.*\..*/', $site_id)) {
$this->log()->warning('Note: Secrets are available for all environments of a site. If you wish to specify secrets for different environments, we recommend using prefixes.');
}
}
}
1 change: 1 addition & 0 deletions src/Commands/SetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function setSecret($site_id, string $name, string $value, array $options
])
{
$site = $this->getSite($site_id);
$this->warnIfEnvironmentPresent($site_id);
$this->setupRequest();
if ($this->secretsApi->setSecret(
$site->id,
Expand Down

0 comments on commit 4223377

Please sign in to comment.