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

mendersoftware / reporting / 738346025

pending completion
738346025

Pull #87

gitlab-ci

Fabio Tranchitella
feat: add support to index the device deployment data in the indexer
Pull Request #87: MEN-5930: index device deployment objects

641 of 884 new or added lines in 15 files covered. (72.51%)

1 existing line in 1 file now uncovered.

2556 of 3139 relevant lines covered (81.43%)

16.26 hits per line

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

0.0
/model/aggregations_deployments.go
1
// Copyright 2022 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 model
16

17
import validation "github.com/go-ozzo/ozzo-validation/v4"
18

19
type AggregateDeploymentsParams struct {
20
        Aggregations []DeploymentsAggregationTerm `json:"aggregations"`
21
        Filters      []DeploymentsFilterPredicate `json:"filters"`
22
        TenantID     string                       `json:"-"`
23
}
24

25
type DeploymentsAggregationTerm struct {
26
        Name         string                       `json:"name"`
27
        Attribute    string                       `json:"attribute"`
28
        Limit        int                          `json:"limit"`
29
        Aggregations []DeploymentsAggregationTerm `json:"aggregations"`
30
}
31

NEW
32
func (sp AggregateDeploymentsParams) Validate() error {
×
NEW
33
        err := validation.ValidateStruct(&sp,
×
NEW
34
                validation.Field(&sp.Aggregations, validation.Required,
×
NEW
35
                        validation.Length(1, maxAggregationTerms)))
×
NEW
36
        if err != nil {
×
NEW
37
                return err
×
NEW
38
        }
×
39

NEW
40
        for _, f := range sp.Filters {
×
NEW
41
                err := f.Validate()
×
NEW
42
                if err != nil {
×
NEW
43
                        return err
×
NEW
44
                }
×
45
        }
NEW
46
        return nil
×
47
}
48

NEW
49
func (f DeploymentsAggregationTerm) Validate() error {
×
NEW
50
        return validation.ValidateStruct(&f,
×
NEW
51
                validation.Field(&f.Name, validation.Required),
×
NEW
52
                validation.Field(&f.Attribute, validation.Required),
×
NEW
53
                validation.Field(&f.Limit, validation.Min(0)),
×
NEW
54
                validation.Field(&f.Aggregations, validation.When(
×
NEW
55
                        len(f.Aggregations) > 0, validation.Length(0, maxAggregationTerms))),
×
NEW
56
        )
×
NEW
57
}
×
58

NEW
59
func BuildDeploymentsAggregations(terms []DeploymentsAggregationTerm) (*Aggregations, error) {
×
NEW
60
        aggs := Aggregations{}
×
NEW
61
        for _, term := range terms {
×
NEW
62
                terms := map[string]interface{}{
×
NEW
63
                        "field": term.Attribute,
×
NEW
64
                }
×
NEW
65
                limit := term.Limit
×
NEW
66
                if limit <= 0 {
×
NEW
67
                        limit = defaultAggregationLimit
×
NEW
68
                }
×
NEW
69
                terms["size"] = limit
×
NEW
70
                agg := map[string]interface{}{
×
NEW
71
                        "terms": terms,
×
NEW
72
                }
×
NEW
73
                if len(term.Aggregations) > 0 {
×
NEW
74
                        subaggs, err := BuildDeploymentsAggregations(term.Aggregations)
×
NEW
75
                        if err != nil {
×
NEW
76
                                return nil, err
×
NEW
77
                        }
×
NEW
78
                        agg["aggs"] = subaggs
×
79
                }
NEW
80
                aggs[term.Name] = agg
×
81
        }
NEW
82
        return &aggs, nil
×
83
}
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