@@ -19,19 +19,66 @@ type Client struct {
19
19
}
20
20
21
21
type Group struct {
22
- Active * string `json:"active,omitempty"`
22
+ Active bool `json:"active"`
23
+ GroupID string `json:"groupId"`
24
+ GroupName string `json:"groupName"`
25
+ LDAPEnabled bool `json:"ldapEnabled"`
26
+ LDAPGroup string `json:"ldapGroup"`
27
+ LDAPMatchAttribute string `json:"ldapMatchAttribute"`
28
+ LDAPSearch string `json:"ldapSearch"`
29
+ LDAPSearchUserBase string `json:"ldapSearchUserBase"`
30
+ LDAPServerURL string `json:"ldapServerURL"`
31
+ LDAPUserDNTemplate string `json:"ldapUserDNTemplate"`
32
+ }
33
+
34
+ // fields must be exported (uppercase) to allow json marshalling
35
+ type groupInternal struct {
36
+ Active string `json:"active"`
23
37
GroupID string `json:"groupId"`
24
- GroupName * string `json:"groupName,omitempty"`
25
- LDAPEnabled * bool `json:"ldapEnabled,omitempty"`
26
- LDAPGroup * string `json:"ldapGroup,omitempty"`
27
- LDAPMatchAttribute * string `json:"ldapMatchAttribute,omitempty"`
28
- LDAPSearch * string `json:"ldapSearch,omitempty"`
29
- LDAPSearchUserBase * string `json:"ldapSearchUserBase,omitempty"`
30
- LDAPServerURL * string `json:"ldapServerURL,omitempty"`
31
- LDAPUserDNTemplate * string `json:"ldapUserDNTemplate,omitempty"`
32
- S3EndpointsHTTP []string `json:"s3endpointshttp,omitempty"`
33
- S3EndpointsHTTPS []string `json:"s3endpointshttps,omitempty"`
34
- S3WebSiteEndpoints []string `json:"s3websiteendpoints,omitempty"`
38
+ GroupName string `json:"groupName"`
39
+ LDAPEnabled bool `json:"ldapEnabled"`
40
+ LDAPGroup string `json:"ldapGroup"`
41
+ LDAPMatchAttribute string `json:"ldapMatchAttribute"`
42
+ LDAPSearch string `json:"ldapSearch"`
43
+ LDAPSearchUserBase string `json:"ldapSearchUserBase"`
44
+ LDAPServerURL string `json:"ldapServerURL"`
45
+ LDAPUserDNTemplate string `json:"ldapUserDNTemplate"`
46
+ S3EndpointsHTTP []string `json:"s3endpointshttp"`
47
+ S3EndpointsHTTPS []string `json:"s3endpointshttps"`
48
+ S3WebSiteEndpoints []string `json:"s3websiteendpoints"`
49
+ }
50
+
51
+ func toInternal (g Group ) groupInternal {
52
+ return groupInternal {
53
+ Active : strconv .FormatBool (g .Active ),
54
+ GroupID : g .GroupID ,
55
+ GroupName : g .GroupName ,
56
+ LDAPEnabled : g .LDAPEnabled ,
57
+ LDAPGroup : g .LDAPGroup ,
58
+ LDAPMatchAttribute : g .LDAPMatchAttribute ,
59
+ LDAPSearch : g .LDAPSearch ,
60
+ LDAPSearchUserBase : g .LDAPSearchUserBase ,
61
+ LDAPServerURL : g .LDAPServerURL ,
62
+ LDAPUserDNTemplate : g .LDAPUserDNTemplate ,
63
+ S3EndpointsHTTP : []string {"ALL" },
64
+ S3EndpointsHTTPS : []string {"ALL" },
65
+ S3WebSiteEndpoints : []string {"ALL" },
66
+ }
67
+ }
68
+
69
+ func fromInternal (g groupInternal ) Group {
70
+ return Group {
71
+ Active : g .Active == "true" ,
72
+ GroupID : g .GroupID ,
73
+ GroupName : g .GroupName ,
74
+ LDAPEnabled : g .LDAPEnabled ,
75
+ LDAPGroup : g .LDAPGroup ,
76
+ LDAPMatchAttribute : g .LDAPMatchAttribute ,
77
+ LDAPSearch : g .LDAPSearch ,
78
+ LDAPSearchUserBase : g .LDAPSearchUserBase ,
79
+ LDAPServerURL : g .LDAPServerURL ,
80
+ LDAPUserDNTemplate : g .LDAPUserDNTemplate ,
81
+ }
35
82
}
36
83
37
84
type User struct {
@@ -179,7 +226,7 @@ func (client Client) DeleteGroup(ctx context.Context, groupId string) error {
179
226
func (client Client ) CreateGroup (ctx context.Context , group Group ) error {
180
227
url := client .baseURL + "/group"
181
228
182
- jsonData , err := json .Marshal (group )
229
+ jsonData , err := json .Marshal (toInternal ( group ) )
183
230
if err != nil {
184
231
return fmt .Errorf ("error marshaling JSON: %w" , err )
185
232
}
@@ -201,7 +248,7 @@ func (client Client) CreateGroup(ctx context.Context, group Group) error {
201
248
func (client Client ) UpdateGroup (ctx context.Context , group Group ) error {
202
249
url := client .baseURL + "/group"
203
250
204
- jsonData , err := json .Marshal (group )
251
+ jsonData , err := json .Marshal (toInternal ( group ) )
205
252
if err != nil {
206
253
return fmt .Errorf ("error marshaling JSON: %w" , err )
207
254
}
@@ -244,12 +291,13 @@ func (client Client) GetGroup(ctx context.Context, groupId string) (*Group, erro
244
291
return nil , fmt .Errorf ("GET reading response body failed: %w" , err )
245
292
}
246
293
247
- var group Group
294
+ var group groupInternal
248
295
if err := json .Unmarshal (body , & group ); err != nil {
249
296
return nil , fmt .Errorf ("GET unmarshal response body failed: %w" , err )
250
297
}
251
298
252
- return & group , nil
299
+ retVal := fromInternal (group )
300
+ return & retVal , nil
253
301
case 204 :
254
302
// Cloudian-API returns 204 if the group does not exist
255
303
return nil , ErrNotFound
0 commit comments