osbuild2: use type aliases for unexported types to prevent recursion
Some osbuild stages added as part of PR#1525 declare unexported types which are complete copies of types with custom MarshalJSON method, to prevent recursion when marshalling to JSON. Modify relevant osbuild stages to use type alias instead of declaring a complete type copy. https://github.com/osbuild/osbuild-composer/pull/1525 Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
2be664de38
commit
5359ff8da7
5 changed files with 14 additions and 62 deletions
|
|
@ -22,11 +22,8 @@ type ChronyConfigServer struct {
|
|||
Prefer *bool `json:"prefer,omitempty"`
|
||||
}
|
||||
|
||||
// Unexported struct for use in ChronyStageOptions's MarshalJSON() to prevent recursion
|
||||
type chronyStageOptions struct {
|
||||
Timeservers []string `json:"timeservers,omitempty"`
|
||||
Servers []ChronyConfigServer `json:"servers,omitempty"`
|
||||
}
|
||||
// Unexported alias for use in ChronyStageOptions's MarshalJSON() to prevent recursion
|
||||
type chronyStageOptions ChronyStageOptions
|
||||
|
||||
func (o ChronyStageOptions) MarshalJSON() ([]byte, error) {
|
||||
if (len(o.Timeservers) != 0 && len(o.Servers) != 0) || (len(o.Timeservers) == 0 && len(o.Servers) == 0) {
|
||||
|
|
|
|||
|
|
@ -23,10 +23,8 @@ type CloudInitConfigFile struct {
|
|||
SystemInfo *CloudInitConfigSystemInfo `json:"system_info,omitempty"`
|
||||
}
|
||||
|
||||
// Unexported struct for use in CloudInitConfigFile's MarshalJSON() to prevent recursion
|
||||
type cloudInitConfigFile struct {
|
||||
SystemInfo *CloudInitConfigSystemInfo `json:"system_info,omitempty"`
|
||||
}
|
||||
// Unexported alias for use in CloudInitConfigFile's MarshalJSON() to prevent recursion
|
||||
type cloudInitConfigFile CloudInitConfigFile
|
||||
|
||||
func (c CloudInitConfigFile) MarshalJSON() ([]byte, error) {
|
||||
if c.SystemInfo == nil {
|
||||
|
|
@ -41,10 +39,8 @@ type CloudInitConfigSystemInfo struct {
|
|||
DefaultUser *CloudInitConfigDefaultUser `json:"default_user,omitempty"`
|
||||
}
|
||||
|
||||
// Unexported struct for use in CloudInitConfigSystemInfo's MarshalJSON() to prevent recursion
|
||||
type cloudInitConfigSystemInfo struct {
|
||||
DefaultUser *CloudInitConfigDefaultUser `json:"default_user,omitempty"`
|
||||
}
|
||||
// Unexported alias for use in CloudInitConfigSystemInfo's MarshalJSON() to prevent recursion
|
||||
type cloudInitConfigSystemInfo CloudInitConfigSystemInfo
|
||||
|
||||
func (si CloudInitConfigSystemInfo) MarshalJSON() ([]byte, error) {
|
||||
if si.DefaultUser == nil {
|
||||
|
|
@ -59,10 +55,8 @@ type CloudInitConfigDefaultUser struct {
|
|||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
// Unexported struct for use in CloudInitConfigDefaultUser's MarshalJSON() to prevent recursion
|
||||
type cloudInitConfigDefaultUser struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
// Unexported alias for use in CloudInitConfigDefaultUser's MarshalJSON() to prevent recursion
|
||||
type cloudInitConfigDefaultUser CloudInitConfigDefaultUser
|
||||
|
||||
func (du CloudInitConfigDefaultUser) MarshalJSON() ([]byte, error) {
|
||||
if du.Name == "" {
|
||||
|
|
|
|||
|
|
@ -54,41 +54,8 @@ type DracutConfigFile struct {
|
|||
Reproducible *bool `json:"reproducible,omitempty"`
|
||||
}
|
||||
|
||||
// Unexported struct for use in DracutConfigFile MarshalJSON() to prevent recursion
|
||||
type dracutConfigFile struct {
|
||||
// Compression method for the initramfs
|
||||
Compress string `json:"compress,omitempty"`
|
||||
|
||||
// Exact list of dracut modules to use
|
||||
Modules []string `json:"dracutmodules,omitempty"`
|
||||
|
||||
// Additional dracut modules to include
|
||||
AddModules []string `json:"add_dracutmodules,omitempty"`
|
||||
|
||||
// Dracut modules to not include
|
||||
OmitModules []string `json:"omit_dracutmodules,omitempty"`
|
||||
|
||||
// Kernel modules to exclusively include
|
||||
Drivers []string `json:"drivers,omitempty"`
|
||||
|
||||
// Add a specific kernel module
|
||||
AddDrivers []string `json:"add_drivers,omitempty"`
|
||||
|
||||
// Add driver and ensure that they are tried to be loaded
|
||||
ForceDrivers []string `json:"force_drivers,omitempty"`
|
||||
|
||||
// Kernel filesystem modules to exclusively include
|
||||
Filesystems []string `json:"filesystems,omitempty"`
|
||||
|
||||
// Install the specified files
|
||||
Install []string `json:"install_items,omitempty"`
|
||||
|
||||
// Combine early microcode with the initramfs
|
||||
EarlyMicrocode *bool `json:"early_microcode,omitempty"`
|
||||
|
||||
// Create reproducible images
|
||||
Reproducible *bool `json:"reproducible,omitempty"`
|
||||
}
|
||||
// Unexported alias for use in DracutConfigFile MarshalJSON() to prevent recursion
|
||||
type dracutConfigFile DracutConfigFile
|
||||
|
||||
func (c DracutConfigFile) MarshalJSON() ([]byte, error) {
|
||||
if c.Compress == "" &&
|
||||
|
|
|
|||
|
|
@ -23,10 +23,8 @@ type X11KeymapOptions struct {
|
|||
Layouts []string `json:"layouts"`
|
||||
}
|
||||
|
||||
// Unexported struct for use in X11KeymapOptions's MarshalJSON() to prevent recursion
|
||||
type x11KeymapOptions struct {
|
||||
Layouts []string `json:"layouts"`
|
||||
}
|
||||
// Unexported alias for use in X11KeymapOptions's MarshalJSON() to prevent recursion
|
||||
type x11KeymapOptions X11KeymapOptions
|
||||
|
||||
func (o X11KeymapOptions) MarshalJSON() ([]byte, error) {
|
||||
if len(o.Layouts) == 0 {
|
||||
|
|
|
|||
|
|
@ -30,12 +30,8 @@ type SystemdLogindConfigLoginSection struct {
|
|||
NAutoVT *int `json:"NAutoVT,omitempty"`
|
||||
}
|
||||
|
||||
// Unexported struct for use in SystemdLogindConfigLoginSection's MarshalJSON() to prevent recursion
|
||||
type systemdLogindConfigLoginSection struct {
|
||||
// Configures how many virtual terminals (VTs) to allocate by default
|
||||
// The option is optional, but zero is a valid value
|
||||
NAutoVT *int `json:"NAutoVT,omitempty"`
|
||||
}
|
||||
// Unexported alias for use in SystemdLogindConfigLoginSection's MarshalJSON() to prevent recursion
|
||||
type systemdLogindConfigLoginSection SystemdLogindConfigLoginSection
|
||||
|
||||
func (s SystemdLogindConfigLoginSection) MarshalJSON() ([]byte, error) {
|
||||
if s.NAutoVT == nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue