morpheus-cli 4.2.8 → 4.2.10

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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/lib/morpheus/api.rb +1 -1
  4. data/lib/morpheus/api/activity_interface.rb +9 -0
  5. data/lib/morpheus/api/api_client.rb +83 -27
  6. data/lib/morpheus/api/apps_interface.rb +21 -0
  7. data/lib/morpheus/api/dashboard_interface.rb +5 -21
  8. data/lib/morpheus/api/instances_interface.rb +3 -10
  9. data/lib/morpheus/api/invoice_line_items_interface.rb +14 -0
  10. data/lib/morpheus/api/invoices_interface.rb +7 -12
  11. data/lib/morpheus/api/library_layouts_interface.rb +8 -0
  12. data/lib/morpheus/api/ping_interface.rb +20 -0
  13. data/lib/morpheus/api/projects_interface.rb +33 -0
  14. data/lib/morpheus/api/setup_interface.rb +19 -36
  15. data/lib/morpheus/api/user_settings_interface.rb +0 -6
  16. data/lib/morpheus/api/whoami_interface.rb +4 -8
  17. data/lib/morpheus/benchmarking.rb +16 -26
  18. data/lib/morpheus/cli.rb +10 -5
  19. data/lib/morpheus/cli/access_token_command.rb +5 -8
  20. data/lib/morpheus/cli/activity_command.rb +146 -0
  21. data/lib/morpheus/cli/apps.rb +312 -121
  22. data/lib/morpheus/cli/archives_command.rb +1 -1
  23. data/lib/morpheus/cli/auth_command.rb +4 -11
  24. data/lib/morpheus/cli/blueprints_command.rb +196 -137
  25. data/lib/morpheus/cli/change_password_command.rb +1 -1
  26. data/lib/morpheus/cli/cli_command.rb +225 -72
  27. data/lib/morpheus/cli/cli_registry.rb +2 -2
  28. data/lib/morpheus/cli/cloud_datastores_command.rb +1 -1
  29. data/lib/morpheus/cli/clouds.rb +5 -20
  30. data/lib/morpheus/cli/clusters.rb +4 -28
  31. data/lib/morpheus/cli/commands/standard/alias_command.rb +2 -9
  32. data/lib/morpheus/cli/commands/standard/benchmark_command.rb +2 -0
  33. data/lib/morpheus/cli/commands/standard/curl_command.rb +2 -3
  34. data/lib/morpheus/cli/commands/standard/history_command.rb +3 -6
  35. data/lib/morpheus/cli/commands/standard/man_command.rb +10 -7
  36. data/lib/morpheus/cli/commands/standard/ssl_verification_command.rb +10 -9
  37. data/lib/morpheus/cli/containers_command.rb +3 -3
  38. data/lib/morpheus/cli/credentials.rb +13 -16
  39. data/lib/morpheus/cli/error_handler.rb +18 -12
  40. data/lib/morpheus/cli/errors.rb +45 -0
  41. data/lib/morpheus/cli/execute_schedules_command.rb +1 -1
  42. data/lib/morpheus/cli/execution_request_command.rb +4 -4
  43. data/lib/morpheus/cli/groups.rb +84 -132
  44. data/lib/morpheus/cli/hosts.rb +6 -16
  45. data/lib/morpheus/cli/instances.rb +100 -183
  46. data/lib/morpheus/cli/invoices_command.rb +505 -71
  47. data/lib/morpheus/cli/library_layouts_command.rb +254 -166
  48. data/lib/morpheus/cli/library_option_lists_command.rb +0 -87
  49. data/lib/morpheus/cli/library_option_types_command.rb +0 -96
  50. data/lib/morpheus/cli/license.rb +3 -0
  51. data/lib/morpheus/cli/login.rb +17 -37
  52. data/lib/morpheus/cli/logout.rb +9 -5
  53. data/lib/morpheus/cli/mixins/accounts_helper.rb +83 -7
  54. data/lib/morpheus/cli/mixins/operations_helper.rb +41 -0
  55. data/lib/morpheus/cli/mixins/option_source_helper.rb +255 -0
  56. data/lib/morpheus/cli/mixins/print_helper.rb +18 -4
  57. data/lib/morpheus/cli/mixins/provisioning_helper.rb +222 -13
  58. data/lib/morpheus/cli/mixins/remote_helper.rb +139 -0
  59. data/lib/morpheus/cli/monitoring_checks_command.rb +11 -3
  60. data/lib/morpheus/cli/network_groups_command.rb +8 -2
  61. data/lib/morpheus/cli/option_types.rb +1 -1
  62. data/lib/morpheus/cli/ping.rb +252 -0
  63. data/lib/morpheus/cli/price_sets_command.rb +16 -27
  64. data/lib/morpheus/cli/prices_command.rb +34 -27
  65. data/lib/morpheus/cli/processes_command.rb +81 -7
  66. data/lib/morpheus/cli/projects_command.rb +607 -0
  67. data/lib/morpheus/cli/recent_activity_command.rb +87 -65
  68. data/lib/morpheus/cli/remote.rb +965 -974
  69. data/lib/morpheus/cli/reports_command.rb +3 -15
  70. data/lib/morpheus/cli/roles.rb +8 -31
  71. data/lib/morpheus/cli/service_plans_command.rb +25 -31
  72. data/lib/morpheus/cli/setup.rb +392 -0
  73. data/lib/morpheus/cli/shell.rb +144 -56
  74. data/lib/morpheus/cli/subnets_command.rb +71 -11
  75. data/lib/morpheus/cli/tasks.rb +3 -3
  76. data/lib/morpheus/cli/user_sources_command.rb +4 -4
  77. data/lib/morpheus/cli/users.rb +135 -109
  78. data/lib/morpheus/cli/version.rb +1 -1
  79. data/lib/morpheus/cli/whitelabel_settings_command.rb +7 -7
  80. data/lib/morpheus/cli/whoami.rb +90 -129
  81. data/lib/morpheus/cli/wiki_command.rb +2 -14
  82. data/lib/morpheus/ext/rest_client.rb +36 -0
  83. data/lib/morpheus/formatters.rb +42 -5
  84. data/lib/morpheus/rest_client.rb +0 -10
  85. data/lib/morpheus/terminal.rb +41 -1
  86. data/lib/morpheus/util.rb +24 -0
  87. metadata +16 -3
  88. data/lib/morpheus/cli/command_error.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39ea88743d6ad4977058a608249545bffa88dfdd0bec6c80b23cd73d904cbf3d
4
- data.tar.gz: 5b775dd9bdb4652c381c8166721560b5b49d9f5f4a64055bd51ef80189072ca6
3
+ metadata.gz: 306e4f72ea1678c854091571261b455432291cb6b2d724ccfdca97f704c89329
4
+ data.tar.gz: 43a8b4a1e73a40a65c9d8e732f7f370145c539db165b63a620385768d3ed3b0a
5
5
  SHA512:
6
- metadata.gz: 00cbddb0b701321221a396758a1a344028c9e02608dfe5a1e8ea8ddc834a02c52b9ddb76b99b9a226f933763c5cefee9c22a07198262f6f57216edb2eb1f844f
7
- data.tar.gz: bd44a4e080bdac78a9c6aae481f61c749041527332ccf09881e72ba63c8359bfb7658d05e9204ac957d8453314893bca24fb63d232007e1ab406bc23071854bf
6
+ metadata.gz: d314342d0bb820cd1c787c7aa9f9738f1cd2febeae2942c2be8001d428857f266a4b2be0cab29c8020233e100c2caccc07bdd544f09a93c3e1514d016beff1cc
7
+ data.tar.gz: c487245071a039afa9ae99e1ba7d50a1ebf241a4a6e67a91cc8af7ffdbf44db930ebe7242fd26af477939a0605a7808ab7c972d02da40c5424cbc122c8d9f1d1
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.8
3
+ RUN gem install morpheus-cli -v 4.2.10
4
4
 
5
5
  ENTRYPOINT ["morpheus"]
@@ -1,5 +1,5 @@
1
1
  require 'morpheus/cli/version'
2
- require 'morpheus/cli/command_error'
2
+ require 'morpheus/cli/errors'
3
3
  require 'morpheus/rest_client'
4
4
  require 'morpheus/formatters'
5
5
  #require 'morpheus/logging'
@@ -0,0 +1,9 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::ActivityInterface < Morpheus::APIClient
4
+
5
+ def list(params={})
6
+ execute(method: :get, url: "/api/activity", headers: {params: params})
7
+ end
8
+
9
+ end
@@ -33,7 +33,7 @@ class Morpheus::APIClient
33
33
  @refresh_token = refresh_token
34
34
  @base_url = base_url
35
35
  if @base_url.to_s.empty?
36
- raise "#{self.class} requires option :url"
36
+ raise "#{self.class} initialized without a required option :url"
37
37
  end
38
38
  @base_url = @base_url.chomp("/")
39
39
  # todo: validate URI
@@ -74,10 +74,24 @@ class Morpheus::APIClient
74
74
  end
75
75
 
76
76
  # set this in your interface, eg. to 'application/json'
77
+ # or let it it default to json when payload is present.
77
78
  def default_content_type
78
79
  nil
79
80
  end
80
81
 
82
+ # set default seconds for interface to timeout after
83
+ # or let it use system default? none, it should not timeout by default..
84
+ # I think execute() may use 30 seconds for get by default.
85
+ # and it should remove timeout when method is post, put, or delete
86
+ def default_timeout
87
+ nil
88
+ end
89
+
90
+ # Authorization is required, except for a couple commands like Ping and Setup
91
+ def authorization_required?
92
+ true
93
+ end
94
+
81
95
  # common global options, hooray.
82
96
  # this is probably needed for CliCommand too..
83
97
  # maybe make this a mixin...
@@ -132,6 +146,14 @@ class Morpheus::APIClient
132
146
  # :headers - Extra headers to add. This expects a Hash like {'Content-Type' => 'application/json'}.
133
147
  # :timeout - A custom timeout in seconds for api requests. The default is 30. todo: separate timeout options
134
148
  def execute(opts, options={})
149
+ # ok, always prepend @base_url, let the caller specify it exactly or leave it off.
150
+ # this allows the Interface definition be lazy and not specify the base_url in every call to execute()
151
+ # it will be used though...
152
+ if opts[:url]
153
+ if !opts[:url].include?(@base_url)
154
+ opts[:url] = "#{@base_url}#{opts[:url]}"
155
+ end
156
+ end
135
157
  # merge in common global @options
136
158
  if @options
137
159
  options = options.merge(@options)
@@ -139,23 +161,26 @@ class Morpheus::APIClient
139
161
  options = options.clone
140
162
  end
141
163
 
142
- # default HTTP method
164
+ # determine HTTP method
143
165
  if opts[:method].nil?
144
- # why not a default? you will get an error from RestClient
145
- # opts[:method] = :get
166
+ opts[:method] = :get
146
167
  else
147
168
  # convert to lowercase Symbol like :get, :post, :put, or :delete
148
169
  opts[:method] = opts[:method].to_s.downcase.to_sym
149
170
  end
171
+
172
+ # could validate method here...
150
173
 
151
174
  # apply default headers
152
175
  opts[:headers] ||= {}
153
176
  # Authorization: apply our access token
154
- if @access_token
155
- if opts[:headers][:authorization].nil? && opts[:headers]['Authorization'].nil?
156
- opts[:headers][:authorization] = "Bearer #{@access_token}"
157
- else
158
- # authorization header has already been set.
177
+ if authorization_required?
178
+ if @access_token
179
+ if opts[:headers][:authorization].nil? && opts[:headers]['Authorization'].nil?
180
+ opts[:headers][:authorization] = "Bearer #{@access_token}"
181
+ else
182
+ # authorization header has already been set.
183
+ end
159
184
  end
160
185
  end
161
186
 
@@ -163,10 +188,20 @@ class Morpheus::APIClient
163
188
  if opts[:headers]['Content-Type'].nil? && default_content_type
164
189
  opts[:headers]['Content-Type'] = default_content_type
165
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'
195
+ end
166
196
 
167
- # use custom timeout eg. from --timeout option
168
- if options[:timeout]
169
- opts[:timeout] = options[:timeout].to_f
197
+ # always use custom timeout eg. from --timeout option
198
+ # or use default_timeout for GET requests only.
199
+ if opts[:timeout].nil?
200
+ if options[:timeout]
201
+ opts[:timeout] = options[:timeout].to_f
202
+ elsif default_timeout && opts[:method] == :get
203
+ opts[:timeout] = default_timeout.to_f
204
+ end
170
205
  end
171
206
 
172
207
  # add extra headers, eg. from --header option
@@ -176,7 +211,6 @@ class Morpheus::APIClient
176
211
  end
177
212
 
178
213
  # this is confusing, but RestClient expects :params inside the headers...?
179
- # right?
180
214
  # move/copy params to headers.params for simplification.
181
215
  # remove this if issues arise
182
216
  if opts[:params] && (opts[:headers][:params].nil? || opts[:headers][:params].empty?)
@@ -275,20 +309,43 @@ class Morpheus::APIClient
275
309
  return self
276
310
  end
277
311
 
278
- def common_iface_opts
279
- {url: @base_url, access_token: @access_token, refresh_token: @refresh_token, expires_at: @expires_at}
312
+ def common_interface_options
313
+ {
314
+ url: @base_url,
315
+ access_token: @access_token,
316
+ refresh_token: @refresh_token,
317
+ expires_at: @expires_at,
318
+ client_id: @client_id
319
+ }
320
+ end
321
+
322
+ def ping
323
+ Morpheus::PingInterface.new(common_interface_options).setopts(@options)
280
324
  end
281
325
 
326
+ def setup
327
+ Morpheus::SetupInterface.new(common_interface_options).setopts(@options)
328
+ end
329
+
282
330
  def auth
331
+ # Morpheus::AuthInterface.new(common_interface_options).setopts(@options)
283
332
  Morpheus::AuthInterface.new({url: @base_url, client_id: @client_id}).setopts(@options)
284
333
  end
285
334
 
286
335
  def whoami
287
- Morpheus::WhoamiInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
336
+ Morpheus::WhoamiInterface.new(common_interface_options).setopts(@options)
288
337
  end
289
338
 
290
339
  def user_settings
291
- Morpheus::UserSettingsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
340
+ Morpheus::UserSettingsInterface.new(common_interface_options).setopts(@options)
341
+ end
342
+
343
+ def dashboard
344
+ Morpheus::DashboardInterface.new(common_interface_options).setopts(@options)
345
+ end
346
+
347
+ def activity
348
+ Morpheus::ActivityInterface.new(common_interface_options).setopts(@options)
292
349
  end
293
350
 
294
351
  def options
@@ -475,10 +532,6 @@ class Morpheus::APIClient
475
532
  Morpheus::OptionTypeListsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
476
533
  end
477
534
 
478
- def dashboard
479
- Morpheus::DashboardInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
480
- end
481
-
482
535
  def power_schedules
483
536
  Morpheus::PowerSchedulesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
484
537
  end
@@ -487,11 +540,6 @@ class Morpheus::APIClient
487
540
  Morpheus::ExecuteSchedulesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
488
541
  end
489
542
 
490
-
491
- def setup
492
- Morpheus::SetupInterface.new(common_iface_opts).setopts(@options).setopts(@options)
493
- end
494
-
495
543
  def monitoring
496
544
  Morpheus::MonitoringInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
497
545
  end
@@ -683,13 +731,21 @@ class Morpheus::APIClient
683
731
  end
684
732
 
685
733
  def invoices
686
- Morpheus::InvoicesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
734
+ Morpheus::InvoicesInterface.new(common_interface_options).setopts(@options)
735
+ end
736
+
737
+ def invoice_line_items
738
+ Morpheus::InvoiceLineItemsInterface.new(common_interface_options).setopts(@options)
687
739
  end
688
740
 
689
741
  def guidance
690
742
  Morpheus::GuidanceInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
691
743
  end
692
744
 
745
+ def projects
746
+ Morpheus::ProjectsInterface.new(common_interface_options).setopts(@options)
747
+ end
748
+
693
749
  # add new interfaces here
694
750
 
695
751
  end
@@ -57,6 +57,27 @@ class Morpheus::AppsInterface < Morpheus::APIClient
57
57
  execute(opts)
58
58
  end
59
59
 
60
+ def refresh(app_id, params, payload)
61
+ url = "#{@base_url}/api/apps/#{app_id}/refresh"
62
+ headers = {:params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
63
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
64
+ execute(opts)
65
+ end
66
+
67
+ def apply(app_id, params, payload)
68
+ url = "#{@base_url}/api/apps/#{app_id}/apply"
69
+ headers = {:params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
70
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
71
+ execute(opts)
72
+ end
73
+
74
+ def prepare_apply(app_id, params, payload)
75
+ url = "#{@base_url}/api/apps/#{app_id}/prepare-apply"
76
+ headers = {:params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
77
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
78
+ execute(opts)
79
+ end
80
+
60
81
  def add_instance(app_id, payload)
61
82
  url = "#{@base_url}/api/apps/#{app_id}/add-instance"
62
83
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -1,30 +1,14 @@
1
1
  require 'morpheus/api/api_client'
2
2
 
3
3
  class Morpheus::DashboardInterface < 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
10
-
11
- def get(options={})
12
- dashboard(options)
13
- end
14
4
 
15
- def dashboard(options={})
16
- url = "#{@base_url}/api/dashboard"
17
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
18
- headers[:params].merge!(options)
19
- execute(method: :get, url: url, headers: headers)
5
+ def get(params={})
6
+ execute(method: :get, url: "/api/dashboard", headers: {params: params})
20
7
  end
21
8
 
22
- def recent_activity(account_id=nil, options={})
23
- url = "#{@base_url}/api/dashboard/recent-activity"
24
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
25
- headers[:params].merge!(options)
26
- headers[:params]['accountId'] = account_id if account_id
27
- execute(method: :get, url: url, headers: headers)
9
+ # [DEPRECATED] Use ActivityInterface.list() instead.
10
+ def recent_activity(params={})
11
+ execute(method: :get, url: "/api/dashboard/recent-activity", headers: {params: params})
28
12
  end
29
13
 
30
14
  end
@@ -217,10 +217,11 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
217
217
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
218
218
  execute(opts)
219
219
  end
220
- def import_snapshot(id, params={})
220
+
221
+ def import_snapshot(id, params={}, payload={})
221
222
  url = "#{@base_url}/api/instances/#{id}/import-snapshot"
222
223
  headers = {:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
223
- opts = {method: :put, url: url, headers: headers}
224
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
224
225
  execute(opts)
225
226
  end
226
227
 
@@ -266,14 +267,6 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
266
267
  execute(opts)
267
268
  end
268
269
 
269
- # deprecated in 4.0
270
- def update_notes(id, payload)
271
- url = "#{@base_url}/api/instances/#{id}/notes"
272
- headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
273
- opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
274
- execute(opts)
275
- end
276
-
277
270
  def history(id, params={})
278
271
  url = "#{@base_url}/api/instances/#{id}/history"
279
272
  headers = { params: params, authorization: "Bearer #{@access_token}" }
@@ -0,0 +1,14 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::InvoiceLineItemsInterface < Morpheus::APIClient
4
+
5
+ def list(params={})
6
+ execute(method: :get, url: "/api/invoice-line-items", headers: {params: params})
7
+ end
8
+
9
+ def get(id, params={})
10
+ raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
11
+ execute(method: :get, url: "/api/invoice-line-items/#{id}", headers: {params: params})
12
+ end
13
+
14
+ end
@@ -1,24 +1,19 @@
1
1
  require 'morpheus/api/api_client'
2
2
 
3
3
  class Morpheus::InvoicesInterface < 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
4
+
5
+ def list(params={})
6
+ execute(method: :get, url: "/api/invoices", headers: {params: params})
9
7
  end
10
8
 
11
9
  def get(id, params={})
12
10
  raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
13
- url = "#{@base_url}/api/invoices/#{id}"
14
- headers = { params: params, authorization: "Bearer #{@access_token}" }
15
- execute(method: :get, url: url, headers: headers)
11
+ execute(method: :get, url: "/api/invoices/#{id}", headers: {params: params})
16
12
  end
17
13
 
18
- def list(params={})
19
- url = "#{@base_url}/api/invoices"
20
- headers = { params: params, authorization: "Bearer #{@access_token}" }
21
- execute(method: :get, url: url, headers: headers)
14
+ def refresh(params={}, payload={})
15
+ headers = {:params => params, 'Content-Type' => 'application/json'}
16
+ execute(method: :post, url: "/api/invoices/refresh", headers: headers, payload: payload.to_json)
22
17
  end
23
18
 
24
19
  end
@@ -46,6 +46,14 @@ class Morpheus::LibraryLayoutsInterface < Morpheus::APIClient
46
46
  execute(opts)
47
47
  end
48
48
 
49
+ def update_permissions(id, options)
50
+ url = build_url(nil, id) + "/permissions"
51
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
52
+ payload = options
53
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
54
+ execute(opts)
55
+ end
56
+
49
57
  private
50
58
 
51
59
  def build_url(instance_type_id=nil, id=nil)
@@ -0,0 +1,20 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::PingInterface < Morpheus::APIClient
4
+
5
+ # no Authorization header is required
6
+ def authorization_required?
7
+ false
8
+ end
9
+
10
+ # health checks use a relatively small timeout by default
11
+ def default_timeout
12
+ 5
13
+ end
14
+
15
+ def get(params={})
16
+ headers = {params: params}
17
+ execute(method: :get, url: "/api/ping", headers: headers)
18
+ end
19
+
20
+ end
@@ -0,0 +1,33 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::ProjectsInterface < Morpheus::APIClient
4
+
5
+ def build_url(id=nil)
6
+ id ? "/api/projects/#{id}" : "/api/projects"
7
+ end
8
+
9
+ def list(params={})
10
+ execute(method: :get, url: build_url(), headers: {params: params})
11
+ end
12
+
13
+ def get(id, params={})
14
+ raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
15
+ execute(method: :get, url: build_url(id), headers: {params: params})
16
+ end
17
+
18
+ def create(payload, params={})
19
+ # headers = {:params => params, 'Content-Type' => 'application/json'}
20
+ headers = {:params => params, 'Content-Type' => 'application/json'}
21
+ execute(method: :post, url: build_url(), headers: headers, payload: payload.to_json)
22
+ end
23
+
24
+ def update(id, payload, params={})
25
+ headers = {:params => params, 'Content-Type' => 'application/json'}
26
+ execute(method: :put, url: build_url(id), headers: headers, payload: payload.to_json)
27
+ end
28
+
29
+ def destroy(id, params={})
30
+ execute(method: :delete, url: build_url(id), headers: {params: params})
31
+ end
32
+
33
+ end