1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Jordan Bieder <[email protected]> |
7
|
|
|
* |
8
|
|
|
* Nextcloud - Two-factor Gateway for Ovh |
9
|
|
|
* |
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
12
|
|
|
* as published by the Free Software Foundation. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider; |
25
|
|
|
|
26
|
|
|
use function array_intersect; |
27
|
|
|
use OCA\TwoFactorGateway\AppInfo\Application; |
28
|
|
|
use OCA\TwoFactorGateway\Exception\ConfigurationException; |
29
|
|
|
use OCP\IConfig; |
30
|
|
|
|
31
|
|
|
class OvhConfig implements IProviderConfig { |
32
|
|
|
|
33
|
|
|
/** @var IConfig */ |
34
|
|
|
private $config; |
35
|
|
|
|
36
|
|
|
public function __construct(IConfig $config) { |
37
|
|
|
$this->config = $config; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
private function getOrFail(string $key): string { |
41
|
|
|
$val = $this->config->getAppValue(Application::APP_NAME, $key, null); |
42
|
|
|
if (is_null($val)) { |
|
|
|
|
43
|
|
|
throw new ConfigurationException(); |
44
|
|
|
} |
45
|
|
|
return $val; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getApplicationKey(): string { |
49
|
|
|
return $this->getOrFail('ovh_application_key'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getApplicationSecret(): string { |
53
|
|
|
return $this->getOrFail('ovh_application_secret'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getConsumerKey(): string { |
57
|
|
|
return $this->getOrFail('ovh_consumer_key'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getEndpoint(): string { |
61
|
|
|
return $this->getOrFail('ovh_endpoint'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getAccount(): string { |
65
|
|
|
return $this->getOrFail('ovh_account'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getSender(): string { |
69
|
|
|
return $this->getOrFail('ovh_sender'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setApplicationKey(string $appKey){ |
73
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_application_key', $appKey); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function setApplicationSecret(string $appSecret){ |
77
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_application_secret', $appSecret); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function setConsumerKey(string $consumerKey){ |
81
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_consumer_key', $consumerKey); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function setEndpoint(string $endpoint){ |
85
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_endpoint', $endpoint); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function setAccount($account){ |
89
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_account', $account); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function setSender($sender){ |
93
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_sender', $sender); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function isComplete(): bool { |
97
|
|
|
$set = $this->config->getAppKeys(Application::APP_NAME); |
98
|
|
|
$expected = [ |
99
|
|
|
'ovh_application_key', |
100
|
|
|
'ovh_application_secret', |
101
|
|
|
'ovh_consumer_key', |
102
|
|
|
'ovh_endpoint', |
103
|
|
|
'ovh_account', |
104
|
|
|
'ovh_sender' |
105
|
|
|
]; |
106
|
|
|
return count(array_intersect($set, $expected)) === count($expected); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
} |
110
|
|
|
|