-
Notifications
You must be signed in to change notification settings - Fork 43
/
registry.go
61 lines (54 loc) · 1.66 KB
/
registry.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
package models
import (
"fmt"
"reflect"
"time"
specV1 "github.com/baetyl/baetyl-go/v2/spec/v1"
"github.com/jinzhu/copier"
)
// Registry Registry
type Registry struct {
Name string `json:"name,omitempty" validate:"omitempty,resourceName"`
Namespace string `json:"namespace,omitempty"`
Address string `json:"address"`
Username string `json:"username"`
Password string `json:"password,omitempty"`
CreationTimestamp time.Time `json:"createTime,omitempty"`
UpdateTimestamp time.Time `json:"updateTime,omitempty"`
Description string `json:"description"`
Version string `json:"version,omitempty"`
}
type RegistryView struct {
Name string `json:"name,omitempty"`
Address string `json:"address,omitempty"`
Username string `json:"username,omitempty"`
}
// RegistryList Registry List
type RegistryList struct {
Total int `json:"total"`
*ListOptions `json:",inline"`
Items []Registry `json:"items"`
}
func (r *Registry) Equal(target *Registry) bool {
return reflect.DeepEqual(r.Address, target.Address) &&
reflect.DeepEqual(r.Username, target.Username) &&
reflect.DeepEqual(r.Password, target.Password) &&
reflect.DeepEqual(r.Description, target.Description)
}
func (r *Registry) ToSecret() *specV1.Secret {
res := &specV1.Secret{
Labels: map[string]string{
specV1.SecretLabel: specV1.SecretRegistry,
},
}
err := copier.Copy(res, r)
if err != nil {
panic(fmt.Sprintf("copier exception: %s", err.Error()))
}
res.Data = map[string][]byte{
"password": []byte(r.Password),
"username": []byte(r.Username),
"address": []byte(r.Address),
}
return res
}