octopus-serverspec-extensions 0.15.5 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/docs/authentication.md +45 -0
  3. data/docs/octopus_deploy_account.md +37 -0
  4. data/docs/octopus_deploy_doc_template.md +17 -0
  5. data/docs/octopus_deploy_environment.md +33 -0
  6. data/docs/octopus_deploy_project_group.md +31 -0
  7. data/docs/octopus_deploy_smtp_config.md +39 -0
  8. data/docs/octopus_deploy_space.md +32 -0
  9. data/docs/octopus_deploy_team.md +26 -0
  10. data/docs/octopus_deploy_tentacle.md +41 -0
  11. data/docs/octopus_deploy_upgrade_config.md +34 -0
  12. data/docs/octopus_deploy_user.md +34 -0
  13. data/docs/octopus_deploy_worker.md +39 -0
  14. data/docs/octopus_deploy_worker_pool.md +26 -0
  15. data/lib/octopus_serverspec_extensions.rb +70 -0
  16. data/lib/octopus_serverspec_extensions/matcher/allow_dynamic_infrastructure.rb +13 -0
  17. data/lib/octopus_serverspec_extensions/matcher/use_guided_failure.rb +13 -0
  18. data/lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb +72 -61
  19. data/lib/octopus_serverspec_extensions/type/octopus_deploy_environment.rb +70 -11
  20. data/lib/octopus_serverspec_extensions/type/octopus_deploy_project_group.rb +77 -52
  21. data/lib/octopus_serverspec_extensions/type/octopus_deploy_smtp_config.rb +109 -0
  22. data/lib/octopus_serverspec_extensions/type/octopus_deploy_space.rb +92 -0
  23. data/lib/octopus_serverspec_extensions/type/octopus_deploy_team.rb +82 -0
  24. data/lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb +7 -8
  25. data/lib/octopus_serverspec_extensions/type/octopus_deploy_upgrade_config.rb +112 -0
  26. data/lib/octopus_serverspec_extensions/type/octopus_deploy_user.rb +111 -0
  27. data/lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb +173 -0
  28. data/lib/octopus_serverspec_extensions/type/octopus_deploy_worker_pool.rb +33 -3
  29. data/lib/octopus_serverspec_extensions/version.rb +1 -1
  30. metadata +25 -3
@@ -2,10 +2,16 @@ require 'octopus_serverspec_extensions/type/chocolatey_package.rb'
2
2
  require 'octopus_serverspec_extensions/type/npm_package.rb'
3
3
  require 'octopus_serverspec_extensions/type/java_property_file.rb'
4
4
  require 'octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb'
5
+ require 'octopus_serverspec_extensions/type/octopus_deploy_worker.rb'
5
6
  require 'octopus_serverspec_extensions/type/octopus_deploy_environment.rb'
6
7
  require 'octopus_serverspec_extensions/type/octopus_deploy_project_group.rb'
7
8
  require 'octopus_serverspec_extensions/type/octopus_deploy_worker_pool.rb'
8
9
  require 'octopus_serverspec_extensions/type/octopus_deploy_account.rb'
10
+ require 'octopus_serverspec_extensions/type/octopus_deploy_smtp_config.rb'
11
+ require 'octopus_serverspec_extensions/type/octopus_deploy_team.rb'
12
+ require 'octopus_serverspec_extensions/type/octopus_deploy_upgrade_config.rb'
13
+ require 'octopus_serverspec_extensions/type/octopus_deploy_user.rb'
14
+ require 'octopus_serverspec_extensions/type/octopus_deploy_space.rb'
9
15
  require 'octopus_serverspec_extensions/type/windows_dsc.rb'
10
16
  require 'octopus_serverspec_extensions/type/windows_firewall.rb'
11
17
  require 'octopus_serverspec_extensions/type/windows_scheduled_task.rb'
@@ -14,3 +20,67 @@ require 'octopus_serverspec_extensions/matcher/run_under_account.rb'
14
20
  require 'octopus_serverspec_extensions/matcher/have_windows_line_endings.rb'
15
21
  require 'octopus_serverspec_extensions/matcher/have_linux_line_endings.rb'
16
22
  require 'octopus_serverspec_extensions/version.rb'
23
+
24
+ private
25
+
26
+ def get_env_var(name)
27
+ raise 'unexpected env var' if name != 'OCTOPUS_CLI_API_KEY' && name != 'OCTOPUS_CLI_SERVER'
28
+ raise "env var #{name} not found" if ENV[name].nil?
29
+ ENV[name]
30
+ end
31
+
32
+ def get_octopus_url(server_url)
33
+ # returns the url or nil
34
+ if server_url.nil?
35
+ server_url = get_env_var('OCTOPUS_CLI_SERVER')
36
+ end
37
+
38
+ server_url
39
+ end
40
+
41
+ def get_octopus_api_key(api_key)
42
+ # returns the api key or nil
43
+ if api_key.nil?
44
+ api_key = get_env_var('OCTOPUS_CLI_API_KEY')
45
+ end
46
+
47
+ api_key
48
+ end
49
+
50
+ def get_octopus_creds(args)
51
+ server = args[0]
52
+ api_key = args[1]
53
+
54
+ if args.length != 0 && args.length != 2
55
+ raise "Supplied credentials invalid. Expected: [url, api_key] Received: #{args}"
56
+ end
57
+
58
+ if server.nil?
59
+ server = get_env_var('OCTOPUS_CLI_SERVER')
60
+ end
61
+
62
+ if api_key.nil?
63
+ api_key = get_env_var('OCTOPUS_CLI_API_KEY')
64
+ end
65
+
66
+ # are they still nil? raise an error
67
+ if api_key.nil? or server.nil?
68
+ raise "Supplied credentials invalid. One or more of [server, api_key] was null. " +
69
+ "If you intended to use Environment Variables, please check the value of OCTOPUS_CLI_SERVER and OCTOPUS_CLI_API_KEY"
70
+ end
71
+
72
+ server = server.chomp("/") # remove the trailing slash if it exists
73
+
74
+ [server, api_key]
75
+ end
76
+
77
+ def check_supports_spaces(server_url)
78
+ begin
79
+ resp = Net::HTTP.get_response(URI.parse("#{server_url}/api/"))
80
+ body = JSON.parse(resp.body)
81
+ version = body['Version']
82
+ return Gem::Version.new(version) > Gem::Version.new('2019.0.0')
83
+ rescue => e
84
+ raise "check_supports_spaces: Unable to connect to #{server_url}: #{e}"
85
+ end
86
+ end
@@ -0,0 +1,13 @@
1
+ RSpec::Matchers.define :allow_dynamic_infrastructure do
2
+ match do |env|
3
+ env.allow_dynamic_infrastructure? == true
4
+ end
5
+
6
+ failure_message do |env|
7
+ "Expected Environment '#{env.environment_name}' to allow dynamic infrastructure, but it didn't"
8
+ end
9
+
10
+ failure_message_when_negated do |env|
11
+ "Expected Environment '#{env.environment_name}' not to allow dynamic infrastructure, but it did"
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ RSpec::Matchers.define :use_guided_failure do
2
+ match do |env|
3
+ env.use_guided_failure? == true
4
+ end
5
+
6
+ failure_message do |env|
7
+ "Expected Environment '#{env.environment_name}' to use guided failure mode, but it didn't"
8
+ end
9
+
10
+ failure_message_when_negated do |env|
11
+ "Expected Environment '#{env.environment_name}' not to use guided failure mode, but it did"
12
+ end
13
+ end
@@ -6,6 +6,7 @@ require 'json'
6
6
  module Serverspec::Type
7
7
  class OctopusDeployAccount < Base
8
8
  @account = nil
9
+ @accountName = nil
9
10
  @serverUrl = nil
10
11
  @apiKey = nil
11
12
  @serverSupportsSpaces = nil
@@ -18,52 +19,38 @@ module Serverspec::Type
18
19
  SSH = 'SshKeypair'.freeze
19
20
  TOKEN = 'Token'.freeze
20
21
  USERNAME = 'UsernamePassword'.freeze
21
- ACCOUNTTYPES = [AZURE, AWS, SSH, TOKEN, USERNAME]
22
+ ACCOUNT_TYPES = [AZURE, AWS, SSH, TOKEN, USERNAME]
23
+
24
+ def initialize(*url_and_api_key, account_name)
25
+ server_url, api_key = get_octopus_creds(url_and_api_key)
26
+
27
+ @serverSupportsSpaces = check_supports_spaces(server_url)
22
28
 
23
- def initialize(serverUrl, apiKey, account_name, space_name = nil)
24
29
  @name = "Octopus Deploy Account #{account_name}"
25
30
  @runner = Specinfra::Runner
26
- @serverUrl = serverUrl
27
- @apiKey = apiKey
31
+ @accountName = account_name
32
+ @serverUrl = server_url
33
+ @apiKey = api_key
28
34
 
29
- if serverUrl.nil?
30
- raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
31
- end
32
- if apiKey.nil?
33
- raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
34
- end
35
- if account_name.nil?
35
+ if account_name.nil? or account_name == ""
36
36
  raise "'account_name' was not provided. Unable to connect to Octopus server to validate configuration."
37
37
  end
38
-
39
- @serverSupportsSpaces = check_supports_spaces(serverUrl)
40
-
41
- if @serverSupportsSpaces
42
- # set the spaceId correctly
43
-
44
- if space_name.nil?
45
- @spaceId = 'Spaces-1' # default to Spaces-1
46
- else
47
- @spaceId = get_space_id?(space_name)
48
- end
49
-
50
- @spaceFragment = "#{@spaceId}/"
51
- end
52
-
53
- @account = get_account_via_api(serverUrl, apiKey, account_name)
54
38
  end
55
39
 
56
40
  def exists?
41
+ load_resource_if_nil()
57
42
  (!@account.nil?) && (@account != [])
58
43
  end
59
44
 
60
45
  def has_description?(account_description)
46
+ load_resource_if_nil()
61
47
  return false if @account.nil?
62
48
  @account["Description"] == account_description
63
49
  end
64
50
 
65
- def is_account_type?(account_type_name)
66
- if !ACCOUNTTYPES.include? account_type_name
51
+ def account_type?(account_type_name)
52
+ load_resource_if_nil()
53
+ if !ACCOUNT_TYPES.include? account_type_name
67
54
  raise("'#{account_type_name}' is not a valid account type")
68
55
  end
69
56
  return false if @account.nil?
@@ -71,33 +58,34 @@ module Serverspec::Type
71
58
  @account["AccountType"] == account_type_name
72
59
  end
73
60
 
74
- def is_azure_account?
61
+ def azure_account?
75
62
  return false if @account.nil?
76
- @account["AccountType"] == AZURE
63
+ account_type?(AZURE)
77
64
  # should also have a subscription number, but Octopus manages validation on this
78
65
  end
79
66
 
80
- def is_aws_account?
67
+ def aws_account?
81
68
  return false if @account.nil?
82
- @account["AccountType"] == AWS
69
+ account_type?(AWS)
83
70
  end
84
71
 
85
- def is_ssh_key_pair?
72
+ def ssh_key_pair?
86
73
  return false if @account.nil?
87
- @account["AccountType"] == SSH
74
+ account_type?(SSH)
88
75
  end
89
76
 
90
- def is_username_password?
77
+ def username_password?
91
78
  return false if @account.nil?
92
- @account["AccountType"] == USERNAME
79
+ account_type?(USERNAME)
93
80
  end
94
81
 
95
- def is_token?
82
+ def token?
96
83
  return false if @account.nil?
97
- @account["AccountType"] == TOKEN
84
+ account_type?(TOKEN)
98
85
  end
99
86
 
100
87
  def in_environment?(environment_name)
88
+ load_resource_if_nil()
101
89
  return false if @account.nil?
102
90
  url = "#{@serverUrl}/api/#{@spaceFragment}environments/all?api-key=#{@apiKey}"
103
91
  resp = Net::HTTP.get_response(URI.parse(url))
@@ -107,17 +95,55 @@ module Serverspec::Type
107
95
  end
108
96
 
109
97
  def has_tenanted_deployment_participation?(mode)
98
+ load_resource_if_nil()
110
99
  return false if @machine.nil?
111
100
  @machine["TenantedDeploymentParticipation"] == mode # copied directly from tentacle
112
101
  end
113
102
 
114
103
  def has_property?(property_name, expected_value)
104
+ load_resource_if_nil()
115
105
  return false if @account.nil?
116
106
  @account[property_name] == expected_value
117
107
  end
108
+
109
+ def in_space(space_name)
110
+ # allows us to tag .in_space() onto the end of the resource. as in
111
+ # describe octopus_account("account name").in_space("MyNewSpace") do
112
+ @spaceId = get_space_id?(space_name)
113
+ if @accountName.nil?
114
+ raise "'account_name' was not provided. Please provide an account name and try again."
115
+ end
116
+ self
117
+ end
118
+
119
+ private
120
+
121
+ def load_resource_if_nil
122
+ if @account.nil?
123
+ @account = get_account_via_api(@serverUrl, @apiKey, @accountName)
124
+ end
125
+ end
126
+
127
+ def get_space_id?(space_name)
128
+ return false if @serverSupportsSpaces.nil?
129
+ url = "#{@serverUrl}/api/Spaces/all?api-key=#{@apiKey}"
130
+ resp = Net::HTTP.get_response(URI.parse(url))
131
+ spaces = JSON.parse(resp.body)
132
+ space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
133
+ space_id
134
+ end
135
+
118
136
  end
119
137
 
120
- def octopus_deploy_account(serverUrl, apiKey, account_name)
138
+ def octopus_deploy_account(*url_and_api_key, account_name)
139
+ serverUrl, apiKey = get_octopus_creds(url_and_api_key)
140
+
141
+ OctopusDeployAccount.new(serverUrl, apiKey, account_name)
142
+ end
143
+
144
+ def octopus_account(*url_and_api_key, account_name)
145
+ serverUrl, apiKey = get_octopus_creds(url_and_api_key)
146
+
121
147
  OctopusDeployAccount.new(serverUrl, apiKey, account_name)
122
148
  end
123
149
 
@@ -125,6 +151,12 @@ module Serverspec::Type
125
151
 
126
152
  def get_account_via_api(serverUrl, apiKey, account_name)
127
153
  account = nil
154
+
155
+ unless @spaceId.nil?
156
+ # set the spaceId correctly
157
+ @spaceFragment = "#{@spaceId}/"
158
+ end
159
+
128
160
  url = "#{serverUrl}/api/#{@spaceFragment}accounts/all?api-key=#{apiKey}"
129
161
 
130
162
  begin
@@ -138,27 +170,6 @@ module Serverspec::Type
138
170
  account
139
171
  end
140
172
 
141
- def check_supports_spaces(serverUrl)
142
- begin
143
- resp = Net::HTTP.get_response(URI.parse("#{serverUrl}/api/"))
144
- body = JSON.parse(resp.body)
145
- version = body['Version']
146
- return Gem::Version.new(version) > Gem::Version.new('2019.0.0')
147
- rescue => e
148
- puts "check_supports_spaces: Unable to connect to #{serverUrl}: #{e}"
149
- end
150
-
151
- false
152
- end
153
-
154
- def get_space_id?(space_name)
155
- return false if @serverSupportsSpaces.nil?
156
- url = "#{@serverUrl}/api/Spaces/all?api-key=#{@apiKey}"
157
- resp = Net::HTTP.get_response(URI.parse(url))
158
- spaces = JSON.parse(resp.body)
159
- space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
160
- space_id
161
- end
162
173
 
163
174
  end
164
175
 
@@ -6,34 +6,87 @@ require 'json'
6
6
  module Serverspec::Type
7
7
  class OctopusDeployEnvironment < Base
8
8
  @environment = nil
9
+ @environment_name = nil
9
10
  @serverUrl = nil
10
11
  @apiKey = nil
12
+ @spaceId = nil
13
+ @spaceFragment = ""
11
14
 
12
- def initialize(serverUrl, apiKey, environment_name)
15
+ def initialize(*url_and_api_key, environment_name)
16
+ serverUrl, apiKey = get_octopus_creds(url_and_api_key)
17
+
18
+ @environment_name = environment_name
13
19
  @name = "Octopus Deploy Environment #{environment_name}"
14
20
  @runner = Specinfra::Runner
15
21
  @serverUrl = serverUrl
16
22
  @apiKey = apiKey
17
23
 
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 (environment_name.nil?)
24
+ if environment_name.nil?
25
25
  raise "'environment_name' was not provided. Unable to connect to Octopus server to validate configuration."
26
26
  end
27
27
 
28
- @environment = get_environment_via_api(serverUrl, apiKey, environment_name)
28
+ @serverSupportsSpaces = check_supports_spaces(serverUrl)
29
29
  end
30
30
 
31
31
  def exists?
32
+ load_resource_if_nil
32
33
  (!@environment.nil?) && (@environment != [])
33
34
  end
35
+
36
+ def use_guided_failure?
37
+ load_resource_if_nil
38
+ false if @environment.nil?
39
+ @environment['UseGuidedFailure'] == true
40
+ end
41
+
42
+ def allow_dynamic_infrastructure?
43
+ load_resource_if_nil
44
+ false if @environment.nil?
45
+ @environment['AllowDynamicInfrastructure'] == true
46
+ end
47
+
48
+ def in_space(space_name)
49
+ # allows us to tag .in_space() onto the end of the resource. as in
50
+ # describe octopus_account("account name").in_space("MyNewSpace") do
51
+ @spaceId = get_space_id(space_name)
52
+ if @environment_name.nil?
53
+ raise "'environment_name' was not provided. Unable to connect to Octopus server to validate configuration."
54
+ end
55
+ if(@spaceId.nil?)
56
+ raise "unable to resolve space '#{@spaceId}'"
57
+ end
58
+ self
59
+ end
60
+
61
+ private
62
+
63
+ def load_resource_if_nil
64
+ if @environment.nil?
65
+ @environment = get_environment_via_api(@serverUrl, @apiKey, @environment_name)
66
+ end
67
+ end
68
+
69
+ def get_space_id(space_name)
70
+ return false if @serverSupportsSpaces.nil?
71
+ url = "#{@serverUrl}/api/Spaces/all?api-key=#{@apiKey}"
72
+ resp = Net::HTTP.get_response(URI.parse(url))
73
+ spaces = JSON.parse(resp.body)
74
+ space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
75
+ space_id
76
+ end
77
+ end
78
+
79
+ # module-level constructors/entrypoints
80
+
81
+ def octopus_deploy_environment(*url_and_api_key, environment_name)
82
+ serverUrl, apiKey = get_octopus_creds(url_and_api_key)
83
+
84
+ OctopusDeployEnvironment.new(serverUrl, apiKey, environment_name)
34
85
  end
35
86
 
36
- def octopus_deploy_environment(serverUrl, apiKey, environment_name)
87
+ def octopus_environment(*url_and_api_key, environment_name)
88
+ serverUrl, apiKey = get_octopus_creds(url_and_api_key)
89
+
37
90
  OctopusDeployEnvironment.new(serverUrl, apiKey, environment_name)
38
91
  end
39
92
 
@@ -41,7 +94,13 @@ module Serverspec::Type
41
94
 
42
95
  def get_environment_via_api(serverUrl, apiKey, environment_name)
43
96
  environment = nil
44
- url = "#{serverUrl}/api/environments?name=#{environment_name}&api-key=#{apiKey}"
97
+
98
+ unless @spaceId.nil?
99
+ # set the spaceId correctly
100
+ @spaceFragment = "#{@spaceId}/"
101
+ end
102
+
103
+ url = "#{serverUrl}/api/#{@spaceFragment}environments?name=#{environment_name}&api-key=#{apiKey}"
45
104
 
46
105
  begin
47
106
  resp = Net::HTTP.get_response(URI.parse(url))
@@ -4,100 +4,125 @@ require 'json'
4
4
 
5
5
  module Serverspec::Type
6
6
  class OctopusDeployProjectGroup < Base
7
- @projectgroup = nil
7
+ @project_group = nil
8
+ @project_group_name = nil
8
9
  @serverUrl = nil
9
10
  @apiKey = nil
10
11
  @serverSupportsSpaces = nil
11
12
  @spaceId = nil
12
13
  @spaceFragment = ""
13
14
 
14
- def initialize(serverUrl, apiKey, projectgroup_name, space_name = nil)
15
- @name = "Octopus Deploy Project Group #{projectgroup_name}"
15
+ def initialize(*url_and_api_key, project_group_name)
16
+ serverUrl, apiKey = get_octopus_creds(url_and_api_key)
17
+
18
+ raise "'project_group_name' was not provided. Unable to connect to Octopus server to validate configuration." if project_group_name.nil?
19
+
20
+ @project_group_name = project_group_name
21
+
22
+ @name = "Octopus Deploy Project Group #{project_group_name}"
16
23
  @runner = Specinfra::Runner
17
24
  @serverUrl = serverUrl
18
25
  @apiKey = apiKey
19
26
 
20
-
21
- if serverUrl.nil?
22
- raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
23
- end
24
- if apiKey.nil?
25
- raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
26
- end
27
- if projectgroup_name.nil?
28
- raise "'projectgroup_name' was not provided. Unable to connect to Octopus server to validate configuration."
29
- end
30
-
31
27
  @serverSupportsSpaces = check_supports_spaces(serverUrl)
28
+ end
32
29
 
33
- if @serverSupportsSpaces
34
- # set the spaceId correctly
30
+ def exists?
31
+ load_resource_if_nil
32
+ (!@project_group.nil?) && (@project_group != [])
33
+ end
35
34
 
36
- if space_name.nil?
37
- @spaceId = 'Spaces-1' # default to Spaces-1
38
- else
39
- @spaceId = get_space_id?(space_name)
40
- end
35
+ def has_description?(project_group_description)
36
+ load_resource_if_nil
37
+ return false if @project_group.nil?
38
+ @project_group["Description"] == project_group_description
39
+ end
41
40
 
42
- @spaceFragment = "#{@spaceId}/"
41
+ def in_space(space_name)
42
+ # allows us to tag .in_space() onto the end of the resource. as in
43
+ # describe octopus_account("account name").in_space("MyNewSpace") do
44
+ @spaceId = get_space_id(space_name)
45
+ if @project_group_name.nil?
46
+ raise "'project_group_name' was not provided. Please provide a project group name and try again."
43
47
  end
44
-
45
- @projectgroup = get_projectgroup_via_api(serverUrl, apiKey, projectgroup_name)
48
+ self
46
49
  end
47
50
 
48
- def exists?
49
- (!@projectgroup.nil?) && (@projectgroup != [])
51
+ private
52
+
53
+ def get_space_id(space_name)
54
+ return false if @serverSupportsSpaces.nil?
55
+ url = "#{@serverUrl}/api/Spaces/all?api-key=#{@apiKey}"
56
+ resp = Net::HTTP.get_response(URI.parse(url))
57
+ spaces = JSON.parse(resp.body)
58
+ space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
59
+ space_id
50
60
  end
51
61
 
52
- def has_description?(projectgroup_description)
53
- return false if @projectgroup.nil?
54
- @projectgroup["Description"] == projectgroup_description
62
+ def load_resource_if_nil
63
+ if @project_group.nil?
64
+ @project_group = get_project_group_via_api(@serverUrl, @apiKey, @project_group_name)
65
+ end
55
66
  end
56
67
  end
57
68
 
58
- def octopus_deploy_projectgroup(serverUrl, apiKey, projectgroup_name, spaceName = nil)
59
- OctopusDeployProjectGroup.new(serverUrl, apiKey, projectgroup_name, spaceName)
69
+ # module-level constructors/entrypoints
70
+
71
+ def octopus_deploy_projectgroup(*url_and_api_key, project_group_name) # deprecated - no underscore in name
72
+ serverUrl, apiKey = get_octopus_creds(url_and_api_key)
73
+ OctopusDeployProjectGroup.new(serverUrl, apiKey, project_group_name)
74
+ end
75
+
76
+ def octopus_deploy_project_group(*url_and_api_key, project_group_name)
77
+ url, apikey = get_octopus_creds(url_and_api_key)
78
+ octopus_deploy_projectgroup(url, apikey, project_group_name)
79
+ end
80
+
81
+ def octopus_project_group(*url_and_api_key, project_group_name)
82
+ url, apikey = get_octopus_creds(url_and_api_key)
83
+ octopus_deploy_projectgroup(url, apikey, project_group_name)
84
+ end
85
+
86
+ def octopus_projectgroup(*url_and_api_key, project_group_name) # deprecated - no underscore in name
87
+ url, apikey = get_octopus_creds(url_and_api_key)
88
+ octopus_deploy_projectgroup(url, apikey, project_group_name)
60
89
  end
61
90
 
62
91
  private
63
92
 
64
- def get_projectgroup_via_api(serverUrl, apiKey, projectgroup_name)
93
+ def get_project_group_via_api(serverUrl, apiKey, project_group_name)
65
94
  pg = nil
66
- url = "#{serverUrl}/api/#{@spaceFragment}projectgroups/all?api-key=#{apiKey}"
67
95
 
68
- begin
69
- resp = Net::HTTP.get_response(URI.parse(url))
70
- body = JSON.parse(resp.body)
71
- pg = body.select {|i| i['Name'] == projectgroup_name }.first unless body.nil?
72
- rescue => e
73
- raise "get_projectgroup_via_api: Unable to connect to #{url}: #{e}"
96
+ raise "'project_group_name' not supplied" if(project_group_name.nil? || project_group_name == '')
97
+
98
+ unless @spaceId.nil?
99
+ @spaceFragment = "#{@spaceId}/"
74
100
  end
75
101
 
76
- pg
77
- end
102
+ url = "#{serverUrl}/api/#{@spaceFragment}projectgroups/all?api-key=#{apiKey}"
78
103
 
79
- def check_supports_spaces(serverUrl)
80
104
  begin
81
- resp = Net::HTTP.get_response(URI.parse("#{serverUrl}/api/"))
105
+ resp = Net::HTTP.get_response(URI.parse(url))
82
106
  body = JSON.parse(resp.body)
83
- version = body['Version']
84
- return Gem::Version.new(version) > Gem::Version.new('2019.0.0')
107
+ pg = body.select {|i| i['Name'] == project_group_name }.first unless body.nil?
85
108
  rescue => e
86
- puts "check_supports_spaces: Unable to connect to #{serverUrl}: #{e}"
109
+ raise "get_project_group_via_api: Unable to connect to #{url}: #{e}"
87
110
  end
88
111
 
89
- false
112
+ pg
90
113
  end
91
114
 
92
115
  def get_space_id?(space_name)
93
- return false if @serverSupportsSpaces.nil?
94
116
  url = "#{@serverUrl}/api/Spaces/all?api-key=#{@apiKey}"
95
- resp = Net::HTTP.get_response(URI.parse(url))
96
- spaces = JSON.parse(resp.body)
97
- space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
117
+ begin
118
+ resp = Net::HTTP.get_response(URI.parse(url))
119
+ spaces = JSON.parse(resp.body)
120
+ space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
121
+ rescue
122
+ raise "get_space_id: unable to connect to #{url}: #{e}"
123
+ end
98
124
  space_id
99
125
  end
100
-
101
126
  end
102
127
 
103
128
  include Serverspec::Type