tiller 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/tiller +6 -2
- data/lib/tiller/data/http.rb +23 -0
- data/lib/tiller/defaults.rb +20 -0
- data/lib/tiller/http.rb +64 -0
- data/lib/tiller/options.rb +3 -0
- data/lib/tiller/template/http.rb +20 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de1c0f1f8381638d2568818134f335b4184a0b1c
|
4
|
+
data.tar.gz: 3613aa2b175fa801b671fab200b234153bfc698b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff24474771f4041cede5a6fdedf6ee47c63f43288a57e9fa77a67f2472257f55d9e14cd496469ecf2f78a596b5f964a9d859721363f9f957c0c18b0d20a42039
|
7
|
+
data.tar.gz: de08322c4b9ecbf1cc2976e0a65fea61a1b8971c26caf3b01c0b90b3e7ae7dce35946b20b44e79b7ff3ad96fc391432ea8b2d5692ed996da31c0ba0a5ef0a8b9
|
data/bin/tiller
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# A tool to create configuration files from a variety of sources, particularly
|
3
|
+
# useful for Docker containers. See https://github.com/markround/tiller for
|
4
|
+
# examples and documentation.
|
5
|
+
#
|
3
6
|
# Named from the first ship-building (Docker) related term I could find that
|
4
7
|
# didn't have an existing gem named after it!
|
8
|
+
#
|
5
9
|
# Mark Dastmalchi-Round <github@markround.com>
|
6
10
|
|
7
|
-
VERSION = '0.6.
|
11
|
+
VERSION = '0.6.1'
|
8
12
|
|
9
13
|
require 'erb'
|
10
14
|
require 'ostruct'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'httpclient'
|
3
|
+
require 'timeout'
|
4
|
+
require 'tiller/http.rb'
|
5
|
+
|
6
|
+
|
7
|
+
class HttpDataSource < Tiller::DataSource
|
8
|
+
|
9
|
+
include Tiller::HttpCommon
|
10
|
+
|
11
|
+
def values(template_name)
|
12
|
+
parse(get_uri(@http_config['uri'] + @http_config['values']['template'], :template => template_name))
|
13
|
+
end
|
14
|
+
|
15
|
+
def global_values
|
16
|
+
parse(get_uri(@http_config['uri'] + @http_config['values']['global']))
|
17
|
+
end
|
18
|
+
|
19
|
+
def target_values(template_name)
|
20
|
+
parse(get_uri(@http_config['uri'] + @http_config['values']['target'], :template => template_name))
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/tiller/defaults.rb
CHANGED
@@ -32,3 +32,23 @@ module Tiller::Zookeeper
|
|
32
32
|
|
33
33
|
end
|
34
34
|
|
35
|
+
|
36
|
+
# Defaults for the HTTP data and template sources
|
37
|
+
module Tiller::Http
|
38
|
+
|
39
|
+
Defaults = {
|
40
|
+
'timeout' => 5,
|
41
|
+
'proxy' => '',
|
42
|
+
'templates' => '/tiller/environments/%e/templates',
|
43
|
+
'template_content' => '/tiller/templates/%t/content',
|
44
|
+
'parser' => 'json',
|
45
|
+
|
46
|
+
'values' => {
|
47
|
+
'global' => '/tiller/globals',
|
48
|
+
'template' => '/tiller/templates/%t/values/%e',
|
49
|
+
'target' => '/tiller/templates/%t/target_values/%e'
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
end
|
54
|
+
|
data/lib/tiller/http.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Common methods for HTTP plugins
|
2
|
+
|
3
|
+
require 'httpclient'
|
4
|
+
require 'timeout'
|
5
|
+
require 'pp'
|
6
|
+
require 'tiller/defaults.rb'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Tiller::HttpCommon
|
10
|
+
|
11
|
+
def setup
|
12
|
+
# Set our defaults if not specified
|
13
|
+
@http_config = Tiller::Http::Defaults
|
14
|
+
|
15
|
+
raise 'No HTTP configuration block' unless @config.has_key?('http')
|
16
|
+
@http_config.merge!(@config['http'])
|
17
|
+
|
18
|
+
# Sanity check
|
19
|
+
['uri'].each {|c| raise "HTTP: Missing HTTP configuration #{c}" unless @http_config.has_key?(c)}
|
20
|
+
|
21
|
+
# Create the client used for all requests
|
22
|
+
@client = HTTPClient.new(@http_config['proxy'])
|
23
|
+
|
24
|
+
# Basic auth for resource
|
25
|
+
if @http_config.has_key?('username')
|
26
|
+
puts 'HTTP: Using basic authentication' if @config[:debug]
|
27
|
+
raise 'HTTP: Missing password for authentication' unless @http_config.has_key?('password')
|
28
|
+
@client.set_auth(nil, @http_config['username'], @http_config['password'])
|
29
|
+
end
|
30
|
+
|
31
|
+
# Basic auth for proxy
|
32
|
+
if @http_config.has_key?('proxy_username')
|
33
|
+
puts 'HTTP: Using proxy basic authentication' if @config[:debug]
|
34
|
+
raise 'HTTP: Missing password for proxy authentication' unless @http_config.has_key?('proxy_password')
|
35
|
+
@client.set_proxy_auth(@http_config['proxy_username'], @http_config['proxy_password'])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Interpolate the placeholders and return content from a URI
|
41
|
+
def get_uri(uri, interpolate={})
|
42
|
+
uri.gsub!('%e', @config[:environment])
|
43
|
+
uri.gsub!('%t', interpolate[:template]) if interpolate[:template]
|
44
|
+
|
45
|
+
puts "HTTP: Fetching #{uri}" if @config[:debug]
|
46
|
+
resp = @client.get(uri, :follow_redirect => true)
|
47
|
+
raise "HTTP: Server responded with status #{resp.status} for #{uri}" if resp.status != 200
|
48
|
+
resp.body
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# Wrap parsing here, so we can implement XML and other parsers later
|
53
|
+
def parse(content)
|
54
|
+
case @http_config['parser']
|
55
|
+
when 'json'
|
56
|
+
puts 'HTTP: Using JSON parser' if @config[:debug]
|
57
|
+
JSON.parse(content)
|
58
|
+
else
|
59
|
+
raise "HTTP: Unsupported parser '#{@http_config['parser']}'"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
data/lib/tiller/options.rb
CHANGED
@@ -6,6 +6,9 @@ def parse_options(config)
|
|
6
6
|
opts.on('-v', '--verbose', 'Display verbose output') do
|
7
7
|
config[:verbose] = true
|
8
8
|
end
|
9
|
+
opts.on('-d', '--debug', 'Display debug output') do
|
10
|
+
config[:debug] = true
|
11
|
+
end
|
9
12
|
opts.on('-a', '--api', 'Enable HTTP API') do
|
10
13
|
config['api_enable'] = true
|
11
14
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'httpclient'
|
3
|
+
require 'timeout'
|
4
|
+
require 'tiller/http.rb'
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
class HttpTemplateSource < Tiller::TemplateSource
|
9
|
+
|
10
|
+
include Tiller::HttpCommon
|
11
|
+
|
12
|
+
def templates
|
13
|
+
parse(get_uri(@http_config['uri'] + @http_config['templates']))
|
14
|
+
end
|
15
|
+
|
16
|
+
def template(template_name)
|
17
|
+
get_uri(@http_config['uri'] + @http_config['template_content'], :template => template_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
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.6.
|
4
|
+
version: 0.6.1
|
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: 2015-
|
11
|
+
date: 2015-07-15 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
|
@@ -55,14 +55,17 @@ files:
|
|
55
55
|
- lib/tiller/data/environment.rb
|
56
56
|
- lib/tiller/data/environment_json.rb
|
57
57
|
- lib/tiller/data/file.rb
|
58
|
+
- lib/tiller/data/http.rb
|
58
59
|
- lib/tiller/data/random.rb
|
59
60
|
- lib/tiller/data/zookeeper.rb
|
60
61
|
- lib/tiller/datasource.rb
|
61
62
|
- lib/tiller/defaults.rb
|
63
|
+
- lib/tiller/http.rb
|
62
64
|
- lib/tiller/json.rb
|
63
65
|
- lib/tiller/loader.rb
|
64
66
|
- lib/tiller/options.rb
|
65
67
|
- lib/tiller/template/file.rb
|
68
|
+
- lib/tiller/template/http.rb
|
66
69
|
- lib/tiller/template/zookeeper.rb
|
67
70
|
- lib/tiller/templatesource.rb
|
68
71
|
- lib/tiller/util.rb
|