serverspec-extra-types 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -0
  3. data/.rspec +0 -0
  4. data/.rubocop.yml +0 -0
  5. data/.travis.yml +0 -0
  6. data/CODE_OF_CONDUCT.md +0 -0
  7. data/Gemfile +0 -0
  8. data/LICENSE.txt +0 -0
  9. data/README.md +0 -0
  10. data/Rakefile +0 -0
  11. data/lib/serverspec_extra_types/helpers/properties.rb +0 -0
  12. data/lib/serverspec_extra_types/matchers/be_a_manager_node.rb +0 -0
  13. data/lib/serverspec_extra_types/matchers/be_a_worker_node.rb +0 -0
  14. data/lib/serverspec_extra_types/matchers/be_active.rb +0 -0
  15. data/lib/serverspec_extra_types/matchers/configure_queue.rb +0 -0
  16. data/lib/serverspec_extra_types/matchers/have_count.rb +0 -0
  17. data/lib/serverspec_extra_types/matchers/have_domain_name.rb +0 -0
  18. data/lib/serverspec_extra_types/matchers/have_engine_version.rb +0 -0
  19. data/lib/serverspec_extra_types/matchers/have_environment_variable.rb +0 -0
  20. data/lib/serverspec_extra_types/matchers/have_ha_mode.rb +0 -0
  21. data/lib/serverspec_extra_types/matchers/have_ha_nodes.rb +0 -0
  22. data/lib/serverspec_extra_types/matchers/have_ha_sync_mode.rb +0 -0
  23. data/lib/serverspec_extra_types/matchers/have_host.rb +16 -3
  24. data/lib/serverspec_extra_types/matchers/have_hostname.rb +0 -0
  25. data/lib/serverspec_extra_types/matchers/have_image.rb +0 -0
  26. data/lib/serverspec_extra_types/matchers/have_image_sha.rb +0 -0
  27. data/lib/serverspec_extra_types/matchers/have_label.rb +0 -0
  28. data/lib/serverspec_extra_types/matchers/have_mount.rb +0 -0
  29. data/lib/serverspec_extra_types/matchers/have_network.rb +0 -0
  30. data/lib/serverspec_extra_types/matchers/have_placement_constraint.rb +0 -0
  31. data/lib/serverspec_extra_types/matchers/have_replica_count.rb +0 -0
  32. data/lib/serverspec_extra_types/matchers/have_restart_limit.rb +0 -0
  33. data/lib/serverspec_extra_types/matchers/have_restart_policy.rb +0 -0
  34. data/lib/serverspec_extra_types/matchers/have_user.rb +0 -0
  35. data/lib/serverspec_extra_types/matchers/have_vhost.rb +0 -0
  36. data/lib/serverspec_extra_types/matchers/http_1xx.rb +0 -0
  37. data/lib/serverspec_extra_types/matchers/http_2xx.rb +0 -0
  38. data/lib/serverspec_extra_types/matchers/http_3xx.rb +0 -0
  39. data/lib/serverspec_extra_types/matchers/http_4xx.rb +0 -0
  40. data/lib/serverspec_extra_types/matchers/http_5xx.rb +0 -0
  41. data/lib/serverspec_extra_types/matchers/include_regex.rb +0 -0
  42. data/lib/serverspec_extra_types/matchers/map_port.rb +0 -0
  43. data/lib/serverspec_extra_types/matchers/mirror_all.rb +0 -0
  44. data/lib/serverspec_extra_types/matchers/publish_all_ports.rb +0 -0
  45. data/lib/serverspec_extra_types/matchers/read_from_queue.rb +0 -0
  46. data/lib/serverspec_extra_types/matchers/url_matchers.rb +0 -0
  47. data/lib/serverspec_extra_types/matchers/write_to_queue.rb +0 -0
  48. data/lib/serverspec_extra_types/matchers.rb +0 -0
  49. data/lib/serverspec_extra_types/types/api_base.rb +3 -1
  50. data/lib/serverspec_extra_types/types/consul_base.rb +0 -0
  51. data/lib/serverspec_extra_types/types/consul_node.rb +0 -0
  52. data/lib/serverspec_extra_types/types/consul_node_list.rb +0 -0
  53. data/lib/serverspec_extra_types/types/consul_service.rb +0 -0
  54. data/lib/serverspec_extra_types/types/consul_service_list.rb +0 -0
  55. data/lib/serverspec_extra_types/types/curl.rb +0 -2
  56. data/lib/serverspec_extra_types/types/docker_container.rb +0 -0
  57. data/lib/serverspec_extra_types/types/docker_network.rb +0 -0
  58. data/lib/serverspec_extra_types/types/docker_node.rb +0 -0
  59. data/lib/serverspec_extra_types/types/docker_service.rb +6 -2
  60. data/lib/serverspec_extra_types/types/jenkins_base.rb +23 -0
  61. data/lib/serverspec_extra_types/types/jenkins_credential.rb +72 -0
  62. data/lib/serverspec_extra_types/types/jenkins_job.rb +123 -0
  63. data/lib/serverspec_extra_types/types/jenkins_plugin.rb +55 -0
  64. data/lib/serverspec_extra_types/types/nfs_export.rb +51 -0
  65. data/lib/serverspec_extra_types/types/rabbitmq_base.rb +0 -0
  66. data/lib/serverspec_extra_types/types/rabbitmq_node_list.rb +0 -0
  67. data/lib/serverspec_extra_types/types/rabbitmq_user_permission.rb +0 -0
  68. data/lib/serverspec_extra_types/types/rabbitmq_vhost_list.rb +0 -0
  69. data/lib/serverspec_extra_types/types/rabbitmq_vhost_policy.rb +0 -0
  70. data/lib/serverspec_extra_types/types.rb +1 -1
  71. data/lib/serverspec_extra_types/version.rb +1 -1
  72. data/lib/serverspec_extra_types.rb +0 -0
  73. data/properties.yml +0 -0
  74. data/serverspec-extra-types.gemspec +0 -0
  75. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c6ed9876f9c9d9b692b0e0c61d8658970cd64f8c630975f14090f53d20d4210
4
- data.tar.gz: 04b559814254f5ba2cf4eeb2cc8fbe18d6d21bd87aa7f4e83543728bbf20a7fa
3
+ metadata.gz: 76ab540d1f788d842385649d4758590f65a23490ff26777a238398093e310675
4
+ data.tar.gz: 68bbe733cc276cba6b97c1b6467ea8feeb18fadc7454ce4873b92a333004083c
5
5
  SHA512:
6
- metadata.gz: 3901bff710b1c68a76a2750de0e8e67556a609b8efc1c878fe5012cdf26d37571a84ab18bf6944bdf16a304f887cc30a833bcdd6e47182e3bb1f126b1deaa3f6
7
- data.tar.gz: f67ddf4df20dc114ea275a9b2cd4f712f2787d1306a3b763631af086046f0411fd90d9eb409084588ffece5a55f438c994a772a9929e09501862faf1e4d2ade2
6
+ metadata.gz: 2d27e4c4471082a245e540a90975e030f667302195d11eb2abfd7b29e13f342eac4356eea498062fcff867965fab36af27f2fddbe645385d18d1efe6ab69e20d
7
+ data.tar.gz: f0e74dda9a865a9f5df9d1a10a081f1f9fca79f07f7481856b585319fadfe44cda39d5ac17e71bbd53635e81fbb6f715f83c8d69cb7487af6ba4d0930ff52640
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/.rubocop.yml CHANGED
File without changes
data/.travis.yml CHANGED
File without changes
data/CODE_OF_CONDUCT.md CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,10 +1,23 @@
1
- # frozen_string_literal: true
1
+ # frozen_string_literal: false
2
2
 
3
3
  RSpec::Matchers.define :have_host do |host|
4
4
  match do |actual|
5
- actual.has_host? host
5
+ if !@option
6
+ actual.has_host? host
7
+ else
8
+ actual.has_host? host, @option
9
+ end
10
+ end
11
+ description do
12
+ msg = "have #{host}"
13
+ msg << " with option #{@option}" if @option
14
+ msg
6
15
  end
7
16
  failure_message do |actual|
8
- "expected #{actual.hosts} to contain #{host}"
17
+ msg = "expected #{actual.hosts} to contain #{host}"
18
+ msg << " with option '#{@option}'" if @option
19
+ msg
9
20
  end
21
+
22
+ chain :with_option, :option
10
23
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -9,6 +9,8 @@ module Serverspec::Type
9
9
  class ApiBase < Base
10
10
  def initialize(name = nil, options = {})
11
11
  super(name, options)
12
+ @insecure = options[:insecure]
13
+ @redirects = options[:follow_redirects]
12
14
  end
13
15
 
14
16
  def [](key)
@@ -31,7 +33,7 @@ module Serverspec::Type
31
33
  private
32
34
 
33
35
  def get_inspection
34
- command = "curl -s #{url}"
36
+ command = "curl -s #{url} #{@insecure ? '-k' : ''} #{@redirects ? '-L' : ''}"
35
37
  @get_inspection ||= @runner.run_command(command)
36
38
  end
37
39
  end
File without changes
File without changes
File without changes
File without changes
@@ -8,8 +8,6 @@ module Serverspec::Type
8
8
  def initialize(name = nil, options = {})
9
9
  super(name, options)
10
10
  @url_base = name
11
- @insecure = options[:insecure]
12
- @redirects = options[:follow_redirects]
13
11
  end
14
12
 
15
13
  def url
File without changes
File without changes
File without changes
@@ -73,8 +73,12 @@ module Serverspec::Type
73
73
  inspection['Spec']['TaskTemplate']['ContainerSpec']['Configs']
74
74
  end
75
75
 
76
- def has_secret?(name)
77
- secrets.find { |secret| secret['SecretName'] == name }
76
+ def has_secret?(name, target = nil)
77
+ if target
78
+ secrets.find { |secret| secret['SecretName'] == name && secret['File']['Name'] == target}
79
+ else
80
+ secrets.find { |secret| secret['SecretName'] == name }
81
+ end
78
82
  end
79
83
 
80
84
  def secrets
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'serverspec'
4
+ require 'serverspec/type/base'
5
+ require 'multi_json'
6
+ require 'serverspec_extra_types/helpers/properties'
7
+ require 'serverspec_extra_types/types/api_base'
8
+
9
+ module Serverspec::Type
10
+ class JenkinsBase < ApiBase
11
+ def initialize(name = nil, options = {})
12
+ super(name, options)
13
+ @user = ENV['JENKINS_USER'] || nil
14
+ @password = ENV['JENKINS_PASSWORD'] || nil
15
+ @url_base = property[:variables][:jenkins_url] || 'http://localhost:8080'
16
+ end
17
+
18
+ def exist?
19
+ get_inspection.success?
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'serverspec'
4
+ require 'serverspec/type/base'
5
+ require 'multi_json'
6
+ require 'serverspec_extra_types/helpers/properties'
7
+ require 'serverspec_extra_types/types/jenkins_base'
8
+
9
+ module Serverspec::Type
10
+ class JenkinsCredential < JenkinsBase
11
+ def initialize(name = nil, options = {})
12
+ super(name, options)
13
+ end
14
+
15
+ def inspection
16
+ @inspection ||= ::MultiJson.load(get_inspection.stdout)
17
+ end
18
+
19
+ def url
20
+ "#{@url_base}/credentials/store/system/domain/_/credential/#{@name}/api/json"
21
+ end
22
+
23
+ def length
24
+ if inspection.is_a? String
25
+ inspection.length
26
+ elsif inspection.is_a? Array
27
+ inspection.length
28
+ else
29
+ 1
30
+ end
31
+ end
32
+
33
+
34
+ def ssh_private_key?
35
+ inspection['typeName'] == 'SSH Username with private key'
36
+ end
37
+
38
+
39
+ def gitlab_api_token?
40
+ inspection['typeName'] == 'GitLab API token'
41
+ end
42
+
43
+
44
+ def aws_credential?
45
+ inspection['typeName'] == 'AWS Credentials'
46
+ end
47
+
48
+ def username_with_password?
49
+ inspection['typeName'] == 'Username with password'
50
+ end
51
+
52
+ def secret_text?
53
+ inspection['typeName'] == 'Secret text'
54
+ end
55
+
56
+ def has_description?(desc)
57
+ inspection['description'] == desc
58
+ end
59
+
60
+ def has_display_text?(text)
61
+ inspection['displayText'] == text
62
+ end
63
+
64
+ private
65
+
66
+ def get_inspection
67
+ userpass = @user ? "-u #{@user}:#{@password}" : ""
68
+ command = "curl -s #{userpass} #{url} #{@insecure ? '-k' : ''} #{@redirects ? '-L' : ''}"
69
+ @get_inspection ||= @runner.run_command(command)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'serverspec'
4
+ require 'serverspec/type/base'
5
+ require 'multi_json'
6
+ require 'serverspec_extra_types/helpers/properties'
7
+ require 'serverspec_extra_types/types/jenkins_base'
8
+
9
+ module Serverspec::Type
10
+ class JenkinsJob < JenkinsBase
11
+ def initialize(name = nil, options = {})
12
+ super(name, options)
13
+ end
14
+
15
+ def inspection
16
+ @inspection ||= ::MultiJson.load(get_inspection.stdout)
17
+ end
18
+
19
+ def url
20
+ jobname = @name.gsub('/','/job/')
21
+ "#{@url_base}/job/#{jobname}/api/json"
22
+ end
23
+
24
+ def length
25
+ if inspection.is_a? String
26
+ inspection.length
27
+ elsif inspection.is_a? Array
28
+ inspection.length
29
+ else
30
+ 1
31
+ end
32
+ end
33
+
34
+ def directory?
35
+ inspection['_class'] == 'com.cloudbees.hudson.plugins.folder.Folder'
36
+ end
37
+
38
+ def multibranch?
39
+ inspection['_class'] == 'org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject'
40
+ end
41
+
42
+ def multibranch_project?
43
+ multibranch?
44
+ end
45
+
46
+ def freestyle?
47
+ inspection['_class'] == 'hudson.model.FreeStyleProject'
48
+ end
49
+
50
+ def freestyle_project?
51
+ freestyle?
52
+ end
53
+
54
+ def maven?
55
+ inspection['_class'] == 'hudson.maven.MavenModuleSet'
56
+ end
57
+
58
+ def maven_project?
59
+ maven?
60
+ end
61
+
62
+ def pipeline?
63
+ inspection['_class'] == 'org.jenkinsci.plugins.workflow.job.WorkflowJob'
64
+ end
65
+
66
+ def pipeline_project?
67
+ pipeline?
68
+ end
69
+
70
+ def has_job_type?(type)
71
+ inspection['_class'] == type
72
+ end
73
+
74
+ def has_project_type?(type)
75
+ has_job_type?(type)
76
+ end
77
+
78
+ def folder?
79
+ directory?
80
+ end
81
+
82
+ def has_name?(text)
83
+ inspection['name'] == text
84
+ end
85
+
86
+ def has_description?(desc)
87
+ inspection['description'] == desc
88
+ end
89
+
90
+ def has_full_name?(text)
91
+ inspection['fullName'] == text
92
+ end
93
+
94
+ def has_job?(job)
95
+ inspection['jobs'].find { |job| job['name'] == job }
96
+ end
97
+
98
+
99
+ def has_job_count?(count)
100
+ inspection['jobs'].length == count
101
+ end
102
+
103
+ def has_display_name?(text)
104
+ inspection['displayName'] == text
105
+ end
106
+
107
+ def has_full_display_name?(text)
108
+ inspection['fullDisplayName'] == text
109
+ end
110
+
111
+ def has_empty_job_list?
112
+ inspection['jobs'].length == 0
113
+ end
114
+
115
+ private
116
+
117
+ def get_inspection
118
+ userpass = @user ? "-u #{@user}:#{@password}" : ""
119
+ command = "curl -s #{userpass} #{url} #{@insecure ? '-k' : ''} #{@redirects ? '-L' : ''}"
120
+ @get_inspection ||= @runner.run_command(command)
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'serverspec'
4
+ require 'serverspec/type/base'
5
+ require 'multi_json'
6
+ require 'serverspec_extra_types/helpers/properties'
7
+ require 'serverspec_extra_types/types/jenkins_base'
8
+
9
+ module Serverspec::Type
10
+ class JenkinsPlugin < JenkinsBase
11
+ def initialize(name = nil, options = {})
12
+ super(name, options)
13
+ end
14
+
15
+ def inspection
16
+ @inspection ||= ::MultiJson.load(get_inspection.stdout)['plugins'].find { |plugin| plugin['shortName'] == @name }
17
+ end
18
+
19
+ def installed?
20
+ inspection != nil
21
+ end
22
+
23
+ def exist?
24
+ inspection != nil
25
+ end
26
+
27
+ def url
28
+ "#{@url_base}/pluginManager/api/json?depth=1"
29
+ end
30
+
31
+ def has_version?(version)
32
+ inspection['version'].to_s == version.to_s
33
+ end
34
+
35
+ def length
36
+ if inspection.is_a? String
37
+ inspection.length
38
+ elsif inspection.is_a? Array
39
+ inspection.length
40
+ else
41
+ 1
42
+ end
43
+ end
44
+
45
+
46
+
47
+ private
48
+
49
+ def get_inspection
50
+ userpass = @user ? "-u #{@user}:#{@password}" : ''
51
+ command = "curl -s #{userpass} #{url} #{@insecure ? '-k' : ''} #{@redirects ? '-L' : ''}"
52
+ @get_inspection ||= @runner.run_command(command)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'serverspec'
4
+ require 'serverspec/type/base'
5
+ require 'serverspec_extra_types/helpers/properties'
6
+
7
+ module Serverspec::Type
8
+ class NfsExport < Base
9
+ def initialize(name = nil, options = {})
10
+ super(name, options)
11
+ @export = name
12
+ end
13
+
14
+ def exists?
15
+ get_inspection.success?
16
+ end
17
+
18
+ def has_host?(host_id, option = nil)
19
+ if option
20
+ host(host_id).include?(option)
21
+ else
22
+ hosts.has_key?(host_id)
23
+ end
24
+
25
+ end
26
+
27
+ def hosts
28
+ unless @hosts
29
+ @hosts = {}
30
+ inspection.split(' ')[1..-1].each do |item|
31
+ (host, options) = item.split('(')
32
+ @hosts[host] = options.split(')')[0].split(',')
33
+ end
34
+ end
35
+ @hosts
36
+ end
37
+
38
+ def host(host_id)
39
+ hosts[host_id]
40
+ end
41
+
42
+ def inspection
43
+ @inspection ||= get_inspection.stdout
44
+ end
45
+
46
+ def get_inspection
47
+ command = "grep #{@export} /etc/exports"
48
+ @get_inspection ||= @runner.run_command(command)
49
+ end
50
+ end
51
+ end
File without changes
@@ -8,7 +8,7 @@ module Serverspec
8
8
  module Type
9
9
  types = %w[docker_service docker_node rabbitmq_vhost_policy rabbitmq_node_list rabbitmq_vhost_list
10
10
  rabbitmq_user_permission consul_service consul_service_list consul_node consul_node_list
11
- curl]
11
+ curl nfs_export jenkins_credential jenkins_job jenkins_plugin]
12
12
 
13
13
  types.each do |type|
14
14
  require "serverspec_extra_types/types/#{type}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ServerspecExtraTypes
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
File without changes
data/properties.yml CHANGED
File without changes
File without changes
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Wardrobe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-24 00:00:00.000000000 Z
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -205,6 +205,11 @@ files:
205
205
  - lib/serverspec_extra_types/types/docker_network.rb
206
206
  - lib/serverspec_extra_types/types/docker_node.rb
207
207
  - lib/serverspec_extra_types/types/docker_service.rb
208
+ - lib/serverspec_extra_types/types/jenkins_base.rb
209
+ - lib/serverspec_extra_types/types/jenkins_credential.rb
210
+ - lib/serverspec_extra_types/types/jenkins_job.rb
211
+ - lib/serverspec_extra_types/types/jenkins_plugin.rb
212
+ - lib/serverspec_extra_types/types/nfs_export.rb
208
213
  - lib/serverspec_extra_types/types/rabbitmq_base.rb
209
214
  - lib/serverspec_extra_types/types/rabbitmq_node_list.rb
210
215
  - lib/serverspec_extra_types/types/rabbitmq_user_permission.rb