...
1 package storage
2
3
4
5
6 import (
7 "net/http"
8 "net/url"
9 "strconv"
10 )
11
12
13 type ServiceProperties struct {
14 Logging *Logging
15 HourMetrics *Metrics
16 MinuteMetrics *Metrics
17 Cors *Cors
18 DeleteRetentionPolicy *RetentionPolicy
19 StaticWebsite *StaticWebsite
20 }
21
22
23 type Logging struct {
24 Version string
25 Delete bool
26 Read bool
27 Write bool
28 RetentionPolicy *RetentionPolicy
29 }
30
31
32 type RetentionPolicy struct {
33 Enabled bool
34 Days *int
35 }
36
37
38 type Metrics struct {
39 Version string
40 Enabled bool
41 IncludeAPIs *bool
42 RetentionPolicy *RetentionPolicy
43 }
44
45
46 type Cors struct {
47 CorsRule []CorsRule
48 }
49
50
51 type CorsRule struct {
52 AllowedOrigins string
53 AllowedMethods string
54 MaxAgeInSeconds int
55 ExposedHeaders string
56 AllowedHeaders string
57 }
58
59
60 type StaticWebsite struct {
61
62 Enabled bool
63
64 IndexDocument *string
65
66 ErrorDocument404Path *string
67 }
68
69 func (c Client) getServiceProperties(service string, auth authentication) (*ServiceProperties, error) {
70 query := url.Values{
71 "restype": {"service"},
72 "comp": {"properties"},
73 }
74 uri := c.getEndpoint(service, "", query)
75 headers := c.getStandardHeaders()
76
77 resp, err := c.exec(http.MethodGet, uri, headers, nil, auth)
78 if err != nil {
79 return nil, err
80 }
81 defer resp.Body.Close()
82
83 if err := checkRespCode(resp, []int{http.StatusOK}); err != nil {
84 return nil, err
85 }
86
87 var out ServiceProperties
88 err = xmlUnmarshal(resp.Body, &out)
89 if err != nil {
90 return nil, err
91 }
92
93 return &out, nil
94 }
95
96 func (c Client) setServiceProperties(props ServiceProperties, service string, auth authentication) error {
97 query := url.Values{
98 "restype": {"service"},
99 "comp": {"properties"},
100 }
101 uri := c.getEndpoint(service, "", query)
102
103
104
105 type StorageServiceProperties struct {
106 Logging *Logging
107 HourMetrics *Metrics
108 MinuteMetrics *Metrics
109 Cors *Cors
110 DeleteRetentionPolicy *RetentionPolicy
111 StaticWebsite *StaticWebsite
112 }
113 input := StorageServiceProperties{
114 Logging: props.Logging,
115 HourMetrics: props.HourMetrics,
116 MinuteMetrics: props.MinuteMetrics,
117 Cors: props.Cors,
118 }
119
120 if service == blobServiceName {
121 input.DeleteRetentionPolicy = props.DeleteRetentionPolicy
122 input.StaticWebsite = props.StaticWebsite
123 }
124
125 body, length, err := xmlMarshal(input)
126 if err != nil {
127 return err
128 }
129
130 headers := c.getStandardHeaders()
131 headers["Content-Length"] = strconv.Itoa(length)
132
133 resp, err := c.exec(http.MethodPut, uri, headers, body, auth)
134 if err != nil {
135 return err
136 }
137 defer drainRespBody(resp)
138 return checkRespCode(resp, []int{http.StatusAccepted})
139 }
140
View as plain text