serverspec-extra-types 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +117 -0
- data/.rubocop.yml +24 -2
- data/.simplecov +7 -0
- data/README.md +344 -15
- data/lib/serverspec-extra-types.rb +5 -0
- data/lib/serverspec_extra_types.rb +4 -3
- data/lib/serverspec_extra_types/matchers.rb +2 -1
- data/lib/serverspec_extra_types/matchers/allowed_to_run_anything.rb +12 -9
- data/lib/serverspec_extra_types/matchers/allowed_to_run_command.rb +8 -6
- data/lib/serverspec_extra_types/matchers/apply_to.rb +7 -0
- data/lib/serverspec_extra_types/matchers/have_host.rb +8 -1
- data/lib/serverspec_extra_types/matchers/have_image.rb +1 -0
- data/lib/serverspec_extra_types/matchers/have_label.rb +1 -3
- data/lib/serverspec_extra_types/types/api_base.rb +3 -2
- data/lib/serverspec_extra_types/types/consul_base.rb +5 -1
- data/lib/serverspec_extra_types/types/consul_node_list.rb +1 -1
- data/lib/serverspec_extra_types/types/consul_service.rb +2 -4
- data/lib/serverspec_extra_types/types/curl.rb +2 -0
- data/lib/serverspec_extra_types/types/docker_config.rb +4 -1
- data/lib/serverspec_extra_types/types/docker_container.rb +2 -0
- data/lib/serverspec_extra_types/types/docker_network.rb +6 -4
- data/lib/serverspec_extra_types/types/docker_node.rb +3 -1
- data/lib/serverspec_extra_types/types/docker_secret.rb +4 -2
- data/lib/serverspec_extra_types/types/docker_service.rb +3 -1
- data/lib/serverspec_extra_types/types/jenkins_base.rb +0 -1
- data/lib/serverspec_extra_types/types/jenkins_credential.rb +5 -6
- data/lib/serverspec_extra_types/types/jenkins_job.rb +7 -6
- data/lib/serverspec_extra_types/types/jenkins_plugin.rb +8 -4
- data/lib/serverspec_extra_types/types/nfs_export.rb +16 -4
- data/lib/serverspec_extra_types/types/rabbitmq_base.rb +2 -2
- data/lib/serverspec_extra_types/types/rabbitmq_node_list.rb +1 -1
- data/lib/serverspec_extra_types/types/rabbitmq_vhost_list.rb +1 -1
- data/lib/serverspec_extra_types/types/rabbitmq_vhost_policy.rb +13 -1
- data/lib/serverspec_extra_types/types/sudo_user.rb +18 -15
- data/lib/serverspec_extra_types/version.rb +1 -1
- data/properties.yml +31 -5
- data/serverspec-extra-types.gemspec +1 -1
- metadata +8 -4
@@ -17,7 +17,7 @@ module Serverspec::Type
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def url
|
20
|
-
jobname = @name.gsub('/','/job/')
|
20
|
+
jobname = @name.gsub('/', '/job/')
|
21
21
|
"#{@url_base}/job/#{jobname}/api/json"
|
22
22
|
end
|
23
23
|
|
@@ -91,11 +91,10 @@ module Serverspec::Type
|
|
91
91
|
inspection['fullName'] == text
|
92
92
|
end
|
93
93
|
|
94
|
-
def has_job?(
|
95
|
-
inspection['jobs'].find { |job| job['name'] ==
|
94
|
+
def has_job?(_job)
|
95
|
+
inspection['jobs'].find { |job| job['name'] == _job }
|
96
96
|
end
|
97
97
|
|
98
|
-
|
99
98
|
def has_job_count?(count)
|
100
99
|
inspection['jobs'].length == count
|
101
100
|
end
|
@@ -109,15 +108,17 @@ module Serverspec::Type
|
|
109
108
|
end
|
110
109
|
|
111
110
|
def has_empty_job_list?
|
112
|
-
inspection['jobs'].
|
111
|
+
inspection['jobs'].empty?
|
113
112
|
end
|
114
113
|
|
115
114
|
private
|
116
115
|
|
116
|
+
# rubocop:disable Naming/AccessorMethodName
|
117
117
|
def get_inspection
|
118
|
-
userpass = @user ? "-u #{@user}:#{@password}" :
|
118
|
+
userpass = @user ? "-u #{@user}:#{@password}" : ''
|
119
119
|
command = "curl -s #{userpass} #{url} #{@insecure ? '-k' : ''} #{@redirects ? '-L' : ''}"
|
120
120
|
@get_inspection ||= @runner.run_command(command)
|
121
121
|
end
|
122
|
+
# rubocop:enable Naming/AccessorMethodName
|
122
123
|
end
|
123
124
|
end
|
@@ -16,8 +16,12 @@ module Serverspec::Type
|
|
16
16
|
@inspection ||= ::MultiJson.load(get_inspection.stdout)['plugins'].find { |plugin| plugin['shortName'] == @name }
|
17
17
|
end
|
18
18
|
|
19
|
-
def installed?
|
20
|
-
|
19
|
+
def installed?(_provider = nil, version = nil)
|
20
|
+
if version
|
21
|
+
!inspection.nil? && inspection['version'].to_s == version.to_s
|
22
|
+
else
|
23
|
+
!inspection.nil?
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
27
|
def exist?
|
@@ -42,14 +46,14 @@ module Serverspec::Type
|
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
45
|
-
|
46
|
-
|
47
49
|
private
|
48
50
|
|
51
|
+
# rubocop:disable Naming/AccessorMethodName
|
49
52
|
def get_inspection
|
50
53
|
userpass = @user ? "-u #{@user}:#{@password}" : ''
|
51
54
|
command = "curl -s #{userpass} #{url} #{@insecure ? '-k' : ''} #{@redirects ? '-L' : ''}"
|
52
55
|
@get_inspection ||= @runner.run_command(command)
|
53
56
|
end
|
57
|
+
# rubocop:enable Naming/AccessorMethodName
|
54
58
|
end
|
55
59
|
end
|
@@ -17,11 +17,10 @@ module Serverspec::Type
|
|
17
17
|
|
18
18
|
def has_host?(host_id, option = nil)
|
19
19
|
if option
|
20
|
-
|
20
|
+
check_options(host_id, option)
|
21
21
|
else
|
22
|
-
hosts.
|
22
|
+
hosts.key?(host_id)
|
23
23
|
end
|
24
|
-
|
25
24
|
end
|
26
25
|
|
27
26
|
def hosts
|
@@ -43,9 +42,22 @@ module Serverspec::Type
|
|
43
42
|
@inspection ||= get_inspection.stdout
|
44
43
|
end
|
45
44
|
|
45
|
+
# rubocop:disable Naming/AccessorMethodName
|
46
46
|
def get_inspection
|
47
47
|
command = "grep #{@export} /etc/exports"
|
48
48
|
@get_inspection ||= @runner.run_command(command)
|
49
49
|
end
|
50
|
+
# rubocop:enable Naming/AccessorMethodName
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def check_options(host_id, opts)
|
55
|
+
options = opts.include?(',') ? opts.spilt(',') : opts
|
56
|
+
if options.is_a? Array
|
57
|
+
host(host_id).split(',').include?(options)
|
58
|
+
else
|
59
|
+
host(host_id).include?(options)
|
60
|
+
end
|
61
|
+
end
|
50
62
|
end
|
51
|
-
end
|
63
|
+
end
|
@@ -29,17 +29,17 @@ module Serverspec::Type
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
32
|
private
|
35
33
|
|
36
34
|
def extra_args
|
37
35
|
"-u #{@user}:#{@password}"
|
38
36
|
end
|
39
37
|
|
38
|
+
# rubocop:disable Naming/AccessorMethodName
|
40
39
|
def get_inspection
|
41
40
|
command = curl_command
|
42
41
|
@get_inspection ||= @runner.run_command(command)
|
43
42
|
end
|
43
|
+
# rubocop:enable Naming/AccessorMethodName
|
44
44
|
end
|
45
45
|
end
|
@@ -50,7 +50,19 @@ module Serverspec::Type
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def mirror_all?
|
53
|
-
|
53
|
+
apply_to?('all')
|
54
|
+
end
|
55
|
+
|
56
|
+
def mirror_queues?
|
57
|
+
apply_to?('queues')
|
58
|
+
end
|
59
|
+
|
60
|
+
def mirror_exchanges?
|
61
|
+
apply_to?('exchanges')
|
62
|
+
end
|
63
|
+
|
64
|
+
def apply_to?(arg)
|
65
|
+
inspection['apply-to'] == arg
|
54
66
|
end
|
55
67
|
|
56
68
|
# TODO: priority method and matcher
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'serverspec'
|
2
4
|
require 'serverspec/type/base'
|
3
5
|
require 'multi_json'
|
@@ -5,7 +7,6 @@ require 'serverspec_extra_types/helpers/properties'
|
|
5
7
|
|
6
8
|
module Serverspec::Type
|
7
9
|
class SudoUser < Base
|
8
|
-
|
9
10
|
def initialize(name)
|
10
11
|
super
|
11
12
|
@user = name
|
@@ -19,8 +20,6 @@ module Serverspec::Type
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
23
|
def allowed_to_run_command?(command, user = nil, checkpw = false)
|
25
24
|
perm = permission(command)
|
26
25
|
if user
|
@@ -34,10 +33,8 @@ module Serverspec::Type
|
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
36
|
def permission(command)
|
40
|
-
permissions.find {|x| x[:command] == command}
|
37
|
+
permissions.find { |x| x[:command] == command }
|
41
38
|
end
|
42
39
|
|
43
40
|
def permissions
|
@@ -52,39 +49,45 @@ module Serverspec::Type
|
|
52
49
|
@inspection ||= get_sudo_perms(get_inspection.stdout)
|
53
50
|
end
|
54
51
|
|
55
|
-
|
56
52
|
private
|
53
|
+
|
54
|
+
# rubocop:disable Naming/AccessorMethodName
|
57
55
|
def get_inspection
|
58
56
|
@get_inspection ||= @runner.run_command("sudo -l -U #{@user}")
|
59
57
|
end
|
58
|
+
# rubocop:enable Naming/AccessorMethodName
|
60
59
|
|
61
60
|
def chunk_permission(perm)
|
62
61
|
chunks = {}
|
63
|
-
parts = perm.sub(' : ', ':').split(/\s+/).reject{ |x| x == '' || x == "\n"}
|
62
|
+
parts = perm.sub(' : ', ':').split(/\s+/).reject { |x| x == '' || x == "\n" }
|
64
63
|
user = parts[0].sub('(', '').sub(')', '')
|
64
|
+
chunk(chunks, parts, perm, user)
|
65
|
+
chunks
|
66
|
+
end
|
67
|
+
|
68
|
+
def chunk(chunks, parts, perm, user)
|
65
69
|
if user.include?(':')
|
66
70
|
chunks[:user] = user.split(':')[0]
|
67
71
|
chunks[:group] = user.split(':')[1]
|
68
72
|
else
|
69
73
|
chunks[:user] = user
|
70
74
|
end
|
71
|
-
if /NOPASSWD:/.match perm
|
75
|
+
if /NOPASSWD:/.match? perm
|
72
76
|
chunks[:nopasswd] = true
|
73
|
-
chunks[:command] = parts[2..-1].join(
|
77
|
+
chunks[:command] = parts[2..-1].join(' ')
|
74
78
|
else
|
75
79
|
chunks[:nopasswd] = false
|
76
80
|
chunks[:command] = parts[1..-1].join(' ')
|
77
81
|
end
|
78
|
-
chunks
|
79
82
|
end
|
80
83
|
|
81
84
|
def get_sudo_perms(output)
|
82
85
|
matches = /Matching Defaults entries for #{@user} on .*\n(.*)\n/.match output
|
83
|
-
defaults = matches[1].split(', ').map(&:strip)
|
84
|
-
matches =
|
86
|
+
defaults = matches ? matches[1].split(', ').map(&:strip) : {}
|
87
|
+
matches = /User #{@user} may run the following commands on .*\n((\W.*\n)*)/.match output
|
85
88
|
|
86
|
-
permissions = matches[1].split("\n").map{ |x| chunk_permission(x.strip) }
|
89
|
+
permissions = matches ? matches[1].split("\n").map { |x| chunk_permission(x.strip) } : {}
|
87
90
|
{ defaults: defaults, permissions: permissions }
|
88
91
|
end
|
89
92
|
end
|
90
|
-
end
|
93
|
+
end
|
data/properties.yml
CHANGED
@@ -26,8 +26,6 @@ targets:
|
|
26
26
|
backend: exec
|
27
27
|
spec_type: docker_network
|
28
28
|
|
29
|
-
|
30
|
-
|
31
29
|
rabbitmq:
|
32
30
|
backend: exec
|
33
31
|
spec_type: rabbit
|
@@ -51,11 +49,39 @@ targets:
|
|
51
49
|
|
52
50
|
sudo:
|
53
51
|
backend: docker
|
54
|
-
docker_build_dir: spec/resources
|
52
|
+
docker_build_dir: spec/resources/dockerfiles/sudo
|
55
53
|
spec_type: sudo
|
56
54
|
|
55
|
+
sudo_matchers:
|
56
|
+
backend: docker
|
57
|
+
docker_build_dir: spec/resources/dockerfiles/sudo
|
58
|
+
spec_type: matchers/sudo_matcher
|
59
|
+
|
57
60
|
|
58
61
|
sudo_user:
|
59
62
|
backend: docker
|
60
|
-
docker_build_dir: spec/resources
|
61
|
-
spec_type: sudo_user
|
63
|
+
docker_build_dir: spec/resources/dockerfiles/sudo
|
64
|
+
spec_type: sudo_user
|
65
|
+
|
66
|
+
nfs_export:
|
67
|
+
backend: docker
|
68
|
+
docker_build_dir: spec/resources/dockerfiles/nfs
|
69
|
+
spec_type: nfs_export
|
70
|
+
|
71
|
+
jenkins_plugin:
|
72
|
+
backend: exec
|
73
|
+
spec_type: jenkins_plugin
|
74
|
+
variables:
|
75
|
+
jenkins_url: http://localhost:38080
|
76
|
+
|
77
|
+
jenkins_credential:
|
78
|
+
backend: exec
|
79
|
+
spec_type: jenkins_credential
|
80
|
+
variables:
|
81
|
+
jenkins_url: http://localhost:38080
|
82
|
+
|
83
|
+
jenkins_job:
|
84
|
+
backend: exec
|
85
|
+
spec_type: jenkins_job
|
86
|
+
variables:
|
87
|
+
jenkins_url: http://localhost:38080
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.8.0'
|
28
28
|
spec.add_development_dependency 'rubocop'
|
29
29
|
spec.add_development_dependency 'simplecov'
|
30
|
-
spec.add_development_dependency 'serverspec_launcher', '~> 0.
|
30
|
+
spec.add_development_dependency 'serverspec_launcher', '~> 0.4.0'
|
31
31
|
spec.add_development_dependency 'rspec-collection_matchers'
|
32
32
|
spec.add_development_dependency 'rest-client'
|
33
33
|
spec.add_development_dependency 'docker-swarm-sdk'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverspec-extra-types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Wardrobe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.4.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.4.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec-collection_matchers
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,8 +172,10 @@ extensions: []
|
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
174
|
- ".gitignore"
|
175
|
+
- ".gitlab-ci.yml"
|
175
176
|
- ".rspec"
|
176
177
|
- ".rubocop.yml"
|
178
|
+
- ".simplecov"
|
177
179
|
- ".travis.yml"
|
178
180
|
- CODE_OF_CONDUCT.md
|
179
181
|
- Gemfile
|
@@ -185,11 +187,13 @@ files:
|
|
185
187
|
- bin/http_doc_gem.rb
|
186
188
|
- bin/setup
|
187
189
|
- http_matchers.md
|
190
|
+
- lib/serverspec-extra-types.rb
|
188
191
|
- lib/serverspec_extra_types.rb
|
189
192
|
- lib/serverspec_extra_types/helpers/properties.rb
|
190
193
|
- lib/serverspec_extra_types/matchers.rb
|
191
194
|
- lib/serverspec_extra_types/matchers/allowed_to_run_anything.rb
|
192
195
|
- lib/serverspec_extra_types/matchers/allowed_to_run_command.rb
|
196
|
+
- lib/serverspec_extra_types/matchers/apply_to.rb
|
193
197
|
- lib/serverspec_extra_types/matchers/be_a_manager_node.rb
|
194
198
|
- lib/serverspec_extra_types/matchers/be_a_worker_node.rb
|
195
199
|
- lib/serverspec_extra_types/matchers/be_active.rb
|