Class: Formatron

Inherits:
Object
  • Object
show all
Defined in:
lib/formatron.rb,
lib/formatron/aws.rb,
lib/formatron/cli.rb,
lib/formatron/dsl.rb,
lib/formatron/chef.rb,
lib/formatron/config.rb,
lib/formatron/logger.rb,
lib/formatron/s3/path.rb,
lib/formatron/version.rb,
lib/formatron/chef/ssh.rb,
lib/formatron/external.rb,
lib/formatron/util/dsl.rb,
lib/formatron/util/ssh.rb,
lib/formatron/util/vpc.rb,
lib/formatron/chef/keys.rb,
lib/formatron/chef/knife.rb,
lib/formatron/cli/deploy.rb,
lib/formatron/completion.rb,
lib/formatron/util/shell.rb,
lib/formatron/cli/destroy.rb,
lib/formatron/chef_clients.rb,
lib/formatron/external/dsl.rb,
lib/formatron/cli/provision.rb,
lib/formatron/config/reader.rb,
lib/formatron/dsl/formatron.rb,
lib/formatron/chef/berkshelf.rb,
lib/formatron/cli/completion.rb,
lib/formatron/cloud_formation.rb,
lib/formatron/generators/util.rb,
lib/formatron/external/outputs.rb,
lib/formatron/s3/configuration.rb,
lib/formatron/dsl/formatron/vpc.rb,
lib/formatron/cli/generators/guid.rb,
lib/formatron/generators/instance.rb,
lib/formatron/s3/chef_server_cert.rb,
lib/formatron/s3/chef_server_keys.rb,
lib/formatron/dsl/formatron/global.rb,
lib/formatron/generators/bootstrap.rb,
lib/formatron/generators/credentials.rb,
lib/formatron/generators/util/readme.rb,
lib/formatron/cli/generators/instance.rb,
lib/formatron/cloud_formation/scripts.rb,
lib/formatron/cli/generators/bootstrap.rb,
lib/formatron/cloud_formation/template.rb,
lib/formatron/dsl/formatron/global/ec2.rb,
lib/formatron/dsl/formatron/vpc/subnet.rb,
lib/formatron/generators/bootstrap/ec2.rb,
lib/formatron/generators/bootstrap/ssl.rb,
lib/formatron/generators/util/cookbook.rb,
lib/formatron/aws/cloud_formation_stack.rb,
lib/formatron/generators/util/gitignore.rb,
lib/formatron/cli/generators/credentials.rb,
lib/formatron/generators/instance/config.rb,
lib/formatron/generators/bootstrap/config.rb,
lib/formatron/s3/cloud_formation_template.rb,
lib/formatron/cloud_formation/template/vpc.rb,
lib/formatron/dsl/formatron/vpc/subnet/acl.rb,
lib/formatron/cli/generators/databag_secret.rb,
lib/formatron/cloud_formation/resources/ec2.rb,
lib/formatron/cloud_formation/resources/iam.rb,
lib/formatron/cloud_formation/resources/route53.rb,
lib/formatron/dsl/formatron/vpc/subnet/instance.rb,
lib/formatron/generators/instance/formatronfile.rb,
lib/formatron/generators/bootstrap/formatronfile.rb,
lib/formatron/cloud_formation/template/parameters.rb,
lib/formatron/cloud_formation/template/vpc/subnet.rb,
lib/formatron/dsl/formatron/vpc/subnet/chef_server.rb,
lib/formatron/dsl/formatron/vpc/subnet/instance/chef.rb,
lib/formatron/cloud_formation/template/vpc/subnet/acl.rb,
lib/formatron/cloud_formation/template/vpc/subnet/nat.rb,
lib/formatron/dsl/formatron/vpc/subnet/instance/setup.rb,
lib/formatron/dsl/formatron/vpc/subnet/instance/policy.rb,
lib/formatron/dsl/formatron/vpc/subnet/instance/volume.rb,
lib/formatron/cloud_formation/resources/cloud_formation.rb,
lib/formatron/cloud_formation/template/vpc/subnet/bastion.rb,
lib/formatron/cloud_formation/template/vpc/subnet/instance.rb,
lib/formatron/dsl/formatron/vpc/subnet/instance/block_device.rb,
lib/formatron/cloud_formation/template/vpc/subnet/chef_server.rb,
lib/formatron/dsl/formatron/vpc/subnet/instance/security_group.rb,
lib/formatron/dsl/formatron/vpc/subnet/instance/setup/variable.rb,
lib/formatron/dsl/formatron/vpc/subnet/chef_server/organization.rb,
lib/formatron/cloud_formation/template/vpc/subnet/instance/setup.rb,
lib/formatron/dsl/formatron/vpc/subnet/instance/policy/statement.rb,
lib/formatron/cloud_formation/template/vpc/subnet/instance/policy.rb,
lib/formatron/cloud_formation/template/vpc/subnet/instance/block_devices.rb,
lib/formatron/cloud_formation/template/vpc/subnet/instance/security_group.rb

Overview

add version to class

Defined Under Namespace

Modules: CloudFormation, Completion, Config, Generators, S3, Util Classes: AWS, CLI, Chef, ChefClients, DSL, External

Constant Summary collapse

FORMATRONFILE =
'Formatronfile'
LOG =
Logger.new($stdout).tap do |log|
  log.progname = 'Formatron'
end
VERSION =
'0.1.13'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials:, directory:, target:) ⇒ Formatron

rubocop:disable Metrics/MethodLength



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/formatron.rb', line 25

def initialize(credentials:, directory:, target:)
  @target = target
  @aws = AWS.new credentials: credentials
  @config = Config.target(
    directory: directory,
    target: target
  )
  @external = External.new(
    target: @target,
    config: @config,
    aws: @aws
  )
  @dsl = DSL.new(
    file: File.join(directory, FORMATRONFILE),
    config: @config,
    target: @target,
    external: @external,
    aws: @aws
  )
  _initialize
end

Instance Attribute Details

#protectedObject (readonly) Also known as: protected?

Returns the value of attribute protected.



21
22
23
# File 'lib/formatron.rb', line 21

def protected
  @protected
end

Instance Method Details

#_deploy_chef_server_certsObject

rubocop:disable Metrics/MethodLength



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/formatron.rb', line 208

def _deploy_chef_server_certs
  @chef_servers.values.each do |chef_servers|
    chef_servers.values.each do |chef_server|
      S3::ChefServerCert.deploy(
        aws: @aws,
        kms_key: @kms_key,
        bucket: @bucket,
        name: @name,
        target: @target,
        guid: chef_server.guid,
        cert: chef_server.ssl_cert,
        key: chef_server.ssl_key
      )
    end
  end
end

#_destroy_chef_server_certObject

rubocop:disable Metrics/MethodLength



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/formatron.rb', line 260

def _destroy_chef_server_cert
  @chef_servers.values.each do |chef_servers|
    chef_servers.values.each do |chef_server|
      S3::ChefServerCert.destroy(
        aws: @aws,
        bucket: @bucket,
        name: @name,
        target: @target,
        guid: chef_server.guid
      )
    end
  end
rescue => error
  LOG.warn error
end

#_destroy_chef_server_keysObject

rubocop:disable Metrics/MethodLength



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/formatron.rb', line 278

def _destroy_chef_server_keys
  @chef_servers.values.each do |chef_servers|
    chef_servers.values.each do |chef_server|
      S3::ChefServerKeys.destroy(
        aws: @aws,
        bucket: @bucket,
        name: @name,
        target: @target,
        guid: chef_server.guid
      )
    end
  end
rescue => error
  LOG.warn error
end

#deployObject

rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/formatron.rb', line 138

def deploy
  _deploy_configuration
  _deploy_chef_server_certs
  if @cloud_formation_template[:Resources].empty?
    _destroy_template
    _destroy_stack
  else
    _deploy_template
    _deploy_stack
  end
end

#destroyObject



187
188
189
190
191
192
193
194
# File 'lib/formatron.rb', line 187

def destroy
  _destroy_chef_instances
  _destroy_configuration
  _destroy_chef_server_cert
  _destroy_chef_server_keys
  _destroy_template
  _destroy_stack
end

#provision(guid: nil) ⇒ Object



150
151
152
153
154
# File 'lib/formatron.rb', line 150

def provision(guid: nil)
  @all_instances.each do |key, instances|
    _provision_vpc key, instances, guid
  end
end