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

mendersoftware / useradm / 1565757771

29 Nov 2024 07:56AM UTC coverage: 87.019%. Remained the same
1565757771

push

gitlab-ci

web-flow
Merge pull request #434 from alfrunes/1.22.x

chore(deps): Upgrade golang to latest

2869 of 3297 relevant lines covered (87.02%)

131.0 hits per line

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

100.0
/common/keys.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 common
16

17
import (
18
        "path/filepath"
19
        "regexp"
20
        "strconv"
21

22
        "github.com/pkg/errors"
23
)
24

25
const KeyIdZero = 0
26

27
var (
28
        ErrKeyIdNotFound  = errors.New("cant locate key by key id")
29
        ErrKeyIdCollision = errors.New("key id already loaded")
30
)
31

32
func KeyIdFromPath(privateKeyPath string, privateKeyFilenamePattern string) (keyId int) {
2,224✔
33
        fileName := filepath.Base(privateKeyPath)
2,224✔
34
        r, _ := regexp.Compile(privateKeyFilenamePattern)
2,224✔
35
        b := []byte(fileName)
2,224✔
36
        indices := r.FindAllSubmatchIndex(b, -1)
2,224✔
37
        keyId = KeyIdZero
2,224✔
38
        if len(indices) > 0 && len(indices[0]) > 3 {
3,247✔
39
                k, err := strconv.Atoi(string(b[indices[0][2]:indices[0][3]]))
1,023✔
40
                if err == nil {
2,046✔
41
                        keyId = k
1,023✔
42
                }
1,023✔
43
        }
44
        return keyId
2,224✔
45
}
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