Skip to content

Commit db32c48

Browse files
support context api
1 parent 8006db3 commit db32c48

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pkg/codefresh/codefresh.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type (
2121
Workflows() IWorkflowAPI
2222
Progresses() IProgressAPI
2323
Clusters() IClusterAPI
24+
Contexts() IContextAPI
2425
}
2526
)
2627

@@ -61,6 +62,10 @@ func (c *codefresh) Clusters() IClusterAPI {
6162
return newClusterAPI(c)
6263
}
6364

65+
func (c *codefresh) Contexts() IContextAPI {
66+
return newContextAPI(c)
67+
}
68+
6469
func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
6570
var body []byte
6671
finalURL := fmt.Sprintf("%s%s", c.host, opt.path)

pkg/codefresh/contexts.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,21 @@ type (
1818
Type string `json:"type"`
1919
Data struct {
2020
Auth struct {
21+
Username string `json:"username"`
2122
Password string `json:"password"`
2223
ApiHost string `json:"apiHost"`
2324
ApiPathPrefix string `json:"apiPathPrefix"`
25+
SshPrivateKey string `json:"sshPrivateKey"`
2426
} `json:"auth"`
2527
} `json:"data"`
2628
} `json:"spec"`
2729
}
2830
)
2931

32+
func newContextAPI(codefresh Codefresh) IContextAPI {
33+
return &context{codefresh}
34+
}
35+
3036
func (c context) GetGitContexts() (error, *[]ContextPayload) {
3137
var result []ContextPayload
3238
var qs = map[string]string{
@@ -36,7 +42,7 @@ func (c context) GetGitContexts() (error, *[]ContextPayload) {
3642

3743
resp, err := c.codefresh.requestAPI(&requestOptions{
3844
method: "GET",
39-
path: "/contexts",
45+
path: "/api/contexts",
4046
qs: qs,
4147
})
4248
if err != nil {
@@ -45,7 +51,7 @@ func (c context) GetGitContexts() (error, *[]ContextPayload) {
4551

4652
err = c.codefresh.decodeResponseInto(resp, &result)
4753

48-
return nil, &result
54+
return err, &result
4955
}
5056

5157
func (c context) GetGitContextByName(name string) (error, *ContextPayload) {
@@ -56,7 +62,7 @@ func (c context) GetGitContextByName(name string) (error, *ContextPayload) {
5662

5763
resp, err := c.codefresh.requestAPI(&requestOptions{
5864
method: "GET",
59-
path: "/contexts/" + name,
65+
path: "/api/contexts/" + name,
6066
qs: qs,
6167
})
6268
if err != nil {

0 commit comments

Comments
 (0)