Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.0.7 agent #410

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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.26.1
0.26.3
12 changes: 10 additions & 2 deletions pkg/codefresh/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func (a *argo) GetIntegrations() ([]*IntegrationPayload, error) {
return nil, err
}

defer resp.Body.Close()

return result, nil
}

Expand All @@ -123,6 +125,8 @@ func (a *argo) GetIntegrationByName(name string) (*IntegrationPayload, error) {
return nil, err
}

defer resp.Body.Close()

return &result, nil
}

Expand Down Expand Up @@ -150,7 +154,7 @@ func (a *argo) HeartBeat(error string, version string, integration string) error
body.AgentVersion = version
}

_, err := a.codefresh.requestAPI(&requestOptions{
resp, err := a.codefresh.requestAPI(&requestOptions{
method: "POST",
path: fmt.Sprintf("/api/argo-agent/%s/heartbeat", integration),
body: body,
Expand All @@ -159,6 +163,8 @@ func (a *argo) HeartBeat(error string, version string, integration string) error
return err
}

defer resp.Body.Close()

return nil
}

Expand All @@ -167,7 +173,7 @@ func (a *argo) SendResources(kind string, items interface{}, amount int, integra
return nil
}

_, err := a.codefresh.requestAPI(&requestOptions{
resp, err := a.codefresh.requestAPI(&requestOptions{
method: "POST",
path: fmt.Sprintf("/api/argo-agent/%s", integration),
body: &AgentState{Kind: kind, Items: items},
Expand All @@ -176,5 +182,7 @@ func (a *argo) SendResources(kind string, items interface{}, amount int, integra
return err
}

defer resp.Body.Close()

return nil
}
6 changes: 6 additions & 0 deletions pkg/codefresh/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func (p *cluster) GetClusterCredentialsByAccountId(selector string) (*Cluster, e
method: "GET",
})
err = p.codefresh.decodeResponseInto(resp, &r)

defer resp.Body.Close()

return r, err
}

Expand All @@ -52,5 +55,8 @@ func (p *cluster) GetAccountClusters() ([]*ClusterMinified, error) {
method: "GET",
})
err = p.codefresh.decodeResponseInto(resp, &r)

defer resp.Body.Close()

return r, err
}
6 changes: 6 additions & 0 deletions pkg/codefresh/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func (c context) GetGitContexts() (error, *[]ContextPayload) {

err = c.codefresh.decodeResponseInto(resp, &result)

defer resp.Body.Close()

return err, &result
}

Expand All @@ -84,6 +86,8 @@ func (c context) GetGitContextByName(name string) (error, *ContextPayload) {

err = c.codefresh.decodeResponseInto(resp, &result)

defer resp.Body.Close()

return nil, &result
}

Expand All @@ -101,5 +105,7 @@ func (c context) GetDefaultGitContext() (error, *ContextPayload) {

err = c.codefresh.decodeResponseInto(resp, &result)

defer resp.Body.Close()

return err, &result
}
60 changes: 44 additions & 16 deletions pkg/codefresh/gitops.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package codefresh

import "fmt"
import (
"errors"
"fmt"
"time"
)

type (
GitopsAPI interface {
CreateEnvironment(name string, project string, application string, integration string) error
CreateEnvironment(name string, project string, application string, integration string, namespace string) error
SendEnvironment(environment Environment) (map[string]interface{}, error)
DeleteEnvironment(name string) error
GetEnvironments() ([]CFEnvironment, error)
Expand All @@ -31,6 +35,7 @@ type (
Spec struct {
Type string `json:"type"`
Application string `json:"application"`
Context string `json:"context"`
} `json:"spec"`
}

Expand All @@ -43,6 +48,7 @@ type (
Context string `json:"context"`
Project string `json:"project"`
Application string `json:"application"`
Namespace string `json:"namespace,omitempty"`
}

EnvironmentPayload struct {
Expand All @@ -56,8 +62,9 @@ type (
}

Commit struct {
Message *string `json:"message"`
Avatar *string `json:"avatar"`
Time *time.Time `json:"time,omitempty"`
Message *string `json:"message"`
Avatar *string `json:"avatar"`
}

EnvironmentActivityRS struct {
Expand All @@ -69,17 +76,19 @@ type (
Current int64 `json:"current"`
Desired int64 `json:"desired"`
}
User struct {
Name string `json:"name"`
Avatar string `json:"avatar"`
}

Annotation struct {
Key string `json:"key"`
Value string `json:"value"`
}

GitopsUser struct {
Name string `json:"name"`
Avatar string `json:"avatar"`
}

Gitops struct {
Comitters []User `json:"comitters"`
Comitters []GitopsUser `json:"comitters"`
Prs []Annotation `json:"prs"`
Issues []Annotation `json:"issues"`
}
Expand All @@ -99,6 +108,9 @@ type (
SyncPolicy SyncPolicy `json:"syncPolicy"`
Date string `json:"date"`
ParentApp string `json:"parentApp"`
Namespace string `json:"namespace"`
Server string `json:"server"`
Context *string `json:"context"`
}

EnvironmentActivity struct {
Expand All @@ -114,17 +126,18 @@ type (
HistoryId int64 `json:"historyId"`
Revision string `json:"revision, omitempty"`
Resources interface{} `json:"resources"`
Context *string `json:"context"`
}
)

func newGitopsAPI(codefresh *codefresh) GitopsAPI {
return &gitops{codefresh}
}

func (a *gitops) CreateEnvironment(name string, project string, application string, integration string) error {
_, err := a.codefresh.requestAPI(&requestOptions{
func (a *gitops) CreateEnvironment(name string, project string, application string, integration string, namespace string) error {
resp, err := a.codefresh.requestAPI(&requestOptions{
method: "POST",
path: "/api/environments-v2",
path: "/api/gitops/application",
body: &EnvironmentPayload{
Version: "1.0",
Metadata: EnvironmentMetadata{
Expand All @@ -135,13 +148,20 @@ func (a *gitops) CreateEnvironment(name string, project string, application stri
Context: integration,
Project: project,
Application: application,
Namespace: namespace,
},
},
})
if resp != nil && resp.StatusCode >= 400 {
return errors.New(fmt.Sprintf("Failed to create environment, reason %v", resp.Status))
}

if err != nil {
return err
}

defer resp.Body.Close()

return nil
}

Expand All @@ -158,17 +178,20 @@ func (a *gitops) SendEnvironment(environment Environment) (map[string]interface{
return nil, err
}

defer resp.Body.Close()

return result, nil
}

func (a *gitops) DeleteEnvironment(name string) error {
_, err := a.codefresh.requestAPI(&requestOptions{
resp, err := a.codefresh.requestAPI(&requestOptions{
method: "DELETE",
path: fmt.Sprintf("/api/environments-v2/%s", name),
})
if err != nil {
return err
}
defer resp.Body.Close()

return nil
}
Expand All @@ -177,12 +200,14 @@ func (a *gitops) GetEnvironments() ([]CFEnvironment, error) {
var result MongoCFEnvWrapper
resp, err := a.codefresh.requestAPI(&requestOptions{
method: "GET",
path: "/api/environments-v2?plain=true&isEnvironment=false",
path: "/api/gitops/application?plain=true&isEnvironment=false",
})
if err != nil {
return nil, err
}

defer resp.Body.Close()

err = a.codefresh.decodeResponseInto(resp, &result)

if err != nil {
Expand All @@ -195,7 +220,7 @@ func (a *gitops) GetEnvironments() ([]CFEnvironment, error) {
func (a *gitops) SendEvent(name string, props map[string]string) error {
event := CodefreshEvent{Event: name, Props: props}

_, err := a.codefresh.requestAPI(&requestOptions{
resp, err := a.codefresh.requestAPI(&requestOptions{
method: "POST",
path: "/api/gitops/system/events",
body: event,
Expand All @@ -204,17 +229,20 @@ func (a *gitops) SendEvent(name string, props map[string]string) error {
return err
}

defer resp.Body.Close()

return nil
}

func (a *gitops) SendApplicationResources(resources *ApplicationResources) error {
_, err := a.codefresh.requestAPI(&requestOptions{
resp, err := a.codefresh.requestAPI(&requestOptions{
method: "POST",
path: fmt.Sprintf("/api/gitops/resources"),
body: &resources,
})
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}