Skip to content

Commit 23e53b3

Browse files
author
Oleg Sucharevich
committed
implement codefresh API to get runtime envs
1 parent 5c1a911 commit 23e53b3

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.3
1+
0.3.4

cmd/get_runtime_environment.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ var getRuntimeEnvironmentCmd = &cobra.Command{
2929
Run: func(cmd *cobra.Command, args []string) {
3030
client := viper.Get("codefresh")
3131
codefreshClient, _ := client.(codefresh.Codefresh)
32-
re, _ := codefreshClient.GetRuntimeEnvironment(args[0])
33-
fmt.Printf(re.Metadata.Name)
32+
if len(args) > 0 {
33+
re, _ := codefreshClient.GetRuntimeEnvironment(args[0])
34+
fmt.Printf(re.Metadata.Name)
35+
} else {
36+
res, _ := codefreshClient.GetRuntimeEnvironments()
37+
for _, re := range res {
38+
fmt.Println(re.Metadata.Name)
39+
}
40+
}
3441
},
3542
}
3643

pkg/codefresh/runtime_enrionment.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package codefresh
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"net/url"
67
"time"
@@ -13,6 +14,7 @@ type (
1314
ValidateRuntimeEnvironment(*ValidateRuntimeOptions) error
1415
SignRuntimeEnvironmentCertificate(*SignCertificatesOptions) ([]byte, error)
1516
GetRuntimeEnvironment(string) (*RuntimeEnvironment, error)
17+
GetRuntimeEnvironments() ([]*RuntimeEnvironment, error)
1618
}
1719

1820
RuntimeEnvironment struct {
@@ -156,3 +158,18 @@ func (c *codefresh) GetRuntimeEnvironment(name string) (*RuntimeEnvironment, err
156158
c.decodeResponseInto(resp, re)
157159
return re, nil
158160
}
161+
162+
func (c *codefresh) GetRuntimeEnvironments() ([]*RuntimeEnvironment, error) {
163+
emptySlice := make([]*RuntimeEnvironment, 0)
164+
resp, err := c.requestAPI(&requestOptions{
165+
path: "/api/runtime-environments",
166+
method: "GET",
167+
})
168+
tokensAsBytes, err := c.getBodyAsBytes(resp)
169+
if err != nil {
170+
return nil, err
171+
}
172+
json.Unmarshal(tokensAsBytes, &emptySlice)
173+
174+
return emptySlice, err
175+
}

0 commit comments

Comments
 (0)