MuranoCLI 3.2.0.beta.9 → 3.2.1.pre.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Rakefile +5 -0
- data/dockers/README.rst +7 -0
- data/dockers/RELEASE.rst +6 -3
- data/dockers/docker-test.sh +45 -17
- data/docs/completions/murano_completion-bash +211 -86
- data/lib/MrMurano/Account.rb +72 -4
- data/lib/MrMurano/Business.rb +163 -2
- data/lib/MrMurano/Commander-Entry.rb +1 -2
- data/lib/MrMurano/Config.rb +19 -18
- data/lib/MrMurano/Content.rb +26 -19
- data/lib/MrMurano/Gateway.rb +51 -10
- data/lib/MrMurano/ReCommander.rb +1 -1
- data/lib/MrMurano/Solution-Services.rb +80 -35
- data/lib/MrMurano/Solution-Users.rb +1 -0
- data/lib/MrMurano/SyncRoot.rb +10 -3
- data/lib/MrMurano/SyncUpDown-Core.rb +47 -36
- data/lib/MrMurano/SyncUpDown-Item.rb +46 -14
- data/lib/MrMurano/SyncUpDown.rb +22 -20
- data/lib/MrMurano/Webservice-Endpoint.rb +20 -18
- data/lib/MrMurano/Webservice-File.rb +63 -20
- data/lib/MrMurano/commands/business.rb +14 -1
- data/lib/MrMurano/commands/child.rb +148 -0
- data/lib/MrMurano/commands/devices.rb +298 -149
- data/lib/MrMurano/commands/element.rb +2 -1
- data/lib/MrMurano/commands/globals.rb +3 -0
- data/lib/MrMurano/commands/network.rb +152 -33
- data/lib/MrMurano/commands/sync.rb +2 -2
- data/lib/MrMurano/commands.rb +1 -0
- data/lib/MrMurano/verbosing.rb +13 -2
- data/lib/MrMurano/version.rb +1 -1
- data/spec/Account_spec.rb +43 -11
- data/spec/Content_spec.rb +5 -3
- data/spec/GatewayBase_spec.rb +1 -1
- data/spec/GatewayDevice_spec.rb +47 -8
- data/spec/GatewayResource_spec.rb +1 -1
- data/spec/GatewaySettings_spec.rb +1 -1
- data/spec/HttpAuthed_spec.rb +17 -3
- data/spec/ProjectFile_spec.rb +59 -23
- data/spec/Setting_spec.rb +2 -1
- data/spec/Solution-ServiceConfig_spec.rb +1 -1
- data/spec/Solution-ServiceEventHandler_spec.rb +27 -20
- data/spec/Solution-ServiceModules_spec.rb +7 -5
- data/spec/Solution-UsersRoles_spec.rb +7 -1
- data/spec/Solution_spec.rb +9 -1
- data/spec/SyncRoot_spec.rb +5 -5
- data/spec/SyncUpDown_spec.rb +262 -211
- data/spec/Verbosing_spec.rb +49 -8
- data/spec/Webservice-Cors_spec.rb +10 -1
- data/spec/Webservice-Endpoint_spec.rb +84 -65
- data/spec/Webservice-File_spec.rb +16 -11
- data/spec/Webservice-Setting_spec.rb +7 -1
- data/spec/_workspace.rb +9 -0
- data/spec/cmd_business_spec.rb +5 -10
- data/spec/cmd_common.rb +67 -32
- data/spec/cmd_config_spec.rb +9 -14
- data/spec/cmd_content_spec.rb +15 -26
- data/spec/cmd_cors_spec.rb +9 -12
- data/spec/cmd_device_spec.rb +31 -45
- data/spec/cmd_domain_spec.rb +12 -10
- data/spec/cmd_element_spec.rb +18 -17
- data/spec/cmd_exchange_spec.rb +1 -4
- data/spec/cmd_init_spec.rb +56 -72
- data/spec/cmd_keystore_spec.rb +17 -26
- data/spec/cmd_link_spec.rb +13 -17
- data/spec/cmd_password_spec.rb +9 -10
- data/spec/cmd_setting_application_spec.rb +95 -68
- data/spec/cmd_setting_product_spec.rb +59 -37
- data/spec/cmd_status_spec.rb +46 -84
- data/spec/cmd_syncdown_application_spec.rb +28 -50
- data/spec/cmd_syncdown_both_spec.rb +44 -93
- data/spec/cmd_syncdown_unit_spec.rb +858 -0
- data/spec/cmd_syncup_spec.rb +21 -56
- data/spec/cmd_token_spec.rb +0 -3
- data/spec/cmd_usage_spec.rb +15 -10
- data/spec/dry_run_formatter.rb +1 -0
- data/spec/fixtures/dumped_config +4 -4
- data/spec/spec_helper.rb +3 -0
- metadata +4 -2
data/lib/MrMurano/Account.rb
CHANGED
@@ -16,7 +16,7 @@ module MrMurano
|
|
16
16
|
include AccountBase
|
17
17
|
include Verbose
|
18
18
|
|
19
|
-
def businesses(bid: nil, name: nil, fuzzy: nil)
|
19
|
+
def businesses(bid: nil, name: nil, fuzzy: nil, options: nil)
|
20
20
|
# Ask user for name and password, if not saved to config and password files.
|
21
21
|
login_info if user.empty?
|
22
22
|
raise 'Missing user?!' if user.empty?
|
@@ -29,6 +29,77 @@ module MrMurano
|
|
29
29
|
# 2017-06-30: The data for each message contains a :bizid, :role, and :name.
|
30
30
|
# :role is probably generally "owner".
|
31
31
|
|
32
|
+
if (options && options.network)
|
33
|
+
# add network information and sort list
|
34
|
+
bizes = add_businesses_network(bizes)
|
35
|
+
match_bid_name_fuzzy!(bizes, bid, name, fuzzy)
|
36
|
+
else
|
37
|
+
# Sort results.
|
38
|
+
match_bid_name_fuzzy!(bizes, bid, name, fuzzy)
|
39
|
+
bizes.sort_by!(&:name)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# ---------------------------------------------------------------------
|
44
|
+
|
45
|
+
def add_businesses_network(bizes)
|
46
|
+
# Get network information
|
47
|
+
bizes_without_network = []
|
48
|
+
bizes_unconfigured = []
|
49
|
+
bizes_in_network = []
|
50
|
+
all_bizes = []
|
51
|
+
|
52
|
+
MrMurano::Verbose.whirly_start 'Fetching Network Information...'
|
53
|
+
bizes.each do |biz|
|
54
|
+
biz[:network] = ''
|
55
|
+
biz[:network_relationship] = ''
|
56
|
+
business_tier = get('business/' + biz[:bizid] + '/tier')
|
57
|
+
network_enabled = business_tier[:features][:network]
|
58
|
+
|
59
|
+
if network_enabled # Parents of business networks
|
60
|
+
add_network_info_parent!(biz, bizes_in_network, bizes_unconfigured)
|
61
|
+
else # check if the biz is a child of a network
|
62
|
+
maybe_add_network_info_child!(biz, bizes_without_network, bizes_in_network)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
MrMurano::Verbose.whirly_stop
|
66
|
+
|
67
|
+
# Assemble the master list so that confgured networks are on top, followed
|
68
|
+
# by unconfigured networks, followed by non-network businesses
|
69
|
+
all_bizes.concat(bizes_in_network.sort_by! { |biz| biz[:network] })
|
70
|
+
all_bizes.concat(bizes_unconfigured.sort_by! { |biz| biz[:name] })
|
71
|
+
all_bizes.concat(bizes_without_network.sort_by! { |biz| biz[:name] })
|
72
|
+
end
|
73
|
+
|
74
|
+
# ---------------------------------------------------------------------
|
75
|
+
def add_network_info_parent!(biz, bizes_in_network, bizes_unconfigured)
|
76
|
+
biz[:network_relationship] = 'parent'
|
77
|
+
network_name = get('business/' + biz[:bizid] + '/network')[:name]
|
78
|
+
if network_name
|
79
|
+
biz[:network] = network_name
|
80
|
+
bizes_in_network.push(biz)
|
81
|
+
else
|
82
|
+
biz[:network] = '--Not configured yet--'
|
83
|
+
bizes_unconfigured.push(biz)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# ---------------------------------------------------------------------
|
88
|
+
def maybe_add_network_info_child!(biz, bizes_without_network, bizes_in_network)
|
89
|
+
owner = get('business/' + biz[:bizid] + '/owner')
|
90
|
+
if owner.empty?
|
91
|
+
biz[:network] = 'N/A'
|
92
|
+
bizes_without_network.push(biz)
|
93
|
+
else
|
94
|
+
biz[:network_relationship] = 'child'
|
95
|
+
biz[:network] = owner[:network][:name]
|
96
|
+
bizes_in_network.push(biz)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# ---------------------------------------------------------------------
|
101
|
+
# helper for filtering businesses when using the find command
|
102
|
+
def match_bid_name_fuzzy!(bizes, bid, name, fuzzy)
|
32
103
|
match_bid = ensure_array(bid)
|
33
104
|
match_name = ensure_array(name)
|
34
105
|
match_fuzzy = ensure_array(fuzzy)
|
@@ -47,9 +118,6 @@ module MrMurano
|
|
47
118
|
end
|
48
119
|
|
49
120
|
bizes.map! { |meta| MrMurano::Business.new(meta) }
|
50
|
-
|
51
|
-
# Sort results.
|
52
|
-
bizes.sort_by!(&:name)
|
53
121
|
end
|
54
122
|
|
55
123
|
# ---------------------------------------------------------------------
|
data/lib/MrMurano/Business.rb
CHANGED
@@ -48,6 +48,11 @@ module MrMurano
|
|
48
48
|
$cfg['business.id'].to_s
|
49
49
|
end
|
50
50
|
|
51
|
+
def cid
|
52
|
+
return @cid unless @cid.to_s.empty?
|
53
|
+
$cfg['business.child'].to_s
|
54
|
+
end
|
55
|
+
|
51
56
|
def name
|
52
57
|
return @name unless @name.to_s.empty?
|
53
58
|
$cfg['business.name'].to_s
|
@@ -89,12 +94,22 @@ module MrMurano
|
|
89
94
|
raise MrMurano::ConfigError.new(Business.missing_business_id_msg) if bid.to_s.empty?
|
90
95
|
end
|
91
96
|
|
97
|
+
def must_child!
|
98
|
+
raise MrMurano::ConfigError.new(Business.missing_child_msg) if cid.to_s.empty?
|
99
|
+
end
|
100
|
+
|
92
101
|
def self.missing_business_id_msg
|
93
102
|
%(
|
94
103
|
business ID not specified. For hints: #{MrMurano::EXE_NAME} business --help
|
95
104
|
).strip
|
96
105
|
end
|
97
106
|
|
107
|
+
def self.missing_child_msg
|
108
|
+
%(
|
109
|
+
network child business ID not specified. For hints: #{MrMurano::EXE_NAME} business --help
|
110
|
+
).strip
|
111
|
+
end
|
112
|
+
|
98
113
|
def pretty_name_and_id
|
99
114
|
"#{fancy_ticks(Rainbow(name).underline)} <#{bid}>"
|
100
115
|
end
|
@@ -112,6 +127,9 @@ module MrMurano
|
|
112
127
|
#end
|
113
128
|
|
114
129
|
def overview(&block)
|
130
|
+
# TODO: (PL) - The overview endpoint has been split up into smaller
|
131
|
+
# endpoints that should be used instead of this one
|
132
|
+
#
|
115
133
|
# Here are all the goodies that the overview endpoint returns:
|
116
134
|
# {:name=>"XXX", :email=>"XXX", :contact=>"XXX",
|
117
135
|
# :billing=>{
|
@@ -373,7 +391,6 @@ module MrMurano
|
|
373
391
|
end
|
374
392
|
end
|
375
393
|
end
|
376
|
-
# ---------------------------------------------------------------------
|
377
394
|
|
378
395
|
# ---------------------------------------------------------------------
|
379
396
|
|
@@ -390,6 +407,130 @@ module MrMurano
|
|
390
407
|
end
|
391
408
|
end
|
392
409
|
end
|
410
|
+
|
411
|
+
# ---------------------------------------------------------------------
|
412
|
+
|
413
|
+
def view_child_businesses(bid)
|
414
|
+
return nil unless check_if_biz_network_capable(bid) == true
|
415
|
+
get('business/' + bid + '/network/business/') do |request, http|
|
416
|
+
response = http.request(request)
|
417
|
+
case response
|
418
|
+
when Net::HTTPSuccess
|
419
|
+
workit_response(response)
|
420
|
+
else
|
421
|
+
showHttpError(request, response)
|
422
|
+
nil
|
423
|
+
end
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
# ---------------------------------------------------------------------
|
428
|
+
|
429
|
+
def add_network_child_business(bid, name)
|
430
|
+
return nil unless check_if_biz_network_capable(bid) == true
|
431
|
+
post('business/' + bid + '/network/business/', name: name) do |request, http|
|
432
|
+
response = http.request(request)
|
433
|
+
case response
|
434
|
+
when Net::HTTPSuccess
|
435
|
+
workit_response(response)
|
436
|
+
when Net::HTTPConflict #409 limit reached
|
437
|
+
MrMurano::Verbose.error(
|
438
|
+
'You have reached your limit of child businesses in your network.'
|
439
|
+
)
|
440
|
+
nil
|
441
|
+
else
|
442
|
+
showHttpError(request, response)
|
443
|
+
nil
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
# ---------------------------------------------------------------------
|
449
|
+
|
450
|
+
def delete_child_business(bid, child_business_id)
|
451
|
+
return nil unless check_if_biz_network_capable(bid) == true
|
452
|
+
delete(
|
453
|
+
'business/' +
|
454
|
+
bid +
|
455
|
+
'/network/business/' +
|
456
|
+
child_business_id
|
457
|
+
) do |request, http|
|
458
|
+
response = http.request(request)
|
459
|
+
case response
|
460
|
+
when Net::HTTPSuccess
|
461
|
+
workit_response(response)
|
462
|
+
else
|
463
|
+
showHttpError(request, response)
|
464
|
+
nil
|
465
|
+
end
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
# ---------------------------------------------------------------------
|
470
|
+
|
471
|
+
def add_member_to_child_business(bid, child_business_id, new_member_email)
|
472
|
+
return nil unless check_if_biz_network_capable(bid)
|
473
|
+
member_in_parent_biz = check_if_member_is_in_biz(bid, new_member_email)
|
474
|
+
unless (member_in_parent_biz)
|
475
|
+
MrMurano::Verbose.error(
|
476
|
+
'User is not a member of the parent business.'
|
477
|
+
)
|
478
|
+
return nil
|
479
|
+
end
|
480
|
+
member_in_child_biz = check_if_member_is_in_biz(child_business_id, new_member_email)
|
481
|
+
if (member_in_child_biz)
|
482
|
+
MrMurano::Verbose.error(
|
483
|
+
'User is already a member of the child business.'
|
484
|
+
)
|
485
|
+
return nil
|
486
|
+
end
|
487
|
+
put(
|
488
|
+
'business/' +
|
489
|
+
bid +
|
490
|
+
'/network/business/' +
|
491
|
+
child_business_id +
|
492
|
+
'/member/' +
|
493
|
+
new_member_email
|
494
|
+
) do |request, http|
|
495
|
+
response = http.request(request)
|
496
|
+
case response
|
497
|
+
when Net::HTTPSuccess
|
498
|
+
workit_response(response)
|
499
|
+
else
|
500
|
+
showHttpError(request, response)
|
501
|
+
nil
|
502
|
+
end
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
# ---------------------------------------------------------------------
|
507
|
+
|
508
|
+
def remove_member_from_child_business(bid, child_business_id, member_email)
|
509
|
+
return nil unless check_if_biz_network_capable(bid)
|
510
|
+
member_in_child_biz = check_if_member_is_in_biz(child_business_id, member_email)
|
511
|
+
unless (member_in_child_biz)
|
512
|
+
MrMurano::Verbose.error(
|
513
|
+
'User is not a member of the child business.'
|
514
|
+
)
|
515
|
+
return nil
|
516
|
+
end
|
517
|
+
delete(
|
518
|
+
'business/' +
|
519
|
+
child_business_id +
|
520
|
+
'/member/' +
|
521
|
+
member_email
|
522
|
+
) do |request, http|
|
523
|
+
response = http.request(request)
|
524
|
+
case response
|
525
|
+
when Net::HTTPSuccess
|
526
|
+
workit_response(response)
|
527
|
+
else
|
528
|
+
showHttpError(request, response)
|
529
|
+
nil
|
530
|
+
end
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
393
534
|
# ---------------------------------------------------------------------
|
394
535
|
|
395
536
|
def check_if_biz_network_capable(bid)
|
@@ -398,7 +539,7 @@ module MrMurano
|
|
398
539
|
case tier_response
|
399
540
|
when Net::HTTPSuccess
|
400
541
|
parsed_response = workit_response(tier_response)
|
401
|
-
if parsed_response[:network] != true
|
542
|
+
if parsed_response[:features][:network] != true
|
402
543
|
MrMurano::Verbose.error(
|
403
544
|
'Your business does not have access to business network features. Please upgrade your business.'
|
404
545
|
)
|
@@ -413,6 +554,26 @@ module MrMurano
|
|
413
554
|
end
|
414
555
|
end
|
415
556
|
|
557
|
+
# ---------------------------------------------------------------------
|
558
|
+
|
559
|
+
def check_if_member_is_in_biz(business_id, email)
|
560
|
+
get('business/' + business_id + '/member/') do |request, http|
|
561
|
+
response = http.request(request)
|
562
|
+
case response
|
563
|
+
when Net::HTTPSuccess
|
564
|
+
parsed_response = workit_response(response)
|
565
|
+
if (parsed_response.none? { |m| m[:email] == email })
|
566
|
+
false
|
567
|
+
else
|
568
|
+
true
|
569
|
+
end
|
570
|
+
else
|
571
|
+
showHttpError(request, response)
|
572
|
+
nil
|
573
|
+
end
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
416
577
|
def self.must_not_be_managed!
|
417
578
|
# Check that the solution(s) are not managed.
|
418
579
|
# NOTE: BizAPI only tells us 'managed' via the business/<bizid>/solutions
|
@@ -10,7 +10,6 @@ require 'English'
|
|
10
10
|
require 'highline'
|
11
11
|
require 'murano-cli-commander/import'
|
12
12
|
require 'pathname'
|
13
|
-
#require 'pp'
|
14
13
|
require 'rainbow'
|
15
14
|
require 'rubygems'
|
16
15
|
require 'MrMurano'
|
@@ -84,7 +83,7 @@ $cfg = MrMurano::Config.new(::Commander::Runner.instance)
|
|
84
83
|
$cfg.load
|
85
84
|
$cfg.validate_cmd
|
86
85
|
|
87
|
-
# Look for a
|
86
|
+
# Look for a Solutionfile.json.
|
88
87
|
$project = MrMurano::ProjectFile.new
|
89
88
|
$project.load
|
90
89
|
|
data/lib/MrMurano/Config.rb
CHANGED
@@ -230,7 +230,6 @@ module MrMurano
|
|
230
230
|
set_defaults_location_newstyle('location.endpoints', 'routes', 'endpoints')
|
231
231
|
end
|
232
232
|
|
233
|
-
# rubocop:disable Style/MethodName: Use snake_case for method names.
|
234
233
|
def set_defaults_location_newstyle(key, formerly, currently)
|
235
234
|
if @project_dir && !@project_dir.join(formerly).exist?
|
236
235
|
set(key, currently, :defaults)
|
@@ -253,7 +252,7 @@ module MrMurano
|
|
253
252
|
def set_defaults_endpoints
|
254
253
|
set('endpoints.searchFor', %w[
|
255
254
|
{,../endpoints}/*.lua
|
256
|
-
{,../endpoints}
|
255
|
+
{,../endpoints}/*/*.lua
|
257
256
|
].join(' '), :defaults)
|
258
257
|
set('endpoints.ignoring', %w[
|
259
258
|
*_test.lua
|
@@ -295,6 +294,8 @@ module MrMurano
|
|
295
294
|
timer.timer
|
296
295
|
tsdb.exportJob
|
297
296
|
user.account
|
297
|
+
config.service
|
298
|
+
config.status
|
298
299
|
].join(' '), :defaults)
|
299
300
|
end
|
300
301
|
|
@@ -336,8 +337,12 @@ module MrMurano
|
|
336
337
|
# Set these so that @known_keys is updated.
|
337
338
|
set('user.name', nil, :defaults)
|
338
339
|
set('business.id', nil, :defaults)
|
340
|
+
set('business.child', nil, :defaults)
|
339
341
|
set('application.id', nil, :defaults)
|
340
|
-
set('
|
342
|
+
set('product.id', nil, :defaults)
|
343
|
+
set('business.name', nil, :defaults)
|
344
|
+
set('application.name', nil, :defaults)
|
345
|
+
set('product.name', nil, :defaults)
|
341
346
|
end
|
342
347
|
|
343
348
|
## Find the root of this project Directory.
|
@@ -395,19 +400,15 @@ module MrMurano
|
|
395
400
|
# Most commands should be run from within a Murano project (sub-)directory.
|
396
401
|
# If user is running a project command not within a project directory,
|
397
402
|
# we'll print a message now and exit the app from run_active_command later.
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
false
|
408
|
-
end
|
409
|
-
end
|
410
|
-
true
|
403
|
+
return if @runner.nil?
|
404
|
+
the_cmd = @runner.active_command if the_cmd.nil?
|
405
|
+
the_cmd = command(cmd) if the_cmd.nil?
|
406
|
+
the_cmd.project_not_required = false unless defined?(the_cmd.project_not_required)
|
407
|
+
return if the_cmd.name == 'help' || the_cmd.project_not_required || @project_exists
|
408
|
+
error %(The "#{the_cmd.name}" command only works in a Murano project.)
|
409
|
+
say INVALID_PROJECT_HINT
|
410
|
+
# Note that commander-rb uses an at_exit hook, which we hack around.
|
411
|
+
@runner.command_exit = 1
|
411
412
|
end
|
412
413
|
|
413
414
|
def self.fix_modes(path)
|
@@ -501,7 +502,7 @@ module MrMurano
|
|
501
502
|
def get(key, scope=CFG_SCOPES)
|
502
503
|
scope = [scope] unless scope.is_a? Array
|
503
504
|
paths = @paths.select { |p| scope.include? p.kind }
|
504
|
-
paths.reject { |p| @exclude_scopes.include? p.kind }
|
505
|
+
paths.reject! { |p| @exclude_scopes.include? p.kind }
|
505
506
|
|
506
507
|
section, ikey = key.split('.')
|
507
508
|
paths.each do |path|
|
@@ -693,7 +694,7 @@ module MrMurano
|
|
693
694
|
locat = ''
|
694
695
|
|
695
696
|
scope_q = fancy_ticks(scope)
|
696
|
-
scope_l = "Scope: #{
|
697
|
+
scope_l = "Scope: #{scope_q}\n\n"
|
697
698
|
locat += Rainbow(scope_l).bright.underline
|
698
699
|
|
699
700
|
cfg_paths = @paths.select { |p| p.kind == scope }
|
data/lib/MrMurano/Content.rb
CHANGED
@@ -83,7 +83,9 @@ module MrMurano
|
|
83
83
|
# ?type=
|
84
84
|
sha256 = Digest::SHA256.new
|
85
85
|
sha256.file(local_path.to_s)
|
86
|
-
|
86
|
+
|
87
|
+
mime = MIME::Types.type_for(local_path.to_s)[0]
|
88
|
+
mime ||= MIME::Types['application/octet-stream'][0]
|
87
89
|
|
88
90
|
params = {
|
89
91
|
sha256: sha256.hexdigest,
|
@@ -97,7 +99,8 @@ module MrMurano
|
|
97
99
|
ret = get("/#{CGI.escape(name)}/upload?#{URI.encode_www_form(params)}")
|
98
100
|
debug "POST instructions: #{ret}"
|
99
101
|
raise "Method isn't POST!!!" unless ret.is_a?(Hash) && ret[:method] == 'POST'
|
100
|
-
|
102
|
+
is_form_data = ret[:enctype] == 'multipart/form-data'
|
103
|
+
raise "EncType isn't multipart/form-data" unless is_form_data
|
101
104
|
|
102
105
|
uri = URI(ret[:url])
|
103
106
|
request = Net::HTTP::Post.new(uri)
|
@@ -128,8 +131,8 @@ module MrMurano
|
|
128
131
|
end
|
129
132
|
|
130
133
|
return if $cfg['tool.dry']
|
131
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |
|
132
|
-
response =
|
134
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
135
|
+
response = http.request(request)
|
133
136
|
case response
|
134
137
|
# rubocop:disable Lint/EmptyWhen
|
135
138
|
# "Avoid when branches without a body."
|
@@ -160,28 +163,32 @@ module MrMurano
|
|
160
163
|
ret = get("/#{CGI.escape(name)}/download")
|
161
164
|
debug "GET instructions: #{ret}"
|
162
165
|
raise "Method isn't GET!!!" unless ret.is_a?(Hash) && ret[:method] == 'GET'
|
163
|
-
|
164
166
|
uri = URI(ret[:url])
|
165
167
|
request = Net::HTTP::Get.new(uri)
|
166
168
|
request['User-Agent'] = "MrMurano/#{MrMurano::VERSION}"
|
169
|
+
download_curldebug(request)
|
170
|
+
download_send(uri, request, &block)
|
171
|
+
end
|
167
172
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
173
|
+
def download_curldebug(request)
|
174
|
+
return unless $cfg['tool.curldebug']
|
175
|
+
args = []
|
176
|
+
args << %(curl -s)
|
177
|
+
args << %(-H 'User-Agent: #{request['User-Agent']}')
|
178
|
+
args << %(-X #{request.method})
|
179
|
+
args << %('#{request.uri}')
|
180
|
+
if $cfg.curlfile_f.nil?
|
181
|
+
puts args.join(' ')
|
182
|
+
else
|
183
|
+
$cfg.curlfile_f << args.join(' ') + "\n\n"
|
184
|
+
$cfg.curlfile_f.flush
|
180
185
|
end
|
186
|
+
end
|
181
187
|
|
188
|
+
def download_send(uri, request, &block)
|
182
189
|
return if $cfg['tool.dry']
|
183
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |
|
184
|
-
|
190
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
191
|
+
http.request(request) do |response|
|
185
192
|
case response
|
186
193
|
when Net::HTTPSuccess
|
187
194
|
if block_given?
|