svcdeps_tasks 0.1.0

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: 06f106ec4c75f6fae0a5ed460659ee6ba2a75e5b
4
+ data.tar.gz: 36b89010e65030cd0c648391b4513f2e82c97e4d
5
+ SHA512:
6
+ metadata.gz: 86b514f2d7ec4b34d78497ff6c5e96c96ee5998c54314e4a8c684b498bfd20891bdd07ed478e7ea09971b41fb7f1f30ea817de50c35a2ba826d51cf4d234983a
7
+ data.tar.gz: ed20a62f4e464ba8cb71677fde5fcef820882b5b791421c07b6d07b9ff4c7de895628e8ef31b4b25578fe3cb71d61c9cc073b0227e821dd184c0fa983915a2a7
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in svcdeps_tasks.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ svcdeps_tasks (0.1.0)
5
+ rspec (~> 3.7)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ minitest (5.11.3)
12
+ rake (10.5.0)
13
+ rspec (3.7.0)
14
+ rspec-core (~> 3.7.0)
15
+ rspec-expectations (~> 3.7.0)
16
+ rspec-mocks (~> 3.7.0)
17
+ rspec-core (3.7.1)
18
+ rspec-support (~> 3.7.0)
19
+ rspec-expectations (3.7.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.7.0)
22
+ rspec-mocks (3.7.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-support (3.7.1)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.16)
32
+ minitest (~> 5.0)
33
+ rake (~> 10.0)
34
+ svcdeps_tasks!
35
+
36
+ BUNDLED WITH
37
+ 1.16.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # RSpec tests for Service Dependencies
2
+
3
+ ### USAGE
4
+
5
+ Add the following to Rakefile:
6
+
7
+ ```ruby
8
+ require 'svcdeps_tasks'
9
+
10
+ ENV['SVCDEPS_PATH'] = '/etc/svcdeps'
11
+ ```
12
+
13
+ And save yaml files describing how to check the service dependencies, like:
14
+
15
+ ```yaml
16
+ deps:
17
+ - type: tcp
18
+ host: www.google.com
19
+ port: 80
20
+ timeout: 2
21
+ desc: Should be able to tcp port ping www.google.com:80
22
+
23
+ - type: udp
24
+ host: 8.8.8.8
25
+ port: 53
26
+ timeout: 2
27
+ desc: Should be able to udp port ping DNS server(8.8.8.8:53)
28
+
29
+ - type: http
30
+ method: get
31
+ url: https://www.google.com
32
+ insecure: false
33
+ timeout: 2
34
+ desc: Should be able to hit https://www.google.com
35
+
36
+ - type: command
37
+ run_as: nobody
38
+ command: ping -c 1 8.8.8.8
39
+ timeout: 2
40
+ desc: Should be able to ping 8.8.8.8
41
+ ```
42
+
43
+ Running:
44
+
45
+ ```
46
+ # rake spec:svcdeps
47
+
48
+ Service Dependencies
49
+ Should be able to tcp port ping www.google.com:80
50
+ Should be able to udp port ping DNS server(8.8.8.8:53)
51
+ Should be able to hit https://www.google.com
52
+ Should be able to ping 8.8.8.8
53
+
54
+ Finished in 0.16224 seconds (files took 0.28904 seconds to load)
55
+ 4 examples, 0 failures
56
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "svcdeps_tasks"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/probe.rb ADDED
@@ -0,0 +1,104 @@
1
+ require 'socket'
2
+ require 'timeout'
3
+ require 'etc'
4
+ require 'yaml'
5
+ require 'net/http'
6
+ require 'openssl'
7
+
8
+ class Probe
9
+ def initialize(opts)
10
+ @type = opts[:type].downcase
11
+ @timeout = opts[:timeout] || 5
12
+ @opts = opts
13
+ end
14
+
15
+ def tcp_probe
16
+ host = @opts[:host]
17
+ port = @opts[:port]
18
+ Timeout::timeout(@timeout) do
19
+ TCPSocket.new(host, port).close
20
+ end
21
+ end
22
+
23
+ def udp_probe
24
+ host = @opts[:host]
25
+ port = @opts[:port]
26
+ Timeout::timeout(@timeout) do
27
+ u = UDPSocket.new
28
+ u.connect(host,port)
29
+ u.puts "check"
30
+ end
31
+ end
32
+
33
+ def command_probe
34
+ cmd = @opts[:command]
35
+ run_as = @opts[:run_as]
36
+
37
+ if run_as.nil?
38
+ run_as = 'nobody' if Process.uid.zero?
39
+ else
40
+ warn "WARNNG: Option 'run_as' requires root, ignoring it." unless Process.uid.zero?
41
+ run_as = nil unless Process.uid.zero?
42
+ end
43
+
44
+ Timeout::timeout(@timeout) do
45
+ user = Etc.getpwnam('nobody')
46
+ pid = Process.fork do
47
+ STDOUT.reopen('/dev/null')
48
+ STDERR.reopen('/dev/null')
49
+ unless run_as.nil?
50
+ Process.egid = Process.gid = user.gid
51
+ Process.euid = Process.uid = user.uid
52
+ end
53
+ exec cmd
54
+ end
55
+ status = Process.wait pid
56
+ exit_status = $?.exitstatus
57
+ raise "Command [#{cmd}] exited with #{exit_status}" if exit_status > 0
58
+ end
59
+ end
60
+
61
+ def http_probe
62
+ url = @opts[:url]
63
+ method = @opts[:method] || 'get'
64
+ payload = @opts[:payload] if @opts.key? :payload
65
+ insecure = @opts[:insecure] || false
66
+ headers = @opts[:headers] || {}
67
+
68
+ Timeout::timeout(@timeout) do
69
+ uri = URI(url)
70
+ is_https = uri.scheme == 'https'
71
+
72
+ uri.path = '/' if uri.path.empty?
73
+ req = Object.const_get("Net::HTTP::#{method.capitalize}").new(uri.path)
74
+ req.body = payload
75
+
76
+ headers.each {|k,v| req[k] = v }
77
+
78
+ opts = {}
79
+ opts[:use_ssl] = is_https
80
+ opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if is_https && insecure
81
+
82
+ Net::HTTP.start( uri.host, uri.port, opts ) do |http|
83
+ res = http.request(req)
84
+ raise "Request to #{url} returned code #{res.code}" unless res.code == '200'
85
+ end
86
+ end
87
+ end
88
+
89
+ def run
90
+ case @type
91
+ when 'tcp'
92
+ tcp_probe
93
+ when 'udp'
94
+ udp_probe
95
+ when 'command'
96
+ command_probe
97
+ when 'http'
98
+ http_probe
99
+ else
100
+ raise "Type '#{@type}' not supported"
101
+ end
102
+ end
103
+ end
104
+
data/lib/specfile.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'rspec'
2
+
3
+ dir = File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__)
4
+ require "#{dir}/probe"
5
+ require 'deep_merge'
6
+ require 'yaml'
7
+
8
+ deps = {}
9
+ deps_dir = ENV['SVCDEPS_PATH']
10
+ deps_files = []
11
+
12
+ raise "Environment variable 'SVCDEPS_PATH' must be set" unless deps_dir
13
+
14
+ Dir.chdir(deps_dir)
15
+ Dir.glob(File.join('**','*.yaml')).each {|f| deps_files << "#{deps_dir}/#{f}" }
16
+
17
+ def symbolize_keys(hash)
18
+ hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v ; memo }
19
+ end
20
+
21
+ deps_files.each do |f|
22
+ deps.deep_merge(YAML.load( File.read( f ) ) )
23
+ end
24
+
25
+ describe 'Service Dependencies' do
26
+ deps['deps'].each do |dep|
27
+ dep = symbolize_keys(dep)
28
+ it "#{dep[:desc]}" do
29
+ p = Probe.new( dep )
30
+ expect { p.run }.to_not raise_error
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module SvcdepsTasks
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'svcdeps_tasks/version'
2
+ require 'rspec'
3
+ require 'rake'
4
+
5
+ dir = File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__)
6
+
7
+ namespace :spec do
8
+ desc 'run service dependencies specs '
9
+ task :svcdeps do
10
+ RSpec.configure do |c|
11
+ c.add_formatter(:documentation)
12
+ end
13
+
14
+ RSpec::Core::Runner.run(["#{dir}/specfile.rb"],STDOUT, STDERR)
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "svcdeps_tasks/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "svcdeps_tasks"
8
+ spec.version = SvcdepsTasks::VERSION
9
+ spec.authors = ["Tiago Lopo"]
10
+ spec.email = ["tiagolopo@yahoo.com.br"]
11
+
12
+ spec.summary = %q{RSpec tests for service dependencies}
13
+ spec.description = %q{RSpec tests for service dependencies}
14
+ spec.homepage = "https://github.com/tlopo-ruby/svcdeps_tasks"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "rspec", "~> 3.7"
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "minitest", "~> 5.0"
36
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: svcdeps_tasks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tiago Lopo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: RSpec tests for service dependencies
70
+ email:
71
+ - tiagolopo@yahoo.com.br
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/probe.rb
86
+ - lib/specfile.rb
87
+ - lib/svcdeps_tasks.rb
88
+ - lib/svcdeps_tasks/version.rb
89
+ - svcdeps_tasks.gemspec
90
+ homepage: https://github.com/tlopo-ruby/svcdeps_tasks
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.14
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: RSpec tests for service dependencies
113
+ test_files: []