forked from mendersoftware/deployments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.go
119 lines (95 loc) · 3.63 KB
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2017 Northern.tech AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package images
import (
"time"
"github.com/asaskevich/govalidator"
)
// Informations provided by the user
type SoftwareImageMetaConstructor struct {
// Image description
Description string `json:"description,omitempty" valid:"length(1|4096),optional"`
}
// Creates new, empty SoftwareImageMetaConstructor
func NewSoftwareImageMetaConstructor() *SoftwareImageMetaConstructor {
return &SoftwareImageMetaConstructor{}
}
// Validate checkes structure according to valid tags.
func (s *SoftwareImageMetaConstructor) Validate() error {
_, err := govalidator.ValidateStruct(s)
return err
}
// Structure with artifact version informations
type ArtifactInfo struct {
// Mender artifact format - the only possible value is "mender"
//Format string `json:"format" valid:"string,equal("mender"),required"`
Format string `json:"format" valid:"required"`
// Mender artifact format version
//Version uint `json:"version" valid:"uint,equal(1),required"`
Version uint `json:"version" valid:"required"`
}
// Information provided with YOCTO image
type SoftwareImageMetaArtifactConstructor struct {
// artifact_name from artifact file
Name string `json:"name" bson:"name" valid:"length(1|4096),required"`
// Compatible device types for the application
DeviceTypesCompatible []string `json:"device_types_compatible" bson:"device_types_compatible" valid:"length(1|4096),required"`
// Artifact version info
Info *ArtifactInfo `json:"info" valid:"required"`
// Flag that indicates if artifact is signed or not
Signed bool `json:"signed" bson:"signed"`
// List of updates
Updates []Update `json:"updates" valid:"-"`
}
func NewSoftwareImageMetaArtifactConstructor() *SoftwareImageMetaArtifactConstructor {
return &SoftwareImageMetaArtifactConstructor{}
}
// Validate checkes structure according to valid tags.
func (s *SoftwareImageMetaArtifactConstructor) Validate() error {
_, err := govalidator.ValidateStruct(s)
return err
}
// SoftwareImage YOCTO image with user application
type SoftwareImage struct {
// User provided field set
SoftwareImageMetaConstructor `bson:"meta"`
// Field set provided with yocto image
SoftwareImageMetaArtifactConstructor `bson:"meta_artifact"`
// Image ID
Id string `json:"id" bson:"_id" valid:"uuidv4,required"`
// Last modification time, including image upload time
Modified *time.Time `json:"modified" valid:"_"`
}
// NewSoftwareImage creates new software image object.
func NewSoftwareImage(
id string,
metaConstructor *SoftwareImageMetaConstructor,
metaArtifactConstructor *SoftwareImageMetaArtifactConstructor) *SoftwareImage {
now := time.Now()
return &SoftwareImage{
SoftwareImageMetaConstructor: *metaConstructor,
SoftwareImageMetaArtifactConstructor: *metaArtifactConstructor,
Modified: &now,
Id: id,
}
}
// SetModified set last modification time for the image.
func (s *SoftwareImage) SetModified(time time.Time) {
s.Modified = &time
}
// Validate checkes structure according to valid tags.
func (s *SoftwareImage) Validate() error {
_, err := govalidator.ValidateStruct(s)
return err
}