@@ -9,8 +9,10 @@ import (
99
1010type (
1111 IRuntimeAPI interface {
12+ Get (ctx context.Context , name string ) (* model.Runtime , error )
1213 List (ctx context.Context ) ([]model.Runtime , error )
1314 Create (ctx context.Context , runtimeName string ) (* model.RuntimeCreationResponse , error )
15+ Delete (ctx context.Context , runtimeName string ) (int , error )
1416 }
1517
1618 argoRuntime struct {
@@ -24,18 +26,76 @@ type (
2426 Errors []graphqlError
2527 }
2628
29+ graphqlRuntimeResponse struct {
30+ Data struct {
31+ Runtime * model.Runtime
32+ }
33+ Errors []graphqlError
34+ }
35+
2736 graphQlRuntimeCreationResponse struct {
2837 Data struct {
2938 Runtime model.RuntimeCreationResponse
3039 }
3140 Errors []graphqlError
3241 }
42+
43+ graphQlDeleteRuntimeResponse struct {
44+ Data struct {
45+ DeleteRuntime int
46+ }
47+ Errors []graphqlError
48+ }
3349)
3450
3551func newArgoRuntimeAPI (codefresh * codefresh ) IRuntimeAPI {
3652 return & argoRuntime {codefresh : codefresh }
3753}
3854
55+ func (r * argoRuntime ) Get (ctx context.Context , name string ) (* model.Runtime , error ) {
56+ jsonData := map [string ]interface {}{
57+ "query" : `
58+ query GetRuntime(
59+ $name: String!
60+ ) {
61+ runtime(name: $name) {
62+ metadata {
63+ name
64+ namespace
65+ }
66+ self {
67+ syncStatus
68+ healthMessage
69+ healthStatus
70+ }
71+ cluster
72+ ingressHost
73+ runtimeVersion
74+ }
75+ }
76+ ` ,
77+ "variables" : map [string ]interface {}{
78+ "name" : name ,
79+ },
80+ }
81+
82+ res := graphqlRuntimeResponse {}
83+ err := r .codefresh .graphqlAPI (ctx , jsonData , & res )
84+ if err != nil {
85+ return nil , fmt .Errorf ("failed making a graphql API call to runtime: %w" , err )
86+ }
87+
88+ if len (res .Errors ) > 0 {
89+ return nil , graphqlErrorResponse {errors : res .Errors }
90+ }
91+
92+ if res .Data .Runtime == nil {
93+ return nil , fmt .Errorf ("runtime '%s' does not exist" , name )
94+ }
95+
96+ return res .Data .Runtime , nil
97+ }
98+
3999func (r * argoRuntime ) List (ctx context.Context ) ([]model.Runtime , error ) {
40100 jsonData := map [string ]interface {}{
41101 "query" : `{
@@ -107,3 +167,30 @@ func (r *argoRuntime) Create(ctx context.Context, runtimeName string) (*model.Ru
107167
108168 return & res .Data .Runtime , nil
109169}
170+
171+ func (r * argoRuntime ) Delete (ctx context.Context , runtimeName string ) (int , error ) {
172+ jsonData := map [string ]interface {}{
173+ "query" : `
174+ mutation DeleteRuntime(
175+ $name: String!
176+ ) {
177+ deleteRuntime(name: $name)
178+ }
179+ ` ,
180+ "variables" : map [string ]interface {}{
181+ "name" : runtimeName ,
182+ },
183+ }
184+
185+ res := graphQlDeleteRuntimeResponse {}
186+ err := r .codefresh .graphqlAPI (ctx , jsonData , & res )
187+ if err != nil {
188+ return 0 , fmt .Errorf ("failed making a graphql API call to deleteRuntime: %w" , err )
189+ }
190+
191+ if len (res .Errors ) > 0 {
192+ return 0 , graphqlErrorResponse {errors : res .Errors }
193+ }
194+
195+ return res .Data .DeleteRuntime , nil
196+ }
0 commit comments