diff --git a/VERSION b/VERSION index 30f6cf8..3f45a64 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.26.1 +0.26.3 diff --git a/pkg/codefresh/argo.go b/pkg/codefresh/argo.go index 02d5044..935b466 100644 --- a/pkg/codefresh/argo.go +++ b/pkg/codefresh/argo.go @@ -102,6 +102,8 @@ func (a *argo) GetIntegrations() ([]*IntegrationPayload, error) { return nil, err } + defer resp.Body.Close() + return result, nil } @@ -123,6 +125,8 @@ func (a *argo) GetIntegrationByName(name string) (*IntegrationPayload, error) { return nil, err } + defer resp.Body.Close() + return &result, nil } @@ -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, @@ -159,6 +163,8 @@ func (a *argo) HeartBeat(error string, version string, integration string) error return err } + defer resp.Body.Close() + return nil } @@ -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}, @@ -176,5 +182,7 @@ func (a *argo) SendResources(kind string, items interface{}, amount int, integra return err } + defer resp.Body.Close() + return nil } diff --git a/pkg/codefresh/cluster.go b/pkg/codefresh/cluster.go index 6e6ec62..86773ce 100644 --- a/pkg/codefresh/cluster.go +++ b/pkg/codefresh/cluster.go @@ -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 } @@ -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 } diff --git a/pkg/codefresh/contexts.go b/pkg/codefresh/contexts.go index c4982c2..6e01ecf 100644 --- a/pkg/codefresh/contexts.go +++ b/pkg/codefresh/contexts.go @@ -64,6 +64,8 @@ func (c context) GetGitContexts() (error, *[]ContextPayload) { err = c.codefresh.decodeResponseInto(resp, &result) + defer resp.Body.Close() + return err, &result } @@ -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 } @@ -101,5 +105,7 @@ func (c context) GetDefaultGitContext() (error, *ContextPayload) { err = c.codefresh.decodeResponseInto(resp, &result) + defer resp.Body.Close() + return err, &result } diff --git a/pkg/codefresh/gitops.go b/pkg/codefresh/gitops.go index 99a5e7a..ac4532c 100644 --- a/pkg/codefresh/gitops.go +++ b/pkg/codefresh/gitops.go @@ -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) @@ -31,6 +35,7 @@ type ( Spec struct { Type string `json:"type"` Application string `json:"application"` + Context string `json:"context"` } `json:"spec"` } @@ -43,6 +48,7 @@ type ( Context string `json:"context"` Project string `json:"project"` Application string `json:"application"` + Namespace string `json:"namespace,omitempty"` } EnvironmentPayload struct { @@ -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 { @@ -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"` } @@ -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 { @@ -114,6 +126,7 @@ type ( HistoryId int64 `json:"historyId"` Revision string `json:"revision, omitempty"` Resources interface{} `json:"resources"` + Context *string `json:"context"` } ) @@ -121,10 +134,10 @@ 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{ @@ -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 } @@ -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 } @@ -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 { @@ -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, @@ -204,11 +229,13 @@ 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, @@ -216,5 +243,6 @@ func (a *gitops) SendApplicationResources(resources *ApplicationResources) error if err != nil { return err } + defer resp.Body.Close() return nil }