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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +117 -0
  3. data/.rubocop.yml +24 -2
  4. data/.simplecov +7 -0
  5. data/README.md +344 -15
  6. data/lib/serverspec-extra-types.rb +5 -0
  7. data/lib/serverspec_extra_types.rb +4 -3
  8. data/lib/serverspec_extra_types/matchers.rb +2 -1
  9. data/lib/serverspec_extra_types/matchers/allowed_to_run_anything.rb +12 -9
  10. data/lib/serverspec_extra_types/matchers/allowed_to_run_command.rb +8 -6
  11. data/lib/serverspec_extra_types/matchers/apply_to.rb +7 -0
  12. data/lib/serverspec_extra_types/matchers/have_host.rb +8 -1
  13. data/lib/serverspec_extra_types/matchers/have_image.rb +1 -0
  14. data/lib/serverspec_extra_types/matchers/have_label.rb +1 -3
  15. data/lib/serverspec_extra_types/types/api_base.rb +3 -2
  16. data/lib/serverspec_extra_types/types/consul_base.rb +5 -1
  17. data/lib/serverspec_extra_types/types/consul_node_list.rb +1 -1
  18. data/lib/serverspec_extra_types/types/consul_service.rb +2 -4
  19. data/lib/serverspec_extra_types/types/curl.rb +2 -0
  20. data/lib/serverspec_extra_types/types/docker_config.rb +4 -1
  21. data/lib/serverspec_extra_types/types/docker_container.rb +2 -0
  22. data/lib/serverspec_extra_types/types/docker_network.rb +6 -4
  23. data/lib/serverspec_extra_types/types/docker_node.rb +3 -1
  24. data/lib/serverspec_extra_types/types/docker_secret.rb +4 -2
  25. data/lib/serverspec_extra_types/types/docker_service.rb +3 -1
  26. data/lib/serverspec_extra_types/types/jenkins_base.rb +0 -1
  27. data/lib/serverspec_extra_types/types/jenkins_credential.rb +5 -6
  28. data/lib/serverspec_extra_types/types/jenkins_job.rb +7 -6
  29. data/lib/serverspec_extra_types/types/jenkins_plugin.rb +8 -4
  30. data/lib/serverspec_extra_types/types/nfs_export.rb +16 -4
  31. data/lib/serverspec_extra_types/types/rabbitmq_base.rb +2 -2
  32. data/lib/serverspec_extra_types/types/rabbitmq_node_list.rb +1 -1
  33. data/lib/serverspec_extra_types/types/rabbitmq_vhost_list.rb +1 -1
  34. data/lib/serverspec_extra_types/types/rabbitmq_vhost_policy.rb +13 -1
  35. data/lib/serverspec_extra_types/types/sudo_user.rb +18 -15
  36. data/lib/serverspec_extra_types/version.rb +1 -1
  37. data/properties.yml +31 -5
  38. data/serverspec-extra-types.gemspec +1 -1
  39. metadata +8 -4
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'serverspec_extra_types/version'
4
+ require 'serverspec_extra_types/matchers'
5
+ require 'serverspec_extra_types/types'
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'serverspec_extra_types/version'
4
- require 'serverspec_extra_types/matchers'
5
- require 'serverspec_extra_types/types'
3
+ puts "Deprecation WARNING: this file has been deprecated as the entry point to the gem. please use:"
4
+ puts "require 'serverspec-extra-types'"
5
+
6
+ require 'serverspec-extra-types'
@@ -30,6 +30,7 @@ require 'serverspec_extra_types/matchers/have_ha_nodes'
30
30
  require 'serverspec_extra_types/matchers/have_vhost'
31
31
  require 'serverspec_extra_types/matchers/have_ha_sync_mode'
32
32
  require 'serverspec_extra_types/matchers/mirror_all'
33
+ require 'serverspec_extra_types/matchers/apply_to'
33
34
  require 'serverspec_extra_types/matchers/read_from_queue'
34
35
  require 'serverspec_extra_types/matchers/write_to_queue'
35
36
  require 'serverspec_extra_types/matchers/configure_queue'
@@ -39,4 +40,4 @@ require 'serverspec_extra_types/matchers/url_matchers'
39
40
 
40
41
  #--- sudo matchers
41
42
  require 'serverspec_extra_types/matchers/allowed_to_run_command'
42
- require 'serverspec_extra_types/matchers/allowed_to_run_anything'
43
+ require 'serverspec_extra_types/matchers/allowed_to_run_anything'
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: false
2
+
1
3
  RSpec::Matchers.define :be_allowed_to_run_anything do
2
4
  chain :as do |user|
3
5
  @user = user
4
6
  end
5
7
  chain :as_anybody do
6
8
  @user = 'ALL'
9
+ @anybody = true
7
10
  end
8
11
  chain :without_password do
9
12
  @checkpw = true
@@ -20,19 +23,19 @@ RSpec::Matchers.define :be_allowed_to_run_anything do
20
23
  end
21
24
 
22
25
  failure_message do |actual|
23
- msg = if @user
24
- "expected to be able to run anything as #{@user} got #{actual.permission('ALL')[:user]}"
25
- else
26
- "expected anything} to be in #{actual.permissions.map{|x| x[:command]}}"
26
+ msg = if @user
27
+ "expected to be able to run anything as #{@user} got #{actual.permission('ALL')[:user]}"
28
+ else
29
+ "expected 'ALL' to be in #{actual.permissions.map { |x| x[:command] }}"
27
30
  end
28
- msg << %( without a password ) if @checkpw
31
+ msg << %( without a password) if @checkpw
29
32
  msg
30
33
  end
31
34
 
32
35
  description do
33
- msg = "be allowed to run anything"
34
- msg << %( as #{@user}) if @user
35
- msg << %( without a password ) if @checkpw
36
+ msg = 'be allowed to run anything'
37
+ msg << %( as #{@anybody ? 'anybody' : "'#{@user}'"}) if @user
38
+ msg << %( without a password) if @checkpw
36
39
  msg
37
40
  end
38
- end
41
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  RSpec::Matchers.define :be_allowed_to_run_command do |command|
2
4
  chain :as do |user|
3
5
  @user = user
@@ -15,17 +17,17 @@ RSpec::Matchers.define :be_allowed_to_run_command do |command|
15
17
  if @user
16
18
  actual.allowed_to_run_command?(command, @user, @checkpw)
17
19
  elsif @anybody
18
- (actual.allowed_to_run_command?(command, 'ALL', @checkpw) || actual.allowed_to_run_command?(command, 'ALL:ALL' ,@checkpw))
20
+ (actual.allowed_to_run_command?(command, 'ALL', @checkpw) || actual.allowed_to_run_command?(command, 'ALL:ALL', @checkpw))
19
21
  else
20
22
  actual.allowed_to_run_command?(command, @checkpw)
21
23
  end
22
24
  end
23
25
 
24
26
  failure_message do |actual|
25
- msg = if @user
26
- "expected to be able to run #{command} as #{@user} got #{actual.permission(command)[:user]}"
27
- else
28
- "expected #{command} to be in #{actual.permissions.map{|x| x[:command]}}"
27
+ msg = if @user
28
+ "expected to be able to run #{command} as #{@user} got #{actual.permission(command)[:user]}"
29
+ else
30
+ "expected #{command} to be in #{actual.permissions.map { |x| x[:command] }}"
29
31
  end
30
32
  msg << %( without a password ) if @checkpw
31
33
  msg
@@ -37,4 +39,4 @@ RSpec::Matchers.define :be_allowed_to_run_command do |command|
37
39
  msg << %( without a password ) if @checkpw
38
40
  msg
39
41
  end
40
- end
42
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec::Matchers.define :apply_to do |arg|
4
+ match do |actual|
5
+ actual.apply_to?(arg)
6
+ end
7
+ end
@@ -3,7 +3,11 @@
3
3
  RSpec::Matchers.define :have_host do |host|
4
4
  match do |actual|
5
5
  if !@option
6
- actual.has_host? host
6
+ if !@options
7
+ actual.has_host? host
8
+ else
9
+ actual.has_host? host, @option
10
+ end
7
11
  else
8
12
  actual.has_host? host, @option
9
13
  end
@@ -11,13 +15,16 @@ RSpec::Matchers.define :have_host do |host|
11
15
  description do
12
16
  msg = "have #{host}"
13
17
  msg << " with option #{@option}" if @option
18
+ msg << " with options #{@options}" if @options
14
19
  msg
15
20
  end
16
21
  failure_message do |actual|
17
22
  msg = "expected #{actual.hosts} to contain #{host}"
18
23
  msg << " with option '#{@option}'" if @option
24
+ msg << " with options '#{@options}'" if @options
19
25
  msg
20
26
  end
21
27
 
22
28
  chain :with_option, :option
29
+ chain :with_options, :options
23
30
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rspec/expectations'
3
4
 
4
5
  RSpec::Matchers.define :have_image do |image|
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec::Matchers.define :be_labeled do |label|
4
-
5
-
6
4
  match do |actual|
7
5
  if !@value
8
6
  actual.labels.key? label
@@ -31,4 +29,4 @@ RSpec::Matchers.define :be_labeled do |label|
31
29
  end
32
30
  end
33
31
  RSpec::Matchers.alias_matcher :have_label, :be_labeled
34
- RSpec::Matchers.alias_matcher :be_labelled, :be_labeled
32
+ RSpec::Matchers.alias_matcher :be_labelled, :be_labeled
@@ -26,7 +26,6 @@ module Serverspec::Type
26
26
  @url_base
27
27
  end
28
28
 
29
-
30
29
  def inspection
31
30
  @inspection ||= ::MultiJson.load(get_inspection.stdout)
32
31
  end
@@ -34,16 +33,18 @@ module Serverspec::Type
34
33
  private
35
34
 
36
35
  def extra_args
37
- ""
36
+ ''
38
37
  end
39
38
 
40
39
  def curl_command
41
40
  "curl #{extra_args} -s #{url} #{@insecure ? '-k' : ''} #{@redirects ? '-L' : ''}"
42
41
  end
43
42
 
43
+ # rubocop:disable Naming/AccessorMethodName
44
44
  def get_inspection
45
45
  command = curl_command
46
46
  @get_inspection ||= @runner.run_command(command)
47
47
  end
48
+ # rubocop:enable Naming/AccessorMethodName
48
49
  end
49
50
  end
@@ -28,6 +28,8 @@ module Serverspec::Type
28
28
  end
29
29
 
30
30
  def inspection
31
+ puts get_inspection.stdout
32
+ puts get_inspection.stderr
31
33
  @inspection ||= ::MultiJson.load(get_inspection.stdout)[0]
32
34
  end
33
35
 
@@ -37,10 +39,12 @@ module Serverspec::Type
37
39
  @token ? "--header 'X-Consul-Token: #{@token}'" : ''
38
40
  end
39
41
 
42
+ # rubocop:disable Naming/AccessorMethodName
40
43
  def get_inspection
41
-
42
44
  command = curl_command
43
45
  @get_inspection ||= @runner.run_command(command)
44
46
  end
47
+ # rubocop:enable Naming/AccessorMethodName
48
+
45
49
  end
46
50
  end
@@ -20,7 +20,7 @@ module Serverspec::Type
20
20
  end
21
21
 
22
22
  def nodes
23
- inspection.map { |node| node['Node']}
23
+ inspection.map { |node| node['Node'] }
24
24
  end
25
25
 
26
26
  def inspection
@@ -19,7 +19,6 @@ module Serverspec::Type
19
19
  @inspection ||= ::MultiJson.load(get_inspection.stdout)[0]
20
20
  end
21
21
 
22
-
23
22
  ##= Generated Code Start =##
24
23
  # TODO: Make these better
25
24
  # Key Type: String
@@ -63,7 +62,7 @@ module Serverspec::Type
63
62
  inspection['TaggedAddresses']
64
63
  end
65
64
 
66
- # Todo: do method for indiviual tagged addresses
65
+ # TODO: do method for indiviual tagged addresses
67
66
  def has_tagged_addresses?(tagged_addresses)
68
67
  self.tagged_addresses == tagged_addresses
69
68
  end
@@ -127,7 +126,7 @@ module Serverspec::Type
127
126
  inspection['ServiceWeights']
128
127
  end
129
128
 
130
- # Todo: do method for indiviual service weight are well as passing/warning
129
+ # TODO: do method for indiviual service weight are well as passing/warning
131
130
  def has_service_weights?(service_weights)
132
131
  self.service_weights == service_weights
133
132
  end
@@ -204,6 +203,5 @@ module Serverspec::Type
204
203
  self.modify_index == modify_index
205
204
  end
206
205
  ##= Generated Code End =##
207
-
208
206
  end
209
207
  end
@@ -48,6 +48,7 @@ module Serverspec::Type
48
48
  "-w \"#{output_format}\""
49
49
  end
50
50
 
51
+ # rubocop:disable Naming/AccessorMethodName
51
52
  def get_inspection
52
53
  command = curl_command
53
54
  unless @get_inspection
@@ -59,6 +60,7 @@ module Serverspec::Type
59
60
 
60
61
  @get_inspection
61
62
  end
63
+ # rubocop:enable Naming/AccessorMethodName
62
64
 
63
65
  def output_format
64
66
  out = '!!SS_URL_YAML!!---\\n'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'base64'
3
4
  module Serverspec::Type
4
5
  class DockerConfig < DockerBase
@@ -15,7 +16,7 @@ module Serverspec::Type
15
16
  end
16
17
 
17
18
  def has_data64?(data)
18
- self.data64 == data
19
+ data64 == data
19
20
  end
20
21
 
21
22
  def data64
@@ -48,8 +49,10 @@ module Serverspec::Type
48
49
 
49
50
  private
50
51
 
52
+ # rubocop:disable Naming/AccessorMethodName
51
53
  def get_inspection
52
54
  @get_inspection ||= @runner.run_command("docker config inspect #{@name}")
53
55
  end
56
+ # rubocop:enable Naming/AccessorMethodName
54
57
  end
55
58
  end
@@ -118,9 +118,11 @@ module Serverspec::Type
118
118
 
119
119
  private
120
120
 
121
+ # rubocop:disable Naming/AccessorMethodName
121
122
  def get_inspection
122
123
  @containers ||= @name.include?('=') ? @runner.run_command("docker ps -qa -f #{@name}").stdout : @name
123
124
  @get_inspection ||= @runner.run_command("docker inspect #{@containers}")
124
125
  end
126
+ # rubocop:enable Naming/AccessorMethodName
125
127
  end
126
128
  end
@@ -3,9 +3,7 @@
3
3
  require 'serverspec'
4
4
 
5
5
  module Serverspec::Type
6
-
7
6
  class DockerNetwork < DockerBase
8
-
9
7
  def name
10
8
  inspection['Name']
11
9
  end
@@ -35,11 +33,11 @@ module Serverspec::Type
35
33
  end
36
34
 
37
35
  def overlay?
38
- self.has_driver? 'overlay'
36
+ has_driver? 'overlay'
39
37
  end
40
38
 
41
39
  def bridge?
42
- self.has_driver? 'bridge'
40
+ has_driver? 'bridge'
43
41
  end
44
42
 
45
43
  def driver
@@ -66,9 +64,11 @@ module Serverspec::Type
66
64
  inspection['Labels']
67
65
  end
68
66
 
67
+ # rubocop:disable Naming/MethodName
69
68
  def IPv6_enabled?
70
69
  inspection['EnableIPv6']
71
70
  end
71
+ # rubocop:enable Naming/MethodName
72
72
 
73
73
  def internal?
74
74
  inspection['Internal']
@@ -88,8 +88,10 @@ module Serverspec::Type
88
88
 
89
89
  private
90
90
 
91
+ # rubocop:disable Naming/AccessorMethodName
91
92
  def get_inspection
92
93
  @get_inspection ||= @runner.run_command("docker network inspect #{@name}")
93
94
  end
95
+ # rubocop:enable Naming/AccessorMethodName
94
96
  end
95
97
  end
@@ -14,7 +14,6 @@ module Serverspec::Type
14
14
  availability == 'pause'
15
15
  end
16
16
 
17
-
18
17
  def availability
19
18
  inspection['Spec']['Availability']
20
19
  end
@@ -46,10 +45,13 @@ module Serverspec::Type
46
45
  def exist?
47
46
  get_inspection.success?
48
47
  end
48
+
49
49
  private
50
50
 
51
+ # rubocop:disable Naming/AccessorMethodName
51
52
  def get_inspection
52
53
  @get_inspection ||= @runner.run_command("docker node inspect #{@name}")
53
54
  end
55
+ # rubocop:enable Naming/AccessorMethodName
54
56
  end
55
57
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'base64'
3
4
  module Serverspec::Type
4
5
  class DockerSecret < DockerBase
@@ -15,10 +16,9 @@ module Serverspec::Type
15
16
  end
16
17
 
17
18
  def has_data64?(data)
18
- self.data64 == data
19
+ data64 == data
19
20
  end
20
21
 
21
-
22
22
  def data64
23
23
  inspection['Spec']['Data']
24
24
  end
@@ -49,8 +49,10 @@ module Serverspec::Type
49
49
 
50
50
  private
51
51
 
52
+ # rubocop:disable Naming/AccessorMethodName
52
53
  def get_inspection
53
54
  @get_inspection ||= @runner.run_command("docker secret inspect #{@name}")
54
55
  end
56
+ # rubocop:enable Naming/AccessorMethodName
55
57
  end
56
58
  end
@@ -75,7 +75,7 @@ module Serverspec::Type
75
75
 
76
76
  def has_secret?(name, target = nil)
77
77
  if target
78
- secrets.find { |secret| secret['SecretName'] == name && secret['File']['Name'] == target}
78
+ secrets.find { |secret| secret['SecretName'] == name && secret['File']['Name'] == target }
79
79
  else
80
80
  secrets.find { |secret| secret['SecretName'] == name }
81
81
  end
@@ -168,9 +168,11 @@ module Serverspec::Type
168
168
 
169
169
  private
170
170
 
171
+ # rubocop:disable Naming/AccessorMethodName
171
172
  def get_inspection
172
173
  @get_inspection ||= @runner.run_command("docker service inspect #{@name}")
173
174
  end
175
+ # rubocop:enable Naming/AccessorMethodName
174
176
  end
175
177
  end
176
178
 
@@ -18,6 +18,5 @@ module Serverspec::Type
18
18
  def exist?
19
19
  get_inspection.success?
20
20
  end
21
-
22
21
  end
23
22
  end
@@ -30,17 +30,14 @@ module Serverspec::Type
30
30
  end
31
31
  end
32
32
 
33
-
34
33
  def ssh_private_key?
35
34
  inspection['typeName'] == 'SSH Username with private key'
36
35
  end
37
36
 
38
-
39
37
  def gitlab_api_token?
40
38
  inspection['typeName'] == 'GitLab API token'
41
39
  end
42
40
 
43
-
44
41
  def aws_credential?
45
42
  inspection['typeName'] == 'AWS Credentials'
46
43
  end
@@ -57,16 +54,18 @@ module Serverspec::Type
57
54
  inspection['description'] == desc
58
55
  end
59
56
 
60
- def has_display_text?(text)
61
- inspection['displayText'] == text
57
+ def has_display_name?(text)
58
+ inspection['displayName'] == text
62
59
  end
63
60
 
64
61
  private
65
62
 
63
+ # rubocop:disable Naming/AccessorMethodName
66
64
  def get_inspection
67
- userpass = @user ? "-u #{@user}:#{@password}" : ""
65
+ userpass = @user ? "-u #{@user}:#{@password}" : ''
68
66
  command = "curl -s #{userpass} #{url} #{@insecure ? '-k' : ''} #{@redirects ? '-L' : ''}"
69
67
  @get_inspection ||= @runner.run_command(command)
70
68
  end
69
+ # rubocop:enable Naming/AccessorMethodName
71
70
  end
72
71
  end