mirror of
https://github.com/cuigh/swirl
synced 2024-12-30 15:53:24 +00:00
Remove invalid attributes when saving template
This commit is contained in:
parent
0c2dae4834
commit
b6c670593f
@ -87,6 +87,7 @@ func templateCreate(ctx web.Context) error {
|
||||
tpl = &model.Template{Name: info.Name}
|
||||
)
|
||||
|
||||
info.Normalize()
|
||||
info.Name = ""
|
||||
content, err = json.Marshal(info)
|
||||
if err != nil {
|
||||
@ -113,6 +114,7 @@ func templateEdit(ctx web.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
service.Normalize()
|
||||
|
||||
service.Name = tpl.Name
|
||||
if service.Registry != "" {
|
||||
@ -162,6 +164,7 @@ func templateUpdate(ctx web.Context) error {
|
||||
}
|
||||
)
|
||||
|
||||
info.Normalize()
|
||||
info.Name = ""
|
||||
content, err = json.Marshal(info)
|
||||
if err != nil {
|
||||
|
@ -74,6 +74,19 @@ func (opts Options) ToMap() map[string]string {
|
||||
return m
|
||||
}
|
||||
|
||||
func (opts Options) Compress() Options {
|
||||
if len(opts) > 0 {
|
||||
var tmp Options
|
||||
for _, opt := range opts {
|
||||
if opt != nil {
|
||||
tmp = append(tmp, opt)
|
||||
}
|
||||
}
|
||||
return tmp
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
type StackListInfo struct {
|
||||
Name string
|
||||
Services []string
|
||||
@ -336,6 +349,31 @@ func (si *ServiceInfo) ToServiceSpec() swarm.ServiceSpec {
|
||||
return swarm.ServiceSpec{}
|
||||
}
|
||||
|
||||
func (si *ServiceInfo) Normalize() {
|
||||
si.Environments = si.Environments.Compress()
|
||||
si.ServiceLabels = si.ServiceLabels.Compress()
|
||||
si.ContainerLabels = si.ContainerLabels.Compress()
|
||||
si.LogDriver.Options = si.LogDriver.Options.Compress()
|
||||
if len(si.Configs) > 0 {
|
||||
var tmp []ConfigInfo
|
||||
for _, c := range si.Configs {
|
||||
if c.ID != "" {
|
||||
tmp = append(tmp, c)
|
||||
}
|
||||
}
|
||||
si.Configs = tmp
|
||||
}
|
||||
if len(si.Secrets) > 0 {
|
||||
var tmp []ConfigInfo
|
||||
for _, c := range si.Secrets {
|
||||
if c.ID != "" {
|
||||
tmp = append(tmp, c)
|
||||
}
|
||||
}
|
||||
si.Secrets = tmp
|
||||
}
|
||||
}
|
||||
|
||||
func (si *ServiceInfo) GetDNSConfig() *swarm.DNSConfig {
|
||||
if si.DNS.Nameservers == "" && si.DNS.Search == "" && si.DNS.Options == "" {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user