Module: Formatron::External::DSL
- Defined in:
- lib/formatron/external/dsl.rb
Overview
merges the given configuration into a formatron object rubocop:disable Metrics/ModuleLength
Class Method Summary collapse
-
.export(formatron:) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
-
.merge(formatron:, configuration:) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
Class Method Details
.export(formatron:) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/formatron/external/dsl.rb', line 101 def self.export(formatron:) name = formatron.name global = formatron.global vpcs = formatron.vpc configuration = { 'vpcs' => {} } unless global.nil? configuration_global = configuration['global'] = {} configuration_global['protect'] = global.protect unless global.protect.nil? configuration_global['kms_key'] = global.kms_key unless global.kms_key.nil? configuration_global['databag_secret'] = global.databag_secret unless global.databag_secret.nil? configuration_global['hosted_zone_id'] = global.hosted_zone_id unless global.hosted_zone_id.nil? configuration_global['hosted_zone_name'] = global.hosted_zone_name unless global.hosted_zone_name.nil? ec2 = global.ec2 unless ec2.nil? configuration_ec2 = configuration_global['ec2'] = {} configuration_ec2['key_pair'] = ec2.key_pair unless ec2.key_pair.nil? configuration_ec2['private_key'] = ec2.private_key unless ec2.private_key.nil? end windows = global.windows unless windows.nil? configuration_windows = configuration_global['windows'] = {} configuration_windows['administrator_name'] = windows.administrator_name unless windows.administrator_name.nil? # rubocop:disable Metrics/LineLength configuration_windows['administrator_password'] = windows.administrator_password unless windows.administrator_password.nil? # rubocop:enable Metrics/LineLength end end vpcs.each do |vpc_key, vpc| vpc_configuration = configuration['vpcs'][vpc_key] = { 'subnets' => {}, 'guid' => vpc.guid, 'cidr' => vpc.cidr } subnets = vpc.subnet subnets.each do |subnet_key, subnet| subnet_configuration = vpc_configuration['subnets'][subnet_key] = { 'nats' => {}, 'bastions' => {}, 'chef_servers' => {}, 'guid' => subnet.guid, 'availability_zone' => subnet.availability_zone, 'gateway' => subnet.gateway } nats = subnet.nat bastions = subnet.bastion chef_servers = subnet.chef_server nats.each do |nat_key, nat| subnet_configuration['nats'][nat_key] = { 'guid' => nat.guid } end bastions.each do |bastion_key, bastion| subnet_configuration['bastions'][bastion_key] = { 'guid' => bastion.guid, 'sub_domain' => bastion.sub_domain } end chef_servers.each do |chef_server_key, chef_server| subnet_configuration['chef_servers'][chef_server_key] = { 'guid' => chef_server.guid, 'username' => chef_server.username, 'ssl_verify' => chef_server.ssl_verify, 'sub_domain' => chef_server.sub_domain, 'organization_short_name' => chef_server.organization.short_name, 'stack' => chef_server.stack || name } end end end configuration end |
.merge(formatron:, configuration:) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/formatron/external/dsl.rb', line 14 def self.merge(formatron:, configuration:) new_global = configuration['global'] formatron.global do |global| global.protect( new_global['protect'] ) unless new_global['protect'].nil? global.kms_key( new_global['kms_key'] ) unless new_global['kms_key'].nil? global.databag_secret( new_global['databag_secret'] ) unless new_global['databag_secret'].nil? global.hosted_zone_id( new_global['hosted_zone_id'] ) unless new_global['hosted_zone_id'].nil? new_ec2 = new_global['ec2'] global.ec2 do |ec2| ec2.key_pair( new_ec2['key_pair'] ) unless new_ec2['key_pair'].nil? ec2.private_key( new_ec2['private_key'] ) unless new_ec2['private_key'].nil? end unless new_ec2.nil? new_windows = new_global['windows'] global.windows do |windows| windows.administrator_name( new_windows['administrator_name'] ) unless new_windows['administrator_name'].nil? windows.administrator_password( new_windows['administrator_password'] ) unless new_windows['administrator_password'].nil? end unless new_windows.nil? end unless new_global.nil? new_vpcs = configuration['vpcs'] new_vpcs.each do |vpc_key, new_vpc| formatron.vpc vpc_key do |vpc| vpc.guid new_vpc['guid'] vpc.cidr new_vpc['cidr'] new_subnets = new_vpc['subnets'] new_subnets.each do |subnet_key, new_subnet| vpc.subnet subnet_key do |subnet| subnet.guid new_subnet['guid'] subnet.availability_zone new_subnet['availability_zone'] subnet.gateway new_subnet['gateway'] new_nats = new_subnet['nats'] new_nats.each do |nat_key, new_nat| subnet.nat nat_key do |nat| nat.guid new_nat['guid'] end end new_bastions = new_subnet['bastions'] new_bastions.each do |bastion_key, new_bastion| subnet.bastion bastion_key do |bastion| bastion.guid new_bastion['guid'] bastion.sub_domain new_bastion['sub_domain'] end end new_chef_servers = new_subnet['chef_servers'] new_chef_servers.each do |chef_server_key, new_chef_server| subnet.chef_server chef_server_key do |chef_server| chef_server.guid new_chef_server['guid'] chef_server.username new_chef_server['username'] chef_server.ssl_verify new_chef_server['ssl_verify'] chef_server.sub_domain new_chef_server['sub_domain'] chef_server.organization do |organization| organization.short_name( new_chef_server['organization_short_name'] ) end chef_server.stack new_chef_server['stack'] end end end end end end end |