octopus-serverspec-extensions 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
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
+ @serverUrl = nil
10
+ @apiKey = nil
11
+
12
+ def initialize(serverUrl, apiKey, worker_pool_name)
13
+ @name = "Octopus Deploy Worker Pool #{worker_pool_name}"
14
+ @runner = Specinfra::Runner
15
+ @serverUrl = serverUrl
16
+ @apiKey = apiKey
17
+
18
+ if (serverUrl.nil?)
19
+ raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
20
+ end
21
+ if (apiKey.nil?)
22
+ raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
23
+ end
24
+ if (worker_pool_name.nil?)
25
+ raise "'worker_pool_name' was not provided. Unable to connect to Octopus server to validate configuration."
26
+ end
27
+
28
+ @worker_pool = get_worker_pool_via_api(serverUrl, apiKey, worker_pool_name)
29
+ end
30
+
31
+ def exists?
32
+ (!@worker_pool.nil?) && (@worker_pool != [])
33
+ end
34
+ end
35
+
36
+ def octopus_deploy_worker_pool(serverUrl, apiKey, worker_pool_name)
37
+ OctopusDeployWorkerPool.new(serverUrl, apiKey, worker_pool_name)
38
+ end
39
+
40
+ private
41
+
42
+ def get_worker_pool_via_api(serverUrl, apiKey, worker_pool_name)
43
+ worker_pool = nil
44
+ url = "#{serverUrl}/api/workerpools/all?api-key=#{apiKey}"
45
+
46
+ begin
47
+ resp = Net::HTTP.get_response(URI.parse(url))
48
+ body = JSON.parse(resp.body)
49
+ worker_pool = body.select {|i| i['Name'] == worker_pool_name } unless body.nil?
50
+ rescue => e
51
+ raise "Unable to connect to #{url}: #{e}"
52
+ end
53
+
54
+ worker_pool
55
+ end
56
+ end
57
+
58
+ include Serverspec::Type
@@ -1,32 +1,32 @@
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_applied_dsc_configuration_successfully?
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 to_s
22
- "Windows DSC"
23
- end
24
-
25
- end
26
-
27
- def windows_dsc
28
- WindowsDSC.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 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_applied_dsc_configuration_successfully?
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 to_s
22
+ "Windows DSC"
23
+ end
24
+
25
+ end
26
+
27
+ def windows_dsc
28
+ WindowsDSC.new
29
+ end
30
+ end
31
+
32
+ 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.14.0"
3
- end
1
+ module OctopusServerSpecExtensions
2
+ VERSION = "0.15.0"
3
+ end
@@ -1,33 +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{SeverSpec extensions for Windows}
12
- spec.description = %q{SeverSpec extensions for Windows, adding support for chocolatey packages, npm packages, service accounts and more.}
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'
27
-
28
- spec.add_development_dependency "bundler", "~> 1.13"
29
- spec.add_development_dependency "rake", "~> 10.0"
30
- spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "rspec-teamcity", "~> 0.0.1"
32
-
33
- 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{SeverSpec extensions for Windows}
12
+ spec.description = %q{SeverSpec extensions for Windows, adding support for chocolatey packages, npm packages, service accounts and more.}
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.2'
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.13"
29
+ spec.add_development_dependency "rake", "~> 10.0"
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopus-serverspec-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Richardson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-13 00:00:00.000000000 Z
11
+ date: 2019-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: serverspec
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.1'
61
+ version: '2.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.1'
68
+ version: '2.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.0.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 3.5.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 3.5.1
125
139
  description: SeverSpec extensions for Windows, adding support for chocolatey packages,
126
140
  npm packages, service accounts and more.
127
141
  email: devops@octopus.com
@@ -148,6 +162,7 @@ files:
148
162
  - lib/octopus_serverspec_extensions/type/npm_package.rb
149
163
  - lib/octopus_serverspec_extensions/type/octopus_deploy_environment.rb
150
164
  - lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb
165
+ - lib/octopus_serverspec_extensions/type/octopus_deploy_worker_pool.rb
151
166
  - lib/octopus_serverspec_extensions/type/windows_dsc.rb
152
167
  - lib/octopus_serverspec_extensions/type/windows_firewall.rb
153
168
  - lib/octopus_serverspec_extensions/type/windows_scheduled_task.rb
@@ -172,8 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
187
  - !ruby/object:Gem::Version
173
188
  version: '0'
174
189
  requirements: []
175
- rubyforge_project:
176
- rubygems_version: 2.6.12
190
+ rubygems_version: 3.0.1
177
191
  signing_key:
178
192
  specification_version: 4
179
193
  summary: SeverSpec extensions for Windows