-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml.go
162 lines (139 loc) · 4.66 KB
/
xml.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
package hcp
import (
"bytes"
"encoding/xml"
)
func unmarshal(in []byte, out Payload) error {
return xml.Unmarshal(in, out)
}
type Payload interface {
Reader() (*bytes.Reader, error)
}
/************************
* UserAccount
************************/
// Roles
const (
ADMINISTRATOR = "ADMINISTRATOR"
COMPLIANCE = "COMPLIANCE"
MONITOR = "MONITOR"
SECURITY = "SECURITY"
)
type UserAccount struct {
XMLName xml.Name `xml:"userAccount"`
Username string `xml:"username,omitempty"`
FullName string `xml:"fullName,omitempty"`
Description string `xml:"description,omitempty"`
LocalAuthentication bool `xml:"localAuthentication,omitempty"`
ForcePasswordChange bool `xml:"forcePasswordChange"`
Enabled bool `xml:"enabled"`
Roles []string `xml:"roles>role,omitempty"`
AllowNamespaceManagement bool `xml:"allowNamespaceManagement,omitempty"`
}
func (uA *UserAccount) marshal() ([]byte, error) {
return xml.Marshal(uA)
}
func (uA *UserAccount) Reader() (*bytes.Reader, error) {
if xml, error := uA.marshal(); error != nil {
return nil, error
} else {
return bytes.NewReader(xml), nil
}
}
/************************
* Namespace
************************/
// Hashing schemes
const (
SHA_512 = "SHA-512"
SHA_384 = "SHA-384"
SHA_256 = "SHA-256"
MD5 = "MD5"
SHA_1 = "SHA-1"
RIPEMD160 = "RIPEMD160"
)
// Optimized for
const (
ALL = "ALL"
CLOUD = "CLOUD"
)
// Hard quota units
const (
GB = "GB"
TB = "TB"
)
// ACL usage
const (
NOT_ENABLED = "NOT_ENABLED"
ENFORCED = "ENFORCED"
NOT_ENFORCED = "NOT_ENFORCED"
)
// Owner type
const (
LOCAL = "LOCAL"
EXTERNAL = "EXTERNAL"
)
type Namespace struct {
XMLName xml.Name `xml:"namespace"`
Name string `xml:"name,omitempty"`
Description string `xml:"description,omitempty"`
HashScheme string `xml:"hashScheme,omitempty"`
EnterpriseMode bool `xml:"enterpriseMode"`
HardQuota string `xml:"hardQuota,omitempty"`
SoftQuota int `xml:"softQuota,omitempty"`
OptimizedFor string `xml:"optimizedFor,omitempty"`
VersioningSettings *VersioningSettings `xml:"versioningSettings,omitempty"`
SearchEnabled bool `xml:"searchEnabled"`
IndexingEnabled bool `xml:"indexingEnabled"`
CustomMetadataIndexingEnabled bool `xml:"customMetadataIndexingEnabled"`
ReplicationEnabled bool `xml:"replicationEnabled"`
ReadFromReplica bool `xml:"readFromReplica"`
ServiceRemoteSystemRequests bool `xml:"serviceRemoteSystemRequests"`
AclsUsage string `xml:"aclsUsage,omitempty"`
OwnerType string `xml:"ownerType,omitempty"`
Owner string `xml:"owner,omitempty"`
Tags []string `xml:"tags>tag,omitempty"`
}
type VersioningSettings struct {
Enabled bool `xml:"enabled"`
Prune bool `xml:"prune"`
PruneDays int `xml:"pruneDays"`
}
func (ns *Namespace) marshal() ([]byte, error) {
return xml.Marshal(ns)
}
func (ns *Namespace) Reader() (*bytes.Reader, error) {
if xml, error := ns.marshal(); error != nil {
return nil, error
} else {
return bytes.NewReader(xml), nil
}
}
/************************
* Namespace Protocol Http
************************/
type HttpProtocol struct {
XMLName xml.Name `xml:"httpProtocol"`
Hs3Enabled bool `xml:"hs3Enabled"`
Hs3RequiresAuthentication bool `xml:"hs3RequiresAuthentication"`
HttpEnabled bool `xml:"httpEnabled"`
HttpsEnabled bool `xml:"httpsEnabled"`
RestEnabled bool `xml:"restEnabled"`
RestRequiresAuthentication bool `xml:"restRequiresAuthentication"`
IpSettings *IpSettings `xml:"ipSettings"`
}
type IpSettings struct {
AllowAddresses []string `xml:"allowAddresses>ipAddress"`
DenyAddresses []string `xml:"denyAddresses>ipAddress"`
AllowIfInBothLists bool `xml:"allowIfInBothLists"`
}
func (uA *HttpProtocol) marshal() ([]byte, error) {
return xml.Marshal(uA)
}
func (uA *HttpProtocol) Reader() (*bytes.Reader, error) {
if xml, error := uA.marshal(); error != nil {
return nil, error
} else {
return bytes.NewReader(xml), nil
}
}