MuranoCLI 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.agignore +1 -0
- data/.rubocop.yml +67 -5
- data/Gemfile +6 -3
- data/MuranoCLI.gemspec +14 -10
- data/README.markdown +299 -126
- data/Rakefile +6 -1
- data/bin/murano +2 -2
- data/docs/completions/murano_completion-bash +93 -0
- data/lib/MrMurano.rb +19 -2
- data/lib/MrMurano/Business.rb +22 -19
- data/lib/MrMurano/Config.rb +19 -9
- data/lib/MrMurano/Content.rb +4 -4
- data/lib/MrMurano/Exchange-Element.rb +99 -0
- data/lib/MrMurano/Exchange.rb +137 -0
- data/lib/MrMurano/Gateway.rb +9 -9
- data/lib/MrMurano/Keystore.rb +4 -2
- data/lib/MrMurano/ReCommander.rb +3 -5
- data/lib/MrMurano/Solution-ServiceConfig.rb +12 -12
- data/lib/MrMurano/Solution-Services.rb +15 -14
- data/lib/MrMurano/Solution-Users.rb +2 -2
- data/lib/MrMurano/Solution.rb +43 -49
- data/lib/MrMurano/SolutionId.rb +28 -28
- data/lib/MrMurano/SyncUpDown.rb +32 -22
- data/lib/MrMurano/Webservice-Endpoint.rb +2 -1
- data/lib/MrMurano/Webservice.rb +5 -5
- data/lib/MrMurano/commands.rb +2 -1
- data/lib/MrMurano/commands/business.rb +21 -19
- data/lib/MrMurano/commands/domain.rb +16 -2
- data/lib/MrMurano/commands/exchange.rb +272 -0
- data/lib/MrMurano/commands/globals.rb +17 -1
- data/lib/MrMurano/commands/init.rb +3 -3
- data/lib/MrMurano/commands/link.rb +16 -16
- data/lib/MrMurano/commands/postgresql.rb +2 -2
- data/lib/MrMurano/commands/show.rb +13 -7
- data/lib/MrMurano/commands/solution.rb +23 -17
- data/lib/MrMurano/commands/solution_picker.rb +49 -44
- data/lib/MrMurano/commands/sync.rb +2 -1
- data/lib/MrMurano/commands/timeseries.rb +2 -2
- data/lib/MrMurano/commands/tsdb.rb +2 -2
- data/lib/MrMurano/hash.rb +19 -7
- data/lib/MrMurano/http.rb +12 -2
- data/lib/MrMurano/orderedhash.rb +200 -0
- data/lib/MrMurano/spec_commander.rb +98 -0
- data/lib/MrMurano/verbosing.rb +2 -2
- data/lib/MrMurano/version.rb +2 -2
- data/spec/Business_spec.rb +8 -6
- data/spec/Solution-ServiceConfig_spec.rb +1 -1
- data/spec/SyncUpDown_spec.rb +6 -6
- data/spec/_workspace.rb +9 -4
- data/spec/cmd_business_spec.rb +8 -2
- data/spec/cmd_common.rb +266 -25
- data/spec/cmd_exchange_spec.rb +118 -0
- data/spec/cmd_help_spec.rb +54 -13
- data/spec/cmd_init_spec.rb +1 -12
- data/spec/cmd_link_spec.rb +94 -72
- data/spec/spec_helper.rb +11 -16
- metadata +23 -17
@@ -1,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.
|
1
|
+
# Last Modified: 2017.09.11 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -40,6 +40,22 @@ global_option('-n', '--dry', %(Do not run actions that make changes)) do
|
|
40
40
|
$cfg['tool.verbose'] = true
|
41
41
|
end
|
42
42
|
|
43
|
+
global_option('--csv', %(Output as comma-separated values)) do
|
44
|
+
$cfg['tool.outformat'] = 'csv'
|
45
|
+
end
|
46
|
+
|
47
|
+
global_option('--json', %(Output as JSON)) do
|
48
|
+
$cfg['tool.outformat'] = 'json'
|
49
|
+
end
|
50
|
+
|
51
|
+
global_option('--yaml', %(Output as Yaml)) do
|
52
|
+
$cfg['tool.outformat'] = 'yaml'
|
53
|
+
end
|
54
|
+
|
55
|
+
global_option('--pp', %(Output using Ruby pretty-printer)) do
|
56
|
+
$cfg['tool.outformat'] = 'pp'
|
57
|
+
end
|
58
|
+
|
43
59
|
exclude_help = %(
|
44
60
|
Except config values from the specified scope(s).
|
45
61
|
SCOPES can be 1 scope or comma-separated list of
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.
|
1
|
+
# Last Modified: 2017.09.11 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -181,12 +181,12 @@ command :init do |c|
|
|
181
181
|
verbose: true,
|
182
182
|
}
|
183
183
|
# Get/Create Application ID
|
184
|
-
sol_opts[:
|
184
|
+
sol_opts[:match_api_id] = options.application_id
|
185
185
|
sol_opts[:match_name] = options.application_name
|
186
186
|
sol_opts[:match_fuzzy] = options.application
|
187
187
|
appl = solution_find_or_create(biz: biz, type: :application, **sol_opts)
|
188
188
|
# Get/Create Product ID
|
189
|
-
sol_opts[:
|
189
|
+
sol_opts[:match_api_id] = options.product_id
|
190
190
|
sol_opts[:match_name] = options.product_name
|
191
191
|
sol_opts[:match_fuzzy] = options.product
|
192
192
|
prod = solution_find_or_create(biz: biz, type: :product, **sol_opts)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.
|
1
|
+
# Last Modified: 2017.09.11 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -48,20 +48,20 @@ List the solutions that are linked.
|
|
48
48
|
biz = MrMurano::Business.new
|
49
49
|
products = biz.products
|
50
50
|
MrMurano::Verbose.whirly_stop
|
51
|
-
pids = products.map(&:
|
51
|
+
pids = products.map(&:api_id)
|
52
52
|
|
53
53
|
sol_opts = { biz: biz, type: :application }
|
54
|
-
sol_opts[:
|
54
|
+
sol_opts[:match_api_id] = $cfg['application.id'] unless options.all
|
55
55
|
appl = solution_find_or_create(**sol_opts)
|
56
56
|
|
57
57
|
if !appl.nil?
|
58
58
|
MrMurano::Verbose.whirly_msg('Fetching application services...')
|
59
|
-
sercfg = MrMurano::ServiceConfig.new(appl.
|
59
|
+
sercfg = MrMurano::ServiceConfig.new(appl.api_id)
|
60
60
|
#scfgs = sercfg.list('?select=service,id,solution_id,script_key,alias')
|
61
61
|
scfgs = sercfg.list
|
62
62
|
MrMurano::Verbose.whirly_stop
|
63
63
|
else
|
64
|
-
sercfg = MrMurano::ServiceConfig.new(MrMurano::SolutionId::
|
64
|
+
sercfg = MrMurano::ServiceConfig.new(MrMurano::SolutionId::INVALID_API_ID)
|
65
65
|
scfgs = []
|
66
66
|
end
|
67
67
|
|
@@ -150,7 +150,7 @@ def link_solutions(sol_a, sol_b, options)
|
|
150
150
|
warn_on_conflict = options[:warn_on_conflict] || false
|
151
151
|
verbose = options[:verbose] || false
|
152
152
|
|
153
|
-
if sol_a.nil? || sol_a.
|
153
|
+
if sol_a.nil? || sol_a.api_id.to_s.empty? || sol_b.nil? || sol_b.api_id.to_s.empty?
|
154
154
|
msg = 'Missing Solution(s) (Applications or Products): Nothing to link'
|
155
155
|
if warn_on_conflict
|
156
156
|
sercfg.warning msg
|
@@ -172,9 +172,9 @@ def link_solutions(sol_a, sol_b, options)
|
|
172
172
|
|
173
173
|
# Get services for solution to which being linked (application),
|
174
174
|
# and look for linkee (product) service.
|
175
|
-
sercfg = MrMurano::ServiceConfig.new(sol_a.
|
175
|
+
sercfg = MrMurano::ServiceConfig.new(sol_a.api_id)
|
176
176
|
MrMurano::Verbose.whirly_msg 'Fetching services...'
|
177
|
-
scfgs = sercfg.search(sol_b.
|
177
|
+
scfgs = sercfg.search(sol_b.api_id)
|
178
178
|
svc_cfg_exists = scfgs.any?
|
179
179
|
MrMurano::Verbose.whirly_stop
|
180
180
|
|
@@ -182,7 +182,7 @@ def link_solutions(sol_a, sol_b, options)
|
|
182
182
|
unless svc_cfg_exists
|
183
183
|
MrMurano::Verbose.whirly_msg 'Linking solutions...'
|
184
184
|
# Call Murano.
|
185
|
-
_ret = sercfg.create(sol_b.
|
185
|
+
_ret = sercfg.create(sol_b.api_id, sol_b.name) do |request, http|
|
186
186
|
response = http.request(request)
|
187
187
|
MrMurano::Verbose.whirly_stop
|
188
188
|
if response.is_a?(Net::HTTPSuccess)
|
@@ -208,8 +208,8 @@ def link_solutions(sol_a, sol_b, options)
|
|
208
208
|
|
209
209
|
# Get event handlers for application, and look for product event handler.
|
210
210
|
MrMurano::Verbose.whirly_msg 'Fetching handlers...'
|
211
|
-
evthlr = MrMurano::EventHandlerSolnApp.new(sol_a.
|
212
|
-
hdlrs = evthlr.search(sol_b.
|
211
|
+
evthlr = MrMurano::EventHandlerSolnApp.new(sol_a.api_id)
|
212
|
+
hdlrs = evthlr.search(sol_b.api_id)
|
213
213
|
evt_hlr_exists = hdlrs.any?
|
214
214
|
MrMurano::Verbose.whirly_stop
|
215
215
|
|
@@ -218,7 +218,7 @@ def link_solutions(sol_a, sol_b, options)
|
|
218
218
|
unless evt_hlr_exists
|
219
219
|
MrMurano::Verbose.whirly_msg 'Setting default event handler...'
|
220
220
|
# Call Murano.
|
221
|
-
evthlr.default_event_script(sol_b.
|
221
|
+
evthlr.default_event_script(sol_b.api_id) do |request, http|
|
222
222
|
response = http.request(request)
|
223
223
|
MrMurano::Verbose.whirly_stop
|
224
224
|
if response.is_a?(Net::HTTPSuccess)
|
@@ -244,10 +244,10 @@ def link_solutions(sol_a, sol_b, options)
|
|
244
244
|
end
|
245
245
|
|
246
246
|
def unlink_solutions(sol_a, sol_b)
|
247
|
-
sercfg = MrMurano::ServiceConfig.new(sol_a.
|
247
|
+
sercfg = MrMurano::ServiceConfig.new(sol_a.api_id)
|
248
248
|
MrMurano::Verbose.whirly_msg 'Fetching services...'
|
249
249
|
#scfgs = sercfg.list('?select=service,id,solution_id,script_key,alias')
|
250
|
-
scfgs = sercfg.search(sol_b.
|
250
|
+
scfgs = sercfg.search(sol_b.api_id)
|
251
251
|
MrMurano::Verbose.whirly_stop
|
252
252
|
|
253
253
|
if scfgs.length > 1
|
@@ -272,8 +272,8 @@ def unlink_solutions(sol_a, sol_b)
|
|
272
272
|
end
|
273
273
|
|
274
274
|
MrMurano::Verbose.whirly_msg 'Fetching handlers...'
|
275
|
-
evthlr = MrMurano::EventHandlerSolnApp.new(sol_a.
|
276
|
-
hdlrs = evthlr.search(sol_b.
|
275
|
+
evthlr = MrMurano::EventHandlerSolnApp.new(sol_a.api_id)
|
276
|
+
hdlrs = evthlr.search(sol_b.api_id)
|
277
277
|
#evt_hlr_exists = hdlrs.any?
|
278
278
|
MrMurano::Verbose.whirly_stop
|
279
279
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.
|
1
|
+
# Last Modified: 2017.09.11 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -10,7 +10,7 @@ require 'MrMurano/Solution-ServiceConfig'
|
|
10
10
|
|
11
11
|
module MrMurano
|
12
12
|
class Postgresql < ServiceConfig
|
13
|
-
def initialize(
|
13
|
+
def initialize(api_id=nil)
|
14
14
|
# FIXME/2017-07-03: What soln types have PSQLs?
|
15
15
|
@solntype = 'application.id'
|
16
16
|
super
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.
|
1
|
+
# Last Modified: 2017.09.11 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -39,7 +39,10 @@ Show readable information about the current configuration.
|
|
39
39
|
unless selected_application_id.to_s.empty?
|
40
40
|
MrMurano::Verbose.whirly_start('Fetching Applications...')
|
41
41
|
biz.applications.each do |sol|
|
42
|
-
|
42
|
+
next unless sol.api_id == selected_application_id
|
43
|
+
#next unless [sol.api_id, sol.sid].include?(selected_application_id)
|
44
|
+
selected_application = sol
|
45
|
+
break
|
43
46
|
end
|
44
47
|
MrMurano::Verbose.whirly_stop
|
45
48
|
end
|
@@ -49,7 +52,10 @@ Show readable information about the current configuration.
|
|
49
52
|
unless selected_product_id.to_s.empty?
|
50
53
|
MrMurano::Verbose.whirly_start('Fetching Products...')
|
51
54
|
biz.products.each do |sol|
|
52
|
-
|
55
|
+
next unless sol.api_id == selected_product_id
|
56
|
+
#next unless [sol.api_id, sol.sid].include?(selected_product_id)
|
57
|
+
selected_product = sol
|
58
|
+
break
|
53
59
|
end
|
54
60
|
MrMurano::Verbose.whirly_stop
|
55
61
|
end
|
@@ -71,11 +77,11 @@ Show readable information about the current configuration.
|
|
71
77
|
|
72
78
|
id_not_in_biz = false
|
73
79
|
|
74
|
-
# E.g., {:bizid=>"ABC", :type=>"application", :
|
80
|
+
# E.g., {:bizid=>"ABC", :type=>"application", :api_id=>"XXX", :sid=>"XXX",
|
75
81
|
# :name=>"ABC", :domain=>"ABC.apps.exosite.io" }
|
76
82
|
if selected_application
|
77
83
|
sol_info = %(application: https://#{selected_application.domain})
|
78
|
-
sol_info += %( <#{selected_application.
|
84
|
+
sol_info += %( <#{selected_application.api_id}>) if options.ids
|
79
85
|
puts sol_info
|
80
86
|
elsif selected_application_id
|
81
87
|
#puts 'selected application not in business'
|
@@ -88,11 +94,11 @@ Show readable information about the current configuration.
|
|
88
94
|
puts 'application ID not found in config'
|
89
95
|
end
|
90
96
|
|
91
|
-
# E.g., {:bizid=>"ABC", :type=>"product", :
|
97
|
+
# E.g., {:bizid=>"ABC", :type=>"product", :api_id=>"XXX", :sid=>"XXX",
|
92
98
|
# :name=>"ABC", :domain=>"ABC.m2.exosite.io" }
|
93
99
|
if selected_product
|
94
100
|
sol_info = %(product: #{selected_product.name})
|
95
|
-
sol_info += %( <#{selected_product.
|
101
|
+
sol_info += %( <#{selected_product.api_id}>) if options.ids
|
96
102
|
puts sol_info
|
97
103
|
elsif selected_product_id
|
98
104
|
#puts 'selected product not in business'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.
|
1
|
+
# Last Modified: 2017.09.11 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -68,11 +68,11 @@ Create a new solution in the current business.
|
|
68
68
|
|
69
69
|
if options.save
|
70
70
|
section = options.type.to_s
|
71
|
-
$cfg.set("#{section}.id", sol.
|
71
|
+
$cfg.set("#{section}.id", sol.api_id)
|
72
72
|
$cfg.set("#{section}.name", sol.name)
|
73
73
|
end
|
74
74
|
|
75
|
-
biz.outf(sol.
|
75
|
+
biz.outf(sol.api_id)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
alias_command 'create application', 'solution create', '--type', 'application'
|
@@ -157,7 +157,9 @@ def cmd_solution_del_get_names_and_ids!(biz, args, options)
|
|
157
157
|
end
|
158
158
|
solz = must_fetch_solutions!(options, args, biz)
|
159
159
|
solz.each do |sol|
|
160
|
-
nmorids += [
|
160
|
+
nmorids += [
|
161
|
+
[sol.api_id, "#{MrMurano::Verbose.fancy_ticks(sol.name)} <#{sol.api_id}>", sol],
|
162
|
+
]
|
161
163
|
end
|
162
164
|
nmorids
|
163
165
|
end
|
@@ -217,7 +219,9 @@ def solution_delete(name_or_id, use_sol: nil, type: :all, yes: false)
|
|
217
219
|
# would return true if, say, sol.meta[:any_key] equaled name_or_id.)
|
218
220
|
unless name_or_id.empty?
|
219
221
|
solz.select! do |sol|
|
220
|
-
sol.
|
222
|
+
sol.api_id == name_or_id \
|
223
|
+
|| sol.name == name_or_id \
|
224
|
+
|| sol.domain =~ /#{Regexp.escape(name_or_id)}\./i
|
221
225
|
end
|
222
226
|
end
|
223
227
|
MrMurano::Verbose.whirly_stop
|
@@ -255,7 +259,7 @@ def solution_delete(name_or_id, use_sol: nil, type: :all, yes: false)
|
|
255
259
|
n_deleted += 1
|
256
260
|
# Clear the ID from the config.
|
257
261
|
MrMurano::Config::CFG_SOLUTION_ID_KEYS.each do |keyn|
|
258
|
-
$cfg.set(keyn, nil) if $cfg[keyn] == sol.
|
262
|
+
$cfg.set(keyn, nil) if $cfg[keyn] == sol.api_id
|
259
263
|
end
|
260
264
|
end
|
261
265
|
end
|
@@ -386,30 +390,32 @@ end
|
|
386
390
|
|
387
391
|
def cmd_solution_output_solutions(biz, solz, options)
|
388
392
|
if options.idonly
|
389
|
-
headers = %i[
|
390
|
-
solz = solz.map { |row| [row.
|
393
|
+
headers = %i[api_id]
|
394
|
+
solz = solz.map { |row| [row.api_id] }
|
391
395
|
elsif options.brief
|
392
|
-
#headers = %i[
|
393
|
-
#solz = solz.map { |row| [row.
|
394
|
-
headers = %i[
|
395
|
-
solz = solz.map { |row| [row.
|
396
|
+
#headers = %i[api_id domain]
|
397
|
+
#solz = solz.map { |row| [row.api_id, row.domain] }
|
398
|
+
headers = %i[api_id sid domain name]
|
399
|
+
solz = solz.map { |row| [row.api_id, row.sid, row.domain, row.name] }
|
396
400
|
else
|
397
401
|
headers = (solz.first && solz.first.meta || {}).keys
|
398
|
-
headers.delete(:sid) if headers.include?(:
|
402
|
+
#headers.delete(:sid) if headers.include?(:api_id) && headers.include?(:sid)
|
399
403
|
headers.sort_by! do |hdr|
|
400
404
|
case hdr
|
401
405
|
when :bizid
|
402
406
|
0
|
403
407
|
when :type
|
404
408
|
1
|
405
|
-
when :
|
409
|
+
when :api_id
|
406
410
|
2
|
407
|
-
when :
|
411
|
+
when :sid
|
408
412
|
3
|
409
|
-
when :
|
413
|
+
when :domain
|
410
414
|
4
|
411
|
-
|
415
|
+
when :name
|
412
416
|
5
|
417
|
+
else
|
418
|
+
6
|
413
419
|
end
|
414
420
|
end
|
415
421
|
solz = solz.map { |row| headers.map { |hdr| row.meta[hdr] } }
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.
|
1
|
+
# Last Modified: 2017.09.11 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -99,18 +99,18 @@ def must_fetch_solutions!(options, args=[], biz=nil)
|
|
99
99
|
if args.any?
|
100
100
|
#raise 'Cannot use options.all and solution pickers' unless options.all.nil?
|
101
101
|
flattened = args.map { |cell| cell.split(',') }.flatten
|
102
|
-
|
102
|
+
api_id = []
|
103
103
|
name = []
|
104
104
|
fuzzy = []
|
105
105
|
if options.id
|
106
|
-
|
106
|
+
api_id = flattened
|
107
107
|
elsif options.name
|
108
108
|
name = flattened
|
109
109
|
else
|
110
110
|
fuzzy = flattened
|
111
111
|
end
|
112
112
|
solz += solution_get_solutions(
|
113
|
-
biz, options.type,
|
113
|
+
biz, options.type, api_id: api_id, name: name, fuzzy: fuzzy
|
114
114
|
)
|
115
115
|
end
|
116
116
|
|
@@ -120,35 +120,35 @@ def must_fetch_solutions!(options, args=[], biz=nil)
|
|
120
120
|
# MAYBE: DRY this code. Rather than copy-paste-find-replace block of code.
|
121
121
|
# See also: any_business_pickers?
|
122
122
|
#
|
123
|
-
|
123
|
+
api_id = []
|
124
124
|
name = []
|
125
125
|
fuzzy = []
|
126
126
|
if options.application_id
|
127
|
-
|
127
|
+
api_id = [options.application_id]
|
128
128
|
elsif options.application_name
|
129
129
|
name = [options.application_name]
|
130
130
|
elsif options.application
|
131
131
|
fuzzy = [options.application]
|
132
132
|
end
|
133
|
-
if !
|
133
|
+
if !api_id.empty? || !name.empty? || !fuzzy.empty?
|
134
134
|
solz += solution_get_solutions(
|
135
|
-
biz, :application,
|
135
|
+
biz, :application, api_id: api_id, name: name, fuzzy: fuzzy
|
136
136
|
)
|
137
137
|
end
|
138
138
|
#
|
139
|
-
|
139
|
+
api_id = []
|
140
140
|
name = []
|
141
141
|
fuzzy = []
|
142
142
|
if options.product_id
|
143
|
-
|
143
|
+
api_id = [options.product_id]
|
144
144
|
elsif options.product_name
|
145
145
|
name = [options.product_name]
|
146
146
|
elsif options.product
|
147
147
|
fuzzy = [options.product]
|
148
148
|
end
|
149
|
-
if !
|
149
|
+
if !api_id.empty? || !name.empty? || !fuzzy.empty?
|
150
150
|
solz += solution_get_solutions(
|
151
|
-
biz, :product,
|
151
|
+
biz, :product, api_id: api_id, name: name, fuzzy: fuzzy
|
152
152
|
)
|
153
153
|
end
|
154
154
|
#
|
@@ -158,12 +158,12 @@ def must_fetch_solutions!(options, args=[], biz=nil)
|
|
158
158
|
if !options.all
|
159
159
|
if %i[all application].include?(options.type) && $cfg['application.id']
|
160
160
|
solz += solution_get_solutions(
|
161
|
-
biz, :application,
|
161
|
+
biz, :application, api_id: $cfg['application.id']
|
162
162
|
)
|
163
163
|
end
|
164
164
|
if %i[all product].include?(options.type) && $cfg['product.id']
|
165
165
|
solz += solution_get_solutions(
|
166
|
-
biz, :product,
|
166
|
+
biz, :product, api_id: $cfg['product.id']
|
167
167
|
)
|
168
168
|
end
|
169
169
|
else
|
@@ -173,10 +173,10 @@ def must_fetch_solutions!(options, args=[], biz=nil)
|
|
173
173
|
|
174
174
|
culled = {}
|
175
175
|
solz.select! do |sol|
|
176
|
-
if culled[sol.
|
176
|
+
if culled[sol.api_id]
|
177
177
|
false
|
178
178
|
else
|
179
|
-
culled[sol.
|
179
|
+
culled[sol.api_id] = true
|
180
180
|
true
|
181
181
|
end
|
182
182
|
end
|
@@ -238,7 +238,7 @@ def any_product_pickers!(options)
|
|
238
238
|
num_ways > 0
|
239
239
|
end
|
240
240
|
|
241
|
-
def solution_get_solutions(biz, type,
|
241
|
+
def solution_get_solutions(biz, type, api_id: nil, name: nil, fuzzy: nil)
|
242
242
|
if type == :all
|
243
243
|
inflection = 'solutions'
|
244
244
|
else
|
@@ -246,7 +246,7 @@ def solution_get_solutions(biz, type, sid: nil, name: nil, fuzzy: nil)
|
|
246
246
|
end
|
247
247
|
MrMurano::Verbose.whirly_start("Fetching #{inflection}...")
|
248
248
|
solz = biz.solutions(
|
249
|
-
type: type,
|
249
|
+
type: type, api_id: api_id, name: name, fuzzy: fuzzy, invalidate: false
|
250
250
|
)
|
251
251
|
MrMurano::Verbose.whirly_stop
|
252
252
|
solz
|
@@ -275,6 +275,11 @@ def solution_ask_for_name(sol)
|
|
275
275
|
end
|
276
276
|
end
|
277
277
|
sol.name
|
278
|
+
rescue EOFError
|
279
|
+
# E.g., the user pressed Ctrl-D.
|
280
|
+
# "error: The input stream is exhausted."
|
281
|
+
MrMurano::Verbose.error('murano out!')
|
282
|
+
exit 2
|
278
283
|
end
|
279
284
|
|
280
285
|
# *** Interact with the user to identify the solution.
|
@@ -289,21 +294,21 @@ def get_two_solutions!(sol_a_id=nil, sol_b_id=nil, **options)
|
|
289
294
|
app_srchs = []
|
290
295
|
prd_srchs = []
|
291
296
|
|
292
|
-
#app_srchs += [[:application, :
|
293
|
-
#prd_srchs += [[:product, :
|
294
|
-
app_srchs += [[nil, :
|
295
|
-
prd_srchs += [[nil, :
|
297
|
+
#app_srchs += [[:application, :api_id, sol_a_id]] unless sol_a_id.to_s.empty?
|
298
|
+
#prd_srchs += [[:product, :api_id, sol_b_id]] unless sol_b_id.to_s.empty?
|
299
|
+
app_srchs += [[nil, :api_id, sol_a_id]] unless sol_a_id.to_s.empty?
|
300
|
+
prd_srchs += [[nil, :api_id, sol_b_id]] unless sol_b_id.to_s.empty?
|
296
301
|
|
297
302
|
app_srchs += get_soln_searches(:application, options)
|
298
303
|
prd_srchs += get_soln_searches(:product, options)
|
299
304
|
|
300
305
|
if app_srchs.length.zero? && prd_srchs.length < 2
|
301
306
|
# TEST/2017-08-16: Clear application.id and test.
|
302
|
-
app_srchs = [[:application, :
|
307
|
+
app_srchs = [[:application, :api_id, $cfg['application.id']]]
|
303
308
|
end
|
304
309
|
if prd_srchs.length.zero? && app_srchs.length < 2
|
305
310
|
# TEST/2017-08-16: Clear product.id and test.
|
306
|
-
prd_srchs = [[:product, :
|
311
|
+
prd_srchs = [[:product, :api_id, $cfg['product.id']]]
|
307
312
|
end
|
308
313
|
|
309
314
|
sol_srchs = app_srchs + prd_srchs
|
@@ -318,8 +323,8 @@ def get_two_solutions!(sol_a_id=nil, sol_b_id=nil, **options)
|
|
318
323
|
sol_srchs.each do |type, desc, value|
|
319
324
|
sol_opts = {}
|
320
325
|
case desc
|
321
|
-
when :
|
322
|
-
sol_opts[:
|
326
|
+
when :api_id
|
327
|
+
sol_opts[:match_api_id] = value
|
323
328
|
when :name
|
324
329
|
sol_opts[:match_name] = value
|
325
330
|
when :term
|
@@ -340,7 +345,7 @@ def get_soln_searches(sol_type, options)
|
|
340
345
|
# E.g., :application_id
|
341
346
|
if options["#{sol_type}_id".to_sym]
|
342
347
|
app_ids = options["#{sol_type}_id".to_sym].split(',')
|
343
|
-
app_ids.each { |
|
348
|
+
app_ids.each { |api_id| sol_srchs += [[sol_type, :api_id, api_id]] }
|
344
349
|
end
|
345
350
|
# E.g., :application_name
|
346
351
|
if options["#{sol_type}_name".to_sym]
|
@@ -374,7 +379,7 @@ module MrMurano
|
|
374
379
|
ignore_cfg: false,
|
375
380
|
verbose: false,
|
376
381
|
match_enable: false,
|
377
|
-
|
382
|
+
match_api_id: nil,
|
378
383
|
match_name: nil,
|
379
384
|
match_fuzzy: nil
|
380
385
|
)
|
@@ -384,23 +389,23 @@ module MrMurano
|
|
384
389
|
@ignore_cfg = ignore_cfg
|
385
390
|
@verbose = verbose
|
386
391
|
@match_enable = match_enable
|
387
|
-
@
|
392
|
+
@match_api_id = match_api_id
|
388
393
|
@match_name = match_name
|
389
394
|
@match_fuzzy = match_fuzzy
|
390
|
-
@
|
395
|
+
@match_api_id = nil if @match_api_id.to_s.empty?
|
391
396
|
@match_name = nil if @match_name.to_s.empty?
|
392
397
|
@match_fuzzy = nil if @match_fuzzy.to_s.empty?
|
393
|
-
@searching = @match_enable && (@
|
398
|
+
@searching = @match_enable && (@match_api_id || @match_name || @match_fuzzy)
|
394
399
|
end
|
395
400
|
|
396
401
|
def find_or_create(model)
|
397
402
|
# First, try to find the solution by solution ID.
|
398
|
-
sol =
|
403
|
+
sol = solution_find_by_api_id(model)
|
399
404
|
# If not found, search existing solutions, and maybe ask user.
|
400
405
|
if sol.nil?
|
401
406
|
if @searching
|
402
407
|
sol = solution_search_by_term(model)
|
403
|
-
sol = solution_create_new_solution(model) if sol.nil? && @create_ok && @
|
408
|
+
sol = solution_create_new_solution(model) if sol.nil? && @create_ok && @match_api_id.nil?
|
404
409
|
else
|
405
410
|
sol = solution_lookup_or_ask(model)
|
406
411
|
end
|
@@ -408,26 +413,26 @@ module MrMurano
|
|
408
413
|
# Finally, if asked, update the config.
|
409
414
|
if @update_cfg && !sol.nil?
|
410
415
|
# Update the config in memory and on disk/file.
|
411
|
-
$cfg.set(sol.cfg_key_id, sol.
|
416
|
+
$cfg.set(sol.cfg_key_id, sol.api_id, :project)
|
412
417
|
$cfg.set(sol.cfg_key_name, sol.name, :project)
|
413
418
|
end
|
414
419
|
sol
|
415
420
|
end
|
416
421
|
|
417
|
-
def
|
422
|
+
def solution_find_by_api_id(sol)
|
418
423
|
exists = false
|
419
424
|
if @searching || @ignore_cfg
|
420
|
-
sol.
|
425
|
+
sol.api_id = @match_api_id || @match_fuzzy
|
421
426
|
else
|
422
427
|
# Note that we verify the solution ID we find in the config,
|
423
428
|
# since the user could've, e.g., deleted it via the web UI.
|
424
429
|
# LATER: This only works so long as there's only one Product
|
425
430
|
# or one Application. Eventually we'll add support for more.
|
426
|
-
sol.
|
431
|
+
sol.api_id = $cfg[sol.cfg_key_id].to_s
|
427
432
|
return sol if @skip_verify
|
428
433
|
end
|
429
|
-
if sol.
|
430
|
-
|
434
|
+
if sol.api_id?
|
435
|
+
tried_api_id = sol.api_id
|
431
436
|
if @searching
|
432
437
|
whirly_msg = "Searching #{sol.type_name} by ID..."
|
433
438
|
else
|
@@ -435,12 +440,12 @@ module MrMurano
|
|
435
440
|
end
|
436
441
|
MrMurano::Verbose.whirly_start(whirly_msg)
|
437
442
|
sol.info_safe
|
438
|
-
if sol.
|
443
|
+
if sol.valid_api_id
|
439
444
|
exists = true
|
440
445
|
# Convert from Solution to proper subclass, perhaps.
|
441
446
|
sol = solution_factory_reset(sol)
|
442
447
|
else
|
443
|
-
sol.
|
448
|
+
sol.api_id = nil
|
444
449
|
end
|
445
450
|
MrMurano::Verbose.whirly_stop
|
446
451
|
# Spit out some messages, maybe.
|
@@ -449,8 +454,8 @@ module MrMurano
|
|
449
454
|
say "Found #{sol.type_name} #{sol.pretty_desc}"
|
450
455
|
elsif !@searching
|
451
456
|
# The solution ID in the config was not found for this business.
|
452
|
-
|
453
|
-
say "The #{sol.type_name} ID #{
|
457
|
+
tried_api_id = MrMurano::Verbose.fancy_ticks(tried_api_id)
|
458
|
+
say "The #{sol.type_name} ID #{tried_api_id} from the config was not found"
|
454
459
|
end
|
455
460
|
puts ''
|
456
461
|
end
|
@@ -519,7 +524,7 @@ module MrMurano
|
|
519
524
|
|
520
525
|
def solution_search_by_term(sol)
|
521
526
|
solz = solution_get_solutions(
|
522
|
-
sol.biz, sol.type,
|
527
|
+
sol.biz, sol.type, api_id: @match_api_id, name: @match_name, fuzzy: @match_fuzzy
|
523
528
|
)
|
524
529
|
if solz.length > 1
|
525
530
|
sol.error("More than one matching #{sol.type_name} found. Please be more specific")
|