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

mendersoftware / mender-server / 1622978334

13 Jan 2025 03:51PM UTC coverage: 72.802% (-3.8%) from 76.608%
1622978334

Pull #300

gitlab-ci

alfrunes
fix: Deployment device count should not exceed max devices

Added a condition to skip deployments when the device count reaches max
devices.

Changelog: Title
Ticket: MEN-7847
Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #300: fix: Deployment device count should not exceed max devices

4251 of 6164 branches covered (68.96%)

Branch coverage included in aggregate %.

0 of 18 new or added lines in 1 file covered. (0.0%)

2544 existing lines in 83 files now uncovered.

42741 of 58384 relevant lines covered (73.21%)

21.49 hits per line

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

85.07
/backend/services/deployments/model/storage_settings.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 model
16

17
import (
18
        "bytes"
19
        "encoding/json"
20
        "io"
21

22
        validation "github.com/go-ozzo/ozzo-validation/v4"
23
        "github.com/pkg/errors"
24
)
25

26
type StorageType uint32
27

28
const (
29
        StorageTypeS3 StorageType = iota
30
        StorageTypeAzure
31
        storageTypeMax
32

33
        storageTypeStrS3    = "s3"
34
        storageTypeStrAzure = "azure"
35
)
36

37
func (typ *StorageType) UnmarshalText(b []byte) error {
1✔
38
        switch {
1✔
39
        case bytes.Equal(b, []byte(storageTypeStrS3)):
1✔
40
                *typ = StorageTypeS3
1✔
41

42
        case bytes.Equal(b, []byte(storageTypeStrAzure)):
1✔
43
                *typ = StorageTypeAzure
1✔
44
        default:
×
45
                return errors.New("storage type invalid")
×
46
        }
47
        return nil
1✔
48
}
49

UNCOV
50
func (typ StorageType) MarshalText() ([]byte, error) {
×
UNCOV
51
        switch typ {
×
UNCOV
52
        case StorageTypeS3:
×
UNCOV
53
                return []byte(storageTypeStrS3), nil
×
54
        case StorageTypeAzure:
×
55
                return []byte(storageTypeStrAzure), nil
×
56
        default:
×
57
                return nil, errors.New("storage type invalid")
×
58
        }
59
}
60

61
type StorageSettings struct {
62
        // Type is the provider type (azblob/s3) for the given settings
63
        Type StorageType `json:"type" bson:"type"`
64
        // Region sets the s3 bucket region (required when StorageType == StorageTypeAWS)
65
        Region string `json:"region" bson:"region"`
66
        // Bucket is the name of the bucket (s3) or container (azblob) storing artifacts.
67
        Bucket string `json:"bucket" bson:"bucket"`
68

69
        // Uri contains the (private) URI used to call the storage APIs.
70
        Uri string `json:"uri" bson:"uri"`
71
        // ExternalUri contains the public bucket / container URI.
72
        ExternalUri string `json:"external_uri" bson:"external_uri"`
73
        // ProxyURI is used for rewriting presigned requests, pointing the
74
        // requests to the proxy URL instead of the direct URL to s3.
75
        ProxyURI *string `json:"proxy_uri,omitempty" bson:"proxy_uri,omitempty"`
76

77
        // Key contains the key identifier (azblob: account name) used to
78
        // authenticate with the storage APIs.
79
        Key string `json:"key,omitempty" bson:"key,omitempty"`
80
        // Secret holds the secret part of the authentication credentials.
81
        Secret string `json:"secret,omitempty" bson:"secret,omitempty"`
82
        // Token (s3) stores the optional session token.
83
        Token string `json:"token,omitempty" bson:"token,omitempty"`
84
        // ConnectionString (azblob) contains the Azure connection string as an
85
        // alternative set of credentials from (Uri, Key, Secret).
86
        ConnectionString *string `json:"connection_string,omitempty" bson:"connection_string,omitempty"`
87
        // ForcePathStyle (s3) enables path-style URL scheme for the s3 API.
88
        ForcePathStyle bool `json:"force_path_style" bson:"force_path_style"`
89
        // UseAccelerate (s3) enables AWS transfer acceleration.
90
        UseAccelerate bool `json:"use_accelerate" bson:"use_accelerate"`
91
}
92

93
func ParseStorageSettingsRequest(source io.Reader) (settings *StorageSettings, err error) {
1✔
94
        // NOTE: by wrapping StorageSettings as an embedded struct field,
1✔
95
        // passing an empty object `{}` will unmarshall as nil.
1✔
96
        type extendedSettingsSchema struct {
1✔
97
                AccountName   *string `json:"account_name"`
1✔
98
                AccountKey    *string `json:"account_key"`
1✔
99
                ContainerName *string `json:"container_name"`
1✔
100
                *StorageSettings
1✔
101
        }
1✔
102
        var s extendedSettingsSchema
1✔
103

1✔
104
        err = json.NewDecoder(source).Decode(&s)
1✔
105
        if err == nil && s.StorageSettings != nil {
2✔
106
                if s.Type == StorageTypeAzure {
2✔
107
                        if s.AccountName != nil {
2✔
108
                                s.Key = *s.AccountName
1✔
109
                        }
1✔
110
                        if s.AccountKey != nil {
2✔
111
                                s.Secret = *s.AccountKey
1✔
112
                        }
1✔
113
                        if s.ContainerName != nil {
2✔
114
                                s.Bucket = *s.ContainerName
1✔
115
                        }
1✔
116
                }
117
                settings = s.StorageSettings
1✔
118
                settings.UseAccelerate = settings.UseAccelerate && settings.Uri == ""
1✔
119
                err = errors.WithMessage(
1✔
120
                        settings.Validate(),
1✔
121
                        "invalid settings schema",
1✔
122
                )
1✔
123
        }
124
        return settings, err
1✔
125
}
126

127
var (
128
        ruleStorageType = validation.Max(storageTypeMax).
129
                        Exclusive().
130
                        Error("storage type invalid")
131
        ruleLen5_20   = validation.Length(5, 20)
132
        ruleLen5_50   = validation.Length(5, 50)
133
        ruleLen5_100  = validation.Length(5, 100)
134
        ruleLen3_2000 = validation.Length(3, 2000)
135
)
136

137
// Validate checks structure according to valid tags
138
func (s StorageSettings) Validate() error {
1✔
139
        return validation.ValidateStruct(&s,
1✔
140
                validation.Field(&s.Type, ruleStorageType),
1✔
141
                validation.Field(&s.Region, validation.When(s.Type == StorageTypeS3,
1✔
142
                        validation.Required, ruleLen5_20,
1✔
143
                )),
1✔
144
                validation.Field(&s.Bucket, validation.Required, ruleLen5_100),
1✔
145
                validation.Field(&s.Key, validation.When(
1✔
146
                        s.Type == StorageTypeS3 || s.ConnectionString == nil,
1✔
147
                        validation.Required, ruleLen5_50,
1✔
148
                )),
1✔
149
                validation.Field(&s.Secret, validation.When(
1✔
150
                        s.Type == StorageTypeS3 || s.ConnectionString == nil,
1✔
151
                        validation.Required, ruleLen5_100,
1✔
152
                )),
1✔
153
                validation.Field(&s.Uri, ruleLen3_2000),
1✔
154
                validation.Field(&s.ExternalUri, ruleLen3_2000),
1✔
155
                validation.Field(&s.Token, ruleLen5_100),
1✔
156
        )
1✔
157
}
1✔
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