octoconfig 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a81b770b5902e648f01973642f3371d851634ec
4
+ data.tar.gz: c8948deb0c65c0837a68c7e79ae3e71b661b1314
5
+ SHA512:
6
+ metadata.gz: 7d6928315ea21e5896f6008a8c00c6d9ae29f10c5d150be35a2af9152bb3eaf43565a815a6b32a921abeebc1217fea195a515f4f0793dcf7c75d04af103c817b
7
+ data.tar.gz: b22d1006cef8c0e180229826a0a137aa59478d9f6cd82b2c7b61b1ed9f7ea54241a63a63ea5ee2cd147df32c7d42d994573fdaf3b135e40e782beeefc10d10de
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ octoconfig (0.0.3)
5
+ gli (= 2.11.0)
6
+ json
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ aruba (0.5.4)
12
+ childprocess (>= 0.3.6)
13
+ cucumber (>= 1.1.1)
14
+ rspec-expectations (>= 2.7.0)
15
+ builder (3.2.2)
16
+ childprocess (0.5.3)
17
+ ffi (~> 1.0, >= 1.0.11)
18
+ cucumber (1.3.15)
19
+ builder (>= 2.1.2)
20
+ diff-lcs (>= 1.1.3)
21
+ gherkin (~> 2.12)
22
+ multi_json (>= 1.7.5, < 2.0)
23
+ multi_test (>= 0.1.1)
24
+ diff-lcs (1.2.5)
25
+ ffi (1.9.3)
26
+ gherkin (2.12.2)
27
+ multi_json (~> 1.3)
28
+ gli (2.11.0)
29
+ json (1.8.1)
30
+ multi_json (1.10.1)
31
+ multi_test (0.1.1)
32
+ rake (10.3.2)
33
+ rdoc (4.1.1)
34
+ json (~> 1.4)
35
+ rspec-expectations (3.0.2)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.0.0)
38
+ rspec-support (3.0.2)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ aruba
45
+ octoconfig!
46
+ rake
47
+ rdoc
data/README.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = octoconfig
2
+
3
+ Describe your project here
4
+
5
+ :include:octoconfig.rdoc
6
+
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+ Rake::RDocTask.new do |rd|
8
+ rd.main = "README.rdoc"
9
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10
+ rd.title = 'Your application title'
11
+ end
12
+
13
+ spec = eval(File.read('octoconfig.gemspec'))
14
+
15
+ Gem::PackageTask.new(spec) do |pkg|
16
+ end
17
+ CUKE_RESULTS = 'results.html'
18
+ CLEAN << CUKE_RESULTS
19
+ desc 'Run features'
20
+ Cucumber::Rake::Task.new(:features) do |t|
21
+ opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22
+ opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23
+ t.cucumber_opts = opts
24
+ t.fork = false
25
+ end
26
+
27
+ desc 'Run features tagged as work-in-progress (@wip)'
28
+ Cucumber::Rake::Task.new('features:wip') do |t|
29
+ tag_opts = ' --tags ~@pending'
30
+ tag_opts = ' --tags @wip'
31
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
32
+ t.fork = false
33
+ end
34
+
35
+ task :cucumber => :features
36
+ task 'cucumber:wip' => 'features:wip'
37
+ task :wip => 'features:wip'
38
+ require 'rake/testtask'
39
+ Rake::TestTask.new do |t|
40
+ t.libs << "test"
41
+ t.test_files = FileList['test/*_test.rb']
42
+ end
43
+
44
+ task :default => [:test,:features]
data/bin/octoconfig ADDED
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'octoconfig'
4
+ require 'open3'
5
+ require 'erb'
6
+
7
+ include GLI::App
8
+
9
+ program_desc 'Setup octohost config files through Consul data.'
10
+
11
+ version Octoconfig::VERSION
12
+
13
+ desc 'Verbose.'
14
+ switch [:v,:verbose]
15
+
16
+ desc 'Daemon to update.'
17
+ default_value 'proxy'
18
+ arg_name 'daemon'
19
+ flag [:d,:daemon]
20
+
21
+ desc 'Config file to update.'
22
+ default_value '/etc/nginx/containers.conf'
23
+ arg_name 'config'
24
+ flag [:c,:config]
25
+
26
+ desc 'Command to get the service catalog.'
27
+ default_value 'octo services:catalog'
28
+ arg_name 'services'
29
+ flag [:s,:services]
30
+
31
+ desc 'Command to reload the daemon.'
32
+ default_value 'service proxy reload'
33
+ arg_name 'reload'
34
+ flag [:r,:reload]
35
+
36
+ desc 'Tag to look for in the service catalog.'
37
+ default_value 'http'
38
+ arg_name 'tag'
39
+ flag [:t,:tag]
40
+
41
+ desc 'Update the config for a {daemon}'
42
+ arg_name 'update'
43
+ command :update do |c|
44
+
45
+ c.action do |global_options,options,args|
46
+
47
+ # Get the services.
48
+ puts "Getting the services."
49
+
50
+ services = Services.new
51
+ services.get(global_options[:services], global_options[:tag])
52
+
53
+ # Load the ./lib/daemons/global_options[:daemon]/global_options[:tag] file.
54
+ filename = "../lib/daemons/#{global_options[:daemon]}/#{global_options[:tag]}.rb"
55
+ require_relative filename
56
+
57
+ template = Template.new(services, global_options[:daemon], global_options[:tag])
58
+ template_content = template.render
59
+
60
+ # Update the config at global_options[:config]
61
+ File.open(global_options[:config], 'w') { |file| file.write(template_content) }
62
+
63
+ # Restart the daemon.
64
+ `#{global_options[:reload]}`
65
+
66
+ puts "Config: #{global_options[:config]} for #{global_options[:daemon]} daemon with #{global_options[:tag]} tag updated."
67
+ end
68
+ end
69
+
70
+ pre do |global,command,options,args|
71
+ # Pre logic here
72
+ # Return true to proceed; false to abort and not call the
73
+ # chosen command
74
+ # Use skips_pre before a command to skip this block
75
+ # on that command only
76
+ true
77
+ end
78
+
79
+ post do |global,command,options,args|
80
+ # Post logic here
81
+ # Use skips_post before a command to skip this
82
+ # block on that command only
83
+ end
84
+
85
+ on_error do |exception|
86
+ # Error logic here
87
+ # return false to skip default error handling
88
+ true
89
+ end
90
+
91
+ exit run(ARGV)
@@ -0,0 +1,8 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "octoconfig"
8
+ Then the exit status should be 0
@@ -0,0 +1,6 @@
1
+ When /^I get help for "([^"]*)"$/ do |app_name|
2
+ @app_name = app_name
3
+ step %(I run `#{app_name} help`)
4
+ end
5
+
6
+ # Add more step definitions here
@@ -0,0 +1,15 @@
1
+ require 'aruba/cucumber'
2
+
3
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
4
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
5
+
6
+ Before do
7
+ # Using "announce" causes massive warnings on 1.9.2
8
+ @puts = true
9
+ @original_rubylib = ENV['RUBYLIB']
10
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
+ end
12
+
13
+ After do
14
+ ENV['RUBYLIB'] = @original_rubylib
15
+ end
@@ -0,0 +1,43 @@
1
+ class Template
2
+ def initialize(services, daemon, tag)
3
+ @services = services
4
+ @daemon = daemon
5
+ @tag = tag
6
+ end
7
+
8
+ def render
9
+ template_data = ""
10
+ services = @services.data
11
+ services.each do |name,urls|
12
+ @domains = self.domains(name)
13
+ unless @domains.nil?
14
+ @urls = urls
15
+ template_data += self.combine(name)
16
+ else
17
+ next
18
+ end
19
+ end
20
+ return template_data
21
+ end
22
+
23
+ def domains(name)
24
+ domains = `/usr/bin/consulkv get #{name}/DOMAINS`
25
+ unless domains.nil? || domains == ''
26
+ return domains = domains.gsub(/,/, ' ')
27
+ else
28
+ return nil
29
+ end
30
+ end
31
+
32
+ def combine(name)
33
+ template = "# ServiceName: #{name}\n"
34
+ template = "upstream #{name} {\n"
35
+ @urls.each do |url|
36
+ template += " server #{url.gsub(/http:\/\//, '')};\n"
37
+ end
38
+ template += "}\n"
39
+ template += "server {\n server_name #{@domains.chomp};\n location / {\n proxy_pass http://#{name};\n"
40
+ template += " }\n}\n"
41
+ return template
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Octoconfig
2
+ VERSION = '0.0.3'
3
+ end
data/lib/octoconfig.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'octoconfig/version.rb'
2
+ require 'services.rb'
3
+ require 'json'
data/lib/services.rb ADDED
@@ -0,0 +1,26 @@
1
+ class Services
2
+ attr_reader :data
3
+ def initialize()
4
+ @data = Hash.new { |hash, key| hash[key] = [] }
5
+ end
6
+ def [](key)
7
+ @data[key]
8
+ end
9
+ def []=(key,urls)
10
+ @data[key] += [urls].flatten
11
+ @data[key].uniq!
12
+ end
13
+ def get(command, service_type=http)
14
+ stdout_str, stderr_str, status = Open3.capture3(command)
15
+ stdout_str.each_line do |line|
16
+ service = JSON.parse(line)
17
+ unless service['ServiceTags'].nil?
18
+ if service['ServiceTags'].include? service_type
19
+ name = service['ServiceName']
20
+ url = "http://#{service['Address']}:#{service['ServicePort']}"
21
+ self[name] = %W( #{url} )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require File.join([File.dirname(__FILE__),'lib','octoconfig','version.rb'])
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'octoconfig'
5
+ s.version = Octoconfig::VERSION
6
+ s.author = 'Darron Froese'
7
+ s.email = 'darron@froese.org'
8
+ s.homepage = 'http://www.octohost.io'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.licenses = ['Apache']
11
+ s.summary = 'Setup octohost config files through Consul data.'
12
+ s.description = "This is a gem used with the octohost project. It pulls data from Consul and outputs an nginx config file."
13
+ s.files = `git ls-files`.split("
14
+ ")
15
+ s.require_paths << 'lib'
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = ['README.rdoc','octoconfig.rdoc']
18
+ s.rdoc_options << '--title' << 'octoconfig' << '--main' << 'README.rdoc' << '--ri'
19
+ s.bindir = 'bin'
20
+ s.executables << 'octoconfig'
21
+ s.add_development_dependency('rake')
22
+ s.add_development_dependency('rdoc')
23
+ s.add_development_dependency('aruba')
24
+ s.add_runtime_dependency('gli','2.11.0')
25
+ s.add_runtime_dependency('json')
26
+ end
data/octoconfig.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = octoconfig
2
+
3
+ Generate this with
4
+ octoconfig rdoc
5
+ After you have described your command line interface
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class DefaultTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_the_truth
12
+ assert true
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ # Add test libraries you want to use here, e.g. mocha
4
+
5
+ class Test::Unit::TestCase
6
+
7
+ # Add global extensions to the test case class here
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octoconfig
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Darron Froese
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gli
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.11.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.11.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This is a gem used with the octohost project. It pulls data from Consul
84
+ and outputs an nginx config file.
85
+ email: darron@froese.org
86
+ executables:
87
+ - octoconfig
88
+ extensions: []
89
+ extra_rdoc_files:
90
+ - README.rdoc
91
+ - octoconfig.rdoc
92
+ files:
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - README.rdoc
96
+ - Rakefile
97
+ - bin/octoconfig
98
+ - features/octoconfig.feature
99
+ - features/step_definitions/octoconfig_steps.rb
100
+ - features/support/env.rb
101
+ - lib/daemons/proxy/http.rb
102
+ - lib/octoconfig.rb
103
+ - lib/octoconfig/version.rb
104
+ - lib/services.rb
105
+ - octoconfig.gemspec
106
+ - octoconfig.rdoc
107
+ - test/default_test.rb
108
+ - test/test_helper.rb
109
+ homepage: http://www.octohost.io
110
+ licenses:
111
+ - Apache
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options:
115
+ - "--title"
116
+ - octoconfig
117
+ - "--main"
118
+ - README.rdoc
119
+ - "--ri"
120
+ require_paths:
121
+ - lib
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.2.2
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Setup octohost config files through Consul data.
139
+ test_files: []