Sha256: d9e19064035a8742477a86f4fc5fc454054a388803b2c1d3e7d4d28c6188b045

Contents?: true

Size: 1.35 KB

Versions: 54

Compression:

Stored size: 1.35 KB

Contents

require 'yao/resources/security_group'
module Yao::Resources
  class SecurityGroupRule < Base
    friendly_attributes :ethertype

    def self.define_attribute_with_guard(_name, _guard_name)
      name = _name.to_s
      guard_name = _guard_name.to_s
      define_method name do
        self[name] || self[guard_name]
      end
    end

    define_attribute_with_guard :port_range_max, :from_port
    define_attribute_with_guard :port_range_min, :to_port
    define_attribute_with_guard :protocol, :ip_protocol
    define_attribute_with_guard :security_group_id, :parent_group_id

    def security_group
      SecurityGroup.find(security_group_id)
    end

    def port
      if port_range_max == port_range_min
        port_range_max
      else
        port_range
      end
    end

    def remote_ip_cidr
      if cidr = self["remote_ip_prefix"]
        cidr
      elsif ip_range = self["ip_range"]
        ip_range["cidr"]
      end
    end

    def port_range
      port_range_max..port_range_min
    end

    def remote_group
      return nil if self["remote_group_id"].nil? && (self["group"].nil? || self["group"].empty?)

      SecurityGroup.new(
        {"id" => self["remote_group_id"]}.merge(self["group"] || {})
      )
    end

    self.service        = "network"
    self.resource_name  = "security-group-rule"
    self.resources_name = "security-group-rules"
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
yao-0.13.4 lib/yao/resources/security_group_rule.rb
yao-0.13.3 lib/yao/resources/security_group_rule.rb
yao-0.13.2 lib/yao/resources/security_group_rule.rb
yao-0.13.1 lib/yao/resources/security_group_rule.rb
yao-0.13.0 lib/yao/resources/security_group_rule.rb
yao-0.12.0 lib/yao/resources/security_group_rule.rb
yao-0.11.3 lib/yao/resources/security_group_rule.rb
yao-0.11.2 lib/yao/resources/security_group_rule.rb
yao-0.11.1 lib/yao/resources/security_group_rule.rb
yao-0.11.0 lib/yao/resources/security_group_rule.rb
yao-0.10.1 lib/yao/resources/security_group_rule.rb
yao-0.10.0 lib/yao/resources/security_group_rule.rb
yao-0.9.1 lib/yao/resources/security_group_rule.rb
yao-0.9.0 lib/yao/resources/security_group_rule.rb
yao-0.8.0 lib/yao/resources/security_group_rule.rb
yao-0.7.0 lib/yao/resources/security_group_rule.rb
yao-0.6.3 lib/yao/resources/security_group_rule.rb
yao-0.6.2 lib/yao/resources/security_group_rule.rb
yao-0.6.1 lib/yao/resources/security_group_rule.rb
yao-0.6.0 lib/yao/resources/security_group_rule.rb