tiller 0.7.10 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87543dcddd7ffe3367e1917fccedb35065d13f56
4
- data.tar.gz: 26180fa0c8340cfaf5dc257f8b4bab72119eebc5
3
+ metadata.gz: acd35e1f4954ea1c60fd5c27ea63f44fe7400eba
4
+ data.tar.gz: 2ec16005714189cbad10709a98a742f35fa944a4
5
5
  SHA512:
6
- metadata.gz: 807408260d5299ab564fba2d7f84f255eb51de4a060e95203c9dbccc09c923c031fcc135c8f856bb29b4a3ec5abe5bacf06bd8601dca3301d10ff831b9e19bc1
7
- data.tar.gz: ec485ee8ecc83048a7e769c42b8dd308a4125aa4686cc72e0c3dc21942d73745abea01e9679a058d176274b04775941fe496018ce9333521a1bdc7037796db11
6
+ metadata.gz: 0987e16d81c94e21d111a35c3241a4522cad991cbcbf65818be9966a9f82f0f3b2940ecb71f11a739dd515cbaebae1536985e85520eef31ec2efe7f0c173356b
7
+ data.tar.gz: 6471f8c24b1465510fb800f2ce3fc22a281ecbc2e13ea8aef968090397ee782473a2ee0bed58a3d2dc7ceea2ce790de4bc25d0147f6ac192b998c39e946fdf39
data/bin/tiller CHANGED
@@ -8,7 +8,7 @@
8
8
  #
9
9
  # Mark Dastmalchi-Round <github@markround.com>
10
10
 
11
- VERSION = '0.7.10'
11
+ VERSION = '0.8.0'
12
12
 
13
13
  require 'erb'
14
14
  require 'ostruct'
@@ -27,6 +27,7 @@ require 'tiller/templatesource'
27
27
  require 'tiller/datasource'
28
28
  require 'tiller/logger'
29
29
  require 'digest/md5'
30
+ require 'tiller/render'
30
31
 
31
32
  EXIT_SUCCESS = 0
32
33
 
@@ -35,11 +36,14 @@ module Tiller
35
36
 
36
37
  puts "tiller v#{VERSION} (https://github.com/markround/tiller) <github@markround.com>"
37
38
 
38
- config = parse_options(Tiller::Defaults)
39
- log = Tiller::Logger.new(config)
39
+ class << self;
40
+ attr_accessor :config, :log, :templates, :tiller
41
+ end
40
42
 
41
- log.debug("Executable: #{__FILE__}")
43
+ Tiller::config = parse_options(Tiller::Defaults)
44
+ Tiller::log = Tiller::Logger.new
42
45
 
46
+ log.debug("Executable: #{__FILE__}")
43
47
 
44
48
  # Add tiller_lib to the LOAD PATH so we can pull in user-defined plugins
45
49
  $LOAD_PATH.unshift(config[:tiller_lib]) unless $LOAD_PATH.include?(config[:tiller_lib])
@@ -73,6 +77,10 @@ module Tiller
73
77
 
74
78
  log.info('Template sources loaded ' + template_classes.to_s)
75
79
  log.info('Data sources loaded ' + data_classes.to_s)
80
+ if (config.key?('helpers'))
81
+ helper_modules = helper_loader(config['helpers'])
82
+ log.info('Helper modules loaded ' + helper_modules.to_s)
83
+ end
76
84
 
77
85
  # Now go through all our data sources and start to assemble our global_values
78
86
  # hash. As hashes are getting merged, new values will take precedence over
@@ -85,19 +93,19 @@ module Tiller
85
93
  # e.g. environment-specific execs and so on. We do this first so that connection strings
86
94
  # to datasources (e.g. zookeeper) can be included in the config before we obtain any
87
95
  # values.
88
- config.merge!(data_class.new(config).common) do |key, old, new|
96
+ config.merge!(data_class.new.common) do |key, old, new|
89
97
  warn_merge(key, old, new, 'common', data_class.to_s)
90
98
  end
91
99
 
92
- global_values.merge!(data_class.new(config).global_values) do |key, old, new|
100
+ global_values.merge!(data_class.new.global_values) do |key, old, new|
93
101
  warn_merge(key, old, new, 'global', data_class.to_s)
94
102
  end
95
103
  end
96
104
 
97
105
  # Get all Templates for the given environment
98
- templates = {}
106
+ Tiller::templates = {}
99
107
  template_classes.each do |template_class|
100
- ts = template_class.new(config)
108
+ ts = template_class.new
101
109
  ts.templates.each do |t|
102
110
  templates[t] = ts.template(t)
103
111
  end
@@ -114,13 +122,13 @@ module Tiller
114
122
  templates.each do |template, content|
115
123
 
116
124
  # Start with a hash of our global values
117
- tiller = Hash.new.merge(global_values)
125
+ Tiller:: tiller = Hash.new.merge(global_values)
118
126
  target_values = {}
119
127
 
120
128
  # Now we add to the 'tiller' hash with values from each DataSource, warning if we
121
129
  # get duplicate values.
122
130
  data_classes.each do |data_class|
123
- dc = data_class.new(config)
131
+ dc = data_class.new
124
132
  if dc.values(template) != nil
125
133
  tiller.merge!(dc.values(template)) do |key, old, new|
126
134
  warn_merge(key, old, new, 'data', data_class.to_s)
@@ -141,11 +149,8 @@ module Tiller
141
149
  # Now, we build the template
142
150
  log.info("Building template #{template}")
143
151
 
144
- # Use an OpenStruct namespace, as it's way easier than faffing around with
145
- # manual binding, and also non-existing values just get replaced by <nil>
146
- # instead of failing on errors.
147
- ns = OpenStruct.new(tiller)
148
- parsed_template = ERB.new(content, nil, '-').result(ns.instance_eval { binding })
152
+ # Use our re-usable render tag
153
+ parsed_template = Tiller::render(template)
149
154
 
150
155
  # Write the template, and also create the directory path if it
151
156
  # doesn't exist.
data/lib/tiller/consul.rb CHANGED
@@ -7,19 +7,19 @@ module Tiller::ConsulCommon
7
7
  def setup
8
8
  # Set our defaults if not specified
9
9
  @consul_config = Tiller::Consul.defaults
10
- raise 'No Consul configuration block' unless @config.has_key?('consul')
11
- @consul_config.deep_merge!(@config['consul'])
10
+ raise 'No Consul configuration block' unless Tiller::config.has_key?('consul')
11
+ @consul_config.deep_merge!(Tiller::config['consul'])
12
12
 
13
13
  # Sanity check
14
14
  ['url'].each {|c| raise "Consul: Missing Consul configuration #{c}" unless @consul_config.has_key?(c)}
15
15
 
16
16
  # Now we connect to Consul
17
17
  Diplomat.configure do |config|
18
- @log.debug("#{self} : Connecting to Consul at #{@consul_config['url']}")
18
+ Tiller::log.debug("#{self} : Connecting to Consul at #{@consul_config['url']}")
19
19
  config.url = @consul_config['url']
20
20
 
21
21
  if @consul_config['acl_token']
22
- @log.debug("#{self} : Using Consul ACL token")
22
+ Tiller::log.debug("#{self} : Using Consul ACL token")
23
23
  config.acl_token = @consul_config['acl_token']
24
24
  end
25
25
  end
@@ -27,7 +27,7 @@ module Tiller::ConsulCommon
27
27
 
28
28
  # Interpolate configuration placeholders with values
29
29
  def interpolate(path, template_name = nil)
30
- path.gsub!('%e', @config[:environment])
30
+ path.gsub!('%e', Tiller::config[:environment])
31
31
  path.gsub!('%t', template_name) if template_name
32
32
  path
33
33
  end
@@ -10,21 +10,21 @@ class ConsulDataSource < Tiller::DataSource
10
10
  def global_values
11
11
  # Fetch globals
12
12
  path = interpolate("#{@consul_config['values']['global']}")
13
- @log.debug("#{self} : Fetching globals from #{path}")
13
+ Tiller::log.debug("#{self} : Fetching globals from #{path}")
14
14
  globals = fetch_all_keys(path)
15
15
 
16
16
  # Do we have per-env globals ? If so, merge them
17
17
  path = interpolate("#{@consul_config['values']['per_env']}")
18
- @log.debug("#{self} : Fetching per-environment globals from #{path}")
18
+ Tiller::log.debug("#{self} : Fetching per-environment globals from #{path}")
19
19
  globals.deep_merge!(fetch_all_keys(path))
20
20
 
21
21
  # Do we want to register services in consul_services hash ?
22
22
  if @consul_config['register_services']
23
- @log.debug("#{self} : Registering Consul services")
23
+ Tiller::log.debug("#{self} : Registering Consul services")
24
24
  globals['consul_services'] = {}
25
25
  services = Diplomat::Service.get_all({ :dc => @consul_config['dc'] })
26
26
  services.marshal_dump.each do |service, _data|
27
- @log.debug("#{self} : Fetching Consul service information for #{service}")
27
+ Tiller::log.debug("#{self} : Fetching Consul service information for #{service}")
28
28
  service_data = Diplomat::Service.get(service, :all, { :dc => @consul_config['dc']})
29
29
  globals['consul_services'].merge!( { "#{service}" => service_data })
30
30
  end
@@ -32,7 +32,7 @@ class ConsulDataSource < Tiller::DataSource
32
32
 
33
33
  # Do we want to register nodes in consul_nodes hash ?
34
34
  if @consul_config['register_nodes']
35
- @log.debug("#{self} : Registering Consul nodes")
35
+ Tiller::log.debug("#{self} : Registering Consul nodes")
36
36
  globals['consul_nodes'] = {}
37
37
  nodes = Diplomat::Node.get_all
38
38
  nodes.each do |n|
@@ -44,13 +44,13 @@ class ConsulDataSource < Tiller::DataSource
44
44
 
45
45
  def values(template_name)
46
46
  path = interpolate("#{@consul_config['values']['template']}", template_name)
47
- @log.debug("#{self} : Fetching template values from #{path}")
47
+ Tiller::log.debug("#{self} : Fetching template values from #{path}")
48
48
  fetch_all_keys(path)
49
49
  end
50
50
 
51
51
  def target_values(template_name)
52
52
  path = interpolate("#{@consul_config['values']['target']}", template_name)
53
- @log.debug("#{self} : Fetching template target values from #{path}")
53
+ Tiller::log.debug("#{self} : Fetching template target values from #{path}")
54
54
  fetch_all_keys(path)
55
55
  end
56
56
 
@@ -60,7 +60,7 @@ class ConsulDataSource < Tiller::DataSource
60
60
  all_keys = {}
61
61
  if keys.is_a? Array
62
62
  keys.each do |k|
63
- @log.debug("#{self} : Fetching key #{k}")
63
+ Tiller::log.debug("#{self} : Fetching key #{k}")
64
64
  all_keys[File.basename(k)] = Diplomat::Kv.get(k, { nil_values: true, :dc => @consul_config['dc'] })
65
65
  end
66
66
  all_keys
@@ -6,14 +6,14 @@ require 'tiller/datasource'
6
6
 
7
7
  class DefaultsDataSource < Tiller::DataSource
8
8
  def setup
9
- defaults_file = File.join(@config[:tiller_base], 'defaults.yaml')
10
- defaults_dir = File.join(@config[:tiller_base], 'defaults.d')
9
+ defaults_file = File.join(Tiller::config[:tiller_base], 'defaults.yaml')
10
+ defaults_dir = File.join(Tiller::config[:tiller_base], 'defaults.d')
11
11
  @defaults_hash = Hash.new
12
12
 
13
13
  # First, try and load defaults from v2 config
14
- if @config.has_key?('defaults')
15
- @log.debug("#{self} : Using values from v2 format common.yaml")
16
- @defaults_hash.deep_merge!(@config['defaults'])
14
+ if Tiller::config.has_key?('defaults')
15
+ Tiller::log.debug("#{self} : Using values from v2 format common.yaml")
16
+ @defaults_hash.deep_merge!(Tiller::config['defaults'])
17
17
  else
18
18
  # Read defaults in from defaults file if no v2 config
19
19
  # Handle empty files - if YAML didn't parse, it returns false so we skip them
@@ -28,7 +28,7 @@ class DefaultsDataSource < Tiller::DataSource
28
28
  if File.directory? defaults_dir
29
29
  Dir.glob(File.join(defaults_dir,'*.yaml')).each do |d|
30
30
  yaml = YAML.load(open(d))
31
- @log.debug("Loading defaults from #{d}")
31
+ Tiller::log.debug("Loading defaults from #{d}")
32
32
  @defaults_hash.deep_merge!(yaml) if yaml != false
33
33
  end
34
34
  end
@@ -52,7 +52,7 @@ class DefaultsDataSource < Tiller::DataSource
52
52
  # Previous versions of Tiller didn't throw an error when we had an empty
53
53
  # template config definition in a defaults file. Tiller 0.7.3 "broke" this, so while it's arguably the
54
54
  # correct thing to bail out, in the interests of backwards-compatibility, we now instead log a warning and continue.
55
- @log.warn("Warning, empty config for #{template_name}")
55
+ Tiller::log.warn("Warning, empty config for #{template_name}")
56
56
  Hash.new
57
57
  end
58
58
  else
@@ -67,7 +67,7 @@ class DefaultsDataSource < Tiller::DataSource
67
67
  values.key?('target') ? values : Hash.new
68
68
  else
69
69
  # See comments for values function.
70
- @log.warn("Warning, empty config for #{template_name}")
70
+ Tiller::log.warn("Warning, empty config for #{template_name}")
71
71
  Hash.new
72
72
  end
73
73
  else
@@ -4,8 +4,8 @@ class EnvironmentDataSource < Tiller::DataSource
4
4
 
5
5
  def setup
6
6
  @plugin_config = Tiller::Environment.defaults
7
- if @config.has_key? 'environment' and @config['environment'].is_a? Hash
8
- @plugin_config.merge!(@config['environment'])
7
+ if Tiller::config.has_key? 'environment' and Tiller::config['environment'].is_a? Hash
8
+ @plugin_config.merge!(Tiller::config['environment'])
9
9
  end
10
10
  end
11
11
 
@@ -13,12 +13,12 @@ class EnvironmentJsonDataSource < Tiller::DataSource
13
13
  @json_structure = parse.is_a?(Hash) ? parse : Hash.new
14
14
  if @json_structure[VERSION_KEY].is_a? Integer
15
15
  @json_version = @json_structure[VERSION_KEY]
16
- @log.debug("Using v#{@json_version} tiller_json format")
16
+ Tiller::log.debug("Using v#{@json_version} tiller_json format")
17
17
  else
18
18
  @json_version = 1
19
19
  end
20
20
  rescue JSON::ParserError
21
- @log.warn('Warning : Error parsing tiller_json environment variable')
21
+ Tiller::log.warn('Warning : Error parsing tiller_json environment variable')
22
22
  end
23
23
  else
24
24
  @json_structure = Hash.new
@@ -7,8 +7,8 @@ class ExternalFileDataSource < Tiller::DataSource
7
7
 
8
8
  def setup
9
9
  @merged_values = Hash.new
10
- if @config.has_key?('external_files')
11
- files = @config['external_files']
10
+ if Tiller::config.has_key?('external_files')
11
+ files = Tiller::config['external_files']
12
12
  files.each do |file|
13
13
  @merged_values.merge!(parse_file(file)) do |key, old, new|
14
14
  warn_merge(key, old, new, 'external file data', file)
@@ -23,14 +23,14 @@ class ExternalFileDataSource < Tiller::DataSource
23
23
 
24
24
  def parse_file(filename)
25
25
  raise("External file '#{filename}' could not be loaded") unless File.file?(filename)
26
- @log.debug("#{self} : Loading #{filename}")
26
+ Tiller::log.debug("#{self} : Loading #{filename}")
27
27
  parse = nil
28
28
 
29
29
  # First try to load it as JSON
30
30
  if ! parse
31
31
  begin
32
32
  parse = JSON.parse(File.read(filename))
33
- @log.debug("#{self} : #{filename} is in JSON format")
33
+ Tiller::log.debug("#{self} : #{filename} is in JSON format")
34
34
  rescue JSON::ParserError
35
35
  end
36
36
  end
@@ -39,7 +39,7 @@ class ExternalFileDataSource < Tiller::DataSource
39
39
  if ! parse
40
40
  begin
41
41
  parse = YAML.load(File.read(filename))
42
- @log.debug("#{self} : #{filename} is in YAML format")
42
+ Tiller::log.debug("#{self} : #{filename} is in YAML format")
43
43
  rescue Psych::SyntaxError
44
44
  end
45
45
  end
@@ -4,26 +4,26 @@ class FileDataSource < Tiller::DataSource
4
4
  # Open and parse the environment file. Tries from v2 format common.yaml first, if that
5
5
  # failes, then it looks for separate environment files.
6
6
  def setup
7
- if @config.has_key?('environments')
7
+ if Tiller::config.has_key?('environments')
8
8
  # Try and load from v2 format common.yaml
9
- if @config['environments'].has_key?(@config[:environment])
10
- @log.debug("#{self} : Using values from v2 format common.yaml")
11
- if @config['environments'][@config[:environment]].is_a? Hash
12
- @config_hash = @config['environments'][@config[:environment]]
9
+ if Tiller::config['environments'].has_key?(Tiller::config[:environment])
10
+ Tiller::log.debug("#{self} : Using values from v2 format common.yaml")
11
+ if Tiller::config['environments'][Tiller::config[:environment]].is_a? Hash
12
+ @config_hash = Tiller::config['environments'][Tiller::config[:environment]]
13
13
  else
14
14
  # This permits "stub"" environments, where all the config is provided by another module e.g. defaults
15
15
  # See https://github.com/markround/tiller/issues/29
16
- @log.info("Using stub environment for #{@config[:environment]}")
16
+ Tiller::log.info("Using stub environment for #{Tiller::config[:environment]}")
17
17
  @config_hash = Hash.new
18
18
  end
19
19
  else
20
- abort("Error : Could not load environment #{@config[:environment]} from common.yaml")
20
+ abort("Error : Could not load environment #{Tiller::config[:environment]} from common.yaml")
21
21
  end
22
22
  else
23
23
  # Try and load from v1 format files
24
24
  begin
25
- env_file = File.join(@config[:tiller_base], 'environments',
26
- "#{@config[:environment]}.yaml")
25
+ env_file = File.join(Tiller::config[:tiller_base], 'environments',
26
+ "#{Tiller::config[:environment]}.yaml")
27
27
  @config_hash = YAML.load(open(env_file))
28
28
  rescue
29
29
  abort("Error : Could not load environment file #{env_file}")
@@ -7,18 +7,18 @@ require 'crack'
7
7
  class XmlFileDataSource < Tiller::DataSource
8
8
 
9
9
  def global_values
10
- parse_xml(@config)
10
+ parse_xml(Tiller::config)
11
11
  end
12
12
 
13
13
  def values(template)
14
- parse_xml(@config['environments'][@config[:environment]][template])
14
+ parse_xml(Tiller::config['environments'][Tiller::config[:environment]][template])
15
15
  end
16
16
 
17
17
  def parse_xml(config_hash)
18
18
  if config_hash.has_key?('xml_file_path') && config_hash.has_key?('xml_file_var')
19
19
  path = config_hash['xml_file_path']
20
20
  var = config_hash['xml_file_var']
21
- @log.info('Opening XML file : ' + path)
21
+ Tiller::log.info('Opening XML file : ' + path)
22
22
  begin
23
23
  xml = Crack::XML.parse(File.open(path))
24
24
  rescue StandardError => e
@@ -26,7 +26,7 @@ class XmlFileDataSource < Tiller::DataSource
26
26
  end
27
27
  struct = {}
28
28
  struct[var] = xml
29
- @log.debug("Created XML structure : #{struct}")
29
+ Tiller::log.debug("Created XML structure : #{struct}")
30
30
  struct
31
31
  else
32
32
  {}
@@ -10,8 +10,8 @@ class ZookeeperDataSource < Tiller::DataSource
10
10
  # Set our defaults if not specified
11
11
  @zk_config = Tiller::Zookeeper::Defaults
12
12
 
13
- raise 'No zookeeper configuration block' unless @config.has_key?('zookeeper')
14
- @zk_config.merge!(@config['zookeeper'])
13
+ raise 'No zookeeper configuration block' unless Tiller::config.has_key?('zookeeper')
14
+ @zk_config.merge!(Tiller::config['zookeeper'])
15
15
 
16
16
  # Sanity check
17
17
  ['uri'].each {|c| raise "Missing Zookeeper configuration #{c}" unless @zk_config.has_key?(c)}
@@ -29,21 +29,21 @@ class ZookeeperDataSource < Tiller::DataSource
29
29
 
30
30
  def values(template_name)
31
31
  path = @zk_config['values']['template']
32
- .gsub('%e',@config[:environment])
32
+ .gsub('%e',Tiller::config[:environment])
33
33
  .gsub('%t',template_name)
34
34
 
35
35
  get_values(path)
36
36
  end
37
37
 
38
38
  def global_values
39
- path = @zk_config['values']['global'].gsub('%e',@config[:environment])
40
- @log.info("Fetching Zookeeper globals from #{path}")
39
+ path = @zk_config['values']['global'].gsub('%e',Tiller::config[:environment])
40
+ Tiller::log.info("Fetching Zookeeper globals from #{path}")
41
41
  get_values(path)
42
42
  end
43
43
 
44
44
  def target_values(template_name)
45
45
  path = @zk_config['values']['target']
46
- .gsub('%e',@config[:environment])
46
+ .gsub('%e',Tiller::config[:environment])
47
47
  .gsub('%t',template_name)
48
48
  get_values(path)
49
49
  end
@@ -1,5 +1,3 @@
1
- require 'tiller/logger'
2
-
3
1
  # Tiller data source base class.
4
2
  module Tiller
5
3
  # Subclasses provide global_values and/or values (things local to a specific
@@ -7,12 +5,7 @@ module Tiller
7
5
  # location, permissions, owner and so on)
8
6
  class DataSource
9
7
 
10
- # Every plugin gets this hash, which is the full parsed config
11
- @config ={}
12
-
13
- def initialize(config)
14
- @config = config
15
- @log = Tiller::Logger.new(config)
8
+ def initialize
16
9
  setup
17
10
  end
18
11
 
@@ -52,7 +45,7 @@ module Tiller
52
45
  end
53
46
 
54
47
  def ping
55
- 'ping!' + @config.to_s
48
+ 'ping!' + Tiller::config.to_s
56
49
  end
57
50
  end
58
51
  end
data/lib/tiller/http.rb CHANGED
@@ -12,8 +12,8 @@ module Tiller::HttpCommon
12
12
  # Set our defaults if not specified
13
13
  @http_config = Tiller::Http.defaults
14
14
 
15
- raise 'No HTTP configuration block' unless @config.has_key?('http')
16
- @http_config.merge!(@config['http'])
15
+ raise 'No HTTP configuration block' unless Tiller::config.has_key?('http')
16
+ @http_config.merge!(Tiller::config['http'])
17
17
 
18
18
  # Sanity check
19
19
  ['uri'].each {|c| raise "HTTP: Missing HTTP configuration #{c}" unless @http_config.has_key?(c)}
@@ -23,14 +23,14 @@ module Tiller::HttpCommon
23
23
 
24
24
  # Basic auth for resource
25
25
  if @http_config.has_key?('username')
26
- @log.debug('HTTP: Using basic authentication')
26
+ Tiller::log.debug('HTTP: Using basic authentication')
27
27
  raise 'HTTP: Missing password for authentication' unless @http_config.has_key?('password')
28
28
  @client.set_auth(nil, @http_config['username'], @http_config['password'])
29
29
  end
30
30
 
31
31
  # Basic auth for proxy
32
32
  if @http_config.has_key?('proxy_username')
33
- @log.debug('HTTP: Using proxy basic authentication')
33
+ Tiller::log.debug('HTTP: Using proxy basic authentication')
34
34
  raise 'HTTP: Missing password for proxy authentication' unless @http_config.has_key?('proxy_password')
35
35
  @client.set_proxy_auth(@http_config['proxy_username'], @http_config['proxy_password'])
36
36
  end
@@ -39,10 +39,10 @@ module Tiller::HttpCommon
39
39
 
40
40
  # Interpolate the placeholders and return content from a URI
41
41
  def get_uri(uri, interpolate={})
42
- uri.gsub!('%e', @config[:environment])
42
+ uri.gsub!('%e', Tiller::config[:environment])
43
43
  uri.gsub!('%t', interpolate[:template]) if interpolate[:template]
44
44
 
45
- @log.debug("HTTP: Fetching #{uri}")
45
+ Tiller::log.debug("HTTP: Fetching #{uri}")
46
46
  resp = @client.get(uri, :follow_redirect => true)
47
47
  raise "HTTP: Server responded with status #{resp.status} for #{uri}" if resp.status != 200
48
48
  resp.body
@@ -53,7 +53,7 @@ module Tiller::HttpCommon
53
53
  def parse(content)
54
54
  case @http_config['parser']
55
55
  when 'json'
56
- @log.debug("HTTP: Using JSON parser")
56
+ Tiller::log.debug("HTTP: Using JSON parser")
57
57
  JSON.parse(content)
58
58
  else
59
59
  raise "HTTP: Unsupported parser '#{@http_config['parser']}'"
data/lib/tiller/loader.rb CHANGED
@@ -2,7 +2,6 @@ require 'tiller/templatesource'
2
2
  require 'tiller/datasource'
3
3
 
4
4
  def loader(type,sources)
5
-
6
5
  case type.to_s
7
6
  when 'Tiller::DataSource'
8
7
  source_path = 'tiller/data'
@@ -27,5 +26,17 @@ def loader(type,sources)
27
26
  end
28
27
 
29
28
  classes
29
+ end
30
+
31
+
32
+ def helper_loader(helpers)
33
+ source_path = 'tiller/helper'
34
+ loaded = []
35
+
36
+ helpers.each do |h|
37
+ require File.join(source_path,"#{h}.rb")
38
+ loaded.push(h)
39
+ end
30
40
 
41
+ loaded
31
42
  end
data/lib/tiller/logger.rb CHANGED
@@ -3,12 +3,12 @@ require 'logger'
3
3
  module Tiller
4
4
 
5
5
  class Logger < Logger
6
- def initialize(config)
6
+ def initialize
7
7
  super(STDOUT)
8
8
 
9
9
  self.level = Logger::WARN
10
- self.level = Logger::INFO if config[:verbose]
11
- self.level = Logger::DEBUG if config[:debug]
10
+ self.level = Logger::INFO if Tiller::config[:verbose]
11
+ self.level = Logger::DEBUG if Tiller::config[:debug]
12
12
 
13
13
  self.formatter = proc do |_severity, _datetime, _progname, msg|
14
14
  "#{msg}\n"
@@ -0,0 +1,12 @@
1
+ module Tiller
2
+ def self.render(template)
3
+ if Tiller::templates.key?(template)
4
+ content = Tiller::templates[template]
5
+ ns = OpenStruct.new(Tiller::tiller)
6
+ ERB.new(content, nil, '-').result(ns.instance_eval { binding })
7
+ else
8
+ Tiller::log.warn("Warning : Requested render of non-existant template #{template}")
9
+ ""
10
+ end
11
+ end
12
+ end
@@ -9,13 +9,13 @@ class ConsulTemplateSource < Tiller::TemplateSource
9
9
 
10
10
  def templates
11
11
  path = interpolate("#{@consul_config['templates']}")
12
- @log.debug("#{self} : Fetching templates from #{path}")
12
+ Tiller::log.debug("#{self} : Fetching templates from #{path}")
13
13
  templates = Diplomat::Kv.get(path, {:keys => true, :dc => @consul_config['dc']}, :return)
14
14
 
15
15
  if templates.is_a? Array
16
16
  templates.map { |t| File.basename(t) }
17
17
  else
18
- @log.warn("Consul : No templates could be fetched from #{path}")
18
+ Tiller::log.warn("Consul : No templates could be fetched from #{path}")
19
19
  []
20
20
  end
21
21
  end
@@ -1,7 +1,7 @@
1
1
  class FileTemplateSource < Tiller::TemplateSource
2
- def initialize(config)
2
+ def initialize
3
3
  super
4
- @template_dir = File.join(@config[:tiller_base], 'templates/')
4
+ @template_dir = File.join(Tiller::config[:tiller_base], 'templates/')
5
5
  end
6
6
 
7
7
  # Simply return a list of all the templates in the $tiller_base/templates
@@ -6,8 +6,8 @@ class ZookeeperTemplateSource < Tiller::TemplateSource
6
6
  # Set our defaults if not specified
7
7
  @zk_config = Tiller::Zookeeper::Defaults
8
8
 
9
- raise 'No zookeeper configuration block' unless @config.has_key?('zookeeper')
10
- @zk_config.merge!(@config['zookeeper'])
9
+ raise 'No zookeeper configuration block' unless Tiller::config.has_key?('zookeeper')
10
+ @zk_config.merge!(Tiller::config['zookeeper'])
11
11
 
12
12
  # Sanity check
13
13
  ['uri'].each {|c| raise "Missing Zookeeper configuration #{c}" unless @zk_config.has_key?(c)}
@@ -24,8 +24,8 @@ class ZookeeperTemplateSource < Tiller::TemplateSource
24
24
  end
25
25
 
26
26
  def templates
27
- path = @zk_config['templates'].gsub('%e',@config[:environment])
28
- @log.info("Fetching Zookeeper templates from #{path}")
27
+ path = @zk_config['templates'].gsub('%e',Tiller::config[:environment])
28
+ Tiller::log.info("Fetching Zookeeper templates from #{path}")
29
29
  templates = []
30
30
  if @zk.exists?(path)
31
31
  templates = @zk.children(path)
@@ -35,7 +35,7 @@ class ZookeeperTemplateSource < Tiller::TemplateSource
35
35
  end
36
36
 
37
37
  def template(template_name)
38
- path = @zk_config['templates'].gsub('%e',@config[:environment]) + "/#{template_name}"
38
+ path = @zk_config['templates'].gsub('%e',Tiller::config[:environment]) + "/#{template_name}"
39
39
  @zk.get(path)[0]
40
40
  end
41
41
 
@@ -1,17 +1,10 @@
1
- require 'tiller/logger'
2
-
3
1
  # Tiller template source base class
4
2
  module Tiller
5
3
  # Subclasses provide templates (an array), and individual template contents
6
4
  # (a string containing ERB data)
7
5
  class TemplateSource
8
6
 
9
- # Every plugin gets this hash, which is the full parsed config
10
- @config = {}
11
-
12
- def initialize(config)
13
- @config = config
14
- @log = Tiller::Logger.new(config)
7
+ def initialize
15
8
  setup
16
9
  end
17
10
 
@@ -29,7 +22,7 @@ module Tiller
29
22
  end
30
23
 
31
24
  def ping
32
- 'ping!' + @config.to_s
25
+ 'ping!' + Tiller::config.to_s
33
26
  end
34
27
  end
35
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.10
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Dastmalchi-Round
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-19 00:00:00.000000000 Z
11
+ date: 2016-07-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A tool to create configuration files from a variety of sources, particularly
14
14
  useful for Docker containers. See https://github.com/markround/tiller for examples
@@ -45,13 +45,14 @@ files:
45
45
  - lib/tiller/loader.rb
46
46
  - lib/tiller/logger.rb
47
47
  - lib/tiller/options.rb
48
+ - lib/tiller/render.rb
48
49
  - lib/tiller/template/consul.rb
49
50
  - lib/tiller/template/file.rb
50
51
  - lib/tiller/template/http.rb
51
52
  - lib/tiller/template/zookeeper.rb
52
53
  - lib/tiller/templatesource.rb
53
54
  - lib/tiller/util.rb
54
- homepage: http://www.markround.com
55
+ homepage: http://www.markround.com/blog/categories/tiller/
55
56
  licenses:
56
57
  - MIT
57
58
  metadata: