1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AtlassianConnectBundle\Command; |
6
|
|
|
|
7
|
|
|
use AtlassianConnectBundle\Repository\TenantRepositoryInterface; |
8
|
|
|
use AtlassianConnectBundle\Service\AtlassianRestClientInterface; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
class RequestAPICommand extends Command |
16
|
|
|
{ |
17
|
|
|
public function __construct( |
18
|
|
|
private TenantRepositoryInterface $repository, |
19
|
|
|
private AtlassianRestClientInterface $restClient |
20
|
|
|
) { |
21
|
|
|
parent::__construct(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function configure(): void |
25
|
|
|
{ |
26
|
|
|
$this |
27
|
|
|
->setName('ac:request-api') |
28
|
|
|
->addArgument('rest-url', InputArgument::REQUIRED, 'REST api endpoint, like /rest/api/2/issue/{issueIdOrKey}') |
29
|
|
|
->addOption('client-key', 'c', InputOption::VALUE_REQUIRED, 'Client-key from tenant') |
30
|
|
|
->addOption('tenant-id', 't', InputOption::VALUE_REQUIRED, 'Tenant-id') |
31
|
|
|
->setDescription('Request REST end-points. Documentation available on https://docs.atlassian.com/jira/REST/cloud/'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
35
|
|
|
{ |
36
|
|
|
$restUrl = $input->getArgument('rest-url'); |
37
|
|
|
|
38
|
|
|
if ($input->getOption('tenant-id')) { |
39
|
|
|
$tenant = $this->repository->findById($input->getOption('tenant-id')); |
40
|
|
|
} elseif ($input->getOption('client-key')) { |
41
|
|
|
$tenant = $this->repository->findByClientKey($input->getOption('client-key')); |
42
|
|
|
} else { |
43
|
|
|
throw new \RuntimeException('Please provide client-key or tenant-id'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->restClient->setTenant($tenant); |
|
|
|
|
47
|
|
|
|
48
|
|
|
$json = $this->restClient->get($restUrl); |
49
|
|
|
|
50
|
|
|
$output->writeln(''); |
51
|
|
|
$output->writeln($json); |
52
|
|
|
$output->writeln(''); |
53
|
|
|
|
54
|
|
|
return 0; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|