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

mendersoftware / mender-cli / 1694875209

01 Mar 2025 09:18PM UTC coverage: 31.802%. Remained the same
1694875209

Pull #274

gitlab-ci

web-flow
chore: bump the golang-dependencies group with 4 updates

Bumps the golang-dependencies group with 4 updates: [github.com/cheggaaa/pb/v3](https://github.com/cheggaaa/pb), [github.com/spf13/cobra](https://github.com/spf13/cobra), [golang.org/x/sys](https://github.com/golang/sys) and [golang.org/x/term](https://github.com/golang/term).


Updates `github.com/cheggaaa/pb/v3` from 3.1.6 to 3.1.7
- [Commits](https://github.com/cheggaaa/pb/compare/v3.1.6...v3.1.7)

Updates `github.com/spf13/cobra` from 1.8.1 to 1.9.1
- [Release notes](https://github.com/spf13/cobra/releases)
- [Commits](https://github.com/spf13/cobra/compare/v1.8.1...v1.9.1)

Updates `golang.org/x/sys` from 0.29.0 to 0.30.0
- [Commits](https://github.com/golang/sys/compare/v0.29.0...v0.30.0)

Updates `golang.org/x/term` from 0.28.0 to 0.29.0
- [Commits](https://github.com/golang/term/compare/v0.28.0...v0.29.0)

---
updated-dependencies:
- dependency-name: github.com/cheggaaa/pb/v3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: golang-dependencies
- dependency-name: github.com/spf13/cobra
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang-dependencies
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang-dependencies
- dependency-name: golang.org/x/term
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: golang-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #274: chore: bump the golang-dependencies group with 4 updates

810 of 2547 relevant lines covered (31.8%)

1.68 hits per line

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

71.43
/client/common.go
1
// Copyright 2023 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
package client
15

16
import (
17
        "crypto/tls"
18
        "fmt"
19
        "io"
20
        "io/ioutil"
21
        "net/http"
22
        "net/http/httputil"
23
        "strings"
24

25
        "github.com/pkg/errors"
26

27
        "github.com/mendersoftware/mender-cli/log"
28
)
29

30
const (
31
        httpErrorBoundary = 300
32
)
33

34
func NewHttpClient(skipVerify bool) *http.Client {
16✔
35
        tr := &http.Transport{
16✔
36
                TLSClientConfig: &tls.Config{InsecureSkipVerify: skipVerify},
16✔
37
        }
16✔
38

16✔
39
        return &http.Client{
16✔
40
                Transport: tr,
16✔
41
        }
16✔
42
}
16✔
43

44
func JoinURL(base, url string) string {
16✔
45
        url = strings.TrimPrefix(url, "/")
16✔
46
        if !strings.HasSuffix(base, "/") {
32✔
47
                base = base + "/"
16✔
48
        }
16✔
49
        return base + url
16✔
50
}
51

52
func DoGetRequest(token, urlPath string, client *http.Client) ([]byte, error) {
5✔
53
        req, err := http.NewRequest(http.MethodGet, urlPath, nil)
5✔
54
        if err != nil {
5✔
55
                return nil, errors.Wrap(err, "Failed to create HTTP request")
×
56
        }
×
57
        req.Header.Set("Authorization", "Bearer "+string(token))
5✔
58

5✔
59
        reqDump, err := httputil.DumpRequest(req, false)
5✔
60
        if err != nil {
5✔
61
                return nil, err
×
62
        }
×
63
        log.Verbf("sending request: \n%s", string(reqDump))
5✔
64

5✔
65
        rsp, err := client.Do(req)
5✔
66
        if err != nil {
5✔
67
                return nil, errors.Wrap(err, fmt.Sprintf("Get %s request failed", urlPath))
×
68
        }
×
69
        if rsp.StatusCode != 200 {
5✔
70
                return nil, fmt.Errorf("Get %s request failed with status %d\n", urlPath, rsp.StatusCode)
×
71
        }
×
72

73
        defer rsp.Body.Close()
5✔
74

5✔
75
        body, err := ioutil.ReadAll(rsp.Body)
5✔
76
        if err != nil {
5✔
77
                return nil, err
×
78
        }
×
79

80
        return body, nil
5✔
81
}
82

83
func DoPostRequest(
84
        token, urlPath string,
85
        client *http.Client,
86
        requestBody io.Reader,
87
) ([]byte, error) {
1✔
88
        req, err := http.NewRequest(http.MethodPost, urlPath, requestBody)
1✔
89
        if err != nil {
1✔
90
                return nil, errors.Wrap(err, "Failed to create HTTP request")
×
91
        }
×
92
        req.Header.Set("Authorization", "Bearer "+string(token))
1✔
93
        req.Header.Set("Content-Type", "application/json; charset=UTF-8")
1✔
94

1✔
95
        reqDump, err := httputil.DumpRequest(req, false)
1✔
96
        if err != nil {
1✔
97
                return nil, err
×
98
        }
×
99
        log.Verbf("sending request: \n%s", string(reqDump))
1✔
100

1✔
101
        rsp, err := client.Do(req)
1✔
102
        if err != nil {
1✔
103
                return nil, errors.Wrap(err, fmt.Sprintf("Post %s request failed", urlPath))
×
104
        }
×
105
        if rsp.StatusCode > httpErrorBoundary {
1✔
106
                return nil, fmt.Errorf("Post %s request failed with status %d\n", urlPath, rsp.StatusCode)
×
107
        }
×
108

109
        defer rsp.Body.Close()
1✔
110

1✔
111
        body, err := io.ReadAll(rsp.Body)
1✔
112
        if err != nil {
1✔
113
                return nil, err
×
114
        }
×
115

116
        return body, nil
1✔
117
}
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