fix defaults not handled by yaml configuration

This commit is contained in:
CrazyMax
2023-09-23 12:54:17 +02:00
parent 286af41566
commit b9615bf2db
21 changed files with 146 additions and 282 deletions

View File

@@ -3,7 +3,6 @@ package model
import (
"time"
"github.com/crazy-max/diun/v4/pkg/registry"
"github.com/crazy-max/diun/v4/pkg/utl"
)
@@ -16,7 +15,7 @@ type Watch struct {
RunOnStartup *bool `yaml:"runOnStartup,omitempty" json:"runOnStartup,omitempty" validate:"required"`
CompareDigest *bool `yaml:"compareDigest,omitempty" json:"compareDigest,omitempty" validate:"required"`
Healthchecks *Healthchecks `yaml:"healthchecks,omitempty" json:"healthchecks,omitempty"`
ImageDefaults *Image `yaml:"defaults,omitempty" json:"defaults,omitempty"`
ImageDefaults *ImageDefaults `yaml:"imageDefaults,omitempty" json:"imageDefaults,omitempty"`
}
// GetDefaults gets the default values
@@ -33,8 +32,4 @@ func (s *Watch) SetDefaults() {
s.FirstCheckNotif = utl.NewFalse()
s.RunOnStartup = utl.NewTrue()
s.CompareDigest = utl.NewTrue()
s.ImageDefaults = &Image{
NotifyOn: NotifyOnDefaults,
SortTags: registry.SortTagReverse,
}
}

View File

@@ -0,0 +1,31 @@
package model
import (
"github.com/crazy-max/diun/v4/pkg/registry"
"github.com/crazy-max/diun/v4/pkg/utl"
)
// ImageDefaults holds data necessary for image defaults configuration
type ImageDefaults struct {
WatchRepo *bool `yaml:"watchRepo,omitempty" json:"watchRepo,omitempty"`
NotifyOn []NotifyOn `yaml:"notifyOn,omitempty" json:"notifyOn,omitempty"`
MaxTags int `yaml:"maxTags,omitempty" json:"maxTags,omitempty"`
SortTags registry.SortTag `yaml:"sortTags,omitempty" json:"sortTags,omitempty"`
IncludeTags []string `yaml:"includeTags,omitempty" json:"includeTags,omitempty"`
ExcludeTags []string `yaml:"excludeTags,omitempty" json:"excludeTags,omitempty"`
Metadata map[string]string `yaml:"metadata,omitempty" json:"metadata,omitempty"`
}
// GetDefaults gets the default values
func (s *ImageDefaults) GetDefaults() *Watch {
n := &Watch{}
n.SetDefaults()
return n
}
// SetDefaults sets the default values
func (s *ImageDefaults) SetDefaults() {
s.WatchRepo = utl.NewFalse()
s.NotifyOn = NotifyOnDefaults
s.SortTags = registry.SortTagReverse
}