Skip to content

Commit 7eaf520

Browse files
add gitops account settings data source
1 parent 55e3ef2 commit 7eaf520

File tree

12 files changed

+723
-68
lines changed

12 files changed

+723
-68
lines changed

codefresh/cfclient/current_account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (client *Client) GetCurrentAccount() (*CurrentAccount, error) {
6060
currentAccount.ID = accX.Get("id").String()
6161
admins := accX.Get("admins").InterSlice()
6262
for _, adminI := range admins {
63-
accountAdminsIDs = append(accountAdminsIDs ,adminI.(string))
63+
accountAdminsIDs = append(accountAdminsIDs, adminI.(string))
6464
}
6565
break
6666
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package cfclient
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
type GitopsActiveAccountResponse struct {
8+
Data struct {
9+
Me struct {
10+
ActiveAccount GitopsActiveAccountInfo `json:"activeAccount,omitempty"`
11+
} `json:"me,omitempty"`
12+
} `json:"data,omitempty"`
13+
}
14+
15+
type GitopsActiveAccountInfo struct {
16+
ID string `json:"id,omitempty"`
17+
AccountName string `json:"name,omitempty"`
18+
GitProvider string `json:"gitProvider,omitempty"`
19+
GitApiUrl string `json:"gitApiUrl,omitempty"`
20+
SharedConfigRepo string `json:"sharedConfigRepo,omitempty"`
21+
Admins []string `json:"admins,omitempty"`
22+
}
23+
24+
func (client *Client) GetActiveGitopsAccountInfo() (*GitopsActiveAccountInfo, error) {
25+
request := GraphQLRequest{
26+
Query: `
27+
query AccountInfo {
28+
me {
29+
activeAccount {
30+
id
31+
name
32+
gitProvider
33+
gitApiUrl
34+
sharedConfigRepo
35+
admins
36+
}
37+
}
38+
}
39+
`,
40+
}
41+
42+
response, err := client.SendGqlRequest(request)
43+
if err != nil {
44+
fmt.Println("Error:", err)
45+
return nil, err
46+
}
47+
48+
var gitopsAccountResponse GitopsActiveAccountResponse
49+
50+
err = DecodeGraphQLResponseInto(response, &gitopsAccountResponse)
51+
52+
if err != nil {
53+
return nil, err
54+
}
55+
56+
gitopsActiveAccountInfo := gitopsAccountResponse.Data.Me.ActiveAccount
57+
58+
return &gitopsActiveAccountInfo, nil
59+
}

codefresh/cfclient/pipeline.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ type RuntimeEnvironment struct {
9191
}
9292

9393
type ExternalResource struct {
94-
ID string `json:"id,omitempty"`
95-
Type string `json:"type"`
96-
Source string `json:"source"`
97-
Context string `json:"context"`
94+
ID string `json:"id,omitempty"`
95+
Type string `json:"type"`
96+
Source string `json:"source"`
97+
Context string `json:"context"`
9898
Destination string `json:"destination"`
99-
IsFolder bool `json:"isFolder"`
100-
Repo string `json:"repo"`
101-
Revision string `json:"revision"`
99+
IsFolder bool `json:"isFolder"`
100+
Repo string `json:"repo"`
101+
Revision string `json:"revision"`
102102
}
103103

104104
func (t *Trigger) SetVariables(variables map[string]interface{}, encrypted bool) {
@@ -134,7 +134,7 @@ type Spec struct {
134134
Hooks *Hooks `json:"hooks,omitempty"`
135135
Options map[string]bool `json:"options,omitempty"`
136136
PermitRestartFromFailedSteps bool `json:"permitRestartFromFailedSteps,omitempty"`
137-
ExternalResources []ExternalResource `json:"externalResources,omitempty"`
137+
ExternalResources []ExternalResource `json:"externalResources,omitempty"`
138138
}
139139

140140
type Steps struct {

codefresh/cfclient/user.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type User struct {
4848
HasPassword bool `json:"hasPassword,omitempty"`
4949
Notifications []NotificationEvent `json:"notifications,omitempty"`
5050
ShortProfile ShortProfile `json:"shortProfile,omitempty"`
51-
PublicProfile PublicProfile `json:"publicProfile,omitempty"`
51+
PublicProfile PublicProfile `json:"publicProfile,omitempty"`
5252
Logins []Login `json:"logins,omitempty"`
5353
InviteURL string `json:"inviteUrl,omitempty"`
5454
}
@@ -374,7 +374,7 @@ func (client *Client) UpdateUserDetails(accountId, userId, userName, userEmail s
374374
return &respUser, nil
375375
}
376376

377-
func (client *Client) UpdateLocalUserPassword(userName, password string) (error) {
377+
func (client *Client) UpdateLocalUserPassword(userName, password string) error {
378378

379379
fullPath := "/admin/user/localProvider"
380380

@@ -395,7 +395,7 @@ func (client *Client) UpdateLocalUserPassword(userName, password string) (error)
395395
return nil
396396
}
397397

398-
func (client *Client) DeleteLocalUserPassword(userName string) (error) {
398+
func (client *Client) DeleteLocalUserPassword(userName string) error {
399399

400400
fullPath := fmt.Sprintf("/admin/user/localProvider?userName=%s", userName)
401401

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package codefresh
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
)
9+
10+
func dataSourceAccountGitopsSettings() *schema.Resource {
11+
return &schema.Resource{
12+
Description: "This data source retrieves gitops settings for the active account",
13+
Read: dataSourceAccountGitopsSettingsRead,
14+
Schema: map[string]*schema.Schema{
15+
"_id": {
16+
Type: schema.TypeString,
17+
Computed: true,
18+
},
19+
"name": {
20+
Type: schema.TypeString,
21+
Computed: true,
22+
},
23+
"git_provider": {
24+
Type: schema.TypeString,
25+
Computed: true,
26+
},
27+
"git_provider_api_url": {
28+
Type: schema.TypeString,
29+
Computed: true,
30+
},
31+
"shared_config_repo": {
32+
Type: schema.TypeString,
33+
Computed: true,
34+
},
35+
"admins": {
36+
Type: schema.TypeList,
37+
Computed: true,
38+
Elem: &schema.Schema{
39+
Type: schema.TypeString,
40+
},
41+
},
42+
},
43+
}
44+
}
45+
46+
func dataSourceAccountGitopsSettingsRead(d *schema.ResourceData, meta interface{}) error {
47+
48+
client := meta.(*cfclient.Client)
49+
var accountGitopsInfo *cfclient.GitopsActiveAccountInfo
50+
51+
accountGitopsInfo, err := client.GetActiveGitopsAccountInfo()
52+
53+
if err != nil {
54+
return err
55+
}
56+
57+
return mapDataAccountGitopsSettingsToResource(accountGitopsInfo, d)
58+
}
59+
60+
func mapDataAccountGitopsSettingsToResource(account *cfclient.GitopsActiveAccountInfo, d *schema.ResourceData) error {
61+
62+
if account == nil || account.ID == "" {
63+
return fmt.Errorf("data.codefresh_account - failed to mapDataAccountToResource")
64+
}
65+
d.SetId(account.ID)
66+
d.Set("_id", account.ID)
67+
d.Set("name", account.AccountName)
68+
d.Set("admins", account.Admins)
69+
d.Set("git_provider", account.GitProvider)
70+
d.Set("git_provider_api_url", account.GitApiUrl)
71+
d.Set("shared_config_repo", account.SharedConfigRepo)
72+
73+
return nil
74+
}

codefresh/internal/idp copy/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package idp is shared by idp-related resources.
2+
package idp

0 commit comments

Comments
 (0)