Skip to content

Commit

Permalink
Merge pull request #38 from simonbronner/bugfix/reduce-payload-size-u…
Browse files Browse the repository at this point in the history
…pdate-user-accounts

Provide just the account id(s) in the payload sent to the /admin/user/account endpoint - significant reduction in payload size
  • Loading branch information
vadimgusev-codefresh authored Mar 17, 2021
2 parents 7dcd8d1 + b735379 commit b4ad609
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion client/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ func (client *Client) DeleteUserFromAccount(accountId, userId string) error {
return nil
}

func ToSlimAccount(account Account) Account {
return Account{ID: account.ID}
}

func ToSlimAccounts(accounts []Account) []Account {
var result []Account
for i := 0; i < len(accounts); i++ {
result = append(result, ToSlimAccount(accounts[i]))
}
return result
}

func (client *Client) UpdateUserAccounts(userId string, accounts []Account) error {

// API call '/accounts/{accountId}/{userId}/adduser' doesn't work
Expand All @@ -287,9 +299,11 @@ func (client *Client) UpdateUserAccounts(userId string, accounts []Account) erro
return err
}

var _accounts = ToSlimAccounts(accounts)

postUser := UserAccounts{
UserName: user.UserName,
Account: accounts,
Account: _accounts,
}

body, err := EncodeToJSON(postUser)
Expand Down

0 comments on commit b4ad609

Please sign in to comment.