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

mendersoftware / mender-server / 1495380963

14 Oct 2024 03:35PM UTC coverage: 70.373% (-2.5%) from 72.904%
1495380963

Pull #101

gitlab-ci

mineralsfree
feat: tenant list added

Ticket: MEN-7568
Changelog: None

Signed-off-by: Mikita Pilinka <mikita.pilinka@northern.tech>
Pull Request #101: feat: tenant list added

4406 of 6391 branches covered (68.94%)

Branch coverage included in aggregate %.

88 of 183 new or added lines in 10 files covered. (48.09%)

2623 existing lines in 65 files now uncovered.

36673 of 51982 relevant lines covered (70.55%)

31.07 hits per line

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

0.0
/backend/services/workflows/app/processor/job.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 processor
16

17
import (
18
        "strings"
19

20
        "go.mongodb.org/mongo-driver/bson"
21
        "go.mongodb.org/mongo-driver/bson/primitive"
22

23
        "github.com/mendersoftware/mender-server/services/workflows/model"
24
)
25

26
type JobProcessor struct {
27
        job *model.Job
28
}
29

30
type JsonOptions struct {
31
}
32

UNCOV
33
func NewJobProcessor(job *model.Job) *JobProcessor {
×
UNCOV
34
        return &JobProcessor{
×
UNCOV
35
                job: job,
×
UNCOV
36
        }
×
UNCOV
37
}
×
38

39
func (j JobProcessor) ProcessJSON(
40
        data interface{},
41
        ps *JobStringProcessor,
42
        options ...*JsonOptions,
UNCOV
43
) interface{} {
×
UNCOV
44
        switch value := data.(type) {
×
UNCOV
45
        case []interface{}:
×
UNCOV
46
                result := make([]interface{}, len(value))
×
UNCOV
47
                for i, item := range value {
×
UNCOV
48
                        result[i] = j.ProcessJSON(item, ps)
×
UNCOV
49
                }
×
UNCOV
50
                return result
×
UNCOV
51
        case map[string]interface{}:
×
UNCOV
52
                result := make(map[string]interface{})
×
UNCOV
53
                for key, item := range value {
×
UNCOV
54
                        result[key] = j.ProcessJSON(item, ps)
×
UNCOV
55
                }
×
UNCOV
56
                return result
×
UNCOV
57
        case string:
×
UNCOV
58
                if len(value) > 3 && value[0:2] == "${" && value[len(value)-1:] == "}" {
×
UNCOV
59
                        key := value[2 : len(value)-1]
×
UNCOV
60
                        if strings.HasPrefix(key, workflowInputVariable) &&
×
UNCOV
61
                                len(key) > len(workflowInputVariable) {
×
UNCOV
62
                                key = key[len(workflowInputVariable):]
×
UNCOV
63
                                for _, param := range j.job.InputParameters {
×
UNCOV
64
                                        if param.Name == key && param.Raw != nil {
×
UNCOV
65
                                                return j.ProcessJSON(param.Raw, ps)
×
UNCOV
66
                                        }
×
67
                                }
68
                                return nil
×
69
                        }
70
                }
UNCOV
71
                return ps.ProcessJobString(value)
×
72
        case primitive.D:
×
73
                result := make(map[string]interface{})
×
74
                var mapValue bson.M
×
75
                bsonValue, err := bson.Marshal(value)
×
76
                if err != nil {
×
77
                        return nil
×
78
                }
×
79
                err = bson.Unmarshal(bsonValue, &mapValue)
×
80
                if err != nil {
×
81
                        return nil
×
82
                }
×
83
                for key, item := range mapValue {
×
84
                        result[key] = j.ProcessJSON(item, ps)
×
85
                }
×
86
                return result
×
87
        case []primitive.D:
×
88
                result := make([]interface{}, len(value))
×
89
                for i, item := range value {
×
90
                        result[i] = j.ProcessJSON(item, ps)
×
91
                }
×
92
                return result
×
93
        }
UNCOV
94
        return data
×
95
}
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