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

mendersoftware / iot-manager / 1401702106

05 Aug 2024 08:32PM UTC coverage: 87.577%. Remained the same
1401702106

push

gitlab-ci

web-flow
Merge pull request #295 from mendersoftware/dependabot/docker/docker-dependencies-03b04ac819

chore: bump golang from 1.22.4-alpine3.19 to 1.22.5-alpine3.19 in the docker-dependencies group

3264 of 3727 relevant lines covered (87.58%)

11.44 hits per line

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

100.0
/model/integration.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 (
18
        "fmt"
19

20
        validation "github.com/go-ozzo/ozzo-validation/v4"
21
        "github.com/google/uuid"
22
)
23

24
type Integration struct {
25
        ID          uuid.UUID   `json:"id" bson:"_id"`
26
        Provider    Provider    `json:"provider" bson:"provider"`
27
        Credentials Credentials `json:"credentials" bson:"credentials"`
28
        Description string      `json:"description,omitempty" bson:"description,omitempty"`
29
}
30

31
var (
32
        lenLessThan1024 = validation.Length(0, 1024)
33
)
34

35
func (itg Integration) Validate() error {
19✔
36
        return validation.ValidateStruct(&itg,
19✔
37
                validation.Field(&itg.ID),
19✔
38
                validation.Field(&itg.Provider,
19✔
39
                        validation.Required,
19✔
40
                        validation.By(itg.compatibleCredentials)),
19✔
41
                validation.Field(&itg.Credentials),
19✔
42
                validation.Field(&itg.Description, lenLessThan1024),
19✔
43
        )
19✔
44
}
19✔
45

46
func (itg Integration) compatibleCredentials(interface{}) error {
19✔
47
        switch itg.Provider {
19✔
48
        case ProviderIoTHub:
4✔
49
                if itg.Credentials.Type == CredentialTypeSAS {
7✔
50
                        return nil
3✔
51
                }
3✔
52
        case ProviderIoTCore:
11✔
53
                if itg.Credentials.Type == CredentialTypeAWS {
22✔
54
                        return nil
11✔
55
                }
11✔
56
        case ProviderWebhook:
4✔
57
                if itg.Credentials.Type == CredentialTypeHTTP {
8✔
58
                        return nil
4✔
59
                }
4✔
60
        }
61
        return fmt.Errorf(
1✔
62
                "'%s' incompatible with credential type '%s'",
1✔
63
                itg.Provider,
1✔
64
                itg.Credentials.Type,
1✔
65
        )
1✔
66
}
67

68
type CredentialType string
69

70
const (
71
        CredentialTypeAWS  CredentialType = "aws"
72
        CredentialTypeSAS  CredentialType = "sas"
73
        CredentialTypeHTTP CredentialType = "http"
74
)
75

76
var credentialTypeRule = validation.In(
77
        CredentialTypeAWS,
78
        CredentialTypeSAS,
79
        CredentialTypeHTTP,
80
)
81

82
func (typ CredentialType) Validate() error {
21✔
83
        return credentialTypeRule.Validate(typ)
21✔
84
}
21✔
85

86
//nolint:lll
87
type Credentials struct {
88
        Type CredentialType `json:"type" bson:"type"`
89

90
        // AWS Iot Core
91
        AWSCredentials *AWSCredentials `json:"aws,omitempty" bson:"aws,omitempty"`
92

93
        // Azure IoT Hub
94
        //nolint:lll
95
        ConnectionString *ConnectionString `json:"connection_string,omitempty" bson:"connection_string,omitempty"`
96

97
        // Webhooks
98
        HTTP *HTTPCredentials `json:"http,omitempty" bson:"http,omitempty"`
99
}
100

101
func (s Credentials) Validate() error {
22✔
102
        return validation.ValidateStruct(&s,
22✔
103
                validation.Field(&s.Type, validation.Required),
22✔
104
                validation.Field(&s.ConnectionString,
22✔
105
                        validation.When(s.Type == CredentialTypeSAS, validation.Required)),
22✔
106
                validation.Field(&s.AWSCredentials,
22✔
107
                        validation.When(s.Type == CredentialTypeAWS, validation.Required)),
22✔
108
                validation.Field(&s.HTTP,
22✔
109
                        validation.When(s.Type == CredentialTypeHTTP, validation.Required)),
22✔
110
        )
22✔
111
}
22✔
112

113
type IntegrationFilter struct {
114
        Skip     int64
115
        Limit    int64
116
        Provider Provider
117
        IDs      []uuid.UUID
118
}
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