Skip to content

Commit 03203dc

Browse files
committed
refactor: simplify genericAttributesWith function signature and logic
- Updated the genericAttributesWith function to accept a single map of attributes instead of a variadic argument. - Improved the logic to initialize and merge attributes, ensuring that extra attributes can override the generic ones. - Adjusted the SimpleResource schema to call genericAttributesWith with nil for clarity. Signed-off-by: Pavel Boldyrev <[email protected]>
1 parent 520e7b4 commit 03203dc

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

fwprovider/cluster/sdn/zone/resource_generic.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,9 @@ func (m *genericModel) getID() string {
6868
return m.ID.ValueString()
6969
}
7070

71-
func genericAttributesWith(extraAttributes ...map[string]schema.Attribute) map[string]schema.Attribute {
72-
if len(extraAttributes) > 1 {
73-
panic("genericAttributesWith expects at most one extraAttributes map")
74-
}
75-
76-
if len(extraAttributes) == 0 {
77-
extraAttributes = append(extraAttributes, make(map[string]schema.Attribute))
78-
}
79-
80-
maps.Copy(extraAttributes[0], map[string]schema.Attribute{
71+
func genericAttributesWith(extraAttributes map[string]schema.Attribute) map[string]schema.Attribute {
72+
// Start with generic attributes as the base
73+
result := map[string]schema.Attribute{
8174
"dns": schema.StringAttribute{
8275
Optional: true,
8376
Description: "DNS API server address.",
@@ -116,9 +109,14 @@ func genericAttributesWith(extraAttributes ...map[string]schema.Attribute) map[s
116109
Optional: true,
117110
Description: "Reverse DNS API server address.",
118111
},
119-
})
112+
}
113+
114+
// Add extra attributes, allowing them to override generic ones if needed
115+
if extraAttributes != nil {
116+
maps.Copy(result, extraAttributes)
117+
}
120118

121-
return extraAttributes[0]
119+
return result
122120
}
123121

124122
type zoneModel interface {

fwprovider/cluster/sdn/zone/resource_simple.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (r *SimpleResource) Schema(_ context.Context, _ resource.SchemaRequest, res
4444
MarkdownDescription: "Simple Zone in Proxmox SDN. It will create an isolated VNet bridge. " +
4545
"This bridge is not linked to a physical interface, and VM traffic is only local on each the node. " +
4646
"It can be used in NAT or routed setups.",
47-
Attributes: genericAttributesWith(),
47+
Attributes: genericAttributesWith(nil),
4848
}
4949
}
5050

0 commit comments

Comments
 (0)