Skip to content

Commit bf48dc0

Browse files
initial resource implementation
1 parent 7eaf520 commit bf48dc0

File tree

9 files changed

+195
-524
lines changed

9 files changed

+195
-524
lines changed

codefresh/cfclient/gitops_account_settings.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,27 @@ func (client *Client) GetActiveGitopsAccountInfo() (*GitopsActiveAccountInfo, er
5757

5858
return &gitopsActiveAccountInfo, nil
5959
}
60+
61+
func (client *Client) UpdateActiveGitopsAccountSettings(gitProvider string, gitProviderApiUrl string, sharedConfigRepo string) error {
62+
request := GraphQLRequest{
63+
Query: `
64+
mutation updateCsdpSettings($gitProvider: GitProviders!, $gitApiUrl: String!, $sharedConfigRepo: String!) {
65+
updateCsdpSettings(gitProvider: $gitProvider, gitApiUrl: $gitApiUrl, sharedConfigRepo: $sharedConfigRepo)
66+
}
67+
`,
68+
Variables: map[string]interface{}{
69+
"gitProvider": gitProvider,
70+
"gitApiUrl": gitProviderApiUrl,
71+
"sharedConfigRepo": sharedConfigRepo,
72+
},
73+
}
74+
75+
_, err := client.SendGqlRequest(request)
76+
77+
if err != nil {
78+
fmt.Println("Error:", err)
79+
return err
80+
}
81+
82+
return nil
83+
}

codefresh/data_account_gitops_settings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func dataSourceAccountGitopsSettings() *schema.Resource {
2828
Type: schema.TypeString,
2929
Computed: true,
3030
},
31-
"shared_config_repo": {
31+
"shared_config_repository": {
3232
Type: schema.TypeString,
3333
Computed: true,
3434
},
@@ -60,15 +60,15 @@ func dataSourceAccountGitopsSettingsRead(d *schema.ResourceData, meta interface{
6060
func mapDataAccountGitopsSettingsToResource(account *cfclient.GitopsActiveAccountInfo, d *schema.ResourceData) error {
6161

6262
if account == nil || account.ID == "" {
63-
return fmt.Errorf("data.codefresh_account - failed to mapDataAccountToResource")
63+
return fmt.Errorf("cannot get gitops settings as account wasn't properly retrived")
6464
}
6565
d.SetId(account.ID)
6666
d.Set("_id", account.ID)
6767
d.Set("name", account.AccountName)
6868
d.Set("admins", account.Admins)
6969
d.Set("git_provider", account.GitProvider)
7070
d.Set("git_provider_api_url", account.GitApiUrl)
71-
d.Set("shared_config_repo", account.SharedConfigRepo)
71+
d.Set("shared_config_repository", account.SharedConfigRepo)
7272

7373
return nil
7474
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package gitops
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
const (
8+
// Git providers enum from https://github.com/codefresh-io/argo-platform/blob/90f86de326422ca3bd1f64ca5dd26aeedf985e3e/libs/ql/schema/entities/common/integration.graphql#L200
9+
GitProviderGitHub string = "GITHUB"
10+
GitProviderGerrit string = "GERRIT"
11+
GitProviderGitlab string = "GITLAB"
12+
GitProviderBitbucket string = "BITBUCKET"
13+
GitProviderBitbucketServer string = "BITBUCKET_SERVER"
14+
)
15+
16+
func GetSupportedGitProvidersList() []string {
17+
return []string{GitProviderGitHub, GitProviderGerrit, GitProviderGitlab, GitProviderBitbucket, GitProviderBitbucketServer}
18+
}
19+
20+
// Matching implementation for https://github.com/codefresh-io/argo-platform/blob/3c6af5b5cbb29aef58ef6617e71159e882987f5c/libs/git/src/helpers.ts#L37.
21+
// Must be updated accordingly
22+
func GetDefaultAPIUrlForProvider(gitProvider string) (*string, error) {
23+
24+
defaultApiUrlProvider := map[string]string{
25+
GitProviderGitHub: "https://api.github.com",
26+
GitProviderGitlab: "https://gitlab.com/api/v4",
27+
GitProviderBitbucket: "https://api.bitbucket.org/2.0",
28+
GitProviderGerrit: "https://gerrit-review.googlesource.com/a",
29+
}
30+
31+
if val, ok := defaultApiUrlProvider[gitProvider]; ok {
32+
return &val, nil
33+
}
34+
35+
return nil, fmt.Errorf("no default API URL for provider %s can be found. For self hosted git providers URL must be provided explicitly", gitProvider)
36+
}

codefresh/internal/gitops/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Shared types, schemas and functions for gitops
2+
package gitops

codefresh/internal/idp copy/doc.go

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)