-
Notifications
You must be signed in to change notification settings - Fork 92
/
bucket_domain.go
132 lines (116 loc) · 3.82 KB
/
bucket_domain.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package cos
import (
"context"
"encoding/xml"
"net/http"
)
type BucketDomainRule struct {
Status string `xml:"Status,omitempty"`
Name string `xml:"Name,omitempty"`
Type string `xml:"Type,omitempty"`
ForcedReplacement string `xml:"ForcedReplacement,omitempty"`
}
type BucketPutDomainOptions struct {
XMLName xml.Name `xml:"DomainConfiguration"`
Rules []BucketDomainRule `xml:"DomainRule,omitempty"`
}
type BucketGetDomainResult BucketPutDomainOptions
func (s *BucketService) PutDomain(ctx context.Context, opt *BucketPutDomainOptions) (*Response, error) {
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?domain",
method: http.MethodPut,
body: opt,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return resp, err
}
type BucketGetDomainOptions struct {
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
}
func (s *BucketService) GetDomain(ctx context.Context, opt ...*BucketGetDomainOptions) (*BucketGetDomainResult, *Response, error) {
var gopt *BucketGetDomainOptions
if len(opt) > 0 {
gopt = opt[0]
}
var res BucketGetDomainResult
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?domain",
method: http.MethodGet,
result: &res,
optHeader: gopt,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return &res, resp, err
}
type BucketDeleteDomainOptions struct {
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
}
func (s *BucketService) DeleteDomain(ctx context.Context, opt ...*BucketDeleteDomainOptions) (*Response, error) {
var dopt *BucketDeleteDomainOptions
if len(opt) > 0 {
dopt = opt[0]
}
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?domain",
method: http.MethodDelete,
optHeader: dopt,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return resp, err
}
type BucketPutDomainCertificateOptions struct {
XMLName xml.Name `xml:"DomainCertificate"`
CertificateInfo *BucketDomainCertificateInfo `xml:"CertificateInfo"`
DomainList []string `xml:"DomainList>DomainName"`
}
type BucketDomainCertificateInfo struct {
CertType string `xml:"CertType,omitempty"`
CustomCert *BucketDomainCustomCert `xml:"CustomCert,omitempty"`
}
type BucketDomainCustomCert struct {
Cert string `xml:"Cert,omitempty"`
PrivateKey string `xml:"PrivateKey,omitempty"`
}
func (s *BucketService) PutDomainCertificate(ctx context.Context, opt *BucketPutDomainCertificateOptions) (*Response, error) {
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?domaincertificate",
method: http.MethodPut,
body: opt,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return resp, err
}
type BucketGetDomainCertificateResult struct {
XMLName xml.Name `xml:"DomainCertificate"`
Status string `xml:"Status,omitempty"`
}
type BucketGetDomainCertificateOptions struct {
DomainName string `url:"domainname"`
}
type BucketDeleteDomainCertificateOptions BucketGetDomainCertificateOptions
func (s *BucketService) GetDomainCertificate(ctx context.Context, opt *BucketGetDomainCertificateOptions) (*BucketGetDomainCertificateResult, *Response, error) {
var res BucketGetDomainCertificateResult
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?domaincertificate",
method: http.MethodGet,
optQuery: opt,
result: &res,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return &res, resp, err
}
func (s *BucketService) DeleteDomainCertificate(ctx context.Context, opt *BucketDeleteDomainCertificateOptions) (*Response, error) {
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?domaincertificate",
method: http.MethodDelete,
optQuery: opt,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return resp, err
}