From b355bd37a5bb1daa787e73300313a87fd02dbefa Mon Sep 17 00:00:00 2001 From: joshirohit100 Date: Sat, 13 Jan 2024 15:03:48 +0530 Subject: [PATCH] Adding new command to encrypt the variable like in pipeline. --- .../Pipeline/PipelineEncryptVariables.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/Command/Pipeline/PipelineEncryptVariables.php diff --git a/src/Command/Pipeline/PipelineEncryptVariables.php b/src/Command/Pipeline/PipelineEncryptVariables.php new file mode 100644 index 000000000..2905c8bca --- /dev/null +++ b/src/Command/Pipeline/PipelineEncryptVariables.php @@ -0,0 +1,60 @@ +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', + ]); + + $request_params = json_encode([ + 'applications' => [$cloudApplicationUuid], + 'data_item' => $encrypting_string, + 'n3_endpoint' => 'https://cloud.acquia.com', + '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; + } + } + +}