Skip to content

Commit c5490af

Browse files
committed
Add user resource
1 parent bf618e4 commit c5490af

File tree

7 files changed

+466
-17
lines changed

7 files changed

+466
-17
lines changed

client/account.go

+41-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package client
33
import (
44
"errors"
55
"fmt"
6-
"github.com/imdario/mergo"
76
"log"
87
"strconv"
8+
9+
"github.com/imdario/mergo"
910
)
1011

1112
type DockerRegistry struct {
@@ -180,6 +181,45 @@ func (client *Client) GetAccountByID(id string) (*Account, error) {
180181
return &account, nil
181182
}
182183

184+
func (client *Client) GetAllAccounts() (*[]Account, error) {
185+
186+
opts := RequestOptions{
187+
Path: "/admin/accounts",
188+
Method: "GET",
189+
}
190+
191+
resp, err := client.RequestAPI(&opts)
192+
193+
if err != nil {
194+
return nil, err
195+
}
196+
197+
var accounts []Account
198+
199+
err = DecodeResponseInto(resp, &accounts)
200+
if err != nil {
201+
return nil, err
202+
}
203+
204+
return &accounts, nil
205+
}
206+
207+
func (client *Client) GetAccountsList(accountsId []string) (*[]Account, error) {
208+
209+
var accounts []Account
210+
211+
for _, accountId := range accountsId {
212+
account, err := client.GetAccountByID(accountId)
213+
if err != nil {
214+
return nil, err
215+
}
216+
217+
accounts = append(accounts, *account)
218+
}
219+
220+
return &accounts, nil
221+
}
222+
183223
func (client *Client) CreateAccount(account *Account) (*Account, error) {
184224

185225
body, err := EncodeToJSON(account)

client/idp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type IDP struct {
2121
CookieIv string `json:"cookieIv,omitempty"`
2222
CookieKey string `json:"cookieKey,omitempty"`
2323
DisplayName string `json:"displayName,omitempty"`
24-
ID string `json:"id,omitempty"`
24+
ID string `json:"_id,omitempty"`
2525
IDPLoginUrl string `json:"IDPLoginUrl,omitempty"`
2626
LoginUrl string `json:"loginUrl,omitempty"`
2727
RedirectUiUrl string `json:"redirectUiUrl,omitempty"`

client/user.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ type User struct {
4646
}
4747

4848
type NewUser struct {
49-
UserName string `json:"userName"`
50-
Email string `json:"email"`
51-
Logins []Login `json:"logins,omitempty"`
52-
Roles []string `json:"roles,omitempty"`
53-
Account []string `json:"account,omitempty"`
49+
ID string `json:"_id,omitempty"`
50+
UserName string `json:"userName"`
51+
Email string `json:"email"`
52+
Logins []Login `json:"logins,omitempty"`
53+
Roles []string `json:"roles,omitempty"`
54+
Account []string `json:"account,omitempty"`
55+
Personal *Personal `json:"personal,omitempty"`
5456
}
5557

5658
type UserAccounts struct {
57-
UserName string `json:"userName`
58-
Account []Account `json:"account`
59+
UserName string `json:"userName"`
60+
Account []Account `json:"account"`
5961
}
6062

6163
func (client *Client) AddNewUserToAccount(accountId, userName, userEmail string) (*User, error) {

codefresh/provider.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ func Provider() terraform.ResourceProvider {
3131
"codefresh_user": dataSourceUser(),
3232
},
3333
ResourcesMap: map[string]*schema.Resource{
34-
"codefresh_project": resourceProject(),
35-
"codefresh_pipeline": resourcePipeline(),
36-
"codefresh_team": resourceTeam(),
37-
"codefresh_account": resourceAccount(),
38-
"codefresh_api_key": resourceApiKey(),
39-
"codefresh_idp_accounts": resourceIDPAccounts(),
34+
"codefresh_project": resourceProject(),
35+
"codefresh_pipeline": resourcePipeline(),
36+
"codefresh_team": resourceTeam(),
37+
"codefresh_account": resourceAccount(),
38+
"codefresh_api_key": resourceApiKey(),
39+
"codefresh_idp_accounts": resourceIDPAccounts(),
4040
"codefresh_account_admins": resourceAccountAdmins(),
41+
"codefresh_user": resourceUser(),
4142
},
4243
ConfigureFunc: configureProvider,
4344
}

codefresh/resource_account.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ func mapResourceToAccount(d *schema.ResourceData) *cfClient.Account {
168168
// admins := d.Get("admins").(*schema.Set).List()
169169

170170
account := &cfClient.Account{
171-
ID: d.Id(),
172-
Name: d.Get("name").(string),
171+
ID: d.Id(),
172+
Name: d.Get("name").(string),
173173
// Admins: convertStringArr(admins),
174174
}
175175

0 commit comments

Comments
 (0)