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

mendersoftware / deployments / 1197570064

01 Mar 2024 06:24PM UTC coverage: 52.222% (-28.4%) from 80.645%
1197570064

Pull #998

gitlab-ci

web-flow
chore: bump github.com/Azure/azure-sdk-for-go/sdk/azcore

Bumps [github.com/Azure/azure-sdk-for-go/sdk/azcore](https://github.com/Azure/azure-sdk-for-go) from 1.9.1 to 1.10.0.
- [Release notes](https://github.com/Azure/azure-sdk-for-go/releases)
- [Changelog](https://github.com/Azure/azure-sdk-for-go/blob/main/documentation/release.md)
- [Commits](https://github.com/Azure/azure-sdk-for-go/compare/sdk/azcore/v1.9.1...sdk/azcore/v1.10.0)

---
updated-dependencies:
- dependency-name: github.com/Azure/azure-sdk-for-go/sdk/azcore
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #998: chore: bump github.com/Azure/azure-sdk-for-go/sdk/azcore from 1.9.1 to 1.10.0

5218 of 9992 relevant lines covered (52.22%)

0.55 hits per line

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

74.6
/model/image.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
        "context"
19
        "io"
20
        "path"
21
        "time"
22

23
        validation "github.com/go-ozzo/ozzo-validation/v4"
24
        "github.com/go-ozzo/ozzo-validation/v4/is"
25
        "github.com/mendersoftware/go-lib-micro/identity"
26
        "github.com/mendersoftware/go-lib-micro/mongo/doc"
27
        "github.com/pkg/errors"
28
        "go.mongodb.org/mongo-driver/bson"
29
        "go.mongodb.org/mongo-driver/bson/bsontype"
30
)
31

32
const (
33
        ArtifactFileSuffix = ".mender"
34
)
35

36
var (
37
        StorageKeyImageProvidesIdxKey   = "meta_artifact.provides_idx.key"
38
        StorageKeyImageProvidesIdxValue = "meta_artifact.provides_idx.value"
39
)
40

41
type ProvidesIdx map[string]string
42

43
func ImagePathFromContext(ctx context.Context, id string) string {
1✔
44
        imgPath := id
1✔
45
        if idty := identity.FromContext(ctx); idty != nil {
2✔
46
                imgPath = path.Join(idty.Tenant, id)
1✔
47
        }
1✔
48
        return imgPath
1✔
49
}
50

51
// Information provided by the user
52
type ImageMeta struct {
53
        // Image description
54
        Description string `json:"description,omitempty" valid:"length(1|4096),optional"`
55
}
56

57
// Creates new, empty ImageMeta
58
func NewImageMeta() *ImageMeta {
×
59
        return &ImageMeta{}
×
60
}
×
61

62
// Validate checks structure according to valid tags.
63
func (s ImageMeta) Validate() error {
1✔
64
        return validation.ValidateStruct(&s,
1✔
65
                validation.Field(&s.Description, lengthLessThan4096),
1✔
66
        )
1✔
67
}
1✔
68

69
// Structure with artifact version information
70
type ArtifactInfo struct {
71
        // Mender artifact format - the only possible value is "mender"
72
        //Format string `json:"format" valid:"string,equal("mender"),required"`
73
        Format string `json:"format" valid:"required"`
74

75
        // Mender artifact format version
76
        //Version uint `json:"version" valid:"uint,equal(1),required"`
77
        Version uint `json:"version" valid:"required"`
78
}
79

80
func (ai ArtifactInfo) Validate() error {
1✔
81
        return validation.ValidateStruct(&ai,
1✔
82
                validation.Field(&ai.Format, validation.Required),
1✔
83
                validation.Field(&ai.Version, validation.In(uint(1), uint(2), uint(3))),
1✔
84
        )
1✔
85
}
1✔
86

87
// Information provided by the Mender Artifact header
88
type ArtifactMeta struct {
89
        // artifact_name from artifact file
90
        Name string `json:"name" bson:"name" valid:"length(1|4096),required"`
91

92
        // Compatible device types for the application
93
        //nolint:lll
94
        DeviceTypesCompatible []string `json:"device_types_compatible" bson:"device_types_compatible" valid:"length(1|4096),required"`
95

96
        // Artifact version info
97
        Info *ArtifactInfo `json:"info"`
98

99
        // Flag that indicates if artifact is signed or not
100
        Signed bool `json:"signed" bson:"signed"`
101

102
        // List of updates
103
        Updates []Update `json:"updates" valid:"-"`
104

105
        // Provides is a map of artifact_provides used
106
        // for checking artifact (version 3) dependencies.
107
        //nolint: lll
108
        Provides map[string]string `json:"artifact_provides,omitempty" bson:"provides,omitempty" valid:"-"`
109

110
        // ProvidesIdx is special representation of provides
111
        // which makes possible to index and query using provides.
112
        ProvidesIdx ProvidesIdx `json:"-" bson:"provides_idx,omitempty"`
113

114
        // Depends is a map[string]interface{} (JSON) of artifact_depends used
115
        // for checking/validate against artifact (version 3) provides.
116
        Depends map[string]interface{} `json:"artifact_depends,omitempty" bson:"depends" valid:"-"`
117

118
        // ClearsProvides is a list of strings (JSON) of clears_artifact_provides used
119
        // for clearing already-installed artifact (version 3) provides.
120
        //nolint:lll
121
        ClearsProvides []string `json:"clears_artifact_provides,omitempty" bson:"clears_provides,omitempty" valid:"-"`
122
}
123

124
// MarshalBSON transparently creates depends_idx field on bson.Marshal
125
func (am ArtifactMeta) MarshalBSON() ([]byte, error) {
×
126
        if err := am.Validate(); err != nil {
×
127
                return nil, err
×
128
        }
×
129
        dependsIdx, err := doc.UnwindMap(am.Depends)
×
130
        if err != nil {
×
131
                return nil, err
×
132
        }
×
133
        doc := doc.DocumentFromStruct(am, bson.E{
×
134
                Key: "depends_idx", Value: dependsIdx,
×
135
        })
×
136
        return bson.Marshal(doc)
×
137
}
138

139
// MarshalBSONValue transparently creates depends_idx field on bson.MarshalValue
140
// which is called if ArtifactMeta is marshaled as an embedded document.
141
func (am ArtifactMeta) MarshalBSONValue() (bsontype.Type, []byte, error) {
1✔
142
        if err := am.Validate(); err != nil {
1✔
143
                return bson.TypeNull, nil, err
×
144
        }
×
145
        dependsIdx, err := doc.UnwindMap(am.Depends)
1✔
146
        if err != nil {
1✔
147
                return bson.TypeNull, nil, err
×
148
        }
×
149
        doc := doc.DocumentFromStruct(am, bson.E{
1✔
150
                Key: "depends_idx", Value: dependsIdx,
1✔
151
        })
1✔
152
        return bson.MarshalValue(doc)
1✔
153
}
154

155
// Validate checks structure according to valid tags.
156
func (am *ArtifactMeta) Validate() error {
1✔
157
        if am.Depends == nil {
1✔
158
                am.Depends = make(map[string]interface{})
×
159
        }
×
160
        am.Depends["device_type"] = am.DeviceTypesCompatible
1✔
161

1✔
162
        return validation.ValidateStruct(am,
1✔
163
                validation.Field(&am.Name, validation.Required, lengthIn1To4096),
1✔
164
                validation.Field(&am.DeviceTypesCompatible,
1✔
165
                        validation.Required,
1✔
166
                        lengthIn0To200,
1✔
167
                        validation.Each(lengthIn1To4096),
1✔
168
                ),
1✔
169
                validation.Field(&am.Info),
1✔
170
        )
1✔
171
}
172

173
func NewArtifactMeta() *ArtifactMeta {
1✔
174
        return &ArtifactMeta{}
1✔
175
}
1✔
176

177
// Image YOCTO image with user application
178
type Image struct {
179
        // Image ID
180
        Id string `json:"id" bson:"_id" valid:"uuidv4,required"`
181

182
        // User provided field set
183
        *ImageMeta `bson:"meta"`
184

185
        // Field set provided with yocto image
186
        *ArtifactMeta `bson:"meta_artifact"`
187

188
        // Artifact total size
189
        Size int64 `json:"size" bson:"size" valid:"-"`
190

191
        // Last modification time, including image upload time
192
        Modified *time.Time `json:"modified" valid:"-"`
193
}
194

195
func (img Image) MarshalBSON() (b []byte, err error) {
1✔
196
        return bson.Marshal(doc.DocumentFromStruct(img))
1✔
197
}
1✔
198

199
func (img Image) MarshalBSONValue() (bsontype.Type, []byte, error) {
1✔
200
        return bson.MarshalValue(doc.DocumentFromStruct(img))
1✔
201
}
1✔
202

203
// Validate checks structure according to valid tags.
204
func (s Image) Validate() error {
1✔
205
        return validation.ValidateStruct(&s,
1✔
206
                validation.Field(&s.Id, validation.Required, is.UUID),
1✔
207
                validation.Field(&s.ImageMeta),
1✔
208
                validation.Field(&s.ArtifactMeta),
1✔
209
        )
1✔
210
}
1✔
211

212
// NewImage creates new software image object.
213
func NewImage(
214
        id string,
215
        metaConstructor *ImageMeta,
216
        metaArtifactConstructor *ArtifactMeta,
217
        artifactSize int64) *Image {
1✔
218

1✔
219
        now := time.Now()
1✔
220

1✔
221
        return &Image{
1✔
222
                ImageMeta:    metaConstructor,
1✔
223
                ArtifactMeta: metaArtifactConstructor,
1✔
224
                Modified:     &now,
1✔
225
                Id:           id,
1✔
226
                Size:         artifactSize,
1✔
227
        }
1✔
228
}
1✔
229

230
// SetModified set last modification time for the image.
231
func (s *Image) SetModified(time time.Time) {
×
232
        s.Modified = &time
×
233
}
×
234

235
type ReadCounter interface {
236
        io.Reader
237
        // Count returns the number of bytes read.
238
        Count() int64
239
}
240

241
// MultipartUploadMsg is a structure with fields extracted from the multipart/form-data form
242
// send in the artifact upload request
243
type MultipartUploadMsg struct {
244
        // user metadata constructor
245
        MetaConstructor *ImageMeta
246
        // ArtifactID contains the artifact ID
247
        ArtifactID string
248
        // reader pointing to the beginning of the artifact data
249
        ArtifactReader io.Reader
250
}
251

252
// MultipartGenerateImageMsg is a structure with fields extracted from the multipart/form-data
253
// form sent in the artifact generation request
254
type MultipartGenerateImageMsg struct {
255
        Name                  string    `json:"name"`
256
        Description           string    `json:"description"`
257
        DeviceTypesCompatible []string  `json:"device_types_compatible"`
258
        Type                  string    `json:"type"`
259
        Args                  string    `json:"args"`
260
        ArtifactID            string    `json:"artifact_id"`
261
        GetArtifactURI        string    `json:"get_artifact_uri"`
262
        DeleteArtifactURI     string    `json:"delete_artifact_uri"`
263
        TenantID              string    `json:"tenant_id"`
264
        Token                 string    `json:"token"`
265
        FileReader            io.Reader `json:"-"`
266
}
267

268
func (msg MultipartGenerateImageMsg) Validate() error {
1✔
269
        if err := validation.ValidateStruct(&msg,
1✔
270
                validation.Field(&msg.Name, validation.Required),
1✔
271
                validation.Field(&msg.DeviceTypesCompatible, validation.Required),
1✔
272
                validation.Field(&msg.Type, validation.Required),
1✔
273
        ); err != nil {
1✔
274
                return err
×
275
        }
×
276
        // Somehow FileReader is not covered by "required" rule.
277
        if msg.FileReader == nil {
1✔
278
                return errors.New("missing 'file' section")
×
279
        }
×
280
        return nil
1✔
281
}
282

283
type provideInternal struct {
284
        Key   string
285
        Value string
286
}
287

288
func (p ProvidesIdx) MarshalBSONValue() (bsontype.Type, []byte, error) {
1✔
289
        attrs := make([]provideInternal, len(p))
1✔
290
        i := 0
1✔
291
        for k, v := range p {
2✔
292
                attrs[i].Key = k
1✔
293
                attrs[i].Value = v
1✔
294
                i++
1✔
295
        }
1✔
296
        return bson.MarshalValue(attrs)
1✔
297
}
298

299
func (p *ProvidesIdx) UnmarshalBSONValue(t bsontype.Type, b []byte) error {
1✔
300
        raw := bson.Raw(b)
1✔
301
        elems, err := raw.Elements()
1✔
302
        if err != nil {
1✔
303
                return err
×
304
        }
×
305
        *p = make(ProvidesIdx, len(elems))
1✔
306
        var tmp provideInternal
1✔
307
        for _, elem := range elems {
2✔
308
                err = elem.Value().Unmarshal(&tmp)
1✔
309
                if err != nil {
1✔
310
                        return err
×
311
                }
×
312
                (*p)[tmp.Key] = tmp.Value
1✔
313
        }
314

315
        return nil
1✔
316
}
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