/
models.go
343 lines (278 loc) · 9.46 KB
/
models.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package aztables
import (
"time"
generated "github.com/Azure/azure-sdk-for-go/sdk/data/aztables/internal"
)
// CorsRule - CORS is an HTTP feature that enables a web application running under one domain to access resources in another domain. Web browsers implement
// a security restriction known as same-origin policy that
// prevents a web page from calling APIs in a different domain; CORS provides a secure way to allow one domain (the origin domain) to call APIs in another
// domain.
type CorsRule struct {
// REQUIRED; The request headers that the origin domain may specify on the CORS request.
AllowedHeaders *string `xml:"AllowedHeaders"`
// REQUIRED; The methods (HTTP request verbs) that the origin domain may use for a CORS request. (comma separated)
AllowedMethods *string `xml:"AllowedMethods"`
// REQUIRED; The origin domains that are permitted to make a request against the service via CORS. The origin domain is the domain from which the request
// originates. Note that the origin must be an exact
// case-sensitive match with the origin that the user age sends to the service. You can also use the wildcard character '*' to allow all origin domains
// to make requests via CORS.
AllowedOrigins *string `xml:"AllowedOrigins"`
// REQUIRED; The response headers that may be sent in the response to the CORS request and exposed by the browser to the request issuer.
ExposedHeaders *string `xml:"ExposedHeaders"`
// REQUIRED; The maximum amount time that a browser should cache the preflight OPTIONS request.
MaxAgeInSeconds *int32 `xml:"MaxAgeInSeconds"`
}
func (c *CorsRule) toGenerated() *generated.CorsRule {
if c == nil {
return nil
}
return &generated.CorsRule{
AllowedHeaders: c.AllowedHeaders,
AllowedMethods: c.AllowedMethods,
AllowedOrigins: c.AllowedOrigins,
ExposedHeaders: c.ExposedHeaders,
MaxAgeInSeconds: c.MaxAgeInSeconds,
}
}
func fromGeneratedCors(c *generated.CorsRule) *CorsRule {
if c == nil {
return nil
}
return &CorsRule{
AllowedHeaders: c.AllowedHeaders,
AllowedMethods: c.AllowedMethods,
AllowedOrigins: c.AllowedOrigins,
ExposedHeaders: c.ExposedHeaders,
MaxAgeInSeconds: c.MaxAgeInSeconds,
}
}
// ServiceProperties - Service Properties for a given table
type ServiceProperties struct {
// The set of CORS rules.
Cors []*CorsRule `xml:"Cors>CorsRule"`
// A summary of request statistics grouped by API in hourly aggregates for tables.
HourMetrics *Metrics `xml:"HourMetrics"`
// Azure Analytics Logging settings.
Logging *Logging `xml:"Logging"`
// A summary of request statistics grouped by API in minute aggregates for tables.
MinuteMetrics *Metrics `xml:"MinuteMetrics"`
}
func (t *ServiceProperties) toGenerated() *generated.TableServiceProperties {
if t == nil {
return &generated.TableServiceProperties{}
}
return &generated.TableServiceProperties{
Cors: toGeneratedCorsRules(t.Cors),
HourMetrics: toGeneratedMetrics(t.HourMetrics),
Logging: toGeneratedLogging(t.Logging),
MinuteMetrics: toGeneratedMetrics(t.MinuteMetrics),
}
}
func toGeneratedCorsRules(corsRules []*CorsRule) []*generated.CorsRule {
var ret []*generated.CorsRule
for _, c := range corsRules {
ret = append(ret, c.toGenerated())
}
return ret
}
// RetentionPolicy - The retention policy.
type RetentionPolicy struct {
// REQUIRED; Indicates whether a retention policy is enabled for the service.
Enabled *bool `xml:"Enabled"`
// Indicates the number of days that metrics or logging or soft-deleted data should be retained. All data older than this value will be deleted.
Days *int32 `xml:"Days"`
}
func toGeneratedRetentionPolicy(r *RetentionPolicy) *generated.RetentionPolicy {
if r == nil {
return &generated.RetentionPolicy{}
}
return &generated.RetentionPolicy{
Enabled: r.Enabled,
Days: r.Days,
}
}
func fromGeneratedRetentionPolicy(r *generated.RetentionPolicy) *RetentionPolicy {
if r == nil {
return &RetentionPolicy{}
}
return &RetentionPolicy{
Enabled: r.Enabled,
Days: r.Days,
}
}
// Logging - Azure Analytics Logging settings.
type Logging struct {
// REQUIRED; Indicates whether all delete requests should be logged.
Delete *bool `xml:"Delete"`
// REQUIRED; Indicates whether all read requests should be logged.
Read *bool `xml:"Read"`
// REQUIRED; The retention policy.
RetentionPolicy *RetentionPolicy `xml:"RetentionPolicy"`
// REQUIRED; The version of Analytics to configure.
Version *string `xml:"Version"`
// REQUIRED; Indicates whether all write requests should be logged.
Write *bool `xml:"Write"`
}
func toGeneratedLogging(l *Logging) *generated.Logging {
if l == nil {
return nil
}
return &generated.Logging{
Delete: l.Delete,
Read: l.Read,
RetentionPolicy: toGeneratedRetentionPolicy(l.RetentionPolicy),
Version: l.Version,
Write: l.Write,
}
}
func fromGeneratedLogging(g *generated.Logging) *Logging {
if g == nil {
return nil
}
return &Logging{
Delete: g.Delete,
Read: g.Read,
Write: g.Write,
Version: g.Version,
RetentionPolicy: (*RetentionPolicy)(g.RetentionPolicy),
}
}
type Metrics struct {
// REQUIRED; Indicates whether metrics are enabled for the Table service.
Enabled *bool `xml:"Enabled"`
// Indicates whether metrics should generate summary statistics for called API operations.
IncludeAPIs *bool `xml:"IncludeAPIs"`
// The retention policy.
RetentionPolicy *RetentionPolicy `xml:"RetentionPolicy"`
// The version of Analytics to configure.
Version *string `xml:"Version"`
}
func toGeneratedMetrics(m *Metrics) *generated.Metrics {
if m == nil {
return nil
}
return &generated.Metrics{
Enabled: m.Enabled,
IncludeAPIs: m.IncludeAPIs,
Version: m.Version,
RetentionPolicy: toGeneratedRetentionPolicy(m.RetentionPolicy),
}
}
func fromGeneratedMetrics(m *generated.Metrics) *Metrics {
if m == nil {
return &Metrics{}
}
return &Metrics{
Enabled: m.Enabled,
IncludeAPIs: m.IncludeAPIs,
Version: m.Version,
RetentionPolicy: fromGeneratedRetentionPolicy(m.RetentionPolicy),
}
}
// SignedIdentifier - A signed identifier.
type SignedIdentifier struct {
// REQUIRED; The access policy.
AccessPolicy *AccessPolicy `xml:"AccessPolicy"`
// REQUIRED; A unique id.
ID *string `xml:"Id"`
}
func toGeneratedSignedIdentifier(s *SignedIdentifier) *generated.SignedIdentifier {
if s == nil {
return nil
}
return &generated.SignedIdentifier{
ID: s.ID,
AccessPolicy: toGeneratedAccessPolicy(s.AccessPolicy),
}
}
func fromGeneratedSignedIdentifier(s *generated.SignedIdentifier) *SignedIdentifier {
if s == nil {
return nil
}
return &SignedIdentifier{
ID: s.ID,
AccessPolicy: fromGeneratedAccessPolicy(s.AccessPolicy),
}
}
// AccessPolicy - An Access policy.
type AccessPolicy struct {
// REQUIRED; The datetime that the policy expires.
Expiry *time.Time `xml:"Expiry"`
// REQUIRED; The permissions for the acl policy.
Permission *string `xml:"Permission"`
// REQUIRED; The datetime from which the policy is active.
Start *time.Time `xml:"Start"`
}
func toGeneratedAccessPolicy(a *AccessPolicy) *generated.AccessPolicy {
if a == nil {
return nil
}
return &generated.AccessPolicy{
Expiry: a.Expiry,
Permission: a.Permission,
Start: a.Start,
}
}
func fromGeneratedAccessPolicy(g *generated.AccessPolicy) *AccessPolicy {
if g == nil {
return nil
}
return &AccessPolicy{
Expiry: g.Expiry,
Permission: g.Permission,
Start: g.Start,
}
}
type GeoReplication struct {
// REQUIRED; A GMT date/time value, to the second. All primary writes preceding this value are guaranteed to be available for read operations at the secondary.
// Primary writes after this point in time may or may
// not be available for reads.
LastSyncTime *time.Time `xml:"LastSyncTime"`
// REQUIRED; The status of the secondary location.
Status *GeoReplicationStatusType `xml:"Status"`
}
func fromGeneratedGeoReplication(g *generated.GeoReplication) *GeoReplication {
if g == nil {
return nil
}
return &GeoReplication{
LastSyncTime: g.LastSyncTime,
Status: toGeneratedStatusType(g.Status),
}
}
// GeoReplicationStatusType - The status of the secondary location.
type GeoReplicationStatusType string
const (
GeoReplicationStatusTypeBootstrap GeoReplicationStatusType = "bootstrap"
GeoReplicationStatusTypeLive GeoReplicationStatusType = "live"
GeoReplicationStatusTypeUnavailable GeoReplicationStatusType = "unavailable"
)
// PossibleGeoReplicationStatusTypeValues returns the possible values for the GeoReplicationStatusType const type.
func PossibleGeoReplicationStatusTypeValues() []GeoReplicationStatusType {
return []GeoReplicationStatusType{
GeoReplicationStatusTypeBootstrap,
GeoReplicationStatusTypeLive,
GeoReplicationStatusTypeUnavailable,
}
}
// ToPtr returns a *GeoReplicationStatusType pointing to the current value.
func (c GeoReplicationStatusType) ToPtr() *GeoReplicationStatusType {
return &c
}
func toGeneratedStatusType(g *generated.GeoReplicationStatusType) *GeoReplicationStatusType {
if g == nil {
return nil
}
if *g == generated.GeoReplicationStatusTypeBootstrap {
return GeoReplicationStatusTypeBootstrap.ToPtr()
}
if *g == generated.GeoReplicationStatusTypeLive {
return GeoReplicationStatusTypeLive.ToPtr()
}
if *g == generated.GeoReplicationStatusTypeUnavailable {
return GeoReplicationStatusTypeUnavailable.ToPtr()
}
return nil
}