-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy.go
46 lines (37 loc) · 903 Bytes
/
policy.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
package headscale
import (
"context"
"net/http"
)
type PolicyResource struct {
Client HeadscaleClientInterface
}
type Policy struct {
Policy string `json:"policy"`
UpdatedAt string `json:"updated_at"`
}
type UpdatePolicyRequest struct {
Policy string `json:"policy"`
}
func (p *PolicyResource) Get(ctx context.Context) (Policy, error) {
var policy Policy
url := p.Client.buildURL("policy")
req, err := p.Client.buildRequest(ctx, http.MethodGet, url, requestOptions{})
if err != nil {
return policy, err
}
err = p.Client.do(ctx, req, &policy)
return policy, err
}
func (p *PolicyResource) Put(ctx context.Context, policy string) error {
url := p.Client.buildURL("policy")
req, err := p.Client.buildRequest(ctx, http.MethodPut, url, requestOptions{
body: UpdatePolicyRequest{
Policy: policy,
},
})
if err != nil {
return err
}
return p.Client.do(ctx, req, nil)
}