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
|
|
|
const expected = [ |
34
|
|
|
'ovh_application_key', |
35
|
|
|
'ovh_application_secret', |
36
|
|
|
'ovh_consumer_key', |
37
|
|
|
'ovh_endpoint', |
38
|
|
|
'ovh_account', |
39
|
|
|
'ovh_sender' |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
/** @var IConfig */ |
43
|
|
|
private $config; |
44
|
|
|
|
45
|
|
|
public function __construct(IConfig $config) { |
46
|
|
|
$this->config = $config; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function getOrFail(string $key): string { |
50
|
|
|
$val = $this->config->getAppValue(Application::APP_NAME, $key, null); |
51
|
|
|
if (is_null($val)) { |
|
|
|
|
52
|
|
|
throw new ConfigurationException(); |
53
|
|
|
} |
54
|
|
|
return $val; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getApplicationKey(): string { |
58
|
|
|
return $this->getOrFail('ovh_application_key'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getApplicationSecret(): string { |
62
|
|
|
return $this->getOrFail('ovh_application_secret'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getConsumerKey(): string { |
66
|
|
|
return $this->getOrFail('ovh_consumer_key'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getEndpoint(): string { |
70
|
|
|
return $this->getOrFail('ovh_endpoint'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getAccount(): string { |
74
|
|
|
return $this->getOrFail('ovh_account'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getSender(): string { |
78
|
|
|
return $this->getOrFail('ovh_sender'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function setApplicationKey(string $appKey) { |
82
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_application_key', $appKey); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function setApplicationSecret(string $appSecret) { |
86
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_application_secret', $appSecret); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function setConsumerKey(string $consumerKey) { |
90
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_consumer_key', $consumerKey); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function setEndpoint(string $endpoint) { |
94
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_endpoint', $endpoint); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function setAccount($account) { |
98
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_account', $account); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function setSender($sender) { |
102
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'ovh_sender', $sender); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function isComplete(): bool { |
106
|
|
|
$set = $this->config->getAppKeys(Application::APP_NAME); |
107
|
|
|
return count(array_intersect($set, self::expected)) === count(self::expected); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function remove() { |
111
|
|
|
foreach(self::expected as $key) { |
112
|
|
|
$this->config->deleteAppValue(Application::APP_NAME, $key); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|