-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new command to encrypt the variable like in pipeline.
- Loading branch information
1 parent
d341ec9
commit fd081e4
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Acquia\Cli\Command\Pipeline; | ||
|
||
use Acquia\Cli\Attribute\RequireAuth; | ||
use Acquia\Cli\Command\CommandBase; | ||
use GuzzleHttp\Client as GuzzleClient; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[RequireAuth] | ||
#[AsCommand(name: 'pipeline:encrypt-var', description: 'Get the encrypted text to be used for pipeline')] | ||
final class PipelineEncryptVariables extends CommandBase { | ||
|
||
protected function configure(): void { | ||
$this->addArgument('encrypting_string', InputArgument::REQUIRED, 'Text that to be encrypted'); | ||
$this->addArgument('applicationUuid', InputArgument::REQUIRED, 'The Cloud Platform application UUID or alias (i.e. an application name optionally prefixed with the realm)'); | ||
$this->addUsage('SOMESTRINGTOENCRYPT APPUUIDHERE'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int { | ||
$cloudApplicationUuid = $this->determineCloudApplication(); | ||
$encrypting_string = $input->getArgument('encrypting_string'); | ||
|
||
$client = new GuzzleClient([ | ||
'base_uri' => 'https://api.pipelines.acquia.com', | ||
'headers' => [ | ||
'X-ACQUIA-PIPELINES-N3-ENDPOINT' => 'https://account.acquia.com', | ||
], | ||
]); | ||
|
||
$request_params = json_encode([ | ||
'applications' => [$cloudApplicationUuid], | ||
'data_item' => $encrypting_string, | ||
'n3_key' => $this->cloudCredentials->getCloudKey(), | ||
'n3_secret' => $this->cloudCredentials->getCloudSecret(), | ||
]); | ||
|
||
try { | ||
$response = $client->request('POST', '/api/v1/ci/encrypt', [ | ||
'body' => $request_params, | ||
]); | ||
|
||
$encrypted_value = $response->getBody()->getContents(); | ||
|
||
$this->io->success("Encrypted value of '$encrypting_string'"); | ||
$this->io->writeln($encrypted_value); | ||
|
||
return Command::SUCCESS; | ||
} | ||
catch (\Exception $e) { | ||
$this->io->error($e->getMessage()); | ||
return Command::FAILURE; | ||
} | ||
} | ||
|
||
} |