Module: Formatron::Generators::Bootstrap

Defined in:
lib/formatron/generators/bootstrap.rb,
lib/formatron/generators/bootstrap/ec2.rb,
lib/formatron/generators/bootstrap/ssl.rb,
lib/formatron/generators/bootstrap/config.rb,
lib/formatron/generators/bootstrap/formatronfile.rb

Overview

generates a bootstrap configuration

Defined Under Namespace

Modules: Config, EC2, Formatronfile, SSL

Class Method Summary collapse

Class Method Details

.generate(directory, params) ⇒ Object

rubocop:disable Metrics/MethodLength



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/formatron/generators/bootstrap.rb', line 73

def self.generate(directory, params)
  validate_params params
  Util::Readme.write directory, params[:name]
  Util::Gitignore.write directory
  Formatronfile.write directory, params
  Config.write directory
  EC2.write directory
  generate_targets(
    directory,
    params[:targets],
    params[:chef_server][:cookbooks_bucket_prefix]
  )
  generate_cookbooks directory
end

.generate_cookbooks(directory) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/formatron/generators/bootstrap.rb', line 62

def self.generate_cookbooks(directory)
  Util::Cookbook.write(
    directory,
    'chef_server_instance',
    'Chef Server instance'
  )
  Util::Cookbook.write directory, 'nat_instance', 'NAT instance'
  Util::Cookbook.write directory, 'bastion_instance', 'Bastion instance'
end

.generate_targets(directory, targets, cookbooks_bucket_prefix) ⇒ Object

rubocop:enable Metrics/MethodLength



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/formatron/generators/bootstrap.rb', line 50

def self.generate_targets(directory, targets, cookbooks_bucket_prefix)
  targets.each do |target, params|
    Config.write(
      directory,
      target,
      params[:protect],
      cookbooks_bucket_prefix
    )
    SSL.write directory, target
  end
end

.validate_hash_params(hash, params) ⇒ Object



19
20
21
22
23
# File 'lib/formatron/generators/bootstrap.rb', line 19

def self.validate_hash_params(hash, params)
  params.each do |param|
    fail "params should contain #{param}" if hash[param].nil?
  end
end

.validate_params(params) ⇒ Object

rubocop:disable Metrics/MethodLength



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

def self.validate_params(params)
  validate_hash_params params, [
    :name,
    :s3_bucket,
    :kms_key,
    :ec2_key_pair,
    :hosted_zone_id,
    :hosted_zone_id,
    :targets,
    :availability_zone,
    :chef_server
  ]
  validate_hash_params params[:chef_server], [
    :organization,
    :username,
    :email,
    :first_name,
    :last_name,
    :password
  ]
  validate_target_params params[:targets]
end

.validate_target_params(targets) ⇒ Object



13
14
15
16
17
# File 'lib/formatron/generators/bootstrap.rb', line 13

def self.validate_target_params(targets)
  targets.each do |_, params|
    fail 'target should have :protect parameter' if params[:protect].nil?
  end
end