-
Notifications
You must be signed in to change notification settings - Fork 15
/
repositories.go
89 lines (74 loc) · 2.2 KB
/
repositories.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package argocd
import (
"context"
"net/url"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/util/io"
)
func (a *ArgoCDClient) CreateRepository(ctx context.Context, repo *Repository) (*v1alpha1.Repository, error) {
conn, appClient, err := a.client.NewRepoClient()
if err != nil {
return nil, err
}
defer io.Close(conn)
resp, err := appClient.CreateRepository(ctx, &repository.RepoCreateRequest{
Repo: &v1alpha1.Repository{
Project: repo.Project,
Repo: repo.Repo,
Username: repo.Username,
Password: repo.Password,
Type: repo.Type,
Insecure: repo.Insecure,
EnableLFS: repo.EnableLFS,
InsecureIgnoreHostKey: repo.InsecureIgnoreHostKey,
ConnectionState: v1alpha1.ConnectionState{
Status: repo.ConnectionState.Status,
Message: repo.ConnectionState.Message,
},
},
Upsert: repo.Upsert,
})
if err != nil {
return nil, err
}
return resp, nil
}
func (a *ArgoCDClient) DeleteRepository(ctx context.Context, repo string) (*repository.RepoResponse, error) {
conn, appClient, err := a.client.NewRepoClient()
if err != nil {
return nil, err
}
defer io.Close(conn)
encodedRepo := url.QueryEscape(repo)
resp, err := appClient.DeleteRepository(ctx, &repository.RepoQuery{Repo: encodedRepo})
if err != nil {
return nil, err
}
return resp, nil
}
func (a *ArgoCDClient) GetRepository(ctx context.Context, repo string) (*v1alpha1.Repository, error) {
conn, appClient, err := a.client.NewRepoClient()
if err != nil {
return nil, err
}
defer io.Close(conn)
encodedRepo := url.QueryEscape(repo)
repository, err := appClient.Get(ctx, &repository.RepoQuery{Repo: encodedRepo})
if err != nil {
return nil, err
}
return repository, nil
}
func (a *ArgoCDClient) ListRepositories(ctx context.Context) (*v1alpha1.RepositoryList, error) {
conn, appClient, err := a.client.NewRepoClient()
if err != nil {
return nil, err
}
defer io.Close(conn)
list, err := appClient.ListRepositories(ctx, &repository.RepoQuery{})
if err != nil {
return nil, err
}
return list, nil
}