Class: Pangea::Contracts::NetworkResult
- Defined in:
- lib/pangea/contracts/network_result.rb
Overview
Base typed result object for the network phase. Provides named accessors instead of raw hash access, ensuring backends and templates agree on the contract.
Provider-specific subclasses (e.g., AWS::NetworkResult) can add fields like :igw, :route_table, :etcd_bucket via inheritance.
Instance Attribute Summary collapse
-
#sg ⇒ Object
Returns the value of attribute sg.
-
#vpc ⇒ Object
Returns the value of attribute vpc.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Hash-style access for backward compatibility.
-
#add_subnet(name, ref, tier: :public) ⇒ Object
Add a subnet to a specific tier.
-
#data_subnet_ids ⇒ Object
Data tier subnet IDs.
-
#data_subnets ⇒ Object
Data tier subnets (databases, caches, internal services).
- #dig(*keys) ⇒ Object
-
#initialize ⇒ NetworkResult
constructor
A new instance of NetworkResult.
- #key?(key) ⇒ Boolean (also: #has_key?, #include?)
-
#public_subnet_ids ⇒ Object
Public subnet IDs.
-
#public_subnets ⇒ Object
Public subnets only (internet-facing: NLBs, NAT gateways).
- #select(&block) ⇒ Object
-
#subnet_ids ⇒ Object
All subnet IDs across all tiers (backward compatible).
-
#subnets ⇒ Object
All subnets across all tiers (backward compatible).
- #to_h ⇒ Object
- #validate! ⇒ Object
-
#web_subnet_ids ⇒ Object
Web tier subnet IDs.
-
#web_subnets ⇒ Object
Web tier subnets (K8s nodes, application workloads).
Constructor Details
#initialize ⇒ NetworkResult
Returns a new instance of NetworkResult.
30 31 32 33 34 |
# File 'lib/pangea/contracts/network_result.rb', line 30 def initialize @vpc = nil @sg = nil @subnets = { public: [], web: [], data: [] } end |
Instance Attribute Details
#sg ⇒ Object
Returns the value of attribute sg.
28 29 30 |
# File 'lib/pangea/contracts/network_result.rb', line 28 def sg @sg end |
#vpc ⇒ Object
Returns the value of attribute vpc.
28 29 30 |
# File 'lib/pangea/contracts/network_result.rb', line 28 def vpc @vpc end |
Instance Method Details
#[](key) ⇒ Object
Hash-style access for backward compatibility
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pangea/contracts/network_result.rb', line 91 def [](key) case key.to_sym when :vpc then vpc when :sg then sg when :public_subnets then public_subnets when :web_subnets then web_subnets when :data_subnets then data_subnets when :subnet_ids then subnet_ids when :public_subnet_ids then public_subnet_ids when :web_subnet_ids then web_subnet_ids when :data_subnet_ids then data_subnet_ids when :subnets then subnets else # Support named keys like :subnet_a, :public_a, :web_b all_subnets = @subnets.values.flatten match = all_subnets.find { |s| s[:name] == key.to_sym } match&.dig(:ref) end end |
#add_subnet(name, ref, tier: :public) ⇒ Object
Add a subnet to a specific tier.
44 45 46 47 48 |
# File 'lib/pangea/contracts/network_result.rb', line 44 def add_subnet(name, ref, tier: :public) tier_sym = tier.to_sym @subnets[tier_sym] ||= [] @subnets[tier_sym] << { name: name, ref: ref } end |
#data_subnet_ids ⇒ Object
Data tier subnet IDs
81 82 83 |
# File 'lib/pangea/contracts/network_result.rb', line 81 def data_subnet_ids data_subnets.map(&:id) end |
#data_subnets ⇒ Object
Data tier subnets (databases, caches, internal services)
66 67 68 |
# File 'lib/pangea/contracts/network_result.rb', line 66 def data_subnets (@subnets[:data] || []).map { |s| s[:ref] } end |
#dig(*keys) ⇒ Object
125 126 127 |
# File 'lib/pangea/contracts/network_result.rb', line 125 def dig(*keys) to_h.dig(*keys) end |
#key?(key) ⇒ Boolean Also known as: has_key?, include?
129 130 131 |
# File 'lib/pangea/contracts/network_result.rb', line 129 def key?(key) !self[key].nil? end |
#public_subnet_ids ⇒ Object
Public subnet IDs
71 72 73 |
# File 'lib/pangea/contracts/network_result.rb', line 71 def public_subnet_ids public_subnets.map(&:id) end |
#public_subnets ⇒ Object
Public subnets only (internet-facing: NLBs, NAT gateways)
56 57 58 |
# File 'lib/pangea/contracts/network_result.rb', line 56 def public_subnets (@subnets[:public] || []).map { |s| s[:ref] } end |
#select(&block) ⇒ Object
111 112 113 |
# File 'lib/pangea/contracts/network_result.rb', line 111 def select(&block) to_h.select(&block) end |
#subnet_ids ⇒ Object
All subnet IDs across all tiers (backward compatible)
86 87 88 |
# File 'lib/pangea/contracts/network_result.rb', line 86 def subnet_ids subnets.map(&:id) end |
#subnets ⇒ Object
All subnets across all tiers (backward compatible)
51 52 53 |
# File 'lib/pangea/contracts/network_result.rb', line 51 def subnets @subnets.values.flatten.map { |s| s[:ref] } end |
#to_h ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/pangea/contracts/network_result.rb', line 115 def to_h hash = {} hash[:vpc] = vpc if vpc hash[:sg] = sg if sg @subnets.each do |tier, subs| subs.each { |s| hash[s[:name]] = s[:ref] } end hash end |
#validate! ⇒ Object
135 136 137 |
# File 'lib/pangea/contracts/network_result.rb', line 135 def validate! raise ContractError, 'NetworkResult requires a vpc reference' if vpc.nil? end |
#web_subnet_ids ⇒ Object
Web tier subnet IDs
76 77 78 |
# File 'lib/pangea/contracts/network_result.rb', line 76 def web_subnet_ids web_subnets.map(&:id) end |
#web_subnets ⇒ Object
Web tier subnets (K8s nodes, application workloads)
61 62 63 |
# File 'lib/pangea/contracts/network_result.rb', line 61 def web_subnets (@subnets[:web] || []).map { |s| s[:ref] } end |