get('chill_doc_store')['openstack']['temp_url']; $this->tempUrlKey = $config['temp_url_key']; $this->basePath = $config['temp_url_base_path']; parent::__construct(); } protected function configure() { $this ->setName('chill:doc-store:configure-openstack') ->addOption('os_token', 'o', InputOption::VALUE_REQUIRED, 'Openstack token') ->addOption('domain', 'd', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Domain name') ; } protected function interact(InputInterface $input, OutputInterface $output) { if (!$input->hasOption('os_token')) { $output->writeln('The option os_token is required'); throw new \RuntimeException('The option os_token is required'); } if (0 === count($input->getOption('domain'))) { $output->writeln('At least one occurence of option domain is required'); throw new \RuntimeException('At least one occurence of option domain is required'); } } protected function execute(InputInterface $input, OutputInterface $output): int { $domains = trim(implode(' ', $input->getOption('domain'))); if ($output->isVerbose()) { $output->writeln(['Domains configured will be', $domains]); } try { $response = $this->client->request('POST', $this->basePath, [ 'headers' => [ 'X-Auth-Token' => $input->getOption('os_token'), 'X-Container-Meta-Access-Control-Allow-Origin' => $domains, 'X-Container-Meta-Temp-URL-Key' => $this->tempUrlKey, ], ]); $response->getContent(); } catch (HttpExceptionInterface $e) { $output->writeln('Error'); $output->writeln($e->getMessage()); if ($output->isVerbose()) { $output->writeln($e->getTraceAsString()); } } return Command::SUCCESS; } }