morpheus-cli 4.1.7 → 4.1.8
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.
- checksums.yaml +4 -4
- data/Dockerfile +2 -2
- data/README.md +22 -10
- data/lib/morpheus/api/api_client.rb +13 -1
- data/lib/morpheus/api/approvals_interface.rb +35 -0
- data/lib/morpheus/api/integrations_interface.rb +29 -0
- data/lib/morpheus/api/jobs_interface.rb +86 -0
- data/lib/morpheus/cli.rb +3 -0
- data/lib/morpheus/cli/appliance_settings_command.rb +13 -7
- data/lib/morpheus/cli/approvals_command.rb +236 -0
- data/lib/morpheus/cli/backup_settings_command.rb +11 -8
- data/lib/morpheus/cli/cli_command.rb +1 -1
- data/lib/morpheus/cli/clouds.rb +6 -1
- data/lib/morpheus/cli/clusters.rb +11 -9
- data/lib/morpheus/cli/groups.rb +3 -2
- data/lib/morpheus/cli/integrations_command.rb +97 -0
- data/lib/morpheus/cli/jobs_command.rb +930 -0
- data/lib/morpheus/cli/log_settings_command.rb +4 -4
- data/lib/morpheus/cli/monitoring_apps_command.rb +3 -3
- data/lib/morpheus/cli/monitoring_checks_command.rb +2 -2
- data/lib/morpheus/cli/monitoring_groups_command.rb +3 -2
- data/lib/morpheus/cli/monitoring_incidents_command.rb +3 -2
- data/lib/morpheus/cli/option_types.rb +21 -6
- data/lib/morpheus/cli/tenants_command.rb +3 -3
- data/lib/morpheus/cli/users.rb +17 -23
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/whitelabel_settings_command.rb +2 -2
- data/morpheus-cli.gemspec +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cd6e1f9ac938239cda4d222bb5f48a1a6567203d030e65a2efa6a5ed4742918
|
4
|
+
data.tar.gz: '09548881659c074b1d2d37219f5d13a3d94d9320672c2cca07803da1311dcac9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bd9c56fdeaf03e419cd48780afaea7d645ef07ab0c898b86a2ec3ca33e381fab349d4b79f7f260890be0ef0d9a579d32949c6834419597862ba380a27672762
|
7
|
+
data.tar.gz: 2675aed77287c61387bdb1c3d1484d0a2eaa96d6fafff21ffca64cc0a2a12be3a4e0745906fd90f6f432524b6f87e7d7cb93da58f84e6dcca620662c0e7d99a4
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
-
# Morpheus
|
1
|
+
# Morpheus CLI
|
2
2
|
|
3
|
-
|
3
|
+
- Website: https://www.morpheusdata.com/
|
4
|
+
- Guide: [Morpheus CLI Wiki](https://github.com/gomorpheus/morpheus-cli/wiki)
|
5
|
+
- Docs: [Morpheus Documentation](https://docs.morpheusdata.com)
|
6
|
+
- Support: [Morpheus Support](https://support.morpheusdata.com)
|
7
|
+
|
8
|
+
<img src="https://www.morpheusdata.com/wp-content/uploads/2018/06/cropped-morpheus_highres.png" width="600px">
|
9
|
+
|
10
|
+
This library is a Ruby gem that provides a command line interface for interacting with the Morpheus Data appliance. The features provided include provisioning clusters, hosts, and containers, deploying and monitoring applications, automating tasks, and much more.
|
4
11
|
|
5
12
|
## Installation
|
6
13
|
|
@@ -10,7 +17,7 @@ Add this line to your application's Gemfile:
|
|
10
17
|
|
11
18
|
And then execute:
|
12
19
|
|
13
|
-
$ bundle
|
20
|
+
$ bundle install
|
14
21
|
|
15
22
|
Or install it yourself as:
|
16
23
|
|
@@ -18,12 +25,17 @@ Or install it yourself as:
|
|
18
25
|
|
19
26
|
## Usage
|
20
27
|
|
21
|
-
|
28
|
+
### morpheus binary
|
29
|
+
|
30
|
+
This gem installs the [morpheus](https://github.com/gomorpheus/morpheus-cli/wiki/CLI-Manual) binary for executing commands in your shell environment.
|
31
|
+
|
32
|
+
```sh
|
33
|
+
morpheus remote add demo https://demo.mymorpheus.com
|
34
|
+
morpheus instances list
|
35
|
+
```
|
36
|
+
|
37
|
+
### ruby code
|
22
38
|
|
23
|
-
|
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).
|
24
40
|
|
25
|
-
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create a new Pull Request
|
41
|
+
For more detailed usage information, visit the [Morpheus CLI Wiki](https://github.com/gomorpheus/morpheus-cli/wiki).
|
@@ -55,7 +55,7 @@ class Morpheus::APIClient
|
|
55
55
|
def inspect
|
56
56
|
to_s
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def dry_run(val=true)
|
60
60
|
@dry_run = !!val
|
61
61
|
self
|
@@ -339,6 +339,14 @@ class Morpheus::APIClient
|
|
339
339
|
Morpheus::InstanceTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
|
340
340
|
end
|
341
341
|
|
342
|
+
def integrations
|
343
|
+
Morpheus::IntegrationsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
|
344
|
+
end
|
345
|
+
|
346
|
+
def jobs
|
347
|
+
Morpheus::JobsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
|
348
|
+
end
|
349
|
+
|
342
350
|
def server_types
|
343
351
|
Morpheus::ServerTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
|
344
352
|
end
|
@@ -399,6 +407,10 @@ class Morpheus::APIClient
|
|
399
407
|
Morpheus::AccountsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
|
400
408
|
end
|
401
409
|
|
410
|
+
def approvals
|
411
|
+
Morpheus::ApprovalsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
|
412
|
+
end
|
413
|
+
|
402
414
|
def users
|
403
415
|
Morpheus::UsersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
|
404
416
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'morpheus/api/api_client'
|
2
|
+
|
3
|
+
class Morpheus::ApprovalsInterface < Morpheus::APIClient
|
4
|
+
def initialize(access_token, refresh_token,expires_at = nil, base_url=nil, api='approvals')
|
5
|
+
@access_token = access_token
|
6
|
+
@refresh_token = refresh_token
|
7
|
+
@base_url = base_url
|
8
|
+
@api_url = "#{base_url}/api/#{api}"
|
9
|
+
@expires_at = expires_at
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(params={})
|
13
|
+
url = @api_url
|
14
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
15
|
+
execute(method: :get, url: url, headers: headers)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(id, params={})
|
19
|
+
url = "#{@api_url}/#{id}"
|
20
|
+
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
21
|
+
execute(method: :get, url: url, headers: headers)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_item(id, params={})
|
25
|
+
url = "#{@base_url}/api/approval-items/#{id}"
|
26
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
27
|
+
execute(method: :get, url: url, headers: headers)
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_item(id, action)
|
31
|
+
url = "#{@base_url}/api/approval-items/#{id}/#{action}"
|
32
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
33
|
+
execute(method: :put, url: url, headers: headers)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'morpheus/api/api_client'
|
2
|
+
|
3
|
+
class Morpheus::IntegrationsInterface < Morpheus::APIClient
|
4
|
+
def initialize(access_token, refresh_token,expires_at = nil, base_url=nil, api='integrations')
|
5
|
+
@access_token = access_token
|
6
|
+
@refresh_token = refresh_token
|
7
|
+
@base_url = base_url
|
8
|
+
@api_url = "#{base_url}/api/#{api}"
|
9
|
+
@expires_at = expires_at
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(params={})
|
13
|
+
url = @api_url
|
14
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
15
|
+
execute(method: :get, url: url, headers: headers)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(id, params={})
|
19
|
+
url = "#{@api_url}/#{id}"
|
20
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
21
|
+
execute(method: :get, url: url, headers: headers)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(payload, params={})
|
25
|
+
url = @api_url
|
26
|
+
headers = { params: params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
27
|
+
execute(method: :put, url: url, headers: headers, payload: payload.to_json)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'morpheus/api/api_client'
|
2
|
+
|
3
|
+
class Morpheus::JobsInterface < Morpheus::APIClient
|
4
|
+
def initialize(access_token, refresh_token,expires_at = nil, base_url=nil, api='jobs')
|
5
|
+
@access_token = access_token
|
6
|
+
@refresh_token = refresh_token
|
7
|
+
@base_url = base_url
|
8
|
+
@api_url = "#{base_url}/api/#{api}"
|
9
|
+
@expires_at = expires_at
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(params={})
|
13
|
+
url = @api_url
|
14
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
15
|
+
execute(method: :get, url: url, headers: headers)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(id, params={})
|
19
|
+
url = "#{@api_url}/#{id}"
|
20
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
21
|
+
if params.is_a?(Hash)
|
22
|
+
headers[:params].merge!(params)
|
23
|
+
elsif params.is_a?(Numeric)
|
24
|
+
url = "#{@api_url}/#{params}"
|
25
|
+
elsif params.is_a?(String)
|
26
|
+
headers[:params]['name'] = params
|
27
|
+
end
|
28
|
+
execute(method: :get, url: url, headers: headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
def create(payload)
|
32
|
+
url = @api_url
|
33
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
34
|
+
execute(method: :post, url: url, headers: headers, payload: payload.to_json)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update(id, payload, params={})
|
38
|
+
url = "#{@api_url}/#{id}"
|
39
|
+
headers = { params: params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
40
|
+
execute(method: :put, url: url, headers: headers, payload: payload.to_json)
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy(id, params={})
|
44
|
+
url = "#{@api_url}/#{id}"
|
45
|
+
headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
46
|
+
execute(method: :delete, url: url, headers: headers)
|
47
|
+
end
|
48
|
+
|
49
|
+
def execute_job(id, params={})
|
50
|
+
url = "#{@api_url}/#{id}/execute"
|
51
|
+
headers = { params: params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
52
|
+
execute(method: :put, url: url, headers: headers)
|
53
|
+
end
|
54
|
+
|
55
|
+
=begin
|
56
|
+
def list_job_executions(id, params={})
|
57
|
+
url = "#{@api_url}/#{id}/executions"
|
58
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
59
|
+
execute(method: :get, url: url, headers: headers)
|
60
|
+
end
|
61
|
+
=end
|
62
|
+
|
63
|
+
def list_executions(params={})
|
64
|
+
url = "#{@base_url}/api/job-executions"
|
65
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
66
|
+
execute(method: :get, url: url, headers: headers)
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_execution(id, params={})
|
70
|
+
url = "#{@base_url}/api/job-executions/#{id}"
|
71
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
72
|
+
execute(method: :get, url: url, headers: headers)
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_execution_event(id, event_id, params={})
|
76
|
+
url = "#{@base_url}/api/job-executions/#{id}/events/#{event_id}"
|
77
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
78
|
+
execute(method: :get, url: url, headers: headers)
|
79
|
+
end
|
80
|
+
|
81
|
+
def options(jobTypeId, params={})
|
82
|
+
url = "#{@base_url}/api/job-options/#{jobTypeId}"
|
83
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
84
|
+
execute(method: :get, url: url, headers: headers)
|
85
|
+
end
|
86
|
+
end
|
data/lib/morpheus/cli.rb
CHANGED
@@ -98,6 +98,8 @@ module Morpheus
|
|
98
98
|
load 'morpheus/cli/deploys.rb'
|
99
99
|
load 'morpheus/cli/license.rb'
|
100
100
|
load 'morpheus/cli/instance_types.rb'
|
101
|
+
load 'morpheus/cli/jobs_command.rb'
|
102
|
+
load 'morpheus/cli/integrations_command.rb'
|
101
103
|
load 'morpheus/cli/security_groups.rb'
|
102
104
|
load 'morpheus/cli/security_group_rules.rb'
|
103
105
|
load 'morpheus/cli/clusters.rb'
|
@@ -153,6 +155,7 @@ module Morpheus
|
|
153
155
|
load 'morpheus/cli/log_settings_command.rb'
|
154
156
|
load 'morpheus/cli/whitelabel_settings_command.rb'
|
155
157
|
load 'morpheus/cli/wiki_command.rb'
|
158
|
+
load 'morpheus/cli/approvals_command.rb'
|
156
159
|
|
157
160
|
# Your new commands go here...
|
158
161
|
|
@@ -3,9 +3,9 @@ require 'morpheus/cli/cli_command'
|
|
3
3
|
class Morpheus::Cli::ApplianceSettingsCommand
|
4
4
|
include Morpheus::Cli::CliCommand
|
5
5
|
include Morpheus::Cli::AccountsHelper
|
6
|
-
set_command_hidden
|
7
|
-
set_command_name :'appliance-settings'
|
8
6
|
|
7
|
+
set_command_name :'appliance-settings'
|
8
|
+
set_command_hidden
|
9
9
|
register_subcommands :get, :update
|
10
10
|
|
11
11
|
set_default_subcommand :get
|
@@ -67,10 +67,10 @@ class Morpheus::Cli::ApplianceSettingsCommand
|
|
67
67
|
"Default User Role" => lambda {|it| it['defaultUserRoleId'] },
|
68
68
|
"Docker Privileged Mode" => lambda {|it| format_boolean(it['dockerPrivilegedMode']) },
|
69
69
|
# User Management Settings
|
70
|
-
"Expire Password After" => lambda {|it| it['expirePwdDays']
|
70
|
+
"Expire Password After" => lambda {|it| format_days(it['expirePwdDays']) },
|
71
71
|
"Disable User After Attempts" => lambda {|it| it['disableAfterAttempts'] == 0 ? 'Disabled' : it['disableAfterAttempts']},
|
72
|
-
"Disable User if Inactive For" => lambda {|it| it['disableAfterDaysInactive']
|
73
|
-
"Send warning email before deactivating" => lambda {|it| it['warnUserDaysBefore']
|
72
|
+
"Disable User if Inactive For" => lambda {|it| format_days(it['disableAfterDaysInactive']) },
|
73
|
+
"Send warning email before deactivating" => lambda {|it| format_days(it['warnUserDaysBefore']) },
|
74
74
|
# Email Settings
|
75
75
|
"SMTP From Address" => lambda {|it| it['smtpMailFrom'] },
|
76
76
|
"SMTP Server" => lambda {|it| it['smtpServer'] },
|
@@ -160,10 +160,10 @@ class Morpheus::Cli::ApplianceSettingsCommand
|
|
160
160
|
params['smtpPort'] = val == 'null' ? nil : val.to_i
|
161
161
|
end
|
162
162
|
opts.on("--smtp-ssl [on|off]", ['on','off'], "Use SSL for SMTP connections") do |val|
|
163
|
-
params['smtpSSL'] =
|
163
|
+
params['smtpSSL'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
|
164
164
|
end
|
165
165
|
opts.on("--smtp-tls [on|off]", ['on','off'], "Use TLS for SMTP connections") do |val|
|
166
|
-
params['smtpTLS'] =
|
166
|
+
params['smtpTLS'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
|
167
167
|
end
|
168
168
|
opts.on("--smtp-user STRING", String, "SMTP user") do |val|
|
169
169
|
params['smtpUser'] = val == 'null' ? nil : val
|
@@ -298,4 +298,10 @@ class Morpheus::Cli::ApplianceSettingsCommand
|
|
298
298
|
exit 1
|
299
299
|
end
|
300
300
|
end
|
301
|
+
|
302
|
+
private
|
303
|
+
|
304
|
+
def format_days(days)
|
305
|
+
days ? (days == 0 ? 'Disabled' : days + ' Days') : ''
|
306
|
+
end
|
301
307
|
end
|
@@ -0,0 +1,236 @@
|
|
1
|
+
require 'morpheus/cli/cli_command'
|
2
|
+
|
3
|
+
class Morpheus::Cli::ApprovalsCommand
|
4
|
+
include Morpheus::Cli::CliCommand
|
5
|
+
include Morpheus::Cli::AccountsHelper
|
6
|
+
|
7
|
+
set_command_name :'approvals'
|
8
|
+
set_command_hidden
|
9
|
+
register_subcommands :list, :get, :approve, :deny, :cancel
|
10
|
+
set_default_subcommand :list
|
11
|
+
|
12
|
+
def connect(opts)
|
13
|
+
@api_client = establish_remote_appliance_connection(opts)
|
14
|
+
@approvals_interface = @api_client.approvals
|
15
|
+
end
|
16
|
+
|
17
|
+
def handle(args)
|
18
|
+
handle_subcommand(args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def list(args)
|
22
|
+
options = {}
|
23
|
+
params = {}
|
24
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
25
|
+
opts.banner = subcommand_usage()
|
26
|
+
build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
|
27
|
+
opts.footer = "List approvals."
|
28
|
+
end
|
29
|
+
optparse.parse!(args)
|
30
|
+
connect(options)
|
31
|
+
if args.count != 0
|
32
|
+
raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args}\n#{optparse}"
|
33
|
+
return 1
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
params.merge!(parse_list_options(options))
|
38
|
+
@approvals_interface.setopts(options)
|
39
|
+
if options[:dry_run]
|
40
|
+
print_dry_run @approvals_interface.dry.list(params)
|
41
|
+
return
|
42
|
+
end
|
43
|
+
json_response = @approvals_interface.list(params)
|
44
|
+
|
45
|
+
render_result = render_with_format(json_response, options, 'approvals')
|
46
|
+
return 0 if render_result
|
47
|
+
|
48
|
+
title = "Morpheus Approvals"
|
49
|
+
subtitles = []
|
50
|
+
subtitles += parse_list_subtitles(options)
|
51
|
+
print_h1 title, subtitles
|
52
|
+
|
53
|
+
approvals = json_response['approvals']
|
54
|
+
if approvals.empty?
|
55
|
+
print yellow,"No approvals found.",reset,"\n"
|
56
|
+
else
|
57
|
+
rows = approvals.collect do |it|
|
58
|
+
{
|
59
|
+
id: it['id'],
|
60
|
+
name: it['name'] || (it['accountIntegration'] ? 'Pending' : 'Not Set'),
|
61
|
+
requestType: it['requestType'],
|
62
|
+
externalName: it['accountIntegration'] ? it['externalName'] || 'Pending' : 'N/A',
|
63
|
+
type: it['accountIntegration'] ? it['accountIntegration']['type'] : 'Internal',
|
64
|
+
status: it['status'],
|
65
|
+
dateCreated: format_local_dt(it['dateCreated']),
|
66
|
+
requestedBy: it['requestBy']
|
67
|
+
}
|
68
|
+
end
|
69
|
+
columns = [
|
70
|
+
:id, :name, :requestType, :externalName, :type, :status, :dateCreated, :requestedBy
|
71
|
+
]
|
72
|
+
print as_pretty_table(rows, columns, options)
|
73
|
+
print_results_pagination(json_response)
|
74
|
+
print reset,"\n"
|
75
|
+
end
|
76
|
+
print reset,"\n"
|
77
|
+
return 0
|
78
|
+
rescue RestClient::Exception => e
|
79
|
+
print_rest_exception(e, options)
|
80
|
+
exit 1
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def get(args)
|
85
|
+
options = {}
|
86
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
87
|
+
opts.banner = subcommand_usage("[approval]")
|
88
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
89
|
+
opts.footer = "Get details about a job.\n" +
|
90
|
+
"[approval] is required. Approval ID or name"
|
91
|
+
end
|
92
|
+
optparse.parse!(args)
|
93
|
+
if args.count != 1
|
94
|
+
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args}\n#{optparse}"
|
95
|
+
end
|
96
|
+
connect(options)
|
97
|
+
return _get(args[0], options)
|
98
|
+
end
|
99
|
+
|
100
|
+
def _get(approval_id, options = {})
|
101
|
+
params = {}
|
102
|
+
begin
|
103
|
+
@approvals_interface.setopts(options)
|
104
|
+
|
105
|
+
if !(approval_id.to_s =~ /\A\d{1,}\Z/)
|
106
|
+
approval = find_approval_by_name_or_id('approval', approval_id)
|
107
|
+
|
108
|
+
if !approval
|
109
|
+
print_red_alert "Approval #{approval_id} not found"
|
110
|
+
exit 1
|
111
|
+
end
|
112
|
+
approval_id = approval['id']
|
113
|
+
end
|
114
|
+
|
115
|
+
if options[:dry_run]
|
116
|
+
print_dry_run @approvals_interface.dry.get(approval_id, params)
|
117
|
+
return
|
118
|
+
end
|
119
|
+
json_response = @approvals_interface.get(approval_id, params)
|
120
|
+
|
121
|
+
render_result = render_with_format(json_response, options, 'approval')
|
122
|
+
return 0 if render_result
|
123
|
+
|
124
|
+
title = "Morpheus Approval"
|
125
|
+
subtitles = []
|
126
|
+
subtitles += parse_list_subtitles(options)
|
127
|
+
print_h1 title, subtitles
|
128
|
+
|
129
|
+
approval = json_response['approval']
|
130
|
+
print cyan
|
131
|
+
description_cols = {
|
132
|
+
"ID" => lambda {|it| it['id']},
|
133
|
+
"Name" => lambda {|it| it['name'] || (it['accountIntegration'] ? 'Pending' : 'Not Set')},
|
134
|
+
"Request Type" => lambda {|it| it['requestType']},
|
135
|
+
"External Name" => lambda {|it|it['accountIntegration'] ? it['externalName'] || 'Pending' : 'N/A'},
|
136
|
+
"Type" => lambda {|it| it['accountIntegration'] ? it['accountIntegration']['type'] : 'Internal'},
|
137
|
+
"Date Created" => lambda {|it| format_local_dt(it['dateCreated'])},
|
138
|
+
"Requested By" => lambda {|it| it['requestBy']}
|
139
|
+
}
|
140
|
+
print_description_list(description_cols, approval)
|
141
|
+
|
142
|
+
print_h2 "Requested Items"
|
143
|
+
approval_items = approval['approvalItems']
|
144
|
+
|
145
|
+
if approval_items && !approval_items.empty?
|
146
|
+
rows = approval_items.collect do |it|
|
147
|
+
{
|
148
|
+
id: it['id'],
|
149
|
+
name: it['name'] || 'Not Set',
|
150
|
+
external_name: it['externalName'] || 'N/A',
|
151
|
+
reference: it['reference'] ? it['reference']['displayName'] || it['reference']['name'] : '',
|
152
|
+
status: (it['status'] || '').capitalize,
|
153
|
+
created: format_local_dt(it['dateCreated']),
|
154
|
+
updated: format_local_dt(it['lastUpdated'])
|
155
|
+
}
|
156
|
+
end
|
157
|
+
columns = [
|
158
|
+
:id, :name, :external_name, :reference, :status, :created, :updated
|
159
|
+
]
|
160
|
+
print as_pretty_table(rows, columns, options)
|
161
|
+
else
|
162
|
+
print yellow,"No requested items.",reset,"\n"
|
163
|
+
end
|
164
|
+
|
165
|
+
print reset,"\n"
|
166
|
+
return 0
|
167
|
+
rescue RestClient::Exception => e
|
168
|
+
print_rest_exception(e, options)
|
169
|
+
exit 1
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def approve(args)
|
174
|
+
return _update_item(args, 'approve')
|
175
|
+
end
|
176
|
+
|
177
|
+
def deny(args)
|
178
|
+
return _update_item(args, 'deny')
|
179
|
+
end
|
180
|
+
|
181
|
+
def cancel(args)
|
182
|
+
return _update_item(args, 'cancel')
|
183
|
+
end
|
184
|
+
|
185
|
+
def _update_item(args, action)
|
186
|
+
options = {}
|
187
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
188
|
+
opts.banner = subcommand_usage( "[id]")
|
189
|
+
build_common_options(opts, options, [:json, :dry_run, :remote, :quiet])
|
190
|
+
opts.footer = "#{action.capitalize} item.\n[id] is required. Approval item ID"
|
191
|
+
end
|
192
|
+
optparse.parse!(args)
|
193
|
+
connect(options)
|
194
|
+
if args.count != 1
|
195
|
+
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args}\n#{optparse}"
|
196
|
+
return 1
|
197
|
+
end
|
198
|
+
|
199
|
+
begin
|
200
|
+
approval_item = @approvals_interface.get_item(args[0].to_i)['approvalItem']
|
201
|
+
|
202
|
+
if !approval_item
|
203
|
+
print_red_alert "Approval item #{args[0]} not found"
|
204
|
+
exit 1
|
205
|
+
end
|
206
|
+
|
207
|
+
@approvals_interface.setopts(options)
|
208
|
+
if options[:dry_run]
|
209
|
+
print_dry_run @approvals_interface.dry.update_item(approval_item['id'], action)
|
210
|
+
return
|
211
|
+
end
|
212
|
+
json_response = @approvals_interface.update_item(approval_item['id'], action)
|
213
|
+
|
214
|
+
if options[:json]
|
215
|
+
puts as_json(json_response, options)
|
216
|
+
elsif !options[:quiet]
|
217
|
+
if json_response['success']
|
218
|
+
print_green_success "Approval item #{action} applied"
|
219
|
+
_get(approval_item['approval']['id'])
|
220
|
+
else
|
221
|
+
print_red_alert "Error updating approval item: #{json_response['msg'] || json_response['errors']}"
|
222
|
+
end
|
223
|
+
end
|
224
|
+
return 0
|
225
|
+
rescue RestClient::Exception => e
|
226
|
+
print_rest_exception(e, options)
|
227
|
+
exit 1
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
private
|
232
|
+
|
233
|
+
def find_approval_by_name_or_id(type, val)
|
234
|
+
(val.to_s =~ /\A\d{1,}\Z/) ? @approvals_interface.get(val.to_i)[typeCamelCase] : @approvals_interface.list({'name' => val})["approvals"].first
|
235
|
+
end
|
236
|
+
end
|