Skip to content

Commit e14ebe9

Browse files
input type instead of separate args
1 parent 8668b92 commit e14ebe9

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

pkg/codefresh/argo_runtime.go

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99

1010
type (
1111
IRuntimeAPI interface {
12+
Create(ctx context.Context, runtimeName, cluster, runtimeVersion, ingressHost string, componentNames []string) (*model.RuntimeCreationResponse, error)
1213
Get(ctx context.Context, name string) (*model.Runtime, error)
1314
List(ctx context.Context) ([]model.Runtime, error)
14-
Create(ctx context.Context, runtimeName, cluster, runtimeVersion, ingressHost string, componentNames []string) (*model.RuntimeCreationResponse, error)
1515
Delete(ctx context.Context, runtimeName string) (int, error)
1616
}
1717

@@ -52,6 +52,42 @@ func newArgoRuntimeAPI(codefresh *codefresh) IRuntimeAPI {
5252
return &argoRuntime{codefresh: codefresh}
5353
}
5454

55+
func (r *argoRuntime) Create(ctx context.Context, runtimeName, cluster, runtimeVersion, ingressHost string, componentNames []string) (*model.RuntimeCreationResponse, error) {
56+
jsonData := map[string]interface{}{
57+
"query": `
58+
mutation CreateRuntime(
59+
$input: InstallationArgs!
60+
) {
61+
runtime(InstallationArgs: $input) {
62+
name
63+
newAccessToken
64+
}
65+
}
66+
`,
67+
"variables": map[string]interface{}{
68+
"InstallationArgs": {
69+
runtimeName,
70+
cluster,
71+
runtimeVersion,
72+
componentNames,
73+
ingressHost,
74+
},
75+
},
76+
}
77+
78+
res := &graphQlRuntimeCreationResponse{}
79+
err := r.codefresh.graphqlAPI(ctx, jsonData, res)
80+
if err != nil {
81+
return nil, fmt.Errorf("failed making a graphql API call while creating runtime: %w", err)
82+
}
83+
84+
if len(res.Errors) > 0 {
85+
return nil, graphqlErrorResponse{errors: res.Errors}
86+
}
87+
88+
return &res.Data.Runtime, nil
89+
}
90+
5591
func (r *argoRuntime) Get(ctx context.Context, name string) (*model.Runtime, error) {
5692
jsonData := map[string]interface{}{
5793
"query": `
@@ -146,40 +182,6 @@ func (r *argoRuntime) List(ctx context.Context) ([]model.Runtime, error) {
146182
return runtimes, nil
147183
}
148184

149-
func (r *argoRuntime) Create(ctx context.Context, runtimeName, cluster, runtimeVersion, ingressHost string, componentNames []string) (*model.RuntimeCreationResponse, error) {
150-
jsonData := map[string]interface{}{
151-
"query": `
152-
mutation CreateRuntime(
153-
$runtimeName: String!, $cluster: String!, $runtimeVersion: String!, $ingressHost: String, $componentNames: [String]!
154-
) {
155-
runtime(runtimeName: $runtimeName, cluster: $cluster, runtimeVersion: $runtimeVersion, ingressHost: $ingressHost, componentNames: $componentNames) {
156-
name
157-
newAccessToken
158-
}
159-
}
160-
`,
161-
"variables": map[string]interface{}{
162-
"runtimeName": runtimeName,
163-
"cluster": cluster,
164-
"runtimeVersion": runtimeVersion,
165-
"ingressHost": ingressHost,
166-
"componentNames": componentNames,
167-
},
168-
}
169-
170-
res := &graphQlRuntimeCreationResponse{}
171-
err := r.codefresh.graphqlAPI(ctx, jsonData, res)
172-
if err != nil {
173-
return nil, fmt.Errorf("failed making a graphql API call while creating runtime: %w", err)
174-
}
175-
176-
if len(res.Errors) > 0 {
177-
return nil, graphqlErrorResponse{errors: res.Errors}
178-
}
179-
180-
return &res.Data.Runtime, nil
181-
}
182-
183185
func (r *argoRuntime) Delete(ctx context.Context, runtimeName string) (int, error) {
184186
jsonData := map[string]interface{}{
185187
"query": `

0 commit comments

Comments
 (0)