Skip to content

Commit 2eb45f3

Browse files
Merge pull request #12 from codefresh-io/cluster-api
cluster api support
2 parents 736d3ca + 76175c8 commit 2eb45f3

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

pkg/codefresh/cluster.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package codefresh
2+
3+
import "fmt"
4+
5+
type (
6+
IClusterAPI interface {
7+
GetClusterCredentialsByAccountId(selector string) (*Cluster, error)
8+
GetAccountClusters() ([]*ClusterMinified, error)
9+
}
10+
11+
cluster struct {
12+
codefresh Codefresh
13+
}
14+
15+
Cluster struct {
16+
Auth struct {
17+
Bearer string
18+
} `json:"auth"`
19+
Ca string `json:"ca"`
20+
Url string `json:"url"`
21+
}
22+
23+
ClusterMinified struct {
24+
Cluster struct {
25+
Name string `json:"name"`
26+
} `json:"cluster"`
27+
28+
BehindFirewall bool `json:"behindFirewall"`
29+
Selector string `json:"selector"`
30+
Provider string `json:"provider"`
31+
}
32+
)
33+
34+
func newClusterAPI(codefresh Codefresh) IClusterAPI {
35+
return &cluster{codefresh}
36+
}
37+
38+
func (p *cluster) GetClusterCredentialsByAccountId(selector string) (*Cluster, error) {
39+
r := &Cluster{}
40+
resp, err := p.codefresh.requestAPI(&requestOptions{
41+
path: fmt.Sprintf("/api/clusters/%s/credentials", selector),
42+
method: "GET",
43+
})
44+
err = p.codefresh.decodeResponseInto(resp, &r)
45+
return r, err
46+
}
47+
48+
func (p *cluster) GetAccountClusters() ([]*ClusterMinified, error) {
49+
r := make([]*ClusterMinified, 0)
50+
resp, err := p.codefresh.requestAPI(&requestOptions{
51+
path: fmt.Sprintf("/api/clusters"),
52+
method: "GET",
53+
})
54+
err = p.codefresh.decodeResponseInto(resp, &r)
55+
return r, err
56+
}

pkg/codefresh/codefresh.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type (
2020
RuntimeEnvironments() IRuntimeEnvironmentAPI
2121
Workflows() IWorkflowAPI
2222
Progresses() IProgressAPI
23+
Clusters() IClusterAPI
2324
}
2425
)
2526

@@ -56,6 +57,10 @@ func (c *codefresh) Progresses() IProgressAPI {
5657
return newProgressAPI(c)
5758
}
5859

60+
func (c *codefresh) Clusters() IClusterAPI {
61+
return newClusterAPI(c)
62+
}
63+
5964
func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
6065
var body []byte
6166
finalURL := fmt.Sprintf("%s%s", c.host, opt.path)

0 commit comments

Comments
 (0)