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 'json'
9
9
  require 'yaml'
@@ -1,12 +1,13 @@
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 'json'
9
9
  require 'net/http'
10
+ require 'pathname'
10
11
  require 'pp'
11
12
  require 'uri'
12
13
  require 'MrMurano/SyncRoot'
@@ -43,7 +44,7 @@ module MrMurano
43
44
  end
44
45
 
45
46
  ##
46
- # This gets all data about all endpoints
47
+ # This gets all data about all endpoints.
47
48
  def list
48
49
  ret = get
49
50
  return [] unless ret.is_a?(Array)
@@ -68,6 +69,7 @@ module MrMurano
68
69
 
69
70
  ret[:content_type] = 'application/json' if ret[:content_type].empty?
70
71
 
72
+ add_terminating_nl = ret[:script].end_with? "\n"
71
73
  script = ret[:script].lines.map(&:chomp)
72
74
 
73
75
  aheader = (script.first || '')
@@ -93,7 +95,8 @@ module MrMurano
93
95
  end
94
96
  # otherwise current header is good.
95
97
 
96
- script = script.join("\n") + "\n"
98
+ script = script.join("\n")
99
+ script += "\n" if add_terminating_nl
97
100
  if block_given?
98
101
  yield script
99
102
  else
@@ -1,14 +1,15 @@
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 'digest/sha1'
9
9
  require 'http/form_data'
10
10
  require 'mime/types'
11
11
  require 'net/http'
12
+ require 'pathname'
12
13
  require 'uri'
13
14
  require 'MrMurano/Webservice'
14
15
  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 'uri'
9
9
  require 'MrMurano/Config'
@@ -38,7 +38,7 @@ module MrMurano
38
38
  # @return URI: The full URI for this endpoint.
39
39
  def endpoint(path='')
40
40
  super
41
- parts = ['https:/', $cfg['net.host'], 'api:1'] + @uriparts
41
+ parts = [$cfg['net.protocol'] + ':/', $cfg['net.host'], 'api:1'] + @uriparts
42
42
  s = parts.map(&:to_s).join('/')
43
43
  URI(s + path.to_s)
44
44
  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/verbosing'
9
9
  require 'MrMurano/Account'
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.08.16 /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 'erb'
9
9
  require 'pp'
@@ -77,7 +77,7 @@ class ::Commander::Runner
77
77
  # Get maximum depth of sub-commands.
78
78
  def cmdMaxDepth
79
79
  depth = 0
80
- @commands.sort.each do |name, _cmd|
80
+ @commands.keys.sort.each do |name|
81
81
  levels = name.split
82
82
  depth = levels.count if levels.count > depth
83
83
  end
@@ -151,7 +151,7 @@ or
151
151
  # end
152
152
 
153
153
  elsif options.subs
154
- runner.instance_variable_get(:@commands).sort.each do |name, _cmd|
154
+ runner.instance_variable_get(:@commands).keys.sort.each do |name|
155
155
  #desc = _cmd.instance_variable_get(:@summary) #.lines[0]
156
156
  #say "#{name}:'#{desc}'"
157
157
  say name.to_s
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.08.16 /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
 
@@ -89,7 +89,9 @@ If section is left out, then key is assumed to be in the 'tool' section.
89
89
  scopes = MrMurano::Config::CFG_SCOPES if scopes.empty?
90
90
  is_wild = $cfg.wild?(args[0])
91
91
  if !is_wild
92
- puts $cfg.get(args[0], scopes)
92
+ val = $cfg.get(args[0], scopes)
93
+ MrMurano::Verbose.verbose "No such key: #{args[0]}" if val.nil?
94
+ puts val
93
95
  else
94
96
  kvals = $cfg.get_wild(args[0], scopes)
95
97
  # LATER/2017-08-16: Honor --json option.
@@ -1,10 +1,11 @@
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
+ require 'pathname'
8
9
  require 'MrMurano/Content'
9
10
  require 'MrMurano/ReCommander'
10
11
 
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.09.13 /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 'yaml'
9
9
  require 'MrMurano/ReCommander'
@@ -1,11 +1,11 @@
1
- # Last Modified: 2017.10.04 /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/Gateway'
10
10
  require 'MrMurano/ReCommander'
11
11
 
@@ -232,7 +232,7 @@ Enables Identifiers, creating devices, or digital shadows, in Murano.
232
232
  # representing microseconds since the epoch, e.g.,
233
233
  # hours * mins/hour * secs/min * msec/sec * μsec/msec
234
234
  # or hours * 60 * 60 * 1000 * 1000
235
- micros_since_epoch = DateTime.now.strftime('%Q').to_i * 1000
235
+ micros_since_epoch = (Time.now.to_f * 1_000_000).to_i
236
236
  mircos_until_purge = options.expire.to_i * 60 * 60 * 1000 * 1000
237
237
  options.expire = micros_since_epoch + mircos_until_purge
238
238
  end
@@ -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'
@@ -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 'highline'
9
9
  require 'MrMurano/verbosing'
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.08.16 /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 'pp'
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/Config'
9
9
 
@@ -84,3 +84,11 @@ global_option('-V', '--verbose', %(Be chatty)) do
84
84
  $cfg['tool.verbose'] = true
85
85
  end
86
86
 
87
+ global_option('--debug', %(Show debug messages)) do
88
+ $cfg['tool.debug'] = true
89
+ end
90
+
91
+ global_option('--sid VALUE', %(Override application or product ID)) do |value|
92
+ $cfg['application.id'] = value
93
+ $cfg['product.id'] = value
94
+ end
@@ -1,11 +1,12 @@
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 'erb'
9
+ require 'pathname'
9
10
  require 'rainbow'
10
11
  require 'MrMurano/verbosing'
11
12
  require 'MrMurano/Account'
@@ -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/Keystore'
9
9
  require 'MrMurano/ReCommander'
@@ -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/Account'
9
9
  require 'MrMurano/ReCommander'
@@ -1,9 +1,9 @@
1
- # Last Modified: 2017.09.21 /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/Account'
9
9
  require 'MrMurano/Config'
@@ -1,107 +1,260 @@
1
- # Last Modified: 2017.08.16 /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 'json'
9
+
10
+ require 'MrMurano/hash'
11
+ require 'MrMurano/http'
8
12
  require 'MrMurano/makePretty'
13
+ require 'MrMurano/verbosing'
14
+ require 'MrMurano/Logs'
9
15
  require 'MrMurano/ReCommander'
10
16
  require 'MrMurano/Solution'
11
17
 
12
- command :logs do |c|
18
+ # FIXME: (landonb): MUR-3081: Remove old http code for v3.1.0. Search: LOGS_USE_HTTP.
19
+ LOGS_USE_HTTP = true
20
+
21
+ def command_logs(c)
22
+ cmd_add_logs_meta(c)
23
+ # Add global solution flag: --type [application|product].
24
+ cmd_add_solntype_pickers(c, exclude_all: true)
25
+ cmd_add_logs_options(c)
26
+ c.action do |args, options|
27
+ c.verify_arg_count!(args)
28
+ logs_action(options)
29
+ end
30
+ end
31
+
32
+ def cmd_add_logs_meta(c)
13
33
  c.syntax = %(murano logs [--options])
14
34
  c.summary = %(Get the logs for a solution)
35
+ if LOGS_USE_HTTP
36
+ c.description = %(Get the logs for a solution.)
37
+ else
38
+ cmd_add_logs_help(c)
39
+ end
40
+ end
41
+
42
+ def cmd_add_logs_help(c)
15
43
  c.description = %(
16
- Get the logs for a solution.
17
- ).strip
44
+ Get the logs for a solution.
18
45
 
19
- # Add flag: --type [application|product].
20
- cmd_add_solntype_pickers(c, exclude_all: true)
46
+ Each log record contains a number of fields, including the following.
47
+
48
+ Severity
49
+ ================================================================
50
+ The severity of the log message, as defined by rsyslog standard.
51
+
52
+ ID | Name | Description
53
+ -- | ------------- | -----------------------------------------
54
+ 0 | Emergency | System is unusable
55
+ 1 | Alert | Action must be taken immediately
56
+ 2 | Critical | Critical conditions
57
+ 3 | Error | Error conditions
58
+ 4 | Warning | Warning conditions
59
+ 5 | Notice | Normal but significant condition
60
+ 6 | Informational | Informational messages
61
+ 7 | Debug | Debug-level messages
62
+
63
+ Type
64
+ ================================================================
65
+ The type (emitter system) of the message.
66
+
67
+ Name | Description
68
+ ------- | ----------------------------------------------------
69
+ Script | Pegasus-Engine: on User Lua “print()” function call
70
+ Call | Dispatcher: On service calls from Lua.
71
+ Event | Dispatcher: On event trigger from services
72
+ Config | Pegasus-API: On solution configuration change or
73
+ | used service deprecation warning.
74
+ Service | Services generated & transmitted to Dispatcher.
21
75
 
76
+ Message
77
+ ================================================================
78
+ Message can be up to 64kb containing plain text describing a log
79
+ of the event
80
+
81
+ Service
82
+ ================================================================
83
+ The service via which the event name is coming or the service of
84
+ which the function is called.
85
+
86
+ Event
87
+ ================================================================
88
+ Depending on the type:
89
+
90
+ Event, Script => Event name
91
+ Call => operationId
92
+
93
+ Tracking ID
94
+ ================================================================
95
+ End to end Murano processing id.
96
+ Used to group logs together for one endpoint request.
97
+ ).strip
98
+ end
99
+
100
+ def cmd_add_logs_options(c)
22
101
  c.option '-f', '--follow', %(Follow logs from server)
23
- c.option '--[no-]pretty', %(Reformat JSON blobs in logs.)
102
+ c.option '-r', '--retry', %(Always retry the connection) unless LOGS_USE_HTTP
24
103
  c.option '--[no-]localtime', %(Adjust Timestamps to be in local time)
104
+ c.option '--[no-]pretty', %(Reformat JSON blobs in logs.)
25
105
  c.option '--raw', %(Don't do any formating of the log data)
26
- # FIXME/2017-06-23: It'd be nice to allow :all
27
- # But then we'd have to interleave output somehow with --follow,
28
- # maybe using separate threads?
106
+ return if LOGS_USE_HTTP
107
+ c.option '--tracking', %(Include start of the Murano Tracking ID)
108
+ c.option '--tracking-full', %(Include the full Murano Tracking ID)
109
+ c.option '--http', %(Use HTTP connection [deprecated; will be removed])
110
+ end
29
111
 
30
- c.action do |args, options|
31
- c.verify_arg_count!(args)
32
- options.default(pretty: true, localtime: true, raw: false, type: :application)
33
- cmd_defaults_solntype_pickers(options, :application)
34
-
35
- if options.type == :application
36
- sol = MrMurano::Application.new
37
- elsif options.type == :product
38
- sol = MrMurano::Product.new
39
- else
40
- MrMurano::Verbose.error "Unknown --type specified: #{options.type}"
41
- exit 1
42
- end
112
+ def logs_action(options)
113
+ cmd_default_logs_options(options)
114
+ cmd_defaults_solntype_pickers(options, :application)
115
+ sol = cmd_get_sol!(options)
116
+ logs_display(sol, options)
117
+ end
43
118
 
44
- if options.follow
45
- # Open a lasting connection and continually feed makePretty().
46
- begin
47
- sol.get('/logs?polling=true') do |request, http|
48
- request['Accept-Encoding'] = 'None'
49
- http.request(request) do |response|
50
- remainder = ''
51
- response.read_body do |chunk|
52
- chunk = remainder + chunk unless remainder.empty?
53
-
54
- # For all complete JSON blobs, make them pretty.
55
- chunk.gsub!(/\{(?>[^}{]+|\g<0>)*\}/m) do |m|
56
- if options.raw
57
- puts m
58
- else
59
- begin
60
- js = JSON.parse(
61
- m,
62
- allow_nan: true,
63
- symbolize_names: true,
64
- create_additions: false,
65
- )
66
- puts MrMurano::Pretties.makePretty(js, options)
67
- rescue
68
- sol.error '=== JSON parse error, showing raw instead ==='
69
- puts m
70
- end
71
- end
72
- '' #remove (we're kinda abusing gsub here.)
73
- end
74
-
75
- # Is there an incomplete one?
76
- chunk.match(/(\{.*$)/m) do |mat|
77
- remainder = mat[1]
78
- end
79
- end
80
- end
81
- end
82
- # rubocop:disable Lint/HandleExceptions: Do not suppress exceptions.
83
- rescue Interrupt => _
119
+ def cmd_default_logs_options(options)
120
+ options.default(
121
+ follow: false,
122
+ retry: false,
123
+ pretty: true,
124
+ localtime: true,
125
+ raw: false,
126
+ type: :application,
127
+ )
128
+ end
129
+
130
+ def cmd_get_sol!(options)
131
+ if options.type == :application
132
+ MrMurano::Application.new
133
+ elsif options.type == :product
134
+ MrMurano::Product.new
135
+ else
136
+ MrMurano::Verbose.error "Unknown --type specified: #{options.type}"
137
+ exit 1
138
+ end
139
+ end
140
+
141
+ def logs_display(sol, options)
142
+ if !options.follow
143
+ logs_once(sol, options)
144
+ else
145
+ logs_follow(sol, options)
146
+ end
147
+ end
148
+
149
+ def logs_once(sol, options)
150
+ ret = sol.get('/logs')
151
+ if ret.is_a?(Hash) && ret.key?(:items)
152
+ ret[:items].reverse.each do |line|
153
+ if options.raw
154
+ puts line
155
+ else
156
+ puts MrMurano::Pretties.MakePrettyLogsV1(line, options)
84
157
  end
158
+ end
159
+ else
160
+ sol.error "Could not get logs: #{ret}"
161
+ exit 1
162
+ end
163
+ end
164
+
165
+ def logs_follow(sol, options)
166
+ if !LOGS_USE_HTTP && !options.http
167
+ logs_follow_wss(sol, options)
168
+ else
169
+ logs_follow_http(sol, options)
170
+ end
171
+ end
85
172
 
86
- else
87
- ret = sol.get('/logs')
173
+ # FIXME: (landonb): MUR-3081: Remove old http code for v3.1.0. Search: LOGS_USE_HTTP.
174
+ def logs_follow_http(sol, options)
175
+ # Open a lasting connection and continually feed MakePrettyLogsV1().
176
+ sol.get('/logs?polling=true') do |request, http|
177
+ request['Accept-Encoding'] = 'None'
178
+ http.request(request) do |response|
179
+ remainder = ''
180
+ response.read_body do |chunk|
181
+ chunk = remainder + chunk unless remainder.empty?
88
182
 
89
- if ret.is_a?(Hash) && ret.key?(:items)
90
- ret[:items].reverse.each do |line|
183
+ # For all complete JSON blobs, make them pretty.
184
+ chunk.gsub!(/\{(?>[^}{]+|\g<0>)*\}/m) do |m|
91
185
  if options.raw
92
- puts line
186
+ puts m
93
187
  else
94
- puts MrMurano::Pretties.makePretty(line, options)
188
+ begin
189
+ js = JSON.parse(
190
+ m,
191
+ allow_nan: true,
192
+ symbolize_names: true,
193
+ create_additions: false,
194
+ )
195
+ puts MrMurano::Pretties.MakePrettyLogsV1(js, options)
196
+ rescue StandardError
197
+ sol.error '=== JSON parse error, showing raw instead ==='
198
+ puts m
199
+ end
95
200
  end
201
+ '' #remove (we're kinda abusing gsub here.)
202
+ end
203
+
204
+ # Is there an incomplete one?
205
+ chunk.match(/(\{.*$)/m) do |mat|
206
+ remainder = mat[1]
96
207
  end
97
- else
98
- sol.error "Couldn't get logs: #{ret}"
99
- # 2017-06-23: Shouldn't this be exit? What're we breaking out of?
100
- break
101
208
  end
102
209
  end
103
210
  end
211
+ # rubocop:disable Lint/HandleExceptions: Do not suppress exceptions.
212
+ rescue Interrupt => _
213
+ end
214
+
215
+ # LATER/2017-12-14 (landonb): Show logs from all associated solutions.
216
+ # We'll have to wire all the WebSockets from within the EM.run block.
217
+ def logs_follow_wss(sol, options)
218
+ formatter = get_formatter(options)
219
+ keep_running = true
220
+ while keep_running
221
+ keep_running = options.retry
222
+ logs = MrMurano::Logs::Follow.new
223
+ logs.run_event_loop(sol) do |line|
224
+ log_entry = parse_logs_line(line)
225
+ formatter.call(log_entry, options) unless log_entry.nil?
226
+ end
227
+ end
228
+ end
229
+
230
+ def parse_logs_line(line)
231
+ log_entry = JSON.parse(line)
232
+ elevate_hash(log_entry)
233
+ rescue StandardError => err
234
+ MrMurano::Verbose.warning "Not JSON: #{err} / #{line}"
235
+ nil
236
+ end
237
+
238
+ def get_formatter(options)
239
+ if options.raw
240
+ method(:print_raw)
241
+ else
242
+ method(:print_pretty)
243
+ end
244
+ end
245
+
246
+ def print_raw(line, _options={})
247
+ puts line
248
+ end
249
+
250
+ def print_pretty(line, options={})
251
+ puts MrMurano::Pretties.MakePrettyLogsV2(line, options)
252
+ rescue StandardError => err
253
+ MrMurano::Verbose.error "Failed to parse log: #{err} / #{line}"
254
+ raise
104
255
  end
256
+
257
+ command :logs, &method(:command_logs)
105
258
  alias_command 'logs application', 'logs', '--type', 'application'
106
259
  alias_command 'logs product', 'logs', '--type', 'product'
107
260
  alias_command 'application logs', 'logs', '--type', 'application'