Skip to content

Commit 99a13d0

Browse files
support runtime list
1 parent 38b1d0c commit 99a13d0

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module github.com/codefresh-io/go-sdk
22

33
require (
44
github.com/BurntSushi/toml v0.3.1 // indirect
5+
github.com/codefresh-io/argo-platform v1.12.4-0.20210630081821-dfc9fd4ddae9
56
github.com/dustin/go-humanize v1.0.0
67
github.com/google/go-querystring v1.1.0
78
github.com/inconshreveable/mousetrap v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
33
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
4+
github.com/codefresh-io/argo-platform v1.12.4-0.20210630081821-dfc9fd4ddae9 h1:lUrKubj1uhE2q60hSJ8uPqVPax9jk6Wzu8UEhK5A5rM=
5+
github.com/codefresh-io/argo-platform v1.12.4-0.20210630081821-dfc9fd4ddae9/go.mod h1:u/eLWAySJ1nRzNWnB5baeyIc5vqINghwYJvydU+EC3c=
46
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
57
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
68
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=

pkg/codefresh/argo_runtime.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package codefresh
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"io/ioutil"
8+
9+
"github.com/codefresh-io/argo-platform/libs/ql/graph/model"
10+
)
11+
12+
13+
type (
14+
IArgoRuntimeAPI interface {
15+
List() ([]model.Runtime, error)
16+
}
17+
argoRuntime struct {
18+
codefresh *codefresh
19+
}
20+
graphqlRuntimesResponse struct {
21+
Data graphqlRuntimesInnerResponse`json:"data"`
22+
// Errors []byte
23+
}
24+
graphqlRuntimesInnerResponse struct {
25+
Runtimes model.RuntimePage `json:"runtimes"`
26+
}
27+
)
28+
29+
func newArgoRuntimeAPI(codefresh *codefresh) IArgoRuntimeAPI {
30+
return &argoRuntime{codefresh: codefresh}
31+
}
32+
func (r *argoRuntime) List() ([]model.Runtime, error) {
33+
34+
jsonData := map[string]interface{}{
35+
"query":`
36+
{
37+
runtimes{
38+
edges{
39+
node {
40+
id
41+
namespace
42+
objectMeta {
43+
name
44+
description
45+
}
46+
}
47+
}
48+
}
49+
}
50+
`,
51+
}
52+
53+
54+
response, err := r.codefresh.requestAPI(&requestOptions{
55+
method: "POST",
56+
path: "/argo/api/graphql",
57+
body: jsonData,
58+
})
59+
defer response.Body.Close()
60+
if err != nil {
61+
fmt.Printf("The HTTP request failed with error %s\n", err)
62+
return nil, err
63+
}
64+
data, err := ioutil.ReadAll(response.Body)
65+
if err != nil {
66+
fmt.Printf("failed to read from response body")
67+
return nil, err
68+
}
69+
res := graphqlRuntimesResponse{}
70+
err = json.Unmarshal(data, &res)
71+
if err != nil {
72+
return nil, err
73+
}
74+
runtimes := []model.Runtime{}
75+
for _, v := range res.Data.Runtimes.Edges {
76+
runtimes = append(runtimes, *v.Node)
77+
}
78+
79+
return runtimes, nil
80+
81+
82+
}

pkg/codefresh/codefresh.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type (
2828
Users() UsersAPI
2929
Argo() ArgoAPI
3030
Gitops() GitopsAPI
31+
ArgoRuntime() IArgoRuntimeAPI
3132
}
3233
)
3334

@@ -84,6 +85,10 @@ func (c *codefresh) Gitops() GitopsAPI {
8485
return newGitopsAPI(c)
8586
}
8687

88+
func (c *codefresh) ArgoRuntime() IArgoRuntimeAPI {
89+
return newArgoRuntimeAPI(c)
90+
}
91+
8792
func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
8893
return c.requestAPIWithContext(context.Background(), opt)
8994
}

0 commit comments

Comments
 (0)