octopus-serverspec-extensions 0.18.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -14
  3. data/.rspec +2 -2
  4. data/.travis.yml +5 -5
  5. data/Gemfile +4 -4
  6. data/LICENSE.txt +12 -12
  7. data/README.md +39 -39
  8. data/Rakefile +6 -6
  9. data/bin/console +14 -14
  10. data/bin/setup +8 -8
  11. data/docs/authentication.md +45 -45
  12. data/docs/octopus_deploy_account.md +37 -37
  13. data/docs/octopus_deploy_doc_template.md +16 -16
  14. data/docs/octopus_deploy_environment.md +32 -32
  15. data/docs/octopus_deploy_project_group.md +30 -30
  16. data/docs/octopus_deploy_smtp_config.md +39 -39
  17. data/docs/octopus_deploy_space.md +32 -32
  18. data/docs/octopus_deploy_team.md +25 -25
  19. data/docs/octopus_deploy_tentacle.md +40 -40
  20. data/docs/octopus_deploy_upgrade_config.md +33 -33
  21. data/docs/octopus_deploy_user.md +33 -33
  22. data/docs/octopus_deploy_worker.md +38 -38
  23. data/docs/octopus_deploy_worker_pool.md +25 -25
  24. data/lib/octopus_serverspec_extensions.rb +85 -85
  25. data/lib/octopus_serverspec_extensions/matcher/allow_dynamic_infrastructure.rb +12 -12
  26. data/lib/octopus_serverspec_extensions/matcher/have_linux_line_endings.rb +13 -13
  27. data/lib/octopus_serverspec_extensions/matcher/have_version.rb +36 -36
  28. data/lib/octopus_serverspec_extensions/matcher/have_windows_line_endings.rb +13 -13
  29. data/lib/octopus_serverspec_extensions/matcher/run_under_account.rb +17 -17
  30. data/lib/octopus_serverspec_extensions/matcher/use_guided_failure.rb +12 -12
  31. data/lib/octopus_serverspec_extensions/type/chocolatey_package.rb +33 -33
  32. data/lib/octopus_serverspec_extensions/type/java_property_file.rb +28 -28
  33. data/lib/octopus_serverspec_extensions/type/npm_package.rb +36 -36
  34. data/lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb +176 -176
  35. data/lib/octopus_serverspec_extensions/type/octopus_deploy_environment.rb +117 -117
  36. data/lib/octopus_serverspec_extensions/type/octopus_deploy_project_group.rb +127 -127
  37. data/lib/octopus_serverspec_extensions/type/octopus_deploy_smtp_config.rb +109 -109
  38. data/lib/octopus_serverspec_extensions/type/octopus_deploy_space.rb +92 -92
  39. data/lib/octopus_serverspec_extensions/type/octopus_deploy_team.rb +81 -81
  40. data/lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb +208 -208
  41. data/lib/octopus_serverspec_extensions/type/octopus_deploy_upgrade_config.rb +112 -112
  42. data/lib/octopus_serverspec_extensions/type/octopus_deploy_user.rb +110 -110
  43. data/lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb +173 -173
  44. data/lib/octopus_serverspec_extensions/type/octopus_deploy_worker_pool.rb +88 -88
  45. data/lib/octopus_serverspec_extensions/type/windows_dsc.rb +37 -37
  46. data/lib/octopus_serverspec_extensions/type/windows_firewall.rb +32 -32
  47. data/lib/octopus_serverspec_extensions/type/windows_scheduled_task.rb +33 -33
  48. data/lib/octopus_serverspec_extensions/version.rb +3 -3
  49. data/octopus-serverspec-extensions.gemspec +34 -34
  50. metadata +15 -16
@@ -1,88 +1,88 @@
1
- require 'serverspec'
2
- require 'serverspec/type/base'
3
- require 'net/http'
4
- require 'json'
5
-
6
- module Serverspec::Type
7
- class OctopusDeployWorkerPool < Base
8
- @worker_pool = nil
9
- @worker_pool_name = nil
10
- @serverUrl = nil
11
- @apiKey = nil
12
-
13
- def initialize(*url_and_api_key, worker_pool_name)
14
- serverUrl = get_octopus_url(url_and_api_key[0])
15
- apiKey = get_octopus_api_key(url_and_api_key[1])
16
-
17
- @worker_pool_name = worker_pool_name
18
-
19
- @name = "Octopus Deploy Worker Pool #{worker_pool_name}"
20
- @runner = Specinfra::Runner
21
- @serverUrl = serverUrl
22
- @apiKey = apiKey
23
-
24
- if (serverUrl.nil?)
25
- raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
26
- end
27
- if (apiKey.nil?)
28
- raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
29
- end
30
- if (worker_pool_name.nil?)
31
- raise "'worker_pool_name' was not provided. Unable to connect to Octopus server to validate configuration."
32
- end
33
-
34
- @worker_pool = get_worker_pool_via_api(serverUrl, apiKey, worker_pool_name)
35
- end
36
-
37
- def in_space(space_name)
38
- # allows us to tag .in_space() onto the end of the resource. as in
39
- # describe octopus_worker_pool("account name").in_space("MyNewSpace") do
40
- @spaceId = get_space_id?(space_name)
41
- if @worker_pool_name.nil?
42
- raise "'worker_pool_name' was not provided. Unable to connect to Octopus server to validate configuration."
43
- end
44
- self
45
- end
46
-
47
- def exists?
48
- (!@worker_pool.nil?) && (@worker_pool != [])
49
- end
50
- end
51
-
52
- def octopus_deploy_worker_pool(*url_and_api_key, worker_pool_name)
53
- serverUrl, apiKey = get_octopus_url(url_and_api_key)
54
-
55
- OctopusDeployWorkerPool.new(serverUrl, apiKey, worker_pool_name)
56
- end
57
-
58
- def octopus_worker_pool(*url_and_api_key, worker_pool_name)
59
- serverUrl, apiKey = get_octopus_url(url_and_api_key)
60
-
61
- OctopusDeployWorkerPool.new(serverUrl, apiKey, worker_pool_name)
62
- end
63
-
64
- private
65
-
66
- def get_worker_pool_via_api(serverUrl, apiKey, worker_pool_name)
67
- worker_pool = nil
68
-
69
- if @serverSupportsSpaces
70
- # set the spaceId correctly
71
- @spaceFragment = "#{@spaceId}/"
72
- end
73
-
74
- url = "#{serverUrl}/api/#{@spaceFragment}workerpools/all?api-key=#{apiKey}"
75
-
76
- begin
77
- resp = Net::HTTP.get_response(URI.parse(url))
78
- body = JSON.parse(resp.body)
79
- worker_pool = body.select {|i| i['Name'] == worker_pool_name } unless body.nil?
80
- rescue => e
81
- raise "Unable to connect to #{url}: #{e}"
82
- end
83
-
84
- worker_pool
85
- end
86
- end
87
-
88
- include Serverspec::Type
1
+ require 'serverspec'
2
+ require 'serverspec/type/base'
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ module Serverspec::Type
7
+ class OctopusDeployWorkerPool < Base
8
+ @worker_pool = nil
9
+ @worker_pool_name = nil
10
+ @serverUrl = nil
11
+ @apiKey = nil
12
+
13
+ def initialize(*url_and_api_key, worker_pool_name)
14
+ serverUrl = get_octopus_url(url_and_api_key[0])
15
+ apiKey = get_octopus_api_key(url_and_api_key[1])
16
+
17
+ @worker_pool_name = worker_pool_name
18
+
19
+ @name = "Octopus Deploy Worker Pool #{worker_pool_name}"
20
+ @runner = Specinfra::Runner
21
+ @serverUrl = serverUrl
22
+ @apiKey = apiKey
23
+
24
+ if (serverUrl.nil?)
25
+ raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
26
+ end
27
+ if (apiKey.nil?)
28
+ raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
29
+ end
30
+ if (worker_pool_name.nil?)
31
+ raise "'worker_pool_name' was not provided. Unable to connect to Octopus server to validate configuration."
32
+ end
33
+
34
+ @worker_pool = get_worker_pool_via_api(serverUrl, apiKey, worker_pool_name)
35
+ end
36
+
37
+ def in_space(space_name)
38
+ # allows us to tag .in_space() onto the end of the resource. as in
39
+ # describe octopus_worker_pool("account name").in_space("MyNewSpace") do
40
+ @spaceId = get_space_id?(space_name)
41
+ if @worker_pool_name.nil?
42
+ raise "'worker_pool_name' was not provided. Unable to connect to Octopus server to validate configuration."
43
+ end
44
+ self
45
+ end
46
+
47
+ def exists?
48
+ (!@worker_pool.nil?) && (@worker_pool != [])
49
+ end
50
+ end
51
+
52
+ def octopus_deploy_worker_pool(*url_and_api_key, worker_pool_name)
53
+ serverUrl, apiKey = get_octopus_url(url_and_api_key)
54
+
55
+ OctopusDeployWorkerPool.new(serverUrl, apiKey, worker_pool_name)
56
+ end
57
+
58
+ def octopus_worker_pool(*url_and_api_key, worker_pool_name)
59
+ serverUrl, apiKey = get_octopus_url(url_and_api_key)
60
+
61
+ OctopusDeployWorkerPool.new(serverUrl, apiKey, worker_pool_name)
62
+ end
63
+
64
+ private
65
+
66
+ def get_worker_pool_via_api(serverUrl, apiKey, worker_pool_name)
67
+ worker_pool = nil
68
+
69
+ if @serverSupportsSpaces
70
+ # set the spaceId correctly
71
+ @spaceFragment = "#{@spaceId}/"
72
+ end
73
+
74
+ url = "#{serverUrl}/api/#{@spaceFragment}workerpools/all?api-key=#{apiKey}"
75
+
76
+ begin
77
+ resp = Net::HTTP.get_response(URI.parse(url))
78
+ body = JSON.parse(resp.body)
79
+ worker_pool = body.select {|i| i['Name'] == worker_pool_name } unless body.nil?
80
+ rescue => e
81
+ raise "Unable to connect to #{url}: #{e}"
82
+ end
83
+
84
+ worker_pool
85
+ end
86
+ end
87
+
88
+ include Serverspec::Type
@@ -1,37 +1,37 @@
1
- require 'serverspec'
2
- require 'serverspec/type/base'
3
-
4
- module Serverspec::Type
5
- class WindowsDSC < Base
6
-
7
- def initialize
8
- @runner = Specinfra::Runner
9
- end
10
-
11
- def able_to_get_dsc_configuration?
12
- command_result = @runner.run_command('$ProgressPreference = "SilentlyContinue"; $state = ""; do { $state = (Get-DscLocalConfigurationManager).LCMState; write-host "LCM state is $state"; Start-Sleep -Seconds 2; } while ($state -ne "Idle"); try { Get-DSCConfiguration -ErrorAction Stop; write-output "Get-DSCConfiguration succeeded"; $true } catch { write-output "Get-DSCConfiguration failed"; write-output $_; $false }')
13
- command_result.stdout.gsub(/\n/, '').match /Get-DSCConfiguration succeeded/
14
- end
15
-
16
- def has_test_dsc_configuration_return_true?
17
- command_result = @runner.run_command('$ProgressPreference = "SilentlyContinue"; $state = ""; do { $state = (Get-DscLocalConfigurationManager).LCMState; write-host "LCM state is $state"; Start-Sleep -Seconds 2; } while ($state -ne "Idle"); try { if (-not (Test-DSCConfiguration -ErrorAction Stop)) { write-output "Test-DSCConfiguration returned false"; exit 1 } write-output "Test-DSCConfiguration succeeded"; exit 0 } catch { write-output "Test-DSCConfiguration failed"; write-output $_; exit 2 }')
18
- command_result.stdout.gsub(/\n/, '').match /Test-DSCConfiguration succeeded/
19
- end
20
-
21
- def has_dsc_configuration_status_of_success?
22
- command_result = @runner.run_command('$ProgressPreference = "SilentlyContinue"; try { $statuses = @(Get-DSCConfigurationStatus -ErrorAction Stop -All); $status = $statuses[0].Status; write-host "Get-DSCConfigurationStatus is \'$status\'"; if ($status -eq "Success") { exit 0 } else { exit 1 } } catch { write-output "Get-DSCConfigurationStatus failed"; write-output $_; exit 2; }')
23
- command_result.stdout.gsub(/\n/, '').match /Get-DSCConfigurationStatus is 'Success'/
24
- end
25
-
26
- def to_s
27
- "Windows DSC"
28
- end
29
-
30
- end
31
-
32
- def windows_dsc
33
- WindowsDSC.new
34
- end
35
- end
36
-
37
- include Serverspec::Type
1
+ require 'serverspec'
2
+ require 'serverspec/type/base'
3
+
4
+ module Serverspec::Type
5
+ class WindowsDSC < Base
6
+
7
+ def initialize
8
+ @runner = Specinfra::Runner
9
+ end
10
+
11
+ def able_to_get_dsc_configuration?
12
+ command_result = @runner.run_command('$ProgressPreference = "SilentlyContinue"; $state = ""; do { $state = (Get-DscLocalConfigurationManager).LCMState; write-host "LCM state is $state"; Start-Sleep -Seconds 2; } while ($state -ne "Idle"); try { Get-DSCConfiguration -ErrorAction Stop; write-output "Get-DSCConfiguration succeeded"; $true } catch { write-output "Get-DSCConfiguration failed"; write-output $_; $false }')
13
+ command_result.stdout.gsub(/\n/, '').match /Get-DSCConfiguration succeeded/
14
+ end
15
+
16
+ def has_test_dsc_configuration_return_true?
17
+ command_result = @runner.run_command('$ProgressPreference = "SilentlyContinue"; $state = ""; do { $state = (Get-DscLocalConfigurationManager).LCMState; write-host "LCM state is $state"; Start-Sleep -Seconds 2; } while ($state -ne "Idle"); try { if (-not (Test-DSCConfiguration -ErrorAction Stop)) { write-output "Test-DSCConfiguration returned false"; exit 1 } write-output "Test-DSCConfiguration succeeded"; exit 0 } catch { write-output "Test-DSCConfiguration failed"; write-output $_; exit 2 }')
18
+ command_result.stdout.gsub(/\n/, '').match /Test-DSCConfiguration succeeded/
19
+ end
20
+
21
+ def has_dsc_configuration_status_of_success?
22
+ command_result = @runner.run_command('$ProgressPreference = "SilentlyContinue"; try { $statuses = @(Get-DSCConfigurationStatus -ErrorAction Stop -All); $status = $statuses[0].Status; write-host "Get-DSCConfigurationStatus is \'$status\'"; if ($status -eq "Success") { exit 0 } else { exit 1 } } catch { write-output "Get-DSCConfigurationStatus failed"; write-output $_; exit 2; }')
23
+ command_result.stdout.gsub(/\n/, '').match /Get-DSCConfigurationStatus is 'Success'/
24
+ end
25
+
26
+ def to_s
27
+ "Windows DSC"
28
+ end
29
+
30
+ end
31
+
32
+ def windows_dsc
33
+ WindowsDSC.new
34
+ end
35
+ end
36
+
37
+ include Serverspec::Type
@@ -1,32 +1,32 @@
1
- require 'serverspec'
2
- require 'serverspec/type/base'
3
-
4
- module Serverspec::Type
5
- class WindowsFirewall < Base
6
-
7
- def initialize
8
- @runner = Specinfra::Runner
9
- end
10
-
11
- def has_open_port?(port)
12
- command_result = @runner.run_command("((New-Object -comObject HNetCfg.FwPolicy2).rules | where-object { $_.LocalPorts -eq #{port} -and $_.Action -eq 1}).Enabled")
13
- command_result.stdout.gsub(/\n/, '') == "True"
14
- end
15
-
16
- def enabled?
17
- command_result = @runner.run_command("(get-service MpsSvc).Status")
18
- command_result.stdout.gsub(/\n/, '') == "Running"
19
- end
20
-
21
- def to_s
22
- "Windows Firewall"
23
- end
24
-
25
- end
26
-
27
- def windows_firewall
28
- WindowsFirewall.new
29
- end
30
- end
31
-
32
- include Serverspec::Type
1
+ require 'serverspec'
2
+ require 'serverspec/type/base'
3
+
4
+ module Serverspec::Type
5
+ class WindowsFirewall < Base
6
+
7
+ def initialize
8
+ @runner = Specinfra::Runner
9
+ end
10
+
11
+ def has_open_port?(port)
12
+ command_result = @runner.run_command("((New-Object -comObject HNetCfg.FwPolicy2).rules | where-object { $_.LocalPorts -eq #{port} -and $_.Action -eq 1}).Enabled")
13
+ command_result.stdout.gsub(/\n/, '') == "True"
14
+ end
15
+
16
+ def enabled?
17
+ command_result = @runner.run_command("(get-service MpsSvc).Status")
18
+ command_result.stdout.gsub(/\n/, '') == "Running"
19
+ end
20
+
21
+ def to_s
22
+ "Windows Firewall"
23
+ end
24
+
25
+ end
26
+
27
+ def windows_firewall
28
+ WindowsFirewall.new
29
+ end
30
+ end
31
+
32
+ include Serverspec::Type
@@ -1,33 +1,33 @@
1
- require 'serverspec'
2
- require 'serverspec/type/base'
3
- require 'csv'
4
-
5
- module Serverspec::Type
6
- class WindowsScheduledTask < Base
7
- attr_reader :state, :user_id, :run_level, :schedule_type, :repeat_every
8
- @exists = false
9
-
10
- def initialize(name)
11
- @name = name
12
- @runner = Specinfra::Runner
13
-
14
- stdout = `schtasks /query /tn \"#{name}\" /fo csv /v`
15
- return unless $?.success?
16
- csv = CSV.parse(stdout)
17
- @exists = true
18
- headers = csv[0]
19
- data = csv[1]
20
- @state = data[headers.index{|x|x=="Status"}]
21
- @user_id = data[headers.index{|x|x=="Run As User"}]
22
- @run_level = data[headers.index{|x|x=="Logon Mode"}]
23
- @schedule_type = data[headers.index{|x|x=="Schedule Type"}].strip
24
- @repeat_every = data[headers.index{|x|x=="Repeat: Every"}]
25
- end
26
- end
27
-
28
- def windows_scheduled_task(name)
29
- WindowsScheduledTask.new(name)
30
- end
31
- end
32
-
33
- include Serverspec::Type
1
+ require 'serverspec'
2
+ require 'serverspec/type/base'
3
+ require 'csv'
4
+
5
+ module Serverspec::Type
6
+ class WindowsScheduledTask < Base
7
+ attr_reader :state, :user_id, :run_level, :schedule_type, :repeat_every
8
+ @exists = false
9
+
10
+ def initialize(name)
11
+ @name = name
12
+ @runner = Specinfra::Runner
13
+
14
+ stdout = `schtasks /query /tn \"#{name}\" /fo csv /v`
15
+ return unless $?.success?
16
+ csv = CSV.parse(stdout)
17
+ @exists = true
18
+ headers = csv[0]
19
+ data = csv[1]
20
+ @state = data[headers.index{|x|x=="Status"}]
21
+ @user_id = data[headers.index{|x|x=="Run As User"}]
22
+ @run_level = data[headers.index{|x|x=="Logon Mode"}]
23
+ @schedule_type = data[headers.index{|x|x=="Schedule Type"}].strip
24
+ @repeat_every = data[headers.index{|x|x=="Repeat: Every"}]
25
+ end
26
+ end
27
+
28
+ def windows_scheduled_task(name)
29
+ WindowsScheduledTask.new(name)
30
+ end
31
+ end
32
+
33
+ include Serverspec::Type
@@ -1,3 +1,3 @@
1
- module OctopusServerSpecExtensions
2
- VERSION = "0.18.1"
3
- end
1
+ module OctopusServerSpecExtensions
2
+ VERSION = "0.19.0"
3
+ end
@@ -1,34 +1,34 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'octopus_serverspec_extensions/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "octopus-serverspec-extensions"
8
- spec.version = OctopusServerSpecExtensions::VERSION
9
- spec.authors = ["Matt Richardson"]
10
- spec.email = "devops@octopus.com"
11
- spec.summary = %q{ServerSpec extensions for Octopus Deploy}
12
- spec.description = %q{ServerSpec extensions for Octopus Deploy, adds support for Octopus Deploy objects and including some common windows objects.}
13
- spec.homepage = "https://github.com/octopus-deploy/octopus-serverspec-extensions"
14
- spec.license = "Apache-2.0"
15
-
16
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
18
- end
19
- spec.bindir = "exe"
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
22
-
23
- spec.add_dependency "serverspec", "~> 2"
24
- spec.add_dependency "specinfra", "~> 2"
25
- spec.add_dependency 'rspec', '~> 3.0'
26
- spec.add_dependency 'json', '~> 2.1.0'
27
-
28
- spec.add_development_dependency "bundler", "~> 1.13"
29
- spec.add_development_dependency "rake", ">= 12.3.3"
30
- spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "rspec-teamcity", "~> 0.0.1"
32
- spec.add_development_dependency "webmock", "~> 3.5.1"
33
-
34
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'octopus_serverspec_extensions/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "octopus-serverspec-extensions"
8
+ spec.version = OctopusServerSpecExtensions::VERSION
9
+ spec.authors = ["Matt Richardson"]
10
+ spec.email = "devops@octopus.com"
11
+ spec.summary = %q{ServerSpec extensions for Octopus Deploy}
12
+ spec.description = %q{ServerSpec extensions for Octopus Deploy, adds support for Octopus Deploy objects and including some common windows objects.}
13
+ spec.homepage = "https://github.com/octopus-deploy/octopus-serverspec-extensions"
14
+ spec.license = "Apache-2.0"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "serverspec", "~> 2"
24
+ spec.add_dependency "specinfra", "~> 2"
25
+ spec.add_dependency 'rspec', '~> 3.0'
26
+ spec.add_dependency 'json', '~> 2.3.0'
27
+
28
+ spec.add_development_dependency "bundler", "~> 2"
29
+ spec.add_development_dependency "rake", ">= 13.0"
30
+ spec.add_development_dependency "rspec", "~> 3"
31
+ spec.add_development_dependency "rspec-teamcity", "~> 1"
32
+ spec.add_development_dependency "webmock", "~> 3"
33
+
34
+ end