MuranoCLI 3.0.7 → 3.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.ignore +1 -1
  4. data/.rubocop.yml +10 -5
  5. data/.trustme.sh +272 -106
  6. data/.trustme.vim +20 -1
  7. data/Gemfile +7 -5
  8. data/LICENSE.txt +14 -15
  9. data/MuranoCLI.gemspec +7 -5
  10. data/Rakefile +5 -5
  11. data/bin/murano +4 -4
  12. data/lib/MrMurano/Account.rb +13 -8
  13. data/lib/MrMurano/Business.rb +6 -7
  14. data/lib/MrMurano/Commander-Entry.rb +5 -5
  15. data/lib/MrMurano/Config-Migrate.rb +4 -4
  16. data/lib/MrMurano/Config.rb +27 -6
  17. data/lib/MrMurano/Content.rb +5 -5
  18. data/lib/MrMurano/Exchange-Element.rb +4 -4
  19. data/lib/MrMurano/Exchange.rb +4 -4
  20. data/lib/MrMurano/Gateway.rb +22 -11
  21. data/lib/MrMurano/Keystore.rb +4 -4
  22. data/lib/MrMurano/Logs.rb +87 -0
  23. data/lib/MrMurano/Mock.rb +5 -4
  24. data/lib/MrMurano/Passwords.rb +4 -5
  25. data/lib/MrMurano/ProjectFile.rb +4 -4
  26. data/lib/MrMurano/ReCommander.rb +4 -4
  27. data/lib/MrMurano/Setting.rb +5 -5
  28. data/lib/MrMurano/Settings-HttpService.rb +9 -6
  29. data/lib/MrMurano/Solution-ServiceConfig.rb +5 -5
  30. data/lib/MrMurano/Solution-Services.rb +76 -50
  31. data/lib/MrMurano/Solution-Users.rb +5 -4
  32. data/lib/MrMurano/Solution.rb +6 -6
  33. data/lib/MrMurano/SolutionId.rb +4 -4
  34. data/lib/MrMurano/SubCmdGroupContext.rb +4 -4
  35. data/lib/MrMurano/SyncAllowed.rb +4 -4
  36. data/lib/MrMurano/SyncRoot.rb +5 -5
  37. data/lib/MrMurano/SyncUpDown-Core.rb +515 -0
  38. data/lib/MrMurano/SyncUpDown-Item.rb +159 -0
  39. data/lib/MrMurano/SyncUpDown.rb +120 -688
  40. data/lib/MrMurano/Webservice-Cors.rb +4 -4
  41. data/lib/MrMurano/Webservice-Endpoint.rb +9 -6
  42. data/lib/MrMurano/Webservice-File.rb +5 -4
  43. data/lib/MrMurano/Webservice.rb +5 -5
  44. data/lib/MrMurano/commands/business.rb +4 -4
  45. data/lib/MrMurano/commands/completion.rb +6 -6
  46. data/lib/MrMurano/commands/config.rb +7 -5
  47. data/lib/MrMurano/commands/content.rb +5 -4
  48. data/lib/MrMurano/commands/cors.rb +4 -4
  49. data/lib/MrMurano/commands/devices.rb +6 -6
  50. data/lib/MrMurano/commands/domain.rb +4 -4
  51. data/lib/MrMurano/commands/exchange.rb +4 -4
  52. data/lib/MrMurano/commands/gb.rb +4 -4
  53. data/lib/MrMurano/commands/globals.rb +12 -4
  54. data/lib/MrMurano/commands/init.rb +5 -4
  55. data/lib/MrMurano/commands/keystore.rb +4 -4
  56. data/lib/MrMurano/commands/link.rb +4 -4
  57. data/lib/MrMurano/commands/login.rb +4 -4
  58. data/lib/MrMurano/commands/logs.rb +229 -76
  59. data/lib/MrMurano/commands/mock.rb +4 -4
  60. data/lib/MrMurano/commands/password.rb +4 -4
  61. data/lib/MrMurano/commands/postgresql.rb +4 -4
  62. data/lib/MrMurano/commands/settings.rb +4 -4
  63. data/lib/MrMurano/commands/show.rb +4 -4
  64. data/lib/MrMurano/commands/solution.rb +4 -4
  65. data/lib/MrMurano/commands/solution_picker.rb +4 -4
  66. data/lib/MrMurano/commands/status.rb +12 -4
  67. data/lib/MrMurano/commands/sync.rb +4 -4
  68. data/lib/MrMurano/commands/timeseries.rb +4 -4
  69. data/lib/MrMurano/commands/tsdb.rb +6 -7
  70. data/lib/MrMurano/commands/usage.rb +4 -4
  71. data/lib/MrMurano/commands.rb +4 -4
  72. data/lib/MrMurano/hash.rb +5 -5
  73. data/lib/MrMurano/http.rb +26 -22
  74. data/lib/MrMurano/makePretty.rb +194 -10
  75. data/lib/MrMurano/optparse.rb +1 -1
  76. data/lib/MrMurano/orderedhash.rb +1 -1
  77. data/lib/MrMurano/progress.rb +4 -4
  78. data/lib/MrMurano/verbosing.rb +6 -6
  79. data/lib/MrMurano/version.rb +5 -5
  80. data/lib/MrMurano.rb +7 -4
  81. data/spec/Account-Passwords_spec.rb +4 -4
  82. data/spec/Account_spec.rb +4 -4
  83. data/spec/Business_spec.rb +4 -4
  84. data/spec/ConfigFile_spec.rb +4 -4
  85. data/spec/ConfigMigrate_spec.rb +5 -4
  86. data/spec/Config_spec.rb +5 -4
  87. data/spec/Content_spec.rb +5 -4
  88. data/spec/GatewayBase_spec.rb +4 -4
  89. data/spec/GatewayDevice_spec.rb +4 -4
  90. data/spec/GatewayResource_spec.rb +5 -4
  91. data/spec/GatewaySettings_spec.rb +4 -4
  92. data/spec/Http_spec.rb +4 -4
  93. data/spec/MakePretties_spec.rb +20 -20
  94. data/spec/Mock_spec.rb +4 -4
  95. data/spec/ProjectFile_spec.rb +4 -4
  96. data/spec/Setting_spec.rb +4 -4
  97. data/spec/Solution-ServiceConfig_spec.rb +4 -4
  98. data/spec/Solution-ServiceEventHandler_spec.rb +5 -4
  99. data/spec/Solution-ServiceModules_spec.rb +5 -4
  100. data/spec/Solution-UsersRoles_spec.rb +5 -4
  101. data/spec/Solution_spec.rb +4 -4
  102. data/spec/SyncRoot_spec.rb +4 -4
  103. data/spec/SyncUpDown_spec.rb +67 -21
  104. data/spec/Verbosing_spec.rb +12 -10
  105. data/spec/Webservice-Cors_spec.rb +4 -4
  106. data/spec/Webservice-Endpoint_spec.rb +5 -4
  107. data/spec/Webservice-File_spec.rb +5 -4
  108. data/spec/Webservice-Setting_spec.rb +4 -4
  109. data/spec/_workspace.rb +4 -4
  110. data/spec/cmd_business_spec.rb +4 -5
  111. data/spec/cmd_common.rb +51 -20
  112. data/spec/cmd_config_spec.rb +4 -5
  113. data/spec/cmd_content_spec.rb +4 -5
  114. data/spec/cmd_cors_spec.rb +4 -5
  115. data/spec/cmd_device_spec.rb +5 -6
  116. data/spec/cmd_domain_spec.rb +4 -5
  117. data/spec/cmd_exchange_spec.rb +4 -5
  118. data/spec/cmd_help_spec.rb +4 -5
  119. data/spec/cmd_init_spec.rb +16 -35
  120. data/spec/cmd_keystore_spec.rb +4 -5
  121. data/spec/cmd_link_spec.rb +11 -12
  122. data/spec/cmd_logs_spec.rb +162 -0
  123. data/spec/cmd_password_spec.rb +4 -5
  124. data/spec/cmd_setting_application_spec.rb +4 -5
  125. data/spec/cmd_setting_product_spec.rb +4 -5
  126. data/spec/cmd_status_spec.rb +44 -81
  127. data/spec/cmd_syncdown_application_spec.rb +7 -10
  128. data/spec/cmd_syncdown_both_spec.rb +10 -25
  129. data/spec/cmd_syncup_spec.rb +31 -37
  130. data/spec/cmd_usage_spec.rb +4 -5
  131. data/spec/fixtures/dumped_config +1 -0
  132. data/spec/fixtures/websocket/logs_blather.rb +27 -0
  133. data/spec/fixtures/websocket/logs_faker.rb +153 -0
  134. data/spec/fixtures/websocket/simple_connection.rb +45 -0
  135. data/spec/fixtures/websocket/simple_options.rb +77 -0
  136. data/spec/fixtures/websocket/simple_server.rb +69 -0
  137. data/spec/fixtures/websocket/wss-echo.rb +48 -0
  138. data/spec/fixtures/websocket/wss-fake-logs.rb +20 -0
  139. metadata +55 -2
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.08.22 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'MrMurano/Mock'
9
9
  require 'MrMurano/ReCommander'
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.08.22 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'MrMurano/ReCommander'
9
9
 
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.09.11 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'MrMurano/ReCommander'
9
9
  require 'MrMurano/Solution-ServiceConfig'
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.08.22 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'vine'
9
9
  require 'yaml'
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.09.11 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'MrMurano/verbosing'
9
9
  require 'MrMurano/Business'
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.09.11 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'MrMurano/verbosing'
9
9
  require 'MrMurano/Account'
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.09.11 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'MrMurano/verbosing'
9
9
  require 'MrMurano/Business'
@@ -1,11 +1,12 @@
1
- # Last Modified: 2017.08.22 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'inflecto'
9
+ require 'pathname'
9
10
  require 'MrMurano/verbosing'
10
11
  require 'MrMurano/SyncRoot'
11
12
 
@@ -124,6 +125,7 @@ Endpoints can be selected with a "#<method>#<path glob>" pattern.
124
125
  )
125
126
  ret[:toadd].each do |item|
126
127
  interject " + #{item[:pp_type]} #{highlight_chg(fmtr(item, options))}"
128
+ pretty_diff(item, options)
127
129
  end
128
130
 
129
131
  pretty_group_header(
@@ -131,6 +133,7 @@ Endpoints can be selected with a "#<method>#<path glob>" pattern.
131
133
  )
132
134
  ret[:todel].each do |item|
133
135
  interject " - #{item[:pp_type]} #{highlight_del(fmtr(item, options))}"
136
+ pretty_diff(item, options)
134
137
  end
135
138
 
136
139
  pretty_group_header(
@@ -174,6 +177,11 @@ Endpoints can be selected with a "#<method>#<path glob>" pattern.
174
177
  end
175
178
  end
176
179
 
180
+ def pretty_diff(item, options)
181
+ return unless options.diff && $cfg['tool.verbose'] && !item[:diff].empty?
182
+ interject item[:diff]
183
+ end
184
+
177
185
  def highlight_chg(msg)
178
186
  Rainbow(msg).green.bright
179
187
  end
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.09.07 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'MrMurano/verbosing'
9
9
  require 'MrMurano/SyncRoot'
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.09.11 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'csv'
9
9
  require 'MrMurano/ReCommander'
@@ -1,11 +1,11 @@
1
- # Last Modified: 2017.10.05 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
- require 'date'
8
+ require 'time'
9
9
  require 'MrMurano/ReCommander'
10
10
  require 'MrMurano/Solution-ServiceConfig'
11
11
  require 'MrMurano/SubCmdGroupContext'
@@ -42,8 +42,7 @@ module MrMurano
42
42
  if str =~ /^\d+(u|ms|s)?$/
43
43
  str
44
44
  else
45
- dt = DateTime.parse(str)
46
- (dt.to_time.to_f * 1_000_000).to_i
45
+ (Time.parse(str).to_f * 1_000_000).to_i
47
46
  end
48
47
  end
49
48
  end
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.09.20 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'MrMurano/ReCommander'
9
9
  require 'MrMurano/Solution'
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.08.29 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  # DEVs: If you want to generate a completion file, uncomment this.
9
9
  # Then run, from the base of the project, e.g.,
data/lib/MrMurano/hash.rb CHANGED
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.09.27 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'MrMurano/orderedhash'
9
9
 
@@ -114,7 +114,7 @@ module HashInit
114
114
  if respond_to? key
115
115
  send("#{key}=", val)
116
116
  elsif defined?(@show_errors) && @show_errors
117
- $stderr.puts %(HashInit: missing hash key "#{key}")
117
+ warn %(HashInit: missing hash key "#{key}")
118
118
  end
119
119
  end
120
120
  end
data/lib/MrMurano/http.rb CHANGED
@@ -1,14 +1,14 @@
1
- # Last Modified: 2017.09.20 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'certified' if Gem.win_platform?
9
- require 'date'
10
9
  require 'json'
11
10
  require 'net/http'
11
+ require 'time'
12
12
  require 'uri'
13
13
  # 2017-06-07: [lb] getting "execution expired (Net::OpenTimeout)" on http.start.
14
14
  # Suggestions online say to load the pure-Ruby DNS implementation, resolv.rb.
@@ -47,43 +47,47 @@ module MrMurano
47
47
  def curldebug(request)
48
48
  return unless $cfg['tool.curldebug']
49
49
  formp = (request.content_type =~ %r{multipart/form-data})
50
- a = []
51
- a << %(curl -s)
50
+ ccmd = []
51
+ ccmd << %(curl -s)
52
52
  if request.key?('Authorization')
53
- a << %(-H 'Authorization: #{request['Authorization']}')
53
+ ccmd << %(-H 'Authorization: #{request['Authorization']}')
54
54
  end
55
- a << %(-H 'User-Agent: #{request['User-Agent']}')
56
- a << %(-H 'Content-Type: #{request.content_type}') unless formp
57
- a << %(-X #{request.method})
58
- a << %('#{request.uri}')
55
+ ccmd << %(-H 'User-Agent: #{request['User-Agent']}')
56
+ ccmd << %(-H 'Content-Type: #{request.content_type}') unless formp
57
+ ccmd << %(-X #{request.method})
58
+ ccmd << %('#{request.uri}')
59
59
  unless request.body.nil?
60
60
  if formp
61
61
  m = request.body.match(
62
62
  /form-data;\s+name="(?<name>[^"]+)";\s+filename="(?<filename>[^"]+)"/
63
63
  )
64
- a << %(-F #{m[:name]}=@#{m[:filename]}) unless m.nil?
64
+ ccmd << %(-F #{m[:name]}=@#{m[:filename]}) unless m.nil?
65
65
  else
66
- a << %(-d '#{request.body}')
66
+ ccmd << %(-d '#{request.body}')
67
67
  end
68
68
  end
69
+ MrMurano::Http.curldebug_log(ccmd.join(' '))
70
+ end
71
+
72
+ def self.curldebug_log(ccmd)
69
73
  if $cfg.curlfile_f.nil?
70
- MrMurano::Progress.instance.whirly_interject { puts a.join(' ') }
74
+ MrMurano::Progress.instance.whirly_interject { puts ccmd }
71
75
  else
72
- $cfg.curlfile_f << a.join(' ') + "\n\n"
76
+ $cfg.curlfile_f << ccmd + "\n\n"
73
77
  $cfg.curlfile_f.flush
74
78
  end
75
79
  end
76
80
 
77
81
  # Default endpoint unless Class overrides it.
78
82
  def endpoint(path)
79
- URI('https://' + $cfg['net.host'] + '/api:1/' + path.to_s)
83
+ URI($cfg['net.protocol'] + '://' + $cfg['net.host'] + '/api:1/' + path.to_s)
80
84
  end
81
85
 
82
86
  def http
83
- uri = URI('https://' + $cfg['net.host'])
87
+ uri = URI($cfg['net.protocol'] + '://' + $cfg['net.host'])
84
88
  if !defined?(@http) || @http.nil?
85
89
  @http = Net::HTTP.new(uri.host, uri.port)
86
- @http.use_ssl = true
90
+ @http.use_ssl = true if $cfg['net.protocol'] == 'https'
87
91
  begin
88
92
  @http.start
89
93
  rescue SocketError => err
@@ -117,7 +121,7 @@ module MrMurano
117
121
  # 2017-08-20: isJSON and showHttpError are grandparented into lint exceptions.
118
122
  def isJSON(data)
119
123
  [true, JSON.parse(data, json_opts)]
120
- rescue
124
+ rescue StandardError
121
125
  [false, data]
122
126
  end
123
127
 
@@ -175,7 +179,7 @@ module MrMurano
175
179
  return {} if response.body.nil?
176
180
  begin
177
181
  JSON.parse(response.body, json_opts)
178
- rescue
182
+ rescue StandardError
179
183
  response.body
180
184
  end
181
185
  end
@@ -299,7 +303,7 @@ if RUBY_VERSION == '2.0.0'
299
303
  s.post_connection_check(@address)
300
304
  end
301
305
  @ssl_session = s.session
302
- rescue => exception
306
+ rescue StandardError => exception
303
307
  D "Conn close because of connect error #{exception}"
304
308
  @socket.close if @socket && !@socket.closed?
305
309
  raise exception
@@ -1,12 +1,12 @@
1
- # Last Modified: 2017.08.20 /coding: utf-8
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
2
3
  # frozen_string_literal: true
3
4
 
4
- # Copyright © 2016-2017 Exosite LLC.
5
- # License: MIT. See LICENSE.txt.
6
- # vim:tw=0:ts=2:sw=2:et:ai
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
- require 'date'
9
8
  require 'json'
9
+ require 'time'
10
10
  require 'highline'
11
11
 
12
12
  module MrMurano
@@ -20,9 +20,9 @@ module MrMurano
20
20
  HighLine.color_scheme = PRETTIES_COLORSCHEME
21
21
 
22
22
  # rubocop:disable Style/MethodName: "Use snake_case for method names."
23
- def self.makeJsonPretty(data, options)
23
+ def self.makeJsonPretty(data, options, indent: nil, object_nl: nil)
24
24
  if options.pretty
25
- ret = JSON.pretty_generate(data).to_s
25
+ ret = JSON.pretty_generate(data, indent: indent, object_nl: object_nl).to_s
26
26
  ret[0] = HighLine.color(ret[0], :json)
27
27
  ret[-1] = HighLine.color(ret[-1], :json)
28
28
  ret
@@ -31,7 +31,8 @@ module MrMurano
31
31
  end
32
32
  end
33
33
 
34
- def self.makePretty(line, options)
34
+ # FIXME: (landonb): MUR-3081: Remove old http code for v3.1.0. Search: LOGS_USE_HTTP.
35
+ def self.MakePrettyLogsV1(line, options)
35
36
  # 2017-07-02: Changing shovel operator << to +=
36
37
  # to support Ruby 3.0 frozen string literals.
37
38
  out = ''
@@ -41,9 +42,9 @@ module MrMurano
41
42
  if line.key?(:timestamp)
42
43
  if line[:timestamp].is_a? Numeric
43
44
  if options.localtime
44
- curtime = Time.at(line[:timestamp]).localtime.to_datetime.iso8601(3)
45
+ curtime = Time.at(line[:timestamp]).localtime.strftime('%Y-%m-%d %H:%M:%S')
45
46
  else
46
- curtime = Time.at(line[:timestamp]).gmtime.to_datetime.iso8601(3)
47
+ curtime = Time.at(line[:timestamp]).gmtime.strftime('%Y-%m-%d %H:%M:%S')
47
48
  end
48
49
  else
49
50
  curtime = line[:timestamp]
@@ -78,6 +79,189 @@ module MrMurano
78
79
  end
79
80
  out
80
81
  end
82
+
83
+ def self.MakePrettyLogsV2(line, options)
84
+ out = log_pretty_assemble_header(line, options)
85
+ out + log_pretty_assemble_body(line, options)
86
+ end
87
+
88
+ def self.fmt_text_padded(text, style, out, raw, min_width: 0)
89
+ padding = min_width - text.length
90
+ padding = ' ' * (padding > 0 && padding || 0)
91
+ out += HighLine.color(text, style) + padding
92
+ raw += text + padding
93
+ [out, raw]
94
+ end
95
+
96
+ def self.log_pretty_assemble_header(line, options)
97
+ out = ''
98
+ raw = ''
99
+ out, raw = log_pretty_header_add_abbreviated_sev(line, out, raw, options)
100
+ out, raw = log_pretty_header_add_log_record_type(line, out, raw, options)
101
+ out, raw = log_pretty_header_add_event_timestamp(line, out, raw, options)
102
+ out, raw = log_pretty_header_add_murano_tracking(line, out, raw, options)
103
+ out, _raw = log_pretty_header_add_a_service_event(line, out, raw, options)
104
+ out + "\n"
105
+ end
106
+
107
+ def self.log_pretty_header_add_abbreviated_sev(line, out, raw, _options)
108
+ fmt_abbreviated_severity(line[:severity], out, raw)
109
+ end
110
+
111
+ def self.log_pretty_header_add_loquacious_sev(line, out, raw, _options)
112
+ fmt_loquacious_severity(line[:severity], out, raw)
113
+ end
114
+
115
+ def self.fmt_abbreviated_severity(severity, out, raw, min_width: 7)
116
+ abbrev, _loquac, style = styled_severity(severity)
117
+ fmt_text_padded(abbrev, style, out, raw, min_width: min_width)
118
+ end
119
+
120
+ def self.fmt_loquacious_severity(severity, min_width: 11)
121
+ _abbrev, loquac, style = styled_severity(severity)
122
+ fmt_text_padded(loquac, style, out, raw, min_width: min_width)
123
+ end
124
+
125
+ def self.styled_severity(severity)
126
+ case severity
127
+ when 0 # Emergency: system is unusable
128
+ ['EMERG', 'EMERGENCY', %i[red bold on_white]]
129
+ when 1 # Alert: action must be taken immediately
130
+ ['ALERT', 'ALERT', %i[red bold]]
131
+ when 2 # Critical: critical conditions
132
+ ['CRIT', 'CRITICAL', %i[red bold]]
133
+ when 3 # Error: error conditions
134
+ ['ERROR', 'ERROR', %i[red]]
135
+ when 4 # Warning: warning conditions
136
+ ['WARN', 'WARNING', %i[yellow]]
137
+ when 5 # Notice: normal but significant condition
138
+ ['NOTE', 'NOTICE', %i[white]]
139
+ when 6 # Informational: informational messages
140
+ ['INFO', 'INFO', %i[blue]]
141
+ when 7 # Debug: debug-level messages ]
142
+ ['DEBUG', 'DEBUG', %i[green]]
143
+ else
144
+ ["????#{severity}", "????#{severity}", %i[red]]
145
+ end
146
+ end
147
+
148
+ def self.log_pretty_header_add_log_record_type(line, out, raw, _options)
149
+ log_type = line[:type].to_s.empty? && '--' || line[:type]
150
+ fmt_text_padded(log_type.upcase, :magenta, out, raw, min_width: 10)
151
+ end
152
+
153
+ def self.log_pretty_header_add_event_timestamp(line, out, raw, options)
154
+ curtime = fmt_log_record_timestamp(line, options)
155
+ fmt_text_padded(curtime, :timestamp, out, raw, min_width: 18)
156
+ end
157
+
158
+ def self.fmt_log_record_timestamp(line, options)
159
+ if line.key?(:timestamp)
160
+ if line[:timestamp].is_a? Numeric
161
+ time_secs_epoch = Time.at(line[:timestamp] / 1000.0)
162
+ if options.localtime
163
+ curtime = time_secs_epoch.localtime
164
+ else
165
+ curtime = time_secs_epoch.gmtime
166
+ end
167
+ curtime = curtime.strftime('%Y-%m-%d %H:%M:%S')
168
+ else
169
+ curtime = line[:timestamp]
170
+ end
171
+ else
172
+ curtime = '<no timestamp>'
173
+ end
174
+ curtime
175
+ end
176
+
177
+ def self.log_pretty_header_add_murano_tracking(line, out, raw, options)
178
+ return [out, raw] unless options.tracking
179
+ tid = line[:tracking_id].to_s.empty? && '--------' || line[:tracking_id].slice(0, 8)
180
+ fmt_text_padded(tid, :yellow, out, raw, min_width: 10)
181
+ end
182
+
183
+ def self.log_pretty_header_add_a_service_event(line, out, raw, _options)
184
+ svc_evt = []
185
+ svc_evt += [line[:service]] unless line[:service].to_s.empty?
186
+ svc_evt += [line[:event]] unless line[:event].to_s.empty?
187
+ svc_evt = "[#{svc_evt.join(' ').upcase}]"
188
+ out += HighLine.color(svc_evt, :subject)
189
+ raw += svc_evt
190
+ [out, raw]
191
+ end
192
+
193
+ def self.log_pretty_assemble_body(line, options)
194
+ out = ''
195
+ @body_prefix = ' '
196
+ out += log_pretty_assemble_message(line, options)
197
+ out += log_pretty_assemble_data(line, options)
198
+ out += log_pretty_assemble_remainder(line, options)
199
+ out + log_pretty_assemble_tracking_id(line, options)
200
+ end
201
+
202
+ def self.log_pretty_assemble_message(line, _options)
203
+ return '' unless line.key?(:message) && !line[:message].to_s.empty?
204
+ @body_prefix + line[:message] + "\n"
205
+ end
206
+
207
+ def self.log_pretty_assemble_data(line, options)
208
+ return '' unless line.key?(:data)
209
+ data = line[:data]
210
+ if data.is_a?(Hash)
211
+ out = ''
212
+ out += log_pretty_emphasize_entry(:request, data, options)
213
+ out += log_pretty_emphasize_entry(:response, data, options)
214
+ out + log_pretty_data_remainder(data, options)
215
+ else
216
+ data.to_s
217
+ end
218
+ end
219
+
220
+ def self.log_pretty_emphasize_entry(entry, hash, options)
221
+ return '' unless hash.key?(entry) && !hash[entry].empty?
222
+ out = @body_prefix + "---------\n"
223
+ out += @body_prefix + "#{entry}: "
224
+ out += log_pretty_json(hash[entry], options)
225
+ out + "\n"
226
+ end
227
+
228
+ def self.log_pretty_data_remainder(data, options)
229
+ known_keys = %i[
230
+ request
231
+ response
232
+ ]
233
+ data = data.reject { |key, _val| known_keys.include?(key) }
234
+ return '' if data.empty?
235
+ out = @body_prefix + "---------\n"
236
+ out + @body_prefix + 'data: ' + log_pretty_json(data, options) + "\n"
237
+ end
238
+
239
+ def self.log_pretty_assemble_remainder(line, options)
240
+ known_keys = %i[
241
+ severity
242
+ type
243
+ timestamp
244
+ service
245
+ event
246
+ message
247
+ tracking_id
248
+ data
249
+ ]
250
+ line = line.reject { |key, _val| known_keys.include?(key) }
251
+ return '' if line.empty?
252
+ @body_prefix + log_pretty_json(line, options) + "\n"
253
+ end
254
+
255
+ def self.log_pretty_assemble_tracking_id(line, options)
256
+ log_pretty_emphasize_entry(:tracking_id, line, options)
257
+ end
258
+
259
+ def self.log_pretty_json(hash, options)
260
+ return '' if hash.empty?
261
+ makeJsonPretty(
262
+ hash, options, indent: @body_prefix, object_nl: "\n" + @body_prefix
263
+ )
264
+ end
81
265
  end
82
266
  end
83
267