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

mendersoftware / deployments / 913012443

pending completion
913012443

Pull #869

gitlab-ci

alfrunes
ci: Bump golangci-lint to v1.15.3 (go1.20)

Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #869: feat: New configuration parameter storage.proxy_uri

179 of 253 new or added lines in 6 files covered. (70.75%)

2 existing lines in 2 files now uncovered.

7373 of 9353 relevant lines covered (78.83%)

33.73 hits per line

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

76.92
/storage/azblob/signature.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

15
package azblob
16

17
import (
18
        "context"
19
        "errors"
20
        "net/url"
21
        "strings"
22

23
        "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
24

25
        "github.com/mendersoftware/deployments/storage"
26
)
27

28
var (
29
        ErrConnStrNoName = errors.New("connection string does not contain an account name")
30
        ErrConnStrNoKey  = errors.New("connection string does not contain an account key")
31
)
32

33
func (c *client) signParamsFromContext(
34
        ctx context.Context,
35
) (creds *azblob.SharedKeyCredential, proxyURL *url.URL, err error) {
2✔
36
        creds = c.credentials
2✔
37
        proxyURL = c.proxyURL
2✔
38
        if settings, _ := storage.SettingsFromContext(ctx); settings != nil {
3✔
39
                if settings.ConnectionString != nil {
1✔
40
                        creds, err = keyFromConnString(*settings.ConnectionString)
×
41
                } else {
1✔
42
                        creds, err = azblob.NewSharedKeyCredential(settings.Key, settings.Secret)
1✔
43
                }
1✔
44
                if err == nil && settings.ProxyURI != nil {
1✔
NEW
45
                        proxyURL, err = url.Parse(*settings.ProxyURI)
×
NEW
46
                }
×
47
        }
48
        return creds, proxyURL, err
2✔
49
}
50

51
func applyProxyURL(signURL string, proxy *url.URL) (string, error) {
2✔
52
        if proxy == nil {
4✔
53
                return signURL, nil
2✔
54
        }
2✔
NEW
55
        old, err := url.Parse(signURL)
×
NEW
56
        if err != nil {
×
NEW
57
                return signURL, err
×
NEW
58
        }
×
NEW
59
        new := proxy.JoinPath(old.Path)
×
NEW
60
        q := new.Query()
×
NEW
61
        for key, value := range old.Query() {
×
NEW
62
                q[key] = value
×
UNCOV
63
        }
×
NEW
64
        new.RawQuery = q.Encode()
×
NEW
65
        new.Fragment = old.Fragment
×
NEW
66
        return new.String(), nil
×
67
}
68

69
func connStringAttr(cs, key string) (string, bool) {
7✔
70
        var start, end int
7✔
71
        for {
15✔
72
                i := strings.Index(cs[start:], key)
8✔
73
                if i < 0 {
10✔
74
                        return "", false
2✔
75
                }
2✔
76
                start += i
6✔
77
                if i == 0 || cs[start-1] == ';' {
11✔
78
                        break
5✔
79
                }
80
                start += len(key)
1✔
81
        }
82
        start += len(key)
5✔
83
        i := strings.IndexRune(cs[start:], ';')
5✔
84
        if i < 0 {
7✔
85
                // cs ends with value
2✔
86
                end = len(cs)
2✔
87
        } else {
5✔
88
                end = start + i
3✔
89
        }
3✔
90
        return cs[start:end], true
5✔
91
}
92

93
func keyFromConnString(cs string) (*azblob.SharedKeyCredential, error) {
4✔
94
        const (
4✔
95
                attrName = "AccountName="
4✔
96
                attrKey  = "AccountKey="
4✔
97
        )
4✔
98
        var (
4✔
99
                accountName, accountKey string
4✔
100
                ok                      bool
4✔
101
        )
4✔
102
        if accountName, ok = connStringAttr(cs, attrName); !ok {
5✔
103
                return nil, ErrConnStrNoName
1✔
104
        }
1✔
105
        if accountKey, ok = connStringAttr(cs, attrKey); !ok {
4✔
106
                return nil, ErrConnStrNoKey
1✔
107
        }
1✔
108
        return azblob.NewSharedKeyCredential(accountName, accountKey)
2✔
109
}
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