Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.27.1
0.28.0
68 changes: 63 additions & 5 deletions pkg/codefresh/argo_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type (
IArgoRuntimeAPI interface {
List() ([]model.Runtime, error)
Create(runtimeName string) (*model.RuntimeCreationResponse, error)
}
argoRuntime struct {
codefresh *codefresh
Expand All @@ -21,19 +22,73 @@ type (
}
Errors []graphqlError
}

graphQlRuntimeCreationResponse struct {
Data struct {
Runtime model.RuntimeCreationResponse
}
Errors []graphqlError
}
)

func newArgoRuntimeAPI(codefresh *codefresh) IArgoRuntimeAPI {
return &argoRuntime{codefresh: codefresh}
}
func (r *argoRuntime) List() ([]model.Runtime, error) {

func (r *argoRuntime) Create(runtimeName string) (*model.RuntimeCreationResponse, error) {
interpolatedMutation := fmt.Sprintf(`mutation {
runtime(name: "%s") {
id
newAccessToken
}
}
`, runtimeName)

jsonData := map[string]interface{}{
"query": interpolatedMutation,
}

response, err := r.codefresh.requestAPI(&requestOptions{
method: "POST",
path: "/argo/api/graphql",
body: jsonData,
})

if err != nil {
fmt.Printf("The HTTP request failed with error %s\n", err)
return nil, err
}

defer response.Body.Close()

data, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("failed to read from response body")
return nil, err
}

res := graphQlRuntimeCreationResponse{}
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}

if len(res.Errors) > 0 {
return nil, graphqlErrorResponse{errors: res.Errors}
}

return &res.Data.Runtime, nil
}

func (r *argoRuntime) List() ([]model.Runtime, error) {
jsonData := map[string]interface{}{
"query": `
{
runtimes(
runtimes
(
pagination: {}
project: "") {
project: ""
) {
edges {
node {
metadata {
Expand All @@ -55,21 +110,25 @@ func (r *argoRuntime) List() ([]model.Runtime, error) {
path: "/argo/api/graphql",
body: jsonData,
})
defer response.Body.Close()
if err != nil {
fmt.Printf("The HTTP request failed with error %s\n", err)
return nil, err
}
defer response.Body.Close()

data, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("failed to read from response body")
return nil, err
}

res := graphqlRuntimesResponse{}
err = json.Unmarshal(data, &res)

if err != nil {
return nil, err
}

runtimes := make([]model.Runtime, len(res.Data.Runtimes.Edges))
for i := range res.Data.Runtimes.Edges {
runtimes[i] = *res.Data.Runtimes.Edges[i].Node
Expand All @@ -80,5 +139,4 @@ func (r *argoRuntime) List() ([]model.Runtime, error) {
}

return runtimes, nil

}
1 change: 1 addition & 0 deletions pkg/codefresh/codefresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (c *codefresh) requestAPIWithContext(ctx context.Context, opt *requestOptio
}
request.Header.Set("Authorization", c.token)
request.Header.Set("Content-Type", "application/json")
request.Header.Set("origin", c.host)

response, err := c.client.Do(request)
if err != nil {
Expand Down