-
Notifications
You must be signed in to change notification settings - Fork 43
/
dnf_automatic_config_stage.go
70 lines (58 loc) · 2 KB
/
dnf_automatic_config_stage.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
package osbuild
import "fmt"
type DNFAutomaticUpgradeTypeValue string
// Valid values of the 'upgrade_type' option
const (
DNFAutomaticUpgradeTypeDefault DNFAutomaticUpgradeTypeValue = "default"
DNFAutomaticUpgradeTypeSecurity DNFAutomaticUpgradeTypeValue = "security"
)
// DNFAutomaticConfigCommands represents the 'commands' configuration section.
type DNFAutomaticConfigCommands struct {
// Whether packages comprising the available updates should be installed
ApplyUpdates *bool `json:"apply_updates,omitempty"`
// What kind of upgrades to look at
UpgradeType DNFAutomaticUpgradeTypeValue `json:"upgrade_type,omitempty"`
}
// DNFAutomaticConfig represents DNF Automatic configuration.
type DNFAutomaticConfig struct {
Commands *DNFAutomaticConfigCommands `json:"commands,omitempty"`
}
type DNFAutomaticConfigStageOptions struct {
Config *DNFAutomaticConfig `json:"config,omitempty"`
}
func (DNFAutomaticConfigStageOptions) isStageOptions() {}
// NewDNFAutomaticConfigStageOptions creates a new DNFAutomaticConfig Stage options object.
func NewDNFAutomaticConfigStageOptions(config *DNFAutomaticConfig) *DNFAutomaticConfigStageOptions {
return &DNFAutomaticConfigStageOptions{
Config: config,
}
}
func (o DNFAutomaticConfigStageOptions) validate() error {
if o.Config != nil && o.Config.Commands != nil {
allowedUpgradeTypeValues := []DNFAutomaticUpgradeTypeValue{
DNFAutomaticUpgradeTypeDefault,
DNFAutomaticUpgradeTypeSecurity,
"", // default empty value when the option is not set
}
valid := false
for _, value := range allowedUpgradeTypeValues {
if o.Config.Commands.UpgradeType == value {
valid = true
break
}
}
if !valid {
return fmt.Errorf("'upgrade_type' option does not allow %q as a value", o.Config.Commands.UpgradeType)
}
}
return nil
}
func NewDNFAutomaticConfigStage(options *DNFAutomaticConfigStageOptions) *Stage {
if err := options.validate(); err != nil {
panic(err)
}
return &Stage{
Type: "org.osbuild.dnf-automatic.config",
Options: options,
}
}