Files
ubicloud/serializers/firewall.rb
Jeremy Evans 582f371598 Fix firewall rule sorting in Serializers::Firewall
fwr.cidr.version is never false or nil, so this only sorts by the
cidr, potentially mixing IPv4 and IPv6 cidrs. I believe the intention
here is to show all IPv4 addresses before all IPv6 addresses, so
this changes the code to do that.
2025-08-08 01:52:14 +09:00

24 lines
637 B
Ruby

# frozen_string_literal: true
class Serializers::Firewall < Serializers::Base
def self.serialize_internal(firewall, options = {})
base = {
id: firewall.ubid,
name: firewall.name,
description: firewall.description,
location: firewall.display_location,
firewall_rules: Serializers::FirewallRule.serialize(firewall.firewall_rules.sort_by { [it.cidr.version, it.cidr.to_s] })
}
if options[:include_path]
base[:path] = firewall.path
end
if options[:detailed]
base[:private_subnets] = Serializers::PrivateSubnet.serialize(firewall.private_subnets)
end
base
end
end