Skip to content

Commit 6b02d1e

Browse files
Merge pull request #61 from codefresh-io/runtime-mutation-using-input-type
runtime-mutation-using-input-type
2 parents da9d25f + 1ceee47 commit 6b02d1e

File tree

4 files changed

+431
-105
lines changed

4 files changed

+431
-105
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.34.5
1+
0.34.6

pkg/codefresh/argo_runtime.go

Lines changed: 29 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, opts *model.RuntimeInstallationArgs) (*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,34 @@ func newArgoRuntimeAPI(codefresh *codefresh) IRuntimeAPI {
5252
return &argoRuntime{codefresh: codefresh}
5353
}
5454

55+
func (r *argoRuntime) Create(ctx context.Context, opts *model.RuntimeInstallationArgs) (*model.RuntimeCreationResponse, error) {
56+
jsonData := map[string]interface{}{
57+
"query": `
58+
mutation CreateRuntime($installationArgs: RuntimeInstallationArgs!) {
59+
runtime(installationArgs: $installationArgs) {
60+
name
61+
newAccessToken
62+
}
63+
}
64+
`,
65+
"variables": map[string]interface{}{
66+
"installationArgs": opts,
67+
},
68+
}
69+
70+
res := &graphQlRuntimeCreationResponse{}
71+
err := r.codefresh.graphqlAPI(ctx, jsonData, res)
72+
if err != nil {
73+
return nil, fmt.Errorf("failed making a graphql API call while creating runtime: %w", err)
74+
}
75+
76+
if len(res.Errors) > 0 {
77+
return nil, graphqlErrorResponse{errors: res.Errors}
78+
}
79+
80+
return &res.Data.Runtime, nil
81+
}
82+
5583
func (r *argoRuntime) Get(ctx context.Context, name string) (*model.Runtime, error) {
5684
jsonData := map[string]interface{}{
5785
"query": `
@@ -146,40 +174,6 @@ func (r *argoRuntime) List(ctx context.Context) ([]model.Runtime, error) {
146174
return runtimes, nil
147175
}
148176

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-
183177
func (r *argoRuntime) Delete(ctx context.Context, runtimeName string) (int, error) {
184178
jsonData := map[string]interface{}{
185179
"query": `

pkg/codefresh/codefresh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (c *codefresh) graphqlAPI(ctx context.Context, body map[string]interface{},
153153
body: body,
154154
})
155155
if err != nil {
156-
return fmt.Errorf("The HTTP request failed: %w", err)
156+
return fmt.Errorf("the HTTP request failed: %w", err)
157157
}
158158
defer response.Body.Close()
159159

0 commit comments

Comments
 (0)