|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2016 SURFnet. |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
7
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
8
|
|
|
* License, or (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU Affero General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
namespace SURFnet\VPN\Server; |
|
19
|
|
|
|
|
20
|
|
|
use SURFnet\VPN\Server\Exception\InstanceException; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Read the configuration of a particular instance. |
|
24
|
|
|
*/ |
|
25
|
|
|
class InstanceConfig extends Config |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Retrieve a configuration object for a pool. |
|
29
|
|
|
*/ |
|
30
|
|
View Code Duplication |
public function pool($poolId) |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
if (!in_array($poolId, $this->pools())) { |
|
33
|
|
|
throw new InstanceException(sprintf('pool "%s" not found', $poolId)); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return new PoolConfig($this->configData['vpnPools'][$poolId]); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Retrieve a list of all pools. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function pools() |
|
43
|
|
|
{ |
|
44
|
|
|
return array_keys($this->v('vpnPools', [])); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function groupProviders() |
|
48
|
|
|
{ |
|
49
|
|
|
return array_keys($this->v('groupProviders', [])); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
View Code Duplication |
public function groupProvider($groupProviderId) |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
if (!in_array($groupProviderId, $this->groupProviders())) { |
|
55
|
|
|
throw new InstanceException(sprintf('group provider "%s" not found', $groupProviderId)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $this->configData['groupProviders'][$groupProviderId]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function apiConsumers() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->v('apiConsumers'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function instanceNumber() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->v('instanceNumber'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.