-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtls.go
62 lines (52 loc) · 1.25 KB
/
tls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package adguard
import (
"encoding/json"
"fmt"
"net/http"
"strings"
)
// GetTlsConfig - Returns TLS configuration and status
func (c *ADG) GetTlsConfig() (*TlsConfig, error) {
// initialize request
req, err := http.NewRequest("GET", fmt.Sprintf("%s/tls/status", c.HostURL), nil)
if err != nil {
return nil, err
}
// perform request
body, err := c.doRequest(req)
if err != nil {
return nil, err
}
// convert response to AccessList object
var tlsConfig TlsConfig
err = json.Unmarshal(body, &tlsConfig)
if err != nil {
return nil, err
}
return &tlsConfig, nil
}
// SetTlsConfig - Sets the TLS configuration
func (c *ADG) SetTlsConfig(tlsConfig TlsConfig) (*TlsConfig, error) {
// convert provided TLS config to JSON
rb, err := json.Marshal(tlsConfig)
if err != nil {
return nil, err
}
// initialize request
req, err := http.NewRequest("POST", fmt.Sprintf("%s/tls/configure", c.HostURL), strings.NewReader(string(rb)))
if err != nil {
return nil, err
}
// perform request
body, err := c.doRequest(req)
if err != nil {
return nil, err
}
// convert response to TlsConfig object
var responseTlsConfig TlsConfig
err = json.Unmarshal(body, &responseTlsConfig)
if err != nil {
return nil, err
}
return &responseTlsConfig, nil
}