Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CLOUDDEV-935): Fixed creating Subnet without Gateway ip #72

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

const (
subnetsBasePathV1 = "/v1/subnets"
gatewayIPTag = "gateway_ip"
)

// SubnetworksService is an interface for creating and managing Subnetworks with the EdgecenterCloud API.
Expand Down Expand Up @@ -72,11 +73,34 @@ type SubnetworkCreateRequest struct {
CIDR string `json:"cidr" required:"true"`
ConnectToNetworkRouter bool `json:"connect_to_network_router"`
DNSNameservers []net.IP `json:"dns_nameservers,omitempty"`
GatewayIP *net.IP `json:"gateway_ip,omitempty"`
GatewayIP *net.IP `json:"gateway_ip"`
Metadata Metadata `json:"metadata,omitempty"`
HostRoutes []HostRoute `json:"host_routes,omitempty"`
}

func (scr *SubnetworkCreateRequest) MarshalJSON() ([]byte, error) {
type alias SubnetworkCreateRequest

scrJSON, err := json.Marshal((*alias)(scr))
if err != nil {
return nil, fmt.Errorf("json.Marshal error: %w", err)
}

if !(scr.GatewayIP == nil && scr.ConnectToNetworkRouter) {
return scrJSON, nil
}

scrMap := make(map[string]any)
err = json.Unmarshal(scrJSON, &scrMap)
if err != nil {
return nil, fmt.Errorf("json.Unmarshal error: %w", err)
}

delete(scrMap, gatewayIPTag)

return json.Marshal(scrMap)
}

// SubnetworkUpdateRequest represents a request to update a Subnetwork properties.
type SubnetworkUpdateRequest struct {
Name string `json:"name,omitempty"`
Expand Down
Loading