tiller 0.2.2 → 0.2.3

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: 1dfd522a871acfb08c4e631ef2fce9d7afac65e2
4
- data.tar.gz: e73da3abffb92950f877c1e79368cfb845b3843b
3
+ metadata.gz: a6a2cb59355573ce5ebb05972afcf096288662e4
4
+ data.tar.gz: 353d75c047d51da10149e14c65abe0af0523615c
5
5
  SHA512:
6
- metadata.gz: 0e224129e75ab34e3e8c568f8b80e8599542dd8e5509db67d3e161aeda291e1c3f66f1a17807450d436814d616f0e582de605d7d101d24304e9060a3d190477a
7
- data.tar.gz: de983f07887c98f3f9f91430420ab8780810a3be927e63f7d2502763027ee7740e70112273e72cb2c4992f282f8954d980c4aa7b9b2ca24299ce1ae94dcf1de1
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.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[:api_enable] = false
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}" if tiller_api_hash['config'][:verbose]
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
- socket = server.accept
27
- request = socket.gets
28
- (method, uri, http_version) = request.split
27
+ begin
28
+ socket = server.accept
29
+ request = socket.gets
30
+ (method, uri, http_version) = request.split
29
31
 
30
- if uri =~ /^\/v([0-9]+)\//
31
- api_version = uri.split('/')[1]
32
- end
32
+ if uri =~ /^\/v([0-9]+)\//
33
+ api_version = uri.split('/')[1]
34
+ end
33
35
 
34
- # Defaults
35
- response = handle_404
36
-
37
- # Routing
38
- case method
39
- when 'GET'
40
- case uri
41
- when '/ping'
42
- response = handle_ping
43
- when /^\/v([0-9]+)\/config/
44
- response = handle_config(api_version, tiller_api_hash)
45
- when /^\/v([0-9]+)\/globals/
46
- response = handle_globals(api_version, tiller_api_hash)
47
- when /^\/v([0-9]+)\/templates/
48
- response = handle_templates(api_version, tiller_api_hash)
49
- when /^\/v([0-9]+)\/template\//
50
- template = uri.split('/')[3]
51
- response = handle_template(api_version, tiller_api_hash, template)
52
- end
53
- end
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
- # Response
56
- socket.print "HTTP/1.1 #{response[:status]}\r\n" +
57
- "Content-Type: application/json\r\n" +
58
- "Server: Tiller #{VERSION} / API v#{API_VERSION}\r\n"
59
- "Content-Length: #{response[:content].bytesize}\r\n" +
60
- "Connection: close\r\n"
61
- socket.print "\r\n"
62
- socket.print response[:content]
63
- socket.close
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'].to_json,
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'].to_json,
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].to_json,
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.to_json,
8
+ :content => dump_json(tiller_api_hash['templates'].keys),
9
9
  :status => '200 OK'
10
10
  }
11
11
  else
@@ -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.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-20 00:00:00.000000000 Z
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