Skip to content

Commit 267bd94

Browse files
Merge pull request #7 from codefresh-io/gofmt-fixes
Gofmt formatting fixes
2 parents 054600d + db0a2e7 commit 267bd94

File tree

21 files changed

+5302
-5309
lines changed

21 files changed

+5302
-5309
lines changed

client/account.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (client *Client) GetAccountByName(name string) (*Account, error) {
183183
opts := RequestOptions{
184184
Path: "/admin/accounts",
185185
Method: "GET",
186-
QS: map[string]string{"filter[name]": name},
186+
QS: map[string]string{"filter[name]": name},
187187
}
188188

189189
resp, err := client.RequestAPI(&opts)
@@ -200,10 +200,10 @@ func (client *Client) GetAccountByName(name string) (*Account, error) {
200200
}
201201

202202
var account *Account
203-
for _, acc := range(accounts) {
203+
for _, acc := range accounts {
204204
if acc.Name == name {
205205
account = &acc
206-
}
206+
}
207207
}
208208
if account == nil {
209209
return nil, fmt.Errorf("GetAccountByName - cannot find account by name %s", name)
@@ -279,7 +279,7 @@ func (client *Client) CreateAccount(account *Account) (*Account, error) {
279279
err = client.setAccountFeatures(account.Features, &respAccount)
280280
if err != nil {
281281
return nil, err
282-
}
282+
}
283283
return &respAccount, nil
284284
}
285285

@@ -324,11 +324,11 @@ func (client *Client) UpdateAccount(account *Account) (*Account, error) {
324324
if err != nil {
325325
return nil, err
326326
}
327-
327+
328328
err = client.setAccountFeatures(account.Features, &respAccount)
329329
if err != nil {
330330
return nil, err
331-
}
331+
}
332332

333333
return &respAccount, nil
334334
}
@@ -371,23 +371,23 @@ func GetAccountAdminsDiff(desiredAdmins []string, existingAdmins []string) (admi
371371
}
372372

373373
// Update Features
374-
func(client *Client) setAccountFeatures(features map[string]bool, account *Account) error {
374+
func (client *Client) setAccountFeatures(features map[string]bool, account *Account) error {
375375
id := account.GetID()
376376
requestOptions := &RequestOptions{}
377-
for k, v := range features{
377+
for k, v := range features {
378378
requestOptions.Body = []byte(fmt.Sprintf("{\"feature\": \"%s\"}", k))
379379
if v {
380380
requestOptions.Path = fmt.Sprintf("/features/%s", id)
381381
requestOptions.Method = "POST"
382382
} else {
383383
requestOptions.Path = fmt.Sprintf("/features/switchOff/%s", id)
384-
requestOptions.Method = "PUT"
385-
}
384+
requestOptions.Method = "PUT"
385+
}
386386
_, err := client.RequestAPI(requestOptions)
387387
if err != nil {
388388
return err
389389
}
390390
account.Features[k] = v
391391
}
392392
return nil
393-
}
393+
}

client/api_key.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ func (client *Client) CreateApiKey(userID string, accountId string, apiKey *ApiK
114114
userID, err = client.createRandomUser(accountId)
115115
if err != nil {
116116
return "", err
117-
}
118-
}
117+
}
118+
}
119119
// login as user
120120
xAccessToken, err = client.GetXAccessToken(userID, accountId)
121121
if err != nil {
122122
return "", err
123-
}
123+
}
124124

125125
// generate token
126126
apiToken, err := client.GenerateToken(xAccessToken, apiKey)
@@ -261,4 +261,4 @@ func (client *Client) createRandomUser(accountId string) (string, error) {
261261
}
262262
return userID, nil
263263

264-
}
264+
}

client/current_account.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package client
22

33
import (
4-
"fmt"
54
"encoding/json"
5+
"fmt"
66
"github.com/stretchr/objx"
77
)
88

@@ -15,9 +15,9 @@ type CurrentAccountUser struct {
1515

1616
// CurrentAccount spec
1717
type CurrentAccount struct {
18-
ID string
19-
Name string
20-
Users []CurrentAccountUser
18+
ID string
19+
Name string
20+
Users []CurrentAccountUser
2121
}
2222

2323
// GetCurrentAccount -
@@ -32,7 +32,7 @@ func (client *Client) GetCurrentAccount() (*CurrentAccount, error) {
3232
return nil, err
3333
}
3434
userRespStr := string(userResp)
35-
currentAccountX, err := objx.FromJSON(userRespStr)
35+
currentAccountX, err := objx.FromJSON(userRespStr)
3636
if err != nil {
3737
return nil, err
3838
}
@@ -42,12 +42,12 @@ func (client *Client) GetCurrentAccount() (*CurrentAccount, error) {
4242
return nil, fmt.Errorf("GetCurrentAccount - cannot get activeAccountName")
4343
}
4444
currentAccount := &CurrentAccount{
45-
Name: activeAccountName,
45+
Name: activeAccountName,
4646
Users: make([]CurrentAccountUser, 0),
4747
}
4848

4949
allAccountsI := currentAccountX.Get("account").InterSlice()
50-
for _, accI := range(allAccountsI) {
50+
for _, accI := range allAccountsI {
5151
accX := objx.New(accI)
5252
if accX.Get("name").String() == activeAccountName {
5353
currentAccount.ID = accX.Get("id").String()
@@ -71,12 +71,12 @@ func (client *Client) GetCurrentAccount() (*CurrentAccount, error) {
7171
if e := json.Unmarshal(accountUsersResp, &accountUsersI); e != nil {
7272
return nil, fmt.Errorf("Cannot unmarshal accountUsers responce for accountId=%s: %v", currentAccount.ID, e)
7373
}
74-
for _, userI := range(accountUsersI) {
74+
for _, userI := range accountUsersI {
7575
userX := objx.New(userI)
7676
userName := userX.Get("userName").String()
7777
email := userX.Get("email").String()
7878
userID := userX.Get("_id").String()
79-
currentAccount.Users= append(currentAccount.Users, CurrentAccountUser{
79+
currentAccount.Users = append(currentAccount.Users, CurrentAccountUser{
8080
ID: userID,
8181
UserName: userName,
8282
Email: email,

client/permission.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import (
77

88
// Permission spec
99
type Permission struct {
10-
ID string `json:"id,omitempty"`
11-
Team string `json:"role,omitempty"`
12-
Resource string `json:"resource,omitempty"`
13-
Action string `json:"action,omitempty"`
14-
Account string `json:"account,omitempty"`
15-
Tags []string `json:"attributes,omitempty"`
10+
ID string `json:"id,omitempty"`
11+
Team string `json:"role,omitempty"`
12+
Resource string `json:"resource,omitempty"`
13+
Action string `json:"action,omitempty"`
14+
Account string `json:"account,omitempty"`
15+
Tags []string `json:"attributes,omitempty"`
1616
}
1717

1818
// NewPermission spec, diffs from Permission is `json:"team,omitempty"` vs `json:"role,omitempty"`
1919
type NewPermission struct {
20-
ID string `json:"_id,omitempty"`
21-
Team string `json:"team,omitempty"`
22-
Resource string `json:"resource,omitempty"`
23-
Action string `json:"action,omitempty"`
24-
Account string `json:"account,omitempty"`
25-
Tags []string `json:"tags,omitempty"`
20+
ID string `json:"_id,omitempty"`
21+
Team string `json:"team,omitempty"`
22+
Resource string `json:"resource,omitempty"`
23+
Action string `json:"action,omitempty"`
24+
Account string `json:"account,omitempty"`
25+
Tags []string `json:"tags,omitempty"`
2626
}
2727

2828
// GetPermissionList -
@@ -56,7 +56,7 @@ func (client *Client) GetPermissionList(teamID, action, resource string) ([]Perm
5656
if resource != "" && p.Resource != resource {
5757
continue
5858
}
59-
permissionsFiltered = append(permissionsFiltered, p)
59+
permissionsFiltered = append(permissionsFiltered, p)
6060
}
6161

6262
return permissionsFiltered, nil
@@ -85,15 +85,15 @@ func (client *Client) GetPermissionByID(id string) (*Permission, error) {
8585
}
8686

8787
// CreatePermision -
88-
func (client *Client) CreatePermission(permission *Permission) (*Permission, error) {
88+
func (client *Client) CreatePermission(permission *Permission) (*Permission, error) {
8989

9090
newPermission := &NewPermission{
91-
ID: permission.ID,
92-
Team: permission.Team,
91+
ID: permission.ID,
92+
Team: permission.Team,
9393
Resource: permission.Resource,
94-
Action: permission.Action,
95-
Account: permission.Account,
96-
Tags: permission.Tags,
94+
Action: permission.Action,
95+
Account: permission.Account,
96+
Tags: permission.Tags,
9797
}
9898

9999
body, err := EncodeToJSON(newPermission)
@@ -125,7 +125,7 @@ func (client *Client) CreatePermission(permission *Permission) (*Permission, er
125125
}
126126

127127
newPermissionID := permissionResp[0].ID
128-
128+
129129
return client.GetPermissionByID(newPermissionID)
130130
}
131131

@@ -144,4 +144,4 @@ func (client *Client) DeletePermission(id string) error {
144144
}
145145

146146
return nil
147-
}
147+
}

codefresh/data_account.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func dataSourceAccount() *schema.Resource {
1010
return &schema.Resource{
11-
Read: dataSourceAccountRead,
11+
Read: dataSourceAccountRead,
1212
Schema: map[string]*schema.Schema{
1313
"_id": {
1414
Type: schema.TypeString,
@@ -24,7 +24,7 @@ func dataSourceAccount() *schema.Resource {
2424
Elem: &schema.Schema{
2525
Type: schema.TypeString,
2626
},
27-
},
27+
},
2828
},
2929
}
3030
}
@@ -50,11 +50,11 @@ func dataSourceAccountRead(d *schema.ResourceData, meta interface{}) error {
5050
return fmt.Errorf("data.codefresh_account - cannot find account")
5151
}
5252

53-
return mapDataAccountToResource(account, d)
53+
return mapDataAccountToResource(account, d)
5454
}
5555

5656
func mapDataAccountToResource(account *cfClient.Account, d *schema.ResourceData) error {
57-
57+
5858
if account == nil || account.ID == "" {
5959
return fmt.Errorf("data.codefresh_account - failed to mapDataAccountToResource")
6060
}
@@ -66,4 +66,3 @@ func mapDataAccountToResource(account *cfClient.Account, d *schema.ResourceData)
6666

6767
return nil
6868
}
69-

codefresh/data_current_account.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func dataSourceCurrentAccount() *schema.Resource {
1010
return &schema.Resource{
11-
Read: dataSourceCurrentAccountRead,
11+
Read: dataSourceCurrentAccountRead,
1212
Schema: map[string]*schema.Schema{
1313
"name": {
1414
Type: schema.TypeString,
@@ -34,15 +34,14 @@ func dataSourceCurrentAccount() *schema.Resource {
3434
"email": {
3535
Type: schema.TypeString,
3636
Required: true,
37-
},
37+
},
3838
},
3939
},
40-
},
40+
},
4141
},
4242
}
4343
}
4444

45-
4645
func dataSourceCurrentAccountRead(d *schema.ResourceData, meta interface{}) error {
4746
client := meta.(*cfClient.Client)
4847
var currentAccount *cfClient.CurrentAccount
@@ -57,22 +56,22 @@ func dataSourceCurrentAccountRead(d *schema.ResourceData, meta interface{}) erro
5756
return fmt.Errorf("data.codefresh_current_account - failed to get current_account")
5857
}
5958

60-
return mapDataCurrentAccountToResource(currentAccount, d)
59+
return mapDataCurrentAccountToResource(currentAccount, d)
6160

6261
}
6362

6463
func mapDataCurrentAccountToResource(currentAccount *cfClient.CurrentAccount, d *schema.ResourceData) error {
65-
64+
6665
if currentAccount == nil || currentAccount.ID == "" {
6766
return fmt.Errorf("data.codefresh_current_account - failed to mapDataCurrentAccountToResource")
6867
}
6968
d.SetId(currentAccount.ID)
7069

7170
d.Set("_id", currentAccount.ID)
7271
d.Set("name", currentAccount.Name)
73-
72+
7473
// users := make(map[string](map[string]interface{}))
75-
// for n, user := range currentAccount.Users {
74+
// for n, user := range currentAccount.Users {
7675
// users[n] = make(map[string]interface{})
7776
// users[n]["name"] = user.UserName
7877
// users[n]["email"] = user.Email
@@ -87,7 +86,7 @@ func mapDataCurrentAccountToResource(currentAccount *cfClient.CurrentAccount, d
8786
users[n]["email"] = user.Email
8887
users[n]["id"] = user.ID
8988
}
90-
91-
d.Set("users", users)
89+
90+
d.Set("users", users)
9291
return nil
9392
}

0 commit comments

Comments
 (0)