Skip to content

Commit 672c9ec

Browse files
close connections
1 parent e380eae commit 672c9ec

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

pkg/codefresh/argo.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ func (a *argo) GetIntegrations() ([]*IntegrationPayload, error) {
102102
return nil, err
103103
}
104104

105+
defer resp.Body.Close()
106+
105107
return result, nil
106108
}
107109

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

128+
defer resp.Body.Close()
129+
126130
return &result, nil
127131
}
128132

@@ -150,7 +154,7 @@ func (a *argo) HeartBeat(error string, version string, integration string) error
150154
body.AgentVersion = version
151155
}
152156

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

166+
defer resp.Body.Close()
167+
162168
return nil
163169
}
164170

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

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

185+
defer resp.Body.Close()
186+
179187
return nil
180188
}

pkg/codefresh/cluster.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func (p *cluster) GetClusterCredentialsByAccountId(selector string) (*Cluster, e
4242
method: "GET",
4343
})
4444
err = p.codefresh.decodeResponseInto(resp, &r)
45+
46+
defer resp.Body.Close()
47+
4548
return r, err
4649
}
4750

@@ -52,5 +55,8 @@ func (p *cluster) GetAccountClusters() ([]*ClusterMinified, error) {
5255
method: "GET",
5356
})
5457
err = p.codefresh.decodeResponseInto(resp, &r)
58+
59+
defer resp.Body.Close()
60+
5561
return r, err
5662
}

pkg/codefresh/contexts.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ func (c context) GetGitContexts() (error, *[]ContextPayload) {
6464

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

67+
defer resp.Body.Close()
68+
6769
return err, &result
6870
}
6971

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

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

89+
defer resp.Body.Close()
90+
8791
return nil, &result
8892
}
8993

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

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

108+
defer resp.Body.Close()
109+
104110
return err, &result
105111
}

pkg/codefresh/gitops.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func newGitopsAPI(codefresh *codefresh) GitopsAPI {
134134
}
135135

136136
func (a *gitops) CreateEnvironment(name string, project string, application string, integration string, namespace string) error {
137-
_, err := a.codefresh.requestAPI(&requestOptions{
137+
resp, err := a.codefresh.requestAPI(&requestOptions{
138138
method: "POST",
139139
path: "/api/gitops/application",
140140
body: &EnvironmentPayload{
@@ -155,6 +155,8 @@ func (a *gitops) CreateEnvironment(name string, project string, application stri
155155
return err
156156
}
157157

158+
defer resp.Body.Close()
159+
158160
return nil
159161
}
160162

@@ -171,17 +173,20 @@ func (a *gitops) SendEnvironment(environment Environment) (map[string]interface{
171173
return nil, err
172174
}
173175

176+
defer resp.Body.Close()
177+
174178
return result, nil
175179
}
176180

177181
func (a *gitops) DeleteEnvironment(name string) error {
178-
_, err := a.codefresh.requestAPI(&requestOptions{
182+
resp, err := a.codefresh.requestAPI(&requestOptions{
179183
method: "DELETE",
180184
path: fmt.Sprintf("/api/environments-v2/%s", name),
181185
})
182186
if err != nil {
183187
return err
184188
}
189+
defer resp.Body.Close()
185190

186191
return nil
187192
}
@@ -196,6 +201,8 @@ func (a *gitops) GetEnvironments() ([]CFEnvironment, error) {
196201
return nil, err
197202
}
198203

204+
defer resp.Body.Close()
205+
199206
err = a.codefresh.decodeResponseInto(resp, &result)
200207

201208
if err != nil {
@@ -208,7 +215,7 @@ func (a *gitops) GetEnvironments() ([]CFEnvironment, error) {
208215
func (a *gitops) SendEvent(name string, props map[string]string) error {
209216
event := CodefreshEvent{Event: name, Props: props}
210217

211-
_, err := a.codefresh.requestAPI(&requestOptions{
218+
resp, err := a.codefresh.requestAPI(&requestOptions{
212219
method: "POST",
213220
path: "/api/gitops/system/events",
214221
body: event,
@@ -217,17 +224,20 @@ func (a *gitops) SendEvent(name string, props map[string]string) error {
217224
return err
218225
}
219226

227+
defer resp.Body.Close()
228+
220229
return nil
221230
}
222231

223232
func (a *gitops) SendApplicationResources(resources *ApplicationResources) error {
224-
_, err := a.codefresh.requestAPI(&requestOptions{
233+
resp, err := a.codefresh.requestAPI(&requestOptions{
225234
method: "POST",
226235
path: fmt.Sprintf("/api/gitops/resources"),
227236
body: &resources,
228237
})
229238
if err != nil {
230239
return err
231240
}
241+
defer resp.Body.Close()
232242
return nil
233243
}

0 commit comments

Comments
 (0)