tiller 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/tiller +2 -2
- data/lib/tiller/api.rb +44 -36
- data/lib/tiller/api/handlers/config.rb +2 -2
- data/lib/tiller/api/handlers/globals.rb +2 -2
- data/lib/tiller/api/handlers/template.rb +2 -2
- data/lib/tiller/api/handlers/templates.rb +2 -2
- data/lib/tiller/json.rb +15 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6a2cb59355573ce5ebb05972afcf096288662e4
|
4
|
+
data.tar.gz: 353d75c047d51da10149e14c65abe0af0523615c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eabac5f8d95506361d2dcfbc00fbb0d3155dc744532f624ce98634159158c6d1865f15d21e5afaf26abe18dfec8f38021d2f18f970040274d888f2c089418254
|
7
|
+
data.tar.gz: 48fa0a3da0bf19a1cfcc626e91acb63516ff03066567b4f6fbe69b43fbdf11ea94d7354c916ed6adc4687a08777e29c43463a013bed55974c4028c96c6dfb835
|
data/bin/tiller
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# didn't have an existing gem named after it!
|
5
5
|
# Mark Round <github@markround.com>
|
6
6
|
|
7
|
-
VERSION = '0.2.
|
7
|
+
VERSION = '0.2.3'
|
8
8
|
|
9
9
|
require 'erb'
|
10
10
|
require 'ostruct'
|
@@ -44,7 +44,7 @@ module Tiller
|
|
44
44
|
# Parse command-line arguments
|
45
45
|
config[:no_exec] = false
|
46
46
|
config[:verbose] = false
|
47
|
-
config[
|
47
|
+
config['api_enable'] = false
|
48
48
|
|
49
49
|
optparse = OptionParser.new do |opts|
|
50
50
|
opts.on('-n', '--no-exec', 'Do not execute a replacement process') do
|
data/lib/tiller/api.rb
CHANGED
@@ -15,53 +15,61 @@ API_PORT=6275
|
|
15
15
|
# after it has generated templates and forked a child process.
|
16
16
|
|
17
17
|
def tiller_api(tiller_api_hash)
|
18
|
+
|
18
19
|
api_port = tiller_api_hash['config']['api_port'] ?
|
19
20
|
tiller_api_hash['config']['api_port'] : API_PORT
|
20
21
|
|
21
|
-
puts "Tiller API starting on port #{api_port}"
|
22
|
+
puts "Tiller API starting on port #{api_port}"
|
22
23
|
|
23
24
|
server = TCPServer.new(api_port)
|
24
25
|
|
25
26
|
loop do
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
begin
|
28
|
+
socket = server.accept
|
29
|
+
request = socket.gets
|
30
|
+
(method, uri, http_version) = request.split
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
if uri =~ /^\/v([0-9]+)\//
|
33
|
+
api_version = uri.split('/')[1]
|
34
|
+
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
36
|
+
# Defaults
|
37
|
+
response = handle_404
|
38
|
+
|
39
|
+
# Routing
|
40
|
+
case method
|
41
|
+
when 'GET'
|
42
|
+
case uri
|
43
|
+
when '/ping'
|
44
|
+
response = handle_ping
|
45
|
+
when /^\/v([0-9]+)\/config/
|
46
|
+
response = handle_config(api_version, tiller_api_hash)
|
47
|
+
when /^\/v([0-9]+)\/globals/
|
48
|
+
response = handle_globals(api_version, tiller_api_hash)
|
49
|
+
when /^\/v([0-9]+)\/templates/
|
50
|
+
response = handle_templates(api_version, tiller_api_hash)
|
51
|
+
when /^\/v([0-9]+)\/template\//
|
52
|
+
template = uri.split('/')[3]
|
53
|
+
response = handle_template(api_version, tiller_api_hash, template)
|
54
|
+
end
|
55
|
+
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
# Response
|
58
|
+
socket.print "HTTP/1.1 #{response[:status]}\r\n" +
|
59
|
+
"Content-Type: application/json\r\n" +
|
60
|
+
"Server: Tiller #{VERSION} / API v#{API_VERSION}\r\n"
|
61
|
+
"Content-Length: #{response[:content].bytesize}\r\n" +
|
62
|
+
"Connection: close\r\n"
|
63
|
+
socket.print "\r\n"
|
64
|
+
socket.print response[:content]
|
65
|
+
socket.close
|
66
|
+
|
67
|
+
rescue Exception => e
|
68
|
+
puts "Error : Exception in Tiller API thread : #{e.class.name}\n#{e}"
|
69
|
+
next
|
70
|
+
end
|
64
71
|
end
|
72
|
+
|
65
73
|
end
|
66
74
|
|
67
75
|
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'json'
|
1
|
+
require 'tiller/json'
|
2
2
|
require 'tiller/api/handlers/404'
|
3
3
|
|
4
4
|
def handle_config(api_version, tiller_api_hash)
|
5
5
|
case api_version
|
6
6
|
when 'v1'
|
7
7
|
{
|
8
|
-
:content => tiller_api_hash['config']
|
8
|
+
:content => dump_json(tiller_api_hash['config']),
|
9
9
|
:status => '200 OK'
|
10
10
|
}
|
11
11
|
else
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'json'
|
1
|
+
require 'tiller/json'
|
2
2
|
require 'tiller/api/handlers/404'
|
3
3
|
|
4
4
|
def handle_globals(api_version, tiller_api_hash)
|
5
5
|
case api_version
|
6
6
|
when 'v1'
|
7
7
|
{
|
8
|
-
:content => tiller_api_hash['global_values']
|
8
|
+
:content => dump_json(tiller_api_hash['global_values']),
|
9
9
|
:status => '200 OK'
|
10
10
|
}
|
11
11
|
else
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'json'
|
1
|
+
require 'tiller/json'
|
2
2
|
require 'tiller/api/handlers/404'
|
3
3
|
|
4
4
|
def handle_template(api_version, tiller_api_hash, template)
|
@@ -6,7 +6,7 @@ def handle_template(api_version, tiller_api_hash, template)
|
|
6
6
|
when 'v1'
|
7
7
|
if tiller_api_hash['templates'].has_key?(template)
|
8
8
|
{
|
9
|
-
:content => tiller_api_hash['templates'][template]
|
9
|
+
:content => dump_json(tiller_api_hash['templates'][template]),
|
10
10
|
:status => '200 OK'
|
11
11
|
}
|
12
12
|
else
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'json'
|
1
|
+
require 'tiller/json'
|
2
2
|
require 'tiller/api/handlers/404'
|
3
3
|
|
4
4
|
def handle_templates(api_version, tiller_api_hash)
|
5
5
|
case api_version
|
6
6
|
when 'v1'
|
7
7
|
{
|
8
|
-
:content => tiller_api_hash['templates'].keys
|
8
|
+
:content => dump_json(tiller_api_hash['templates'].keys),
|
9
9
|
:status => '200 OK'
|
10
10
|
}
|
11
11
|
else
|
data/lib/tiller/json.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Switchable JSON dumpers. If Oj gem is installed then we'll use that,
|
2
|
+
# otherwise we'll fall back to to_json. This is because to_json may have issues
|
3
|
+
# with encoding, but I don't want to force people to install a C-language
|
4
|
+
# gem, along with a compiler and ruby development libraries etc.
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
def dump_json(structure)
|
9
|
+
begin
|
10
|
+
require 'Oj'
|
11
|
+
Oj.dump(structure, :mode => :compat)
|
12
|
+
rescue LoadError
|
13
|
+
structure.to_json
|
14
|
+
end
|
15
|
+
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Round
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A tool to create configuration files in Docker containers from a variety
|
14
14
|
of sources. See https://github.com/markround/tiller for examples and documentation.
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/tiller/data/file.rb
|
44
44
|
- lib/tiller/data/random.rb
|
45
45
|
- lib/tiller/datasource.rb
|
46
|
+
- lib/tiller/json.rb
|
46
47
|
- lib/tiller/template/file.rb
|
47
48
|
- lib/tiller/templatesource.rb
|
48
49
|
homepage: http://www.markround.com
|