Skip to content

Commit 80321de

Browse files
committed
tf_module access_control and examples
1 parent d9f6a13 commit 80321de

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

client/account.go

+30-19
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ func (client *Client) CreateAccount(account *Account) (*Account, error) {
239239
return nil, err
240240
}
241241

242+
err = client.setAccountFeatures(account.Features, &respAccount)
243+
if err != nil {
244+
return nil, err
245+
}
242246
return &respAccount, nil
243247
}
244248

@@ -284,24 +288,10 @@ func (client *Client) UpdateAccount(account *Account) (*Account, error) {
284288
return nil, err
285289
}
286290

287-
// Update Features
288-
requestOptions := &RequestOptions{}
289-
for k, v := range account.Features{
290-
requestOptions.Body = []byte(fmt.Sprintf("{\"feature\": \"%s\"}", k))
291-
if v {
292-
requestOptions.Path = fmt.Sprintf("/features/%s", id)
293-
requestOptions.Method = "POST"
294-
} else {
295-
requestOptions.Path = fmt.Sprintf("/features/switchOff/%s", id)
296-
requestOptions.Method = "PUT"
297-
}
298-
_, err = client.RequestAPI(requestOptions)
299-
if err != nil {
300-
return nil, err
301-
}
302-
respAccount.Features[k] = v
303-
}
304-
291+
err = client.setAccountFeatures(account.Features, &respAccount)
292+
if err != nil {
293+
return nil, err
294+
}
305295

306296
return &respAccount, nil
307297
}
@@ -335,11 +325,32 @@ func GetAccountAdminsDiff(desiredAdmins []string, existingAdmins []string) (admi
335325
}
336326

337327
for _, id := range desiredAdmins {
338-
339328
if ok := FindInSlice(existingAdmins, id); !ok {
340329
adminsToAdd = append(adminsToAdd, id)
341330
}
342331
}
343332

344333
return adminsToAdd, adminsToDelete
345334
}
335+
336+
// Update Features
337+
func(client *Client) setAccountFeatures(features map[string]bool, account *Account) error {
338+
id := account.GetID()
339+
requestOptions := &RequestOptions{}
340+
for k, v := range features{
341+
requestOptions.Body = []byte(fmt.Sprintf("{\"feature\": \"%s\"}", k))
342+
if v {
343+
requestOptions.Path = fmt.Sprintf("/features/%s", id)
344+
requestOptions.Method = "POST"
345+
} else {
346+
requestOptions.Path = fmt.Sprintf("/features/switchOff/%s", id)
347+
requestOptions.Method = "PUT"
348+
}
349+
_, err := client.RequestAPI(requestOptions)
350+
if err != nil {
351+
return err
352+
}
353+
account.Features[k] = v
354+
}
355+
return nil
356+
}

0 commit comments

Comments
 (0)