-
Notifications
You must be signed in to change notification settings - Fork 596
/
cloud_connector.go
71 lines (56 loc) · 1.84 KB
/
cloud_connector.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
63
64
65
66
67
68
69
70
71
package cloudflare
import (
"context"
"fmt"
"net/http"
"github.com/goccy/go-json"
)
type CloudConnectorRulesResponse struct {
Response
Result []CloudConnectorRule `json:"result"`
}
type CloudConnectorRuleParameters struct {
Host string `json:"host"`
}
type CloudConnectorRule struct {
ID string `json:"id"`
Enabled *bool `json:"enabled,omitempty"`
Expression string `json:"expression"`
Provider string `json:"provider"`
Parameters CloudConnectorRuleParameters `json:"parameters"`
Description string `json:"description"`
}
func (api *API) ListZoneCloudConnectorRules(ctx context.Context, rc *ResourceContainer) ([]CloudConnectorRule, error) {
if rc.Identifier == "" {
return nil, ErrMissingZoneID
}
uri := buildURI(fmt.Sprintf("/zones/%s/cloud_connector/rules", rc.Identifier), nil)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, err
}
result := CloudConnectorRulesResponse{}
if err := json.Unmarshal(res, &result); err != nil {
return nil, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return result.Result, nil
}
func (api *API) UpdateZoneCloudConnectorRules(ctx context.Context, rc *ResourceContainer, params []CloudConnectorRule) ([]CloudConnectorRule, error) {
if rc.Identifier == "" {
return nil, ErrMissingZoneID
}
uri := fmt.Sprintf("/zones/%s/cloud_connector/rules", rc.Identifier)
payload, err := json.Marshal(params)
if err != nil {
return nil, err
}
res, err := api.makeRequestContext(ctx, http.MethodPut, uri, payload)
if err != nil {
return nil, err
}
result := CloudConnectorRulesResponse{}
if err := json.Unmarshal(res, &result); err != nil {
return nil, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return result.Result, nil
}