• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / workflows / 1354855011

01 Jul 2024 12:34AM UTC coverage: 81.632% (-0.3%) from 81.882%
1354855011

Pull #327

gitlab-ci

web-flow
chore: bump golang in the docker-dependencies group

Bumps the docker-dependencies group with 1 update: golang.


Updates `golang` from 1.22.3-alpine3.19 to 1.22.4-alpine3.19

---
updated-dependencies:
- dependency-name: golang
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: docker-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #327: chore: bump golang from 1.22.3-alpine3.19 to 1.22.4-alpine3.19 in the docker-dependencies group

1631 of 1998 relevant lines covered (81.63%)

14.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.11
/app/worker/http.go
1
// Copyright 2022 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
package worker
16

17
import (
18
        "encoding/json"
19
        "fmt"
20
        "io/ioutil"
21
        "net/http"
22
        "net/url"
23
        "strings"
24
        "time"
25

26
        "github.com/mendersoftware/go-lib-micro/log"
27

28
        "github.com/mendersoftware/workflows/app/processor"
29
        "github.com/mendersoftware/workflows/model"
30
)
31

32
var makeHTTPRequest = func(req *http.Request, timeout time.Duration) (*http.Response, error) {
32✔
33
        var httpClient = &http.Client{
32✔
34
                Timeout: timeout,
32✔
35
        }
32✔
36
        res, err := httpClient.Do(req)
32✔
37
        if err != nil {
32✔
38
                return nil, err
×
39
        }
×
40
        return res, nil
32✔
41
}
42

43
func processHTTPTask(
44
        httpTask *model.HTTPTask,
45
        ps *processor.JobStringProcessor,
46
        jp *processor.JobProcessor,
47
        l *log.Logger,
48
) (*model.TaskResult, error) {
45✔
49
        uri := ps.ProcessJobString(httpTask.URI)
45✔
50
        l.Infof("processHTTPTask: starting with: method=%s uri=%s",
45✔
51
                httpTask.Method,
45✔
52
                uri,
45✔
53
        )
45✔
54

45✔
55
        var payloadString string
45✔
56
        if len(httpTask.FormData) > 0 {
46✔
57
                form := url.Values{}
1✔
58
                for key, value := range httpTask.FormData {
2✔
59
                        key = ps.ProcessJobString(key)
1✔
60
                        key = ps.MaybeExecuteGoTemplate(key)
1✔
61
                        value = ps.ProcessJobString(value)
1✔
62
                        value = ps.MaybeExecuteGoTemplate(value)
1✔
63
                        form.Add(key, value)
1✔
64
                }
1✔
65
                payloadString = form.Encode()
1✔
66
        } else if httpTask.JSON != nil {
56✔
67
                payloadJSON := jp.ProcessJSON(httpTask.JSON, ps)
12✔
68
                payloadBytes, err := json.Marshal(payloadJSON)
12✔
69
                if err != nil {
12✔
70
                        return nil, err
×
71
                }
×
72
                payloadString = string(payloadBytes)
12✔
73
        } else {
32✔
74
                payloadString = ps.ProcessJobString(httpTask.Body)
32✔
75
                payloadString = ps.MaybeExecuteGoTemplate(payloadString)
32✔
76
        }
32✔
77
        payload := strings.NewReader(payloadString)
45✔
78

45✔
79
        req, err := http.NewRequest(httpTask.Method, uri, payload)
45✔
80
        if err != nil {
45✔
81
                return nil, err
×
82
        }
×
83

84
        if httpTask.ContentType != "" {
60✔
85
                req.Header.Add("Content-Type", httpTask.ContentType)
15✔
86
        }
15✔
87

88
        var headersToBeSent []string
45✔
89
        for name, value := range httpTask.Headers {
83✔
90
                headerValue := ps.ProcessJobString(value)
38✔
91
                req.Header.Add(name, headerValue)
38✔
92
                headersToBeSent = append(headersToBeSent,
38✔
93
                        fmt.Sprintf("%s: %s", name, headerValue))
38✔
94
        }
38✔
95

96
        l.Debugf("processHTTPTask makeHTTPRequest '%v'", req)
45✔
97
        res, err := makeHTTPRequest(req, time.Duration(httpTask.ReadTimeOut)*time.Second)
45✔
98
        l.Debugf("processHTTPTask makeHTTPRequest returned '%v','%v'", res, err)
45✔
99
        if err != nil {
45✔
100
                return nil, err
×
101
        }
×
102

103
        defer res.Body.Close()
45✔
104
        resBody, _ := ioutil.ReadAll(res.Body)
45✔
105

45✔
106
        var success bool
45✔
107
        if len(httpTask.StatusCodes) == 0 {
76✔
108
                success = true
31✔
109
                if res.StatusCode >= 400 {
41✔
110
                        success = false
10✔
111
                }
10✔
112
        } else {
14✔
113
                success = false
14✔
114
                for _, statusCode := range httpTask.StatusCodes {
37✔
115
                        if statusCode == res.StatusCode {
36✔
116
                                success = true
13✔
117
                                break
13✔
118
                        }
119
                }
120
        }
121

122
        result := &model.TaskResult{
45✔
123
                Success: success,
45✔
124
                HTTPRequest: &model.TaskResultHTTPRequest{
45✔
125
                        URI:     uri,
45✔
126
                        Method:  httpTask.Method,
45✔
127
                        Body:    payloadString,
45✔
128
                        Headers: headersToBeSent,
45✔
129
                },
45✔
130
                HTTPResponse: &model.TaskResultHTTPResponse{
45✔
131
                        StatusCode: res.StatusCode,
45✔
132
                        Body:       string(resBody),
45✔
133
                },
45✔
134
        }
45✔
135

45✔
136
        return result, nil
45✔
137
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc