1 | <?php |
||
22 | class AuthenticationService implements Authentication, ApplicationInitializedEventAware |
||
23 | { |
||
24 | private const HTTP_OK = 200; |
||
25 | /** @var QueryRepository */ |
||
26 | private $queryRepository; |
||
27 | |||
28 | /** @var ExternalLibraryHttpClient */ |
||
29 | private $httpClient; |
||
30 | |||
31 | /** @var FileManagerService */ |
||
32 | private $fileManager; |
||
33 | |||
34 | /** @var LoggerInterface */ |
||
35 | private $logger; |
||
36 | |||
37 | /** @var EventDispatcherInterface */ |
||
38 | private $dispatcher; |
||
39 | |||
40 | 10 | public function __construct( |
|
53 | |||
54 | 1 | public function onApplicationInitialized(ApplicationInitializedEvent $event = null) : void |
|
63 | |||
64 | /** |
||
65 | * Checks wether you have permission to access chosen ticket tracking platform. |
||
66 | */ |
||
67 | 4 | public function validateTicketTrackingPlatform() : bool |
|
86 | |||
87 | /** |
||
88 | * Checks wether you have permission to access chosen git platform. |
||
89 | * |
||
90 | * @throws ClientException |
||
91 | */ |
||
92 | 4 | public function validateGitPlatform() : bool |
|
93 | { |
||
94 | /** @var string */ |
||
95 | 4 | $bitbucketPath = '/bitbucket'; |
|
96 | |||
97 | try { |
||
98 | 4 | $response = $this->httpClient->request( |
|
99 | 4 | ExternalLibraryHttpClient::GET, |
|
100 | 4 | $bitbucketPath |
|
101 | ); |
||
102 | |||
103 | 3 | if (self::HTTP_OK !== $response->getStatusCode()) { |
|
104 | 1 | $this->logger->warning('Failed to login Bitbucket.'); |
|
105 | |||
106 | 1 | return false; |
|
107 | } |
||
108 | 1 | } catch (ClientException $exception) { |
|
109 | 1 | $this->logger->warning( |
|
110 | 1 | sprintf( |
|
111 | 1 | 'Failed to login Bitbucket. %s ', |
|
112 | 1 | $exception->getMessage() |
|
113 | ) |
||
114 | ); |
||
115 | |||
116 | 1 | return false; |
|
117 | } |
||
118 | |||
119 | 2 | return true; |
|
120 | } |
||
121 | |||
122 | /** |
||
123 | * Checks wether you have permission to access filesystem. |
||
124 | */ |
||
125 | 4 | public function validateFilesystem() : bool |
|
158 | |||
159 | 1 | private function hasProperAccess() : bool |
|
165 | |||
166 | /** |
||
167 | * Combines jira rest api url with jql. |
||
168 | */ |
||
169 | 4 | private function createUrl(string $jql) : string |
|
177 | |||
178 | /** |
||
179 | * Check wether user has permissions to create necessary directories. |
||
180 | * Returns true if yes, false otherwise. |
||
181 | */ |
||
182 | 4 | private function createDirectories(string $projectHomedir, string $symlinkTarget) : bool |
|
187 | |||
188 | /** |
||
189 | * Check wether user has permissions to create necessary files. |
||
190 | * Tries to write to and read from file. |
||
191 | * Returns true if yes, false otherwise. |
||
192 | * |
||
193 | * @throws IOException |
||
194 | * @throws FileNotFoundException |
||
195 | */ |
||
196 | 4 | private function createFiles( |
|
206 | |||
207 | /** |
||
208 | * Check wether user has permissions to remove necessary directories and files. |
||
209 | * Returns true if yes, false otherwise. |
||
210 | * |
||
211 | * @throws IOException |
||
212 | */ |
||
213 | 2 | private function removeFilesAndDirs(string $projectHomedir, string $symlinkTarget, string $snapshot) : bool |
|
222 | } |
||
223 |