Module: Formatron::Generators::Bootstrap::Config

Defined in:
lib/formatron/generators/bootstrap/config.rb

Overview

generates an empty config

Class Method Summary collapse

Class Method Details

.write(directory, target = nil, protect = true, cookbooks_bucket_prefix = nil) ⇒ Object

rubocop:disable Metrics/MethodLength



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/formatron/generators/bootstrap/config.rb', line 37

def self.write(
  directory,
  target = nil,
  protect = true,
  cookbooks_bucket_prefix = nil
)
  target_directory = File.join(
    directory,
    'config',
    target.nil? ? '_default' : target.to_s
  )
  FileUtils.mkdir_p target_directory
  file = File.join target_directory, '_default.json'
  write_default(file) if target.nil?
  write_target(
    file,
    target,
    protect,
    cookbooks_bucket_prefix
  ) unless target.nil?
end

.write_default(file) ⇒ Object



6
7
8
9
10
11
# File 'lib/formatron/generators/bootstrap/config.rb', line 6

def self.write_default(file)
  File.write file, <<-EOH.gsub(/^ {12}/, '')
    {
    }
  EOH
end

.write_target(file, target, protect, cookbooks_bucket_prefix) ⇒ Object

rubocop:disable Metrics/MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/formatron/generators/bootstrap/config.rb', line 14

def self.write_target(file, target, protect, cookbooks_bucket_prefix)
  File.write file, <<-EOH.gsub(/^ {12}/, '')
    {
      "protected": #{protect},
      "bastion": {
        "sub_domain": "bastion-#{target}"
      },
      "nat": {
        "sub_domain": "nat-#{target}"
      },
      "chef_server": {
        "sub_domain": "chef-#{target}",
        "cookbooks_bucket": "#{cookbooks_bucket_prefix}-#{target}",
        "ssl": {
          "verify": true
        }
      }
    }
  EOH
end