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

mendersoftware / deployments / 920043239

pending completion
920043239

Pull #872

gitlab-ci

alfrunes
chore: Restrict tag character set

Changelog: None
Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #872: MEN-6348: Add tags to releases

220 of 229 new or added lines in 7 files covered. (96.07%)

223 existing lines in 7 files now uncovered.

7560 of 9480 relevant lines covered (79.75%)

34.07 hits per line

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

97.78
/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
        "strings"
21

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

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

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

32
func (c *client) credentialsFromContext(
33
        ctx context.Context,
34
) (creds *azblob.SharedKeyCredential, err error) {
2✔
35
        creds = c.credentials
2✔
36
        if settings, _ := storage.SettingsFromContext(ctx); settings != nil {
3✔
37
                if settings.ConnectionString != nil {
1✔
UNCOV
38
                        creds, err = keyFromConnString(*settings.ConnectionString)
×
39
                } else {
1✔
40
                        creds, err = azblob.NewSharedKeyCredential(settings.Key, settings.Secret)
1✔
41
                }
1✔
42
        }
43
        return creds, err
2✔
44
}
45

46
func connStringAttr(cs, key string) (string, bool) {
7✔
47
        var start, end int
7✔
48
        for {
15✔
49
                i := strings.Index(cs[start:], key)
8✔
50
                if i < 0 {
10✔
51
                        return "", false
2✔
52
                }
2✔
53
                start += i
6✔
54
                if i == 0 || cs[start-1] == ';' {
11✔
55
                        break
5✔
56
                }
57
                start += len(key)
1✔
58
        }
59
        start += len(key)
5✔
60
        i := strings.IndexRune(cs[start:], ';')
5✔
61
        if i < 0 {
7✔
62
                // cs ends with value
2✔
63
                end = len(cs)
2✔
64
        } else {
5✔
65
                end = start + i
3✔
66
        }
3✔
67
        return cs[start:end], true
5✔
68
}
69

70
func keyFromConnString(cs string) (*azblob.SharedKeyCredential, error) {
4✔
71
        const (
4✔
72
                attrName = "AccountName="
4✔
73
                attrKey  = "AccountKey="
4✔
74
        )
4✔
75
        var (
4✔
76
                accountName, accountKey string
4✔
77
                ok                      bool
4✔
78
        )
4✔
79
        if accountName, ok = connStringAttr(cs, attrName); !ok {
5✔
80
                return nil, ErrConnStrNoName
1✔
81
        }
1✔
82
        if accountKey, ok = connStringAttr(cs, attrKey); !ok {
4✔
83
                return nil, ErrConnStrNoKey
1✔
84
        }
1✔
85
        return azblob.NewSharedKeyCredential(accountName, accountKey)
2✔
86
}
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