ClientHelper::getMonitorURL()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace BiffBangPow\SSMonitor\Server\Helper;
4
5
use BiffBangPow\SSMonitor\Server\Model\Client;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Control\Director;
8
use SilverStripe\Core\Environment;
9
10
class ClientHelper
11
{
12
    const CLIENT_ENDPOINT = 'montoro';
13
14
    private Client $client;
15
16
    private $encHelper;
17
18
    public function __construct(Client $client)
19
    {
20
        $this->client = $client;
21
        $storageSecret = Environment::getEnv('MONITORING_STORAGE_SECRET');
22
        $storageSalt = Environment::getEnv('MONITORING_STORAGE_SALT');
23
        $this->encHelper = new EncryptionHelper($storageSecret, $storageSalt);
24
    }
25
26
    /**
27
     * Builds the full monitoring URL for the client
28
     * @return string
29
     */
30
    public function getMonitorURL()
31
    {
32
        return Controller::join_links([
33
            $this->client->BaseURL,
34
            self::CLIENT_ENDPOINT
35
        ]);
36
    }
37
38
    /**
39
     * Get the API key for the client
40
     * @return false|string
41
     */
42
    public function getAPIKey()
43
    {
44
        return $this->encHelper->decrypt($this->client->APIKey);
45
    }
46
47
    /**
48
     * Get the encryption secret for the client
49
     * @return false|string
50
     */
51
    public function getEncryptionSecret()
52
    {
53
        return $this->encHelper->decrypt($this->client->EncSecret);
54
    }
55
56
    /**
57
     * Get the encryption salt for the client
58
     * @return false|string
59
     */
60
    public function getEncryptionSalt()
61
    {
62
        return $this->encHelper->decrypt($this->client->EncSalt);
63
    }
64
65
}
66