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, "    {\n    }\n  EOH\nend\n".gsub(/^ {12}/, '')

.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, "    {\n      \"protected\": \#{protect},\n      \"bastion\": {\n        \"sub_domain\": \"bastion-\#{target}\"\n      },\n      \"nat\": {\n        \"sub_domain\": \"nat-\#{target}\"\n      },\n      \"chef_server\": {\n        \"sub_domain\": \"chef-\#{target}\",\n        \"cookbooks_bucket\": \"\#{cookbooks_bucket_prefix}-\#{target}\",\n        \"ssl\": {\n          \"verify\": true\n        }\n      }\n    }\n  EOH\nend\n".gsub(/^ {12}/, '')