From 897b2d9eb534eb1087ef1504f2f302569b399566 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 17 Mar 2025 13:46:17 +0000 Subject: [PATCH 1/2] Provide tunnel:info --env option to generate environment variables --- src/Command/Tunnel/TunnelInfoCommand.php | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Command/Tunnel/TunnelInfoCommand.php b/src/Command/Tunnel/TunnelInfoCommand.php index 77e3fa911e..157e04e0c5 100644 --- a/src/Command/Tunnel/TunnelInfoCommand.php +++ b/src/Command/Tunnel/TunnelInfoCommand.php @@ -13,7 +13,8 @@ protected function configure() ->setName('tunnel:info') ->setDescription("View relationship info for SSH tunnels") ->addOption('property', 'P', InputOption::VALUE_REQUIRED, 'The relationship property to view') - ->addOption('encode', 'c', InputOption::VALUE_NONE, 'Output as base64-encoded JSON'); + ->addOption('encode', 'c', InputOption::VALUE_NONE, 'Output as base64-encoded JSON') + ->addOption('env', null, InputOption::VALUE_NONE, 'Output as a list of environment variables'); $this->addProjectOption(); $this->addEnvironmentOption(); $this->addAppOption(); @@ -60,6 +61,29 @@ protected function execute(InputInterface $input, OutputInterface $output) return 1; } + if ($input->getOption('env')) { + if ($input->getOption('property') || $input->getOption('encode')) { + $this->stdErr->writeln('You cannot combine --env with --encode or --property.'); + return 1; + } + + $envPrefix = $this->config()->get('service.env_prefix'); + $output->writeln($envPrefix . 'RELATIONSHIPS=' . base64_encode(json_encode($relationships))); + + foreach ($relationships as $name => $services) { + if (!isset($services[0])) { + continue; + } + foreach ($services[0] as $key => $value) { + if (is_scalar($value)) { + $output->writeln(strtoupper($name) . '_' . strtoupper($key) . '=' . $value); + } + } + } + + return 0; + } + if ($input->getOption('encode')) { if ($input->getOption('property')) { $this->stdErr->writeln('You cannot combine --encode with --property.'); From 9c74a1e12ff57ff9af3392cd83a8e1f58674b07e Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 17 Mar 2025 14:33:45 +0000 Subject: [PATCH 2/2] Add "export" prefix --- src/Command/Tunnel/TunnelInfoCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Command/Tunnel/TunnelInfoCommand.php b/src/Command/Tunnel/TunnelInfoCommand.php index 157e04e0c5..58eed0f9d5 100644 --- a/src/Command/Tunnel/TunnelInfoCommand.php +++ b/src/Command/Tunnel/TunnelInfoCommand.php @@ -14,7 +14,7 @@ protected function configure() ->setDescription("View relationship info for SSH tunnels") ->addOption('property', 'P', InputOption::VALUE_REQUIRED, 'The relationship property to view') ->addOption('encode', 'c', InputOption::VALUE_NONE, 'Output as base64-encoded JSON') - ->addOption('env', null, InputOption::VALUE_NONE, 'Output as a list of environment variables'); + ->addOption('env', null, InputOption::VALUE_NONE, 'Output as a list of environment variables ("export" statements)'); $this->addProjectOption(); $this->addEnvironmentOption(); $this->addAppOption(); @@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $envPrefix = $this->config()->get('service.env_prefix'); - $output->writeln($envPrefix . 'RELATIONSHIPS=' . base64_encode(json_encode($relationships))); + $output->writeln('export ' . $envPrefix . 'RELATIONSHIPS=' . base64_encode(json_encode($relationships))); foreach ($relationships as $name => $services) { if (!isset($services[0])) { @@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } foreach ($services[0] as $key => $value) { if (is_scalar($value)) { - $output->writeln(strtoupper($name) . '_' . strtoupper($key) . '=' . $value); + $output->writeln('export ' . strtoupper($name) . '_' . strtoupper($key) . '=' . $value); } } }