Skip to content

Commit

Permalink
Add user resource
Browse files Browse the repository at this point in the history
  • Loading branch information
palson-cf committed Jul 17, 2020
1 parent bf618e4 commit c5490af
Show file tree
Hide file tree
Showing 7 changed files with 466 additions and 17 deletions.
42 changes: 41 additions & 1 deletion client/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package client
import (
"errors"
"fmt"
"github.com/imdario/mergo"
"log"
"strconv"

"github.com/imdario/mergo"
)

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

func (client *Client) GetAllAccounts() (*[]Account, error) {

opts := RequestOptions{
Path: "/admin/accounts",
Method: "GET",
}

resp, err := client.RequestAPI(&opts)

if err != nil {
return nil, err
}

var accounts []Account

err = DecodeResponseInto(resp, &accounts)
if err != nil {
return nil, err
}

return &accounts, nil
}

func (client *Client) GetAccountsList(accountsId []string) (*[]Account, error) {

var accounts []Account

for _, accountId := range accountsId {
account, err := client.GetAccountByID(accountId)
if err != nil {
return nil, err
}

accounts = append(accounts, *account)
}

return &accounts, nil
}

func (client *Client) CreateAccount(account *Account) (*Account, error) {

body, err := EncodeToJSON(account)
Expand Down
2 changes: 1 addition & 1 deletion client/idp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type IDP struct {
CookieIv string `json:"cookieIv,omitempty"`
CookieKey string `json:"cookieKey,omitempty"`
DisplayName string `json:"displayName,omitempty"`
ID string `json:"id,omitempty"`
ID string `json:"_id,omitempty"`
IDPLoginUrl string `json:"IDPLoginUrl,omitempty"`
LoginUrl string `json:"loginUrl,omitempty"`
RedirectUiUrl string `json:"redirectUiUrl,omitempty"`
Expand Down
16 changes: 9 additions & 7 deletions client/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ type User struct {
}

type NewUser struct {
UserName string `json:"userName"`
Email string `json:"email"`
Logins []Login `json:"logins,omitempty"`
Roles []string `json:"roles,omitempty"`
Account []string `json:"account,omitempty"`
ID string `json:"_id,omitempty"`
UserName string `json:"userName"`
Email string `json:"email"`
Logins []Login `json:"logins,omitempty"`
Roles []string `json:"roles,omitempty"`
Account []string `json:"account,omitempty"`
Personal *Personal `json:"personal,omitempty"`
}

type UserAccounts struct {
UserName string `json:"userName`
Account []Account `json:"account`
UserName string `json:"userName"`
Account []Account `json:"account"`
}

func (client *Client) AddNewUserToAccount(accountId, userName, userEmail string) (*User, error) {
Expand Down
13 changes: 7 additions & 6 deletions codefresh/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ func Provider() terraform.ResourceProvider {
"codefresh_user": dataSourceUser(),
},
ResourcesMap: map[string]*schema.Resource{
"codefresh_project": resourceProject(),
"codefresh_pipeline": resourcePipeline(),
"codefresh_team": resourceTeam(),
"codefresh_account": resourceAccount(),
"codefresh_api_key": resourceApiKey(),
"codefresh_idp_accounts": resourceIDPAccounts(),
"codefresh_project": resourceProject(),
"codefresh_pipeline": resourcePipeline(),
"codefresh_team": resourceTeam(),
"codefresh_account": resourceAccount(),
"codefresh_api_key": resourceApiKey(),
"codefresh_idp_accounts": resourceIDPAccounts(),
"codefresh_account_admins": resourceAccountAdmins(),
"codefresh_user": resourceUser(),
},
ConfigureFunc: configureProvider,
}
Expand Down
4 changes: 2 additions & 2 deletions codefresh/resource_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ func mapResourceToAccount(d *schema.ResourceData) *cfClient.Account {
// admins := d.Get("admins").(*schema.Set).List()

account := &cfClient.Account{
ID: d.Id(),
Name: d.Get("name").(string),
ID: d.Id(),
Name: d.Get("name").(string),
// Admins: convertStringArr(admins),
}

Expand Down

0 comments on commit c5490af

Please sign in to comment.