Files
ubicloud/model/firewall_rule.rb
Jeremy Evans 718370f4c9 Convert ResourceMethods to a plugin
Allow plugin to take an etc_type keyword argument for using the
TYPE_ETC ubid type, and remove the separate definitions in every
model that uses the TYPE_ETC ubid type.

This was the cleanest way to DRY things up.  You cannot extend
the models with a module to do this before including ResourceMethods,
because then ResourceMethods::ClassMethods will override it, and
you cannot extend the models with a module to do this after
including ResourceMethods, because the inclusion will not work
correctly due to the eager definition of @ubid_format.

Best reviewed without whitespace differences.
2025-06-04 04:55:45 +09:00

28 lines
800 B
Ruby

# frozen_string_literal: true
require_relative "../model"
class FirewallRule < Sequel::Model
many_to_one :firewall, key: :firewall_id
plugin ResourceMethods
def ip6?
cidr.to_s.include?(":")
end
end
# Table: firewall_rule
# Columns:
# id | uuid | PRIMARY KEY
# cidr | cidr |
# port_range | int4range | DEFAULT '[0,65536)'::int4range
# firewall_id | uuid | NOT NULL
# Indexes:
# firewall_rule_pkey | PRIMARY KEY btree (id)
# firewall_rule_cidr_port_range_firewall_id_key | UNIQUE btree (cidr, port_range, firewall_id)
# Check constraints:
# port_range_min_max | (lower(port_range) >= 0 AND upper(port_range) <= 65536)
# Foreign key constraints:
# firewall_rule_firewall_id_fkey | (firewall_id) REFERENCES firewall(id)