morpheus-cli 4.2.16 → 4.2.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/README.md +8 -6
  4. data/lib/morpheus/api/api_client.rb +32 -14
  5. data/lib/morpheus/api/auth_interface.rb +4 -2
  6. data/lib/morpheus/api/backup_jobs_interface.rb +9 -0
  7. data/lib/morpheus/api/backups_interface.rb +16 -0
  8. data/lib/morpheus/api/deploy_interface.rb +25 -56
  9. data/lib/morpheus/api/deployments_interface.rb +43 -54
  10. data/lib/morpheus/api/doc_interface.rb +57 -0
  11. data/lib/morpheus/api/instances_interface.rb +5 -0
  12. data/lib/morpheus/api/rest_interface.rb +40 -0
  13. data/lib/morpheus/api/user_sources_interface.rb +0 -15
  14. data/lib/morpheus/api/users_interface.rb +2 -3
  15. data/lib/morpheus/benchmarking.rb +2 -2
  16. data/lib/morpheus/cli.rb +3 -1
  17. data/lib/morpheus/cli/access_token_command.rb +27 -10
  18. data/lib/morpheus/cli/apps.rb +21 -15
  19. data/lib/morpheus/cli/backup_jobs_command.rb +276 -0
  20. data/lib/morpheus/cli/backups_command.rb +271 -0
  21. data/lib/morpheus/cli/boot_scripts_command.rb +1 -1
  22. data/lib/morpheus/cli/cli_command.rb +92 -41
  23. data/lib/morpheus/cli/clusters.rb +0 -18
  24. data/lib/morpheus/cli/commands/standard/benchmark_command.rb +7 -7
  25. data/lib/morpheus/cli/commands/standard/man_command.rb +1 -1
  26. data/lib/morpheus/cli/credentials.rb +13 -9
  27. data/lib/morpheus/cli/deploy.rb +374 -0
  28. data/lib/morpheus/cli/deployments.rb +521 -197
  29. data/lib/morpheus/cli/deploys.rb +271 -126
  30. data/lib/morpheus/cli/doc.rb +182 -0
  31. data/lib/morpheus/cli/error_handler.rb +23 -8
  32. data/lib/morpheus/cli/errors.rb +3 -2
  33. data/lib/morpheus/cli/image_builder_command.rb +2 -2
  34. data/lib/morpheus/cli/instances.rb +136 -17
  35. data/lib/morpheus/cli/invoices_command.rb +51 -38
  36. data/lib/morpheus/cli/library_layouts_command.rb +1 -1
  37. data/lib/morpheus/cli/login.rb +9 -3
  38. data/lib/morpheus/cli/mixins/accounts_helper.rb +158 -100
  39. data/lib/morpheus/cli/mixins/backups_helper.rb +115 -0
  40. data/lib/morpheus/cli/mixins/deployments_helper.rb +135 -0
  41. data/lib/morpheus/cli/mixins/option_source_helper.rb +1 -1
  42. data/lib/morpheus/cli/mixins/print_helper.rb +110 -74
  43. data/lib/morpheus/cli/mixins/provisioning_helper.rb +2 -2
  44. data/lib/morpheus/cli/mixins/whoami_helper.rb +19 -6
  45. data/lib/morpheus/cli/network_routers_command.rb +1 -1
  46. data/lib/morpheus/cli/option_parser.rb +48 -5
  47. data/lib/morpheus/cli/option_types.rb +1 -1
  48. data/lib/morpheus/cli/remote.rb +3 -2
  49. data/lib/morpheus/cli/roles.rb +49 -92
  50. data/lib/morpheus/cli/security_groups.rb +7 -1
  51. data/lib/morpheus/cli/service_plans_command.rb +10 -10
  52. data/lib/morpheus/cli/setup.rb +1 -1
  53. data/lib/morpheus/cli/shell.rb +7 -6
  54. data/lib/morpheus/cli/subnets_command.rb +1 -1
  55. data/lib/morpheus/cli/tenants_command.rb +133 -163
  56. data/lib/morpheus/cli/user_groups_command.rb +20 -65
  57. data/lib/morpheus/cli/user_settings_command.rb +115 -13
  58. data/lib/morpheus/cli/user_sources_command.rb +57 -24
  59. data/lib/morpheus/cli/users.rb +210 -186
  60. data/lib/morpheus/cli/version.rb +1 -1
  61. data/lib/morpheus/cli/whitelabel_settings_command.rb +29 -5
  62. data/lib/morpheus/cli/whoami.rb +113 -6
  63. data/lib/morpheus/cli/workflows.rb +1 -1
  64. data/lib/morpheus/ext/hash.rb +21 -0
  65. data/lib/morpheus/terminal.rb +1 -0
  66. metadata +12 -3
  67. data/lib/morpheus/cli/auth_command.rb +0 -105
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3481d47679761310fbffd07ad968588ace4b92d9f428f68983f90a3ef4e13799
4
- data.tar.gz: 5c900c15f68c14d5ab10d89b148e2bee5216653c123004b528f3d8bf1c1740cb
3
+ metadata.gz: 5ca98cbe4891f98ca85702bb9794a0f255e8208a22b30189220bbec1a48dd3b0
4
+ data.tar.gz: 5c46ca8fc5d4944d7e5f363731652f1933e7a07226904d4b1c3829d9456ba64c
5
5
  SHA512:
6
- metadata.gz: 384148f22d822c664456d5de65813d8ff6e4ea07b9a26a68ab8803131aa43247e093f4cae9304cb591d58f6f075bebccdbbdd2ca614f615b33ebc46b242a8cf2
7
- data.tar.gz: 8ae2af56264a5bb3163ae5b8bb04747f58ef4e96f3ecdfed5b3a66e14ebce5147ef73623624fc22ab16536d4834a21b7de8a7b57952b86a9ad128abb712cf37f
6
+ metadata.gz: 5f8b8ead51a8d5953f51b3543e293eff03b329a5ec1f8194a5956426f7f38716a210c99d4114c5e14feff24f74f9756c88db71be0dd094db279a40122ef115f4
7
+ data.tar.gz: bf432f7ec48ea911a36029ae66f58339627e34a3548f60f36d7a49f7cc018728f3f77556d6abec53f1cff8490a6354db14b1664e3c546cf625dc2c637b573271
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  FROM ruby:2.5.1
2
2
 
3
- RUN gem install morpheus-cli -v 4.2.16
3
+ RUN gem install morpheus-cli -v 4.2.17
4
4
 
5
5
  ENTRYPOINT ["morpheus"]
data/README.md CHANGED
@@ -11,7 +11,11 @@ This library is a Ruby gem that provides a command line interface for interactin
11
11
 
12
12
  ## Installation
13
13
 
14
- Add this line to your application's Gemfile:
14
+ Install it using rubygems
15
+
16
+ $ gem install morpheus-cli
17
+
18
+ Or add this line to your application's Gemfile:
15
19
 
16
20
  gem 'morpheus-cli'
17
21
 
@@ -19,15 +23,13 @@ And then execute:
19
23
 
20
24
  $ bundle install
21
25
 
22
- Or install it yourself as:
23
26
 
24
- $ gem install morpheus-cli
25
27
 
26
28
  ## Usage
27
29
 
28
- ### morpheus binary
30
+ ### morpheus command
29
31
 
30
- This gem installs the [morpheus](https://github.com/gomorpheus/morpheus-cli/wiki/CLI-Manual) binary for executing commands in your shell environment.
32
+ This gem installs the [morpheus](https://github.com/gomorpheus/morpheus-cli/wiki/CLI-Manual) binary for running commands in your terminal shell.
31
33
 
32
34
  ```sh
33
35
  morpheus remote add demo https://demo.mymorpheus.com
@@ -36,6 +38,6 @@ morpheus instances list
36
38
 
37
39
  ### ruby code
38
40
 
39
- If you want to interface with your Morpheus appliance via ruby directly, you can use [Morpheus::APIClient](https://github.com/gomorpheus/morpheus-cli/wiki/APIClient) or [Morpheus::Terminal](https://github.com/gomorpheus/morpheus-cli/wiki/Terminal).
41
+ If you are interested in interfacing with the Morpheus appliance in ruby directly, you can use [Morpheus::APIClient](https://github.com/gomorpheus/morpheus-cli/wiki/APIClient) or [Morpheus::Terminal](https://github.com/gomorpheus/morpheus-cli/wiki/Terminal).
40
42
 
41
43
  For more detailed usage information, visit the [Morpheus CLI Wiki](https://github.com/gomorpheus/morpheus-cli/wiki).
@@ -173,6 +173,9 @@ class Morpheus::APIClient
173
173
 
174
174
  # apply default headers
175
175
  opts[:headers] ||= {}
176
+
177
+ is_multipart = (opts[:payload].is_a?(Hash) && opts[:payload][:multipart])
178
+
176
179
  # Authorization: apply our access token
177
180
  if authorization_required?
178
181
  if @access_token
@@ -184,16 +187,16 @@ class Morpheus::APIClient
184
187
  end
185
188
  end
186
189
 
187
- # Content-Type: apply interface default
188
- if opts[:headers]['Content-Type'].nil? && default_content_type
189
- opts[:headers]['Content-Type'] = default_content_type
190
- end
191
-
192
- # default Content-Type to application/json if you pass a payload.
193
- if opts[:headers]['Content-Type'].nil? && options[:payload]
194
- opts[:headers]['Content-Type'] = 'application/json'
190
+ # Content-Type default is application/json
191
+ if opts[:headers]['Content-Type'].nil? && opts[:payload] && is_multipart == false
192
+ opts[:headers]['Content-Type'] = (default_content_type || 'application/json')
195
193
  end
196
194
 
195
+ # this could be nice too..
196
+ # if opts[:headers]['Content-Type'] == 'application/json' && opts[:payload].is_a?(Hash)
197
+ # opts[:payload] = opts[:payload].to_json
198
+ # end
199
+
197
200
  # always use custom timeout eg. from --timeout option
198
201
  # or use default_timeout for GET requests only.
199
202
  if opts[:timeout].nil?
@@ -213,9 +216,9 @@ class Morpheus::APIClient
213
216
  # this is confusing, but RestClient expects :params inside the headers...?
214
217
  # move/copy params to headers.params for simplification.
215
218
  # remove this if issues arise
216
- if opts[:params] && (opts[:headers][:params].nil? || opts[:headers][:params].empty?)
217
- opts[:headers][:params] = opts[:params] # .delete(:params) maybe?
218
- end
219
+ # if opts[:params] && (opts[:headers][:params].nil? || opts[:headers][:params].empty?)
220
+ # opts[:headers][:params] = opts.delete(:params) # .delete(:params) maybe?
221
+ # end
219
222
 
220
223
  # :command_options for these
221
224
  # if options[:curl]
@@ -287,11 +290,14 @@ class Morpheus::APIClient
287
290
  return self
288
291
  end
289
292
 
290
- def refresh_token()
291
- if @refresh_token.nil?
293
+ def use_refresh_token(t=nil)
294
+ if t.nil?
295
+ t = @refresh_token
296
+ end
297
+ if t.nil?
292
298
  raise "#{self.class} does not currently have a refresh_token"
293
299
  end
294
- response = auth.use_refresh_token(@refresh_token, self.client_id)
300
+ response = auth.use_refresh_token(t, self.client_id)
295
301
  @access_token = response['access_token']
296
302
  @refresh_token = response['refresh_token']
297
303
  if response['expires_in'] != nil
@@ -319,6 +325,10 @@ class Morpheus::APIClient
319
325
  }
320
326
  end
321
327
 
328
+ def doc
329
+ Morpheus::DocInterface.new(common_interface_options).setopts(@options)
330
+ end
331
+
322
332
  def ping
323
333
  Morpheus::PingInterface.new(common_interface_options).setopts(@options)
324
334
  end
@@ -746,6 +756,14 @@ class Morpheus::APIClient
746
756
  Morpheus::ProjectsInterface.new(common_interface_options).setopts(@options)
747
757
  end
748
758
 
759
+ def backups
760
+ Morpheus::BackupsInterface.new(common_interface_options).setopts(@options)
761
+ end
762
+
763
+ def backup_jobs
764
+ Morpheus::BackupJobsInterface.new(common_interface_options).setopts(@options)
765
+ end
766
+
749
767
  # add new interfaces here
750
768
 
751
769
  end
@@ -15,7 +15,8 @@ class Morpheus::AuthInterface < Morpheus::APIClient
15
15
  url = "#{@base_url}/oauth/token"
16
16
  params = {grant_type: 'password', scope:'write', client_id: self.client_id, username: username}
17
17
  payload = {password: password}
18
- opts = {method: :post, url: url, headers:{ params: params}, payload: payload, timeout: 5}
18
+ headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
19
+ opts = {method: :post, url: url, headers: headers, params: params, payload: payload, timeout: 5}
19
20
  response = execute(opts)
20
21
  return response if @dry_run
21
22
  @access_token = response['access_token']
@@ -35,7 +36,8 @@ class Morpheus::AuthInterface < Morpheus::APIClient
35
36
  url = "#{@base_url}/oauth/token"
36
37
  params = {grant_type: 'refresh_token', scope:'write', client_id: self.client_id}
37
38
  payload = {refresh_token: refresh_token}
38
- opts = {method: :post, url: url, headers:{ params: params}, payload: payload}
39
+ headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
40
+ opts = {method: :post, url: url, headers: headers, params: params, payload: payload, timeout: 5}
39
41
  response = execute(opts)
40
42
  return response if @dry_run
41
43
  @access_token = response['access_token']
@@ -0,0 +1,9 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::BackupJobsInterface < Morpheus::RestInterface
4
+
5
+ def base_path
6
+ "/api/backups/jobs"
7
+ end
8
+
9
+ end
@@ -0,0 +1,16 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::BackupsInterface < Morpheus::RestInterface
4
+
5
+ def base_path
6
+ "/api/backups"
7
+ end
8
+
9
+ def summary(params={})
10
+ execute(method: :get, url: "#{base_path}/summary", params: params)
11
+ end
12
+
13
+ def history(params={})
14
+ execute(method: :get, url: "#{base_path}/history", params: params)
15
+ end
16
+ end
@@ -10,71 +10,40 @@ class Morpheus::DeployInterface < Morpheus::APIClient
10
10
  @expires_at = expires_at
11
11
  end
12
12
 
13
-
14
- def get(instanceId, options=nil)
15
- url = "#{@base_url}/api/instances/#{instanceId}/deploy"
16
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
17
-
18
- if options.is_a?(Hash)
19
- headers[:params].merge!(options)
20
- elsif options.is_a?(String)
21
- headers[:params]['name'] = options
22
- end
23
- execute(method: :get, url: url, headers: headers)
13
+ def base_path
14
+ # /api/deploys is now available in 5.0, switch to that eventually...
15
+ "/api/deploy"
24
16
  end
25
-
26
-
27
- def create(instanceId, options=nil)
28
- url = "#{@base_url}/api/instances/#{instanceId}/deploy"
29
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
30
- payload = options || {}
31
- execute(method: :post, url: url, headers: headers, payload: payload.to_json)
17
+ def list(params={})
18
+ execute(method: :get, url: "#{base_path}", params: params)
32
19
  end
33
20
 
34
- def list_files(id)
35
- url = "#{@base_url}/api/deploy/#{id}/files"
36
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
37
- payload = options
38
- execute(method: :get, url: url, headers: headers)
21
+ def get(instance_id, id, params={})
22
+ validate_id!(id)
23
+ execute(method: :get, url: "#{base_path}/#{id}", params: params)
39
24
  end
40
25
 
41
- # todo: use execute() to support @dry_run?
42
- def upload_file(id,path,destination=nil)
43
- url = "#{@base_url}/api/deploy/#{id}/files"
44
- if !destination.empty?
45
- url += "/#{destination}"
46
- end
47
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/octet-stream' }
48
- opts = { method: :post, url: url, headers: headers, payload: File.new(path,'rb')}
49
- if @dry_run
50
- return opts
26
+ def create(instance_id, payload, params={})
27
+ if instance_id
28
+ execute(method: :post, url: "/api/instances/#{instance_id}/deploy", params: params, payload: payload.to_json)
29
+ else
30
+ execute(method: :post, url: "#{base_path}", params: params, payload: payload.to_json)
51
31
  end
52
- uri = URI.parse(url)
53
- req = Net::HTTP::Post::Multipart.new uri.path,
54
- "file" => UploadIO.new(File.new(path,'rb'), "image/jpeg", File.basename(path))
55
- # todo: iterate headers and abstract th :upload_io to execute() too.
56
- req['Authorization'] = "Bearer #{@access_token}"
57
- res = Net::HTTP.start(uri.host, uri.port) do |http|
58
- http.request(req)
59
- end
60
- res
61
32
  end
62
33
 
63
- def destroy(id)
64
- url = "#{@base_url}/api/deploy/#{id}"
65
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
66
- execute(method: :delete, url: url, headers: headers)
34
+ def update(id, payload, params={})
35
+ validate_id!(id)
36
+ execute(url: "#{base_path}/#{id}", params: params, payload: payload.to_json, method: :put)
67
37
  end
68
38
 
69
- def deploy(id, options)
70
- url = "#{@base_url}/api/deploy/#{id}/deploy"
71
- payload = options
72
- if !options[:appDeploy].nil?
73
- if !options[:appDeploy][:config].nil?
74
- options[:appDeploy][:config] = options[:appDeploy][:config].to_json
75
- end
76
- end
77
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
78
- execute(method: :post, url: url, headers: headers, timeout: nil, payload: payload.to_json)
39
+ def destroy(id, params = {})
40
+ validate_id!(id)
41
+ execute(url: "#{base_path}/#{id}", params: params, method: :delete)
79
42
  end
43
+
44
+ def deploy(id, payload, params = {})
45
+ validate_id!(id)
46
+ execute(url: "#{base_path}/#{id}/deploy", params: params, payload: payload.to_json, method: :post)
47
+ end
48
+
80
49
  end
@@ -1,71 +1,60 @@
1
1
  require 'morpheus/api/api_client'
2
2
 
3
- class Morpheus::DeploymentsInterface < Morpheus::APIClient
4
- def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
5
- @access_token = access_token
6
- @refresh_token = refresh_token
7
- @base_url = base_url
8
- @expires_at = expires_at
9
- end
3
+ class Morpheus::DeploymentsInterface < Morpheus::RestInterface
10
4
 
11
- def list(params={})
12
- url = "#{@base_url}/api/deployments"
13
- headers = { params: params, authorization: "Bearer #{@access_token}" }
14
- opts = {method: :get, url: url, headers: headers}
15
- execute(opts)
16
- end
17
-
18
- def get(options=nil)
19
- url = "#{@base_url}/api/deployments"
20
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
21
- if options.is_a?(Hash)
22
- headers[:params].merge!(options)
23
- elsif options.is_a?(Numeric)
24
- url = "#{@base_url}/api/deployments/#{options}"
25
- elsif options.is_a?(String)
26
- headers[:params]['name'] = options
27
- end
28
- execute(method: :get, url: url, headers: headers)
5
+ def base_path
6
+ "/api/deployments"
29
7
  end
30
8
 
31
- def list_versions(deployment_id,options=nil)
32
- url = "#{@base_url}/api/deployments/#{deployment_id}/versions"
33
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
9
+ def list_versions(deployment_id, params={})
10
+ execute(method: :get, url: "#{base_path}/#{deployment_id}/versions", params: params)
11
+ end
34
12
 
35
- if options.is_a?(Hash)
36
- headers[:params].merge!(options)
37
- elsif options.is_a?(Numeric)
38
- url = "#{@base_url}/api/deployments/#{deployment_id}/versions/#{options}"
39
- elsif options.is_a?(String)
40
- headers[:params]['name'] = options
41
- end
42
- execute(method: :get, url: url, headers: headers)
13
+ def get_version(deployment_id, id, params={})
14
+ validate_id!(id)
15
+ execute(method: :get, url: "#{base_path}/#{deployment_id}/versions/#{id}", params: params)
43
16
  end
44
17
 
45
- def get_version(deployment_id,version_id)
46
- url = "#{@base_url}/api/deployments/#{deployment_id}/versions/#{version_id}"
47
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
48
- execute(method: :get, url: url, headers: headers)
18
+ def create_version(deployment_id, payload, params={})
19
+ execute(method: :post, url: "#{base_path}/#{deployment_id}/versions", params: params, payload: payload.to_json)
49
20
  end
50
21
 
22
+ def update_version(deployment_id, id, payload, params={})
23
+ validate_id!(id)
24
+ execute(method: :put, url: "#{base_path}/#{deployment_id}/versions/#{id}", params: params, payload: payload.to_json)
25
+ end
51
26
 
52
- def create(options)
53
- url = "#{@base_url}/api/deployments"
54
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
55
- payload = options
56
- execute(method: :post, url: url, headers: headers, payload: payload.to_json)
27
+ def destroy_version(deployment_id, id, params = {})
28
+ validate_id!(id)
29
+ execute(method: :delete, url: "#{base_path}/#{deployment_id}/versions/#{id}", params: params)
57
30
  end
58
31
 
59
- def update(id, options)
60
- url = "#{@base_url}/api/deployments/#{id}"
61
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
62
- payload = options
63
- execute(method: :put, url: url, headers: headers, payload: payload.to_json)
32
+ def list_files(deployment_id, id, params={})
33
+ execute(method: :get, url: "#{base_path}/#{deployment_id}/versions/#{id}/files", params: params)
64
34
  end
65
35
 
66
- def destroy(id)
67
- url = "#{@base_url}/api/deployments/#{id}"
68
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
69
- execute(method: :delete, url: url, headers: headers)
36
+ # upload a file without multipart
37
+ # local_file is the full absolute local filename
38
+ # destination should be the full remote file path, including the file name.
39
+ def upload_file(deployment_id, id, local_file, destination, params={})
40
+ if destination.empty? || destination == "/" || destination == "." || destination.include?("../")
41
+ raise "#{self.class}.upload_file() passed a bad destination: '#{destination}'"
42
+ end
43
+ url = "#{@base_url}/#{base_path}/#{deployment_id}/versions/#{id}/files"
44
+ if !destination.to_s.empty?
45
+ url += "/#{destination}"
46
+ end
47
+ # use URI to escape path
48
+ uri = URI.parse(url)
49
+ url = uri.path
50
+ # params[:filename] = File.basename(destination)
51
+ if !local_file.kind_of?(File)
52
+ local_file = File.new(local_file, 'rb')
53
+ end
54
+ payload = local_file
55
+ headers = {'Content-Type' => 'application/octet-stream'}
56
+ headers['Content-Length'] = local_file.size # File.size(local_file)
57
+ execute(method: :post, url: url, headers: headers, payload: payload, params: params, timeout: 172800)
70
58
  end
59
+
71
60
  end
@@ -0,0 +1,57 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::DocInterface < Morpheus::APIClient
4
+
5
+ # no Authorization header is required
6
+ def authorization_required?
7
+ false
8
+ end
9
+
10
+ def list(params={})
11
+ url = "/api/doc"
12
+ headers = {params: params}
13
+ execute(method: :get, url: url, headers: headers)
14
+ end
15
+
16
+ def swagger(params={})
17
+ url = "/api/doc/swagger"
18
+ # prefer /swagger.yml instead of /swagger?format=yml
19
+ fmt = params.delete('format')
20
+ if fmt
21
+ url = url + "." + fmt
22
+ end
23
+ is_yaml = fmt == "yml" || fmt == "yaml"
24
+ headers = {params: params}
25
+ execute(method: :get, url: url, headers: headers, timeout: 172800, parse_json: !is_yaml)
26
+ end
27
+
28
+ def download_swagger(outfile, params={})
29
+ # note that RestClient.execute still requires the full path with base_url
30
+ url = "#{@base_url}/api/doc/swagger"
31
+ # prefer /swagger.yml instead of /swagger?format=yml
32
+ fmt = params.delete('format')
33
+ if fmt
34
+ url = url + "." + fmt
35
+ end
36
+ headers = {params: params}
37
+ opts = {method: :get, url: url, headers: headers, timeout: 172800, parse_json: false}
38
+
39
+ if @dry_run
40
+ return opts
41
+ end
42
+
43
+ http_response = nil
44
+ File.open(File.expand_path(outfile), 'w') {|f|
45
+ block = proc { |response|
46
+ response.read_body do |chunk|
47
+ # writing to #{outfile} ..."
48
+ f.write chunk
49
+ end
50
+ }
51
+ opts[:block_response] = block
52
+ http_response = Morpheus::RestClient.execute(opts)
53
+ }
54
+ http_response
55
+ end
56
+
57
+ end