openc3 7.5.0 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -0
  3. data/bin/openc3cli +82 -5
  4. data/data/config/_params.yaml +3 -0
  5. data/data/config/command_modifiers.yaml +5 -3
  6. data/data/config/default_plugins.yaml +1 -0
  7. data/data/config/interface_modifiers.yaml +17 -1
  8. data/data/config/item_modifiers.yaml +24 -1
  9. data/data/config/microservice.yaml +15 -1
  10. data/data/config/parameter_modifiers.yaml +4 -4
  11. data/data/config/plugins.yaml +511 -3
  12. data/data/config/settings.yaml +17 -0
  13. data/data/config/target.yaml +53 -0
  14. data/data/config/telemetry.yaml +58 -2
  15. data/data/config/widgets.yaml +30 -0
  16. data/lib/openc3/accessors/accessor.rb +14 -2
  17. data/lib/openc3/accessors/binary_accessor.rb +25 -5
  18. data/lib/openc3/api/CLAUDE.md +1 -0
  19. data/lib/openc3/api/api.rb +1 -0
  20. data/lib/openc3/api/cmd_api.rb +9 -1
  21. data/lib/openc3/api/interface_api.rb +7 -2
  22. data/lib/openc3/api/limits_api.rb +236 -195
  23. data/lib/openc3/api/router_api.rb +7 -2
  24. data/lib/openc3/api/settings_api.rb +4 -1
  25. data/lib/openc3/api/shared_resource_api.rb +107 -0
  26. data/lib/openc3/api/tlm_api.rb +229 -61
  27. data/lib/openc3/interfaces/http_client_interface.rb +84 -27
  28. data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +6 -2
  29. data/lib/openc3/interfaces/tcpip_server_interface.rb +205 -125
  30. data/lib/openc3/io/json_api.rb +2 -10
  31. data/lib/openc3/io/json_api_object.rb +2 -10
  32. data/lib/openc3/logs/log_writer.rb +9 -8
  33. data/lib/openc3/logs/packet_log_writer.rb +8 -3
  34. data/lib/openc3/microservices/decom_common.rb +4 -1
  35. data/lib/openc3/microservices/decom_microservice.rb +73 -5
  36. data/lib/openc3/microservices/interface_decom_common.rb +16 -1
  37. data/lib/openc3/microservices/interface_microservice.rb +50 -11
  38. data/lib/openc3/microservices/limits_group_microservice.rb +513 -0
  39. data/lib/openc3/microservices/log_microservice.rb +22 -8
  40. data/lib/openc3/microservices/microservice.rb +8 -2
  41. data/lib/openc3/microservices/multi_microservice.rb +76 -22
  42. data/lib/openc3/microservices/queue_microservice.rb +29 -24
  43. data/lib/openc3/migrations/20260704000000_default_bridge.rb +1 -2
  44. data/lib/openc3/migrations/20261103000001_limits_group_backfill.rb +193 -0
  45. data/lib/openc3/models/bridge_model.rb +3 -3
  46. data/lib/openc3/models/cvt_model.rb +10 -3
  47. data/lib/openc3/models/host_interface_microservice_model.rb +4 -4
  48. data/lib/openc3/models/interface_model.rb +27 -7
  49. data/lib/openc3/models/microservice_group.rb +167 -0
  50. data/lib/openc3/models/microservice_model.rb +88 -2
  51. data/lib/openc3/models/panel_model.rb +109 -0
  52. data/lib/openc3/models/plugin_model.rb +1006 -26
  53. data/lib/openc3/models/plugin_store_model.rb +6 -1
  54. data/lib/openc3/models/protected_storage_model.rb +64 -0
  55. data/lib/openc3/models/queue_model.rb +19 -10
  56. data/lib/openc3/models/scope_model.rb +80 -3
  57. data/lib/openc3/models/setting_model.rb +2 -2
  58. data/lib/openc3/models/shared_resource_model.rb +381 -0
  59. data/lib/openc3/models/target_model.rb +333 -74
  60. data/lib/openc3/operators/microservice_operator.rb +76 -9
  61. data/lib/openc3/operators/operator.rb +29 -0
  62. data/lib/openc3/packets/commands.rb +16 -16
  63. data/lib/openc3/packets/limits.rb +2 -0
  64. data/lib/openc3/packets/packet.rb +75 -4
  65. data/lib/openc3/packets/packet_config.rb +152 -13
  66. data/lib/openc3/packets/packet_item.rb +48 -22
  67. data/lib/openc3/packets/packet_item_limits.rb +67 -6
  68. data/lib/openc3/packets/parsers/limits_parser.rb +69 -2
  69. data/lib/openc3/packets/parsers/packet_item_parser.rb +6 -0
  70. data/lib/openc3/packets/parsers/packet_parser.rb +45 -0
  71. data/lib/openc3/packets/parsers/state_parser.rb +1 -1
  72. data/lib/openc3/script/CLAUDE.md +1 -0
  73. data/lib/openc3/script/api_shared.rb +27 -17
  74. data/lib/openc3/script/calendar.rb +18 -6
  75. data/lib/openc3/script/commands.rb +11 -9
  76. data/lib/openc3/script/critical_cmd.rb +22 -2
  77. data/lib/openc3/script/extract.rb +52 -5
  78. data/lib/openc3/script/metadata.rb +30 -4
  79. data/lib/openc3/script/plugins.rb +8 -0
  80. data/lib/openc3/script/script.rb +9 -25
  81. data/lib/openc3/script/web_socket_api.rb +23 -17
  82. data/lib/openc3/system/system.rb +9 -3
  83. data/lib/openc3/top_level.rb +17 -0
  84. data/lib/openc3/topics/command_topic.rb +7 -1
  85. data/lib/openc3/topics/decom_interface_topic.rb +9 -3
  86. data/lib/openc3/topics/discovery_topic.rb +84 -0
  87. data/lib/openc3/topics/limits_event_topic.rb +317 -11
  88. data/lib/openc3/topics/router_topic.rb +6 -2
  89. data/lib/openc3/topics/system_events_topic.rb +9 -6
  90. data/lib/openc3/topics/telemetry_decom_topic.rb +12 -3
  91. data/lib/openc3/topics/topic.rb +9 -1
  92. data/lib/openc3/utilities/authentication.rb +67 -16
  93. data/lib/openc3/utilities/bucket.rb +5 -0
  94. data/lib/openc3/utilities/cli_generator.rb +117 -25
  95. data/lib/openc3/utilities/client_ip_header_filter.rb +38 -0
  96. data/lib/openc3/utilities/config_overlay.rb +24 -1
  97. data/lib/openc3/utilities/cosmos_rails_formatter.rb +18 -10
  98. data/lib/openc3/utilities/hardware_discovery.rb +279 -0
  99. data/lib/openc3/utilities/limits_rollup.rb +81 -0
  100. data/lib/openc3/utilities/local_mode.rb +48 -5
  101. data/lib/openc3/utilities/questdb_client.rb +256 -54
  102. data/lib/openc3/utilities/reingest_job.rb +12 -3
  103. data/lib/openc3/utilities/running_script.rb +206 -49
  104. data/lib/openc3/utilities/script.rb +24 -12
  105. data/lib/openc3/utilities/script_env.rb +164 -0
  106. data/lib/openc3/utilities/script_message_signing.rb +133 -0
  107. data/lib/openc3/utilities/secrets.rb +5 -0
  108. data/lib/openc3/utilities/store_autoload.rb +35 -2
  109. data/lib/openc3/utilities/store_queued.rb +5 -1
  110. data/lib/openc3/version.rb +5 -5
  111. data/templates/command_validator/command_validator.py +9 -9
  112. data/templates/{tool_react/pnpm-workspace.yaml → panel/.prettierrc.cjs} +7 -5
  113. data/templates/panel/Rakefile +24 -0
  114. data/templates/panel/package.json +17 -0
  115. data/templates/{tool_angular → panel}/pnpm-workspace.yaml +5 -0
  116. data/templates/panel/src/Panel.js +52 -0
  117. data/templates/panel/src/Panel.vue +60 -0
  118. data/templates/panel/src/panelSdk.js +24 -0
  119. data/templates/panel/vite-Panel.config.js +43 -0
  120. data/templates/tool_vue/package.json +3 -3
  121. data/templates/widget/package.json +2 -2
  122. metadata +24 -56
  123. data/templates/tool_angular/.editorconfig +0 -16
  124. data/templates/tool_angular/.gitignore +0 -44
  125. data/templates/tool_angular/.vscode/extensions.json +0 -4
  126. data/templates/tool_angular/.vscode/launch.json +0 -20
  127. data/templates/tool_angular/.vscode/tasks.json +0 -42
  128. data/templates/tool_angular/angular.json +0 -111
  129. data/templates/tool_angular/extra-webpack.config.js +0 -8
  130. data/templates/tool_angular/package.json +0 -48
  131. data/templates/tool_angular/src/app/app-routing.module.ts +0 -15
  132. data/templates/tool_angular/src/app/app.component.html +0 -22
  133. data/templates/tool_angular/src/app/app.component.scss +0 -18
  134. data/templates/tool_angular/src/app/app.component.spec.ts +0 -29
  135. data/templates/tool_angular/src/app/app.component.ts +0 -52
  136. data/templates/tool_angular/src/app/app.module.ts +0 -30
  137. data/templates/tool_angular/src/app/custom-overlay-container.ts +0 -17
  138. data/templates/tool_angular/src/app/empty-route/empty-route.component.ts +0 -7
  139. data/templates/tool_angular/src/app/openc3-api.d.ts +0 -1
  140. data/templates/tool_angular/src/assets/.gitkeep +0 -0
  141. data/templates/tool_angular/src/environments/environment.prod.ts +0 -3
  142. data/templates/tool_angular/src/environments/environment.ts +0 -16
  143. data/templates/tool_angular/src/favicon.ico +0 -0
  144. data/templates/tool_angular/src/index.html +0 -13
  145. data/templates/tool_angular/src/main.single-spa.ts +0 -40
  146. data/templates/tool_angular/src/single-spa/asset-url.ts +0 -12
  147. data/templates/tool_angular/src/single-spa/single-spa-props.ts +0 -8
  148. data/templates/tool_angular/src/styles.scss +0 -1
  149. data/templates/tool_angular/tsconfig.app.json +0 -13
  150. data/templates/tool_angular/tsconfig.json +0 -33
  151. data/templates/tool_angular/tsconfig.spec.json +0 -14
  152. data/templates/tool_react/.eslintrc +0 -7
  153. data/templates/tool_react/.gitignore +0 -71
  154. data/templates/tool_react/.prettierignore +0 -8
  155. data/templates/tool_react/babel.config.json +0 -29
  156. data/templates/tool_react/jest.config.js +0 -12
  157. data/templates/tool_react/package.json +0 -51
  158. data/templates/tool_react/src/openc3-tool_name.js +0 -24
  159. data/templates/tool_react/src/root.component.js +0 -88
  160. data/templates/tool_react/src/root.component.test.js +0 -9
  161. data/templates/tool_react/webpack.config.js +0 -27
  162. data/templates/tool_svelte/.gitignore +0 -71
  163. data/templates/tool_svelte/.prettierignore +0 -8
  164. data/templates/tool_svelte/.prettierrc.js +0 -5
  165. data/templates/tool_svelte/babel.config.js +0 -12
  166. data/templates/tool_svelte/build/smui.css +0 -1
  167. data/templates/tool_svelte/jest.config.js +0 -9
  168. data/templates/tool_svelte/package.json +0 -49
  169. data/templates/tool_svelte/pnpm-workspace.yaml +0 -20
  170. data/templates/tool_svelte/rollup.config.js +0 -74
  171. data/templates/tool_svelte/src/App.svelte +0 -42
  172. data/templates/tool_svelte/src/App.test.js +0 -9
  173. data/templates/tool_svelte/src/theme/_smui-theme.scss +0 -25
  174. data/templates/tool_svelte/src/tool_name.js +0 -17
  175. data/templates/widget/LICENSE.md +0 -20
@@ -0,0 +1,279 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2026 OpenC3, Inc.
4
+ # All Rights Reserved.
5
+ #
6
+ # This program is distributed in the hope that it will be useful,
7
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
8
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
+ # See LICENSE.md for more details.
10
+ #
11
+ # This file may also be used under the terms of a commercial license
12
+ # if purchased from OpenC3, Inc.
13
+
14
+ require 'json'
15
+ require 'openc3/models/bridge_model'
16
+ require 'openc3/models/gem_model'
17
+ require 'openc3/models/plugin_model'
18
+ require 'openc3/models/plugin_store_model'
19
+ require 'openc3/topics/discovery_topic'
20
+
21
+ module OpenC3
22
+ # Hardware discovery scans the hosts connected through bridges for devices and
23
+ # proposes plugins to install for them. Plugins are matched by the hardware
24
+ # their plugin.txt can discover (PluginModel.discovery_matchers): plugins in
25
+ # the OpenC3 Store, which computes their matchers when they're uploaded, and
26
+ # plugins already installed in COSMOS, which can be installed again for
27
+ # another device.
28
+ module HardwareDiscovery
29
+ # Seconds to wait for a host to scan. Scanning takes about 10s.
30
+ SCAN_TIMEOUT_S = 40
31
+
32
+ # Matchers of installed plugin gems by gem filename. Gem files don't change
33
+ # once uploaded so this only grows with new versions.
34
+ @gem_matchers = {}
35
+ @gem_matchers_mutex = Mutex.new
36
+
37
+ # Scan the host of one bridge, or every paired bridge with 'ALL', and
38
+ # propose plugins for the devices found
39
+ #
40
+ # @return [Hash] 'devices' found with their 'candidates' (plugins to
41
+ # install), 'errors' scanning, the number of matchers 'skipped' and
42
+ # whether the OpenC3 Store provided any matchers ('store_matchers')
43
+ def self.scan(bridge: 'DEFAULT', scope:)
44
+ sources = plugin_sources(scope: scope)
45
+ matchers, candidates_by_id = unique_matchers(sources)
46
+ bridges = bridge_names(bridge, scope: scope)
47
+ if bridges.empty?
48
+ raise "No bridge is paired with openc3-cosmos-app" if bridge.to_s.upcase == 'ALL'
49
+ raise "Bridge '#{bridge.to_s.upcase}' is not paired with openc3-cosmos-app"
50
+ end
51
+
52
+ results = {}
53
+ bridges.map do |bridge_name|
54
+ Thread.new do
55
+ results[bridge_name] = DiscoveryTopic.scan(bridge_name, { 'matchers' => matchers }, timeout: SCAN_TIMEOUT_S, scope: scope)
56
+ rescue => error
57
+ results[bridge_name] = { 'error' => error.message }
58
+ end
59
+ end.each(&:join)
60
+
61
+ devices = []
62
+ errors = []
63
+ skipped = 0
64
+ bridges.each do |bridge_name|
65
+ result = results[bridge_name]
66
+ if result['error']
67
+ errors << { 'bridge' => bridge_name, 'message' => result['error'] }
68
+ next
69
+ end
70
+ (result['errors'] || {}).each do |discovery_class, message|
71
+ errors << { 'bridge' => bridge_name, 'class' => discovery_class, 'message' => message }
72
+ end
73
+ skipped += (result['skipped'] || {}).length
74
+ claims = Hash.new do |hash, discovery_class|
75
+ hash[discovery_class] = PluginModel.discovery_claims(bridge_name, discovery_class, scope: scope)
76
+ end
77
+ (result['devices'] || []).each do |device|
78
+ devices << device_proposal(bridge_name, device, candidates_by_id, claims)
79
+ end
80
+ end
81
+ {
82
+ 'devices' => devices,
83
+ 'errors' => errors,
84
+ 'skipped' => skipped,
85
+ 'store_matchers' => sources.any? { |source| source['source'] == 'store' and !source['matchers'].empty? },
86
+ }
87
+ end
88
+
89
+ # The plugins that can be proposed, each with its matchers: OpenC3 Store
90
+ # plugins with discovery data, then installed plugins not already offered
91
+ # by the store
92
+ def self.plugin_sources(scope:)
93
+ installed = PluginModel.all(scope: scope)
94
+ installed_gems = installed.keys.map { |name| name.split('__')[0] }.uniq
95
+ installed_names = installed_gems.map { |gem| gem_name(gem) }
96
+ installed_store_ids = installed.values.map { |plugin| plugin['store_plugin_id'] }.compact
97
+
98
+ sources = []
99
+ store_plugins.each do |plugin|
100
+ matchers = store_matchers(plugin)
101
+ next if matchers.empty?
102
+ name = gem_name(plugin['gem_filename'].to_s)
103
+ sources << {
104
+ 'source' => 'store',
105
+ 'store_id' => plugin['id'],
106
+ 'store_version_id' => plugin['current_version_id'],
107
+ 'name' => name,
108
+ 'title' => plugin['title'],
109
+ 'image_url' => plugin['image_url'],
110
+ 'entitled' => plugin.fetch('entitled', true) != false,
111
+ 'installed' => installed_store_ids.include?(plugin['id']) || installed_names.include?(name),
112
+ 'matchers' => matchers,
113
+ }
114
+ end
115
+ store_names = sources.map { |source| source['name'] }
116
+ installed_gems.each do |gem|
117
+ next if store_names.include?(gem_name(gem))
118
+ matchers = gem_discovery_matchers(gem, scope: scope)
119
+ next if matchers.empty?
120
+ sources << {
121
+ 'source' => 'installed',
122
+ 'gem' => gem,
123
+ 'name' => gem_name(gem),
124
+ 'title' => gem_name(gem),
125
+ 'entitled' => true,
126
+ 'installed' => true,
127
+ 'matchers' => matchers,
128
+ }
129
+ end
130
+ sources
131
+ end
132
+
133
+ # The OpenC3 Store catalog, or none if it can't be read
134
+ def self.store_plugins
135
+ plugins = JSON.parse(PluginStoreModel.all || '[]')
136
+ plugins.is_a?(Array) ? plugins : []
137
+ rescue JSON::ParserError
138
+ []
139
+ end
140
+
141
+ # The matchers the Store computed for a plugin, if they're in a format this
142
+ # COSMOS understands. The Store bumps the format when matchers change
143
+ # meaning, which older COSMOS versions must not guess at.
144
+ def self.store_matchers(plugin)
145
+ discovery = plugin['discovery']
146
+ return [] unless discovery.is_a?(Hash) and discovery['format'] == PluginModel::DISCOVERY_MATCHERS_FORMAT
147
+
148
+ Array(discovery['matchers']).select { |matcher| matcher.is_a?(Hash) and matcher['class'].is_a?(String) and matcher['variable'].is_a?(String) }
149
+ end
150
+
151
+ # The matchers of an installed plugin gem, from its plugin.txt
152
+ def self.gem_discovery_matchers(gem, scope:)
153
+ @gem_matchers_mutex.synchronize do
154
+ return @gem_matchers[gem] if @gem_matchers.key?(gem)
155
+ variables = PluginModel.install_phase1(GemModel.get(gem), validate_only: true, scope: scope)['variables']
156
+ # plugin.txt is read as binary but its titles are UTF-8 text, as the store's are
157
+ # Only successful reads are cached so a failure is retried on the next scan
158
+ @gem_matchers[gem] = utf8(PluginModel.discovery_matchers(variables)['matchers'])
159
+ rescue => error
160
+ Logger.warn("Hardware discovery could not read the plugin.txt of #{gem}: #{error.message}", scope: scope)
161
+ []
162
+ end
163
+ end
164
+
165
+ # Each distinct discovery (class and parameters) is checked once on the
166
+ # host, though many plugins may use it. Returns the matchers to send and
167
+ # the plugin candidates for each matcher id.
168
+ def self.unique_matchers(sources)
169
+ ids = {}
170
+ candidates_by_id = Hash.new { |hash, id| hash[id] = [] }
171
+ sources.each do |source|
172
+ source['matchers'].each do |matcher|
173
+ key = [PluginModel.discovery_class_key(matcher['class']), Array(matcher['params'])]
174
+ id = (ids[key] ||= (ids.length + 1).to_s)
175
+ candidates_by_id[id] << [source, matcher]
176
+ end
177
+ end
178
+ matchers = ids.map { |(discovery_class, params), id| { 'id' => id, 'class' => discovery_class, 'params' => params } }
179
+ [matchers, candidates_by_id]
180
+ end
181
+
182
+ def self.bridge_names(bridge, scope:)
183
+ bridge = bridge.to_s.upcase
184
+ paired = BridgeModel.all(scope: scope).select { |_name, model| model['app_public_key'] }.keys.sort
185
+ return paired if bridge == 'ALL'
186
+ paired.include?(bridge) ? [bridge] : []
187
+ end
188
+
189
+ # A device found on a host with the plugins proposed for it, most specific
190
+ # match first
191
+ def self.device_proposal(bridge_name, device, candidates_by_id, claims)
192
+ discovery_class = device['class']
193
+ matched_params = Hash(device['matched_params'])
194
+ candidates = Array(device['matches']).flat_map do |id|
195
+ candidates_by_id[id].map do |source, matcher|
196
+ variables = Hash(matcher['set']).merge(matcher['variable'] => device['value'], PluginModel::BRIDGE_VARIABLE_NAME => bridge_name)
197
+ candidate = source.slice('source', 'store_id', 'store_version_id', 'gem', 'name', 'title', 'image_url', 'entitled', 'installed').compact
198
+ # Rated by the parameters the device matched when the host says
199
+ # which (a matcher's parameters are usually alternatives)
200
+ params = Array(matcher['params'])
201
+ indexes = matched_params[id.to_s]
202
+ params = params.values_at(*indexes).compact if indexes.is_a?(Array) and !indexes.empty?
203
+ candidate.merge(
204
+ 'match_title' => matcher['title'],
205
+ 'variables' => variables,
206
+ 'specificity' => specificity(discovery_class, params),
207
+ 'possible' => name_pattern_only?(discovery_class, params),
208
+ )
209
+ end
210
+ end
211
+ # A plugin matched more than once for the device keeps its best match,
212
+ # and matches by a name pattern alone come after the others
213
+ candidates = candidates.sort_by { |candidate| [candidate['possible'] ? 1 : 0, -candidate['specificity'], candidate['title'].to_s.downcase] }
214
+ candidates = candidates.uniq { |candidate| [candidate['source'], candidate['name'], candidate['match_title'], candidate['variables']] }
215
+ {
216
+ 'bridge' => bridge_name,
217
+ 'class' => discovery_class,
218
+ 'value' => device['value'],
219
+ 'text' => device['text'],
220
+ 'details' => device['details'] || {},
221
+ 'claimed_by' => claims[discovery_class][device['value'].to_s],
222
+ 'candidates' => candidates,
223
+ }
224
+ end
225
+
226
+ # How specifically a matcher identifies hardware, so an exact USB product
227
+ # ranks above a USB serial chip many devices use
228
+ def self.specificity(discovery_class, params)
229
+ case discovery_class.split('.').last
230
+ when 'serial_discovery'
231
+ params.map { |param| param =~ /:[0-9A-Fa-f]+\z/ ? 2 : 1 }.max || 0
232
+ when 'hid_discovery'
233
+ params.count { |param| !%w(0 0x0 nil none).include?(param.to_s.strip.downcase) && !param.to_s.strip.empty? }
234
+ when 'usb_discovery'
235
+ # |-separated conditions where a VID:PID is two (vendor and product)
236
+ params.map { |param| param.split('|').sum { |condition| condition =~ /\A\h+:\h+\z/ ? 2 : 1 } }.max || 0
237
+ else
238
+ # zeroconf, bluetooth, ssdp and neighbor matchers are |-separated conditions
239
+ params.map { |param| param.split('|').length }.max || 0
240
+ end
241
+ end
242
+
243
+ # The conditions that only match a device's name, by discovery class
244
+ NAME_CONDITIONS = {
245
+ 'bluetooth_discovery' => %w(local_name),
246
+ 'neighbor_discovery' => %w(hostname),
247
+ 'usb_discovery' => %w(manufacturer product),
248
+ 'ssdp_discovery' => %w(friendlyname),
249
+ }
250
+
251
+ # Whether a match is only by a name pattern (e.g. a Bluetooth local_name of
252
+ # Govee*), which other devices from the same maker can share, so the plugin
253
+ # may not support the device
254
+ def self.name_pattern_only?(discovery_class, params)
255
+ keys = NAME_CONDITIONS[discovery_class.to_s.split('.').last]
256
+ return false if keys.nil? or params.empty?
257
+ params.all? do |param|
258
+ param.to_s.split('|').all? do |condition|
259
+ key, glob = condition.split('=', 2)
260
+ keys.include?(key.to_s.strip.downcase) and glob.to_s.match?(/[*?\[]/)
261
+ end
262
+ end
263
+ end
264
+
265
+ def self.utf8(value)
266
+ case value
267
+ when String then value.dup.force_encoding('UTF-8')
268
+ when Array then value.map { |item| utf8(item) }
269
+ when Hash then value.to_h { |key, item| [utf8(key), utf8(item)] }
270
+ else value
271
+ end
272
+ end
273
+
274
+ # A gem's name without its version, e.g. openc3-cosmos-demo
275
+ def self.gem_name(gem_filename)
276
+ File.basename(gem_filename.to_s, '.gem').sub(/-\d[\w.]*\z/, '')
277
+ end
278
+ end
279
+ end
@@ -0,0 +1,81 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2026 OpenC3, Inc.
4
+ # All Rights Reserved.
5
+ #
6
+ # This program is distributed in the hope that it will be useful,
7
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
8
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
+ # See LICENSE.md for more details.
10
+
11
+ # This file may also be used under the terms of a commercial license
12
+ # if purchased from OpenC3, Inc.
13
+
14
+ module OpenC3
15
+ # Reduces item limits states to a single color. Shared by
16
+ # get_overall_limits_state and the limits group rollup so they rank
17
+ # states the same way. Keep in sync with python/openc3/utilities/limits_rollup.py
18
+ module LimitsRollup
19
+ COLORS = {
20
+ 'RED' => 'RED', 'RED_HIGH' => 'RED', 'RED_LOW' => 'RED',
21
+ 'YELLOW' => 'YELLOW', 'YELLOW_HIGH' => 'YELLOW', 'YELLOW_LOW' => 'YELLOW',
22
+ 'GREEN' => 'GREEN', 'GREEN_HIGH' => 'GREEN', 'GREEN_LOW' => 'GREEN',
23
+ 'BLUE' => 'BLUE',
24
+ }.freeze
25
+ # BLUE ranks below GREEN so a rollup is only BLUE when every state is BLUE
26
+ SEVERITY = { 'BLUE' => -1, 'GREEN' => 0, 'YELLOW' => 1, 'RED' => 2 }.freeze
27
+ # A group whose members all have limits disabled
28
+ DISABLED = 'DISABLED'.freeze
29
+ # Whether limits are enabled on a group's members: all, none, or some of them
30
+ ENABLED_TRUE = 'TRUE'.freeze
31
+ ENABLED_FALSE = 'FALSE'.freeze
32
+ ENABLED_PARTIAL = 'PARTIAL'.freeze
33
+
34
+ # @param state [String, nil] An item limits state such as RED_HIGH or BLUE
35
+ # @return [String, nil] 'BLUE', 'GREEN', 'YELLOW' or 'RED', or nil for a missing or unknown state
36
+ def self.color(state)
37
+ COLORS[state]
38
+ end
39
+
40
+ # @param states [Array<String, nil>] Item limits states
41
+ # @return [String, nil] The most severe color, or nil if no state counts
42
+ def self.worst(states)
43
+ states.map { |state| color(state) }.compact.max_by { |color| SEVERITY[color] }
44
+ end
45
+
46
+ # @param enabled [Boolean, String] true or false for an item, or
47
+ # ENABLED_TRUE, ENABLED_FALSE or ENABLED_PARTIAL for a nested group
48
+ # @return [String] ENABLED_TRUE, ENABLED_FALSE or ENABLED_PARTIAL
49
+ def self.enabled_state(enabled)
50
+ case enabled
51
+ when true then ENABLED_TRUE
52
+ when false, nil then ENABLED_FALSE
53
+ else enabled
54
+ end
55
+ end
56
+
57
+ # Roll up a limits group from its members.
58
+ #
59
+ # The group is enabled (ENABLED_TRUE) when every member is, disabled
60
+ # (ENABLED_FALSE) when no member is or the group is empty, and otherwise
61
+ # ENABLED_PARTIAL. A disabled group's state is DISABLED. Otherwise it's the
62
+ # most severe state of the members which aren't disabled, ignoring missing states.
63
+ #
64
+ # @param members [Array<Array(String|nil, Boolean|String)>] [limits_state, enabled]
65
+ # per member. Items pass true or false for enabled, nested groups pass
66
+ # their rolled up [state, enabled].
67
+ # @return [Array(String|nil, String)] [state, enabled] where state is nil
68
+ # when no member which counts has a state
69
+ def self.rollup(members)
70
+ members = members.map { |state, enabled| [state, enabled_state(enabled)] }
71
+ enabled_states = members.map { |_state, enabled| enabled }.uniq
72
+ if enabled_states.empty? or enabled_states == [ENABLED_FALSE]
73
+ return [DISABLED, ENABLED_FALSE]
74
+ end
75
+
76
+ enabled = enabled_states == [ENABLED_TRUE] ? ENABLED_TRUE : ENABLED_PARTIAL
77
+ states = members.reject { |_state, member_enabled| member_enabled == ENABLED_FALSE }.map { |state, _enabled| state }
78
+ return [worst(states), enabled]
79
+ end
80
+ end
81
+ end
@@ -47,6 +47,7 @@ module OpenC3
47
47
 
48
48
  if gems.length == 1 and plugin_instance
49
49
  # If one gem file and plugin_instance.json - Install instance
50
+ restore_local_uploads(full_folder_path, scope: scope_dir.upcase)
50
51
  load_plugin(gems[0], scope: scope_dir.upcase, plugin_hash_file: plugin_instance)
51
52
  elsif gems.length == 1
52
53
  # Else If just gem - Install with default settings
@@ -191,6 +192,7 @@ module OpenC3
191
192
  File.open(File.join(File.dirname(plugin_file_path), 'plugin_instance.json'), 'wb') do |file|
192
193
  file.write(JSON.pretty_generate(plugin_hash, allow_nan: true))
193
194
  end
195
+ save_local_uploads(File.dirname(plugin_file_path), plugin_hash, scope: scope)
194
196
  else
195
197
  # From online install / update
196
198
  # Or init install of container plugin
@@ -219,7 +221,7 @@ module OpenC3
219
221
  if json["name"] == old_plugin_name
220
222
  # Found plugin to update
221
223
  found = true
222
- update_local_plugin_files(full_folder_path, plugin_file_path, plugin_hash, gem_name)
224
+ update_local_plugin_files(full_folder_path, plugin_file_path, plugin_hash, gem_name, scope: scope)
223
225
  end
224
226
  else
225
227
  # New install of same plugin - Leave it alone
@@ -229,7 +231,7 @@ module OpenC3
229
231
  # This shouldn't happen without users using this wrong
230
232
  # We will update
231
233
  found = true
232
- update_local_plugin_files(full_folder_path, plugin_file_path, plugin_hash, gem_name)
234
+ update_local_plugin_files(full_folder_path, plugin_file_path, plugin_hash, gem_name, scope: scope)
233
235
  end
234
236
  end
235
237
  end
@@ -245,13 +247,13 @@ module OpenC3
245
247
  count += 1
246
248
  end
247
249
  full_folder_path = "#{OPENC3_LOCAL_MODE_PATH}/#{scope}/#{folder_name}"
248
- update_local_plugin_files(full_folder_path, plugin_file_path, plugin_hash, gem_name)
250
+ update_local_plugin_files(full_folder_path, plugin_file_path, plugin_hash, gem_name, scope: scope)
249
251
  end
250
252
  end
251
253
  end
252
254
  end
253
255
 
254
- def self.update_local_plugin_files(full_folder_path, plugin_file_path, plugin_hash, gem_name)
256
+ def self.update_local_plugin_files(full_folder_path, plugin_file_path, plugin_hash, gem_name, scope: nil)
255
257
  return if DefaultPlugins::NAMES.include?(gem_name)
256
258
  puts "Updating local plugin files: #{full_folder_path}"
257
259
  FileUtils.mkdir_p(full_folder_path)
@@ -271,11 +273,45 @@ module OpenC3
271
273
  File.open(File.join(full_folder_path, 'plugin_instance.json'), 'wb') do |file|
272
274
  file.write(JSON.pretty_generate(plugin_hash, allow_nan: true))
273
275
  end
276
+ save_local_uploads(full_folder_path, plugin_hash, scope: scope) if scope
274
277
  ensure
275
278
  FileUtils.remove_entry_secure(temp_dir, true)
276
279
  end
277
280
  end
278
281
 
282
+ # Files uploaded for VARIABLE_FILE variables are kept in the bucket, so
283
+ # they're also saved in the local plugin folder (plugin_uploads/<id>/<file>)
284
+ # beside plugin_instance.json. Then a fresh clone, or a bucket that was
285
+ # wiped, can install the plugin again.
286
+ def self.save_local_uploads(full_folder_path, plugin_hash, scope:)
287
+ uploads_path = File.join(full_folder_path, PluginModel::UPLOADS_PATH)
288
+ FileUtils.rm_rf(uploads_path)
289
+ (plugin_hash['variables'] || {}).each do |name, variable|
290
+ next unless variable.is_a?(Hash) and variable['type'] == PluginModel::FILE_VARIABLE_TYPE
291
+ key = PluginModel.upload_key(variable['value'], scope: scope)
292
+ next unless key
293
+ path = File.join(uploads_path, variable['value'])
294
+ FileUtils.mkdir_p(File.dirname(path))
295
+ Bucket.getClient().get_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: key, path: path)
296
+ puts "Could not save the file uploaded for VARIABLE_FILE #{name} locally" unless File.exist?(path)
297
+ end
298
+ end
299
+
300
+ # Put the uploads saved in a local plugin folder back in the bucket
301
+ # before the plugin is installed from its plugin_instance.json
302
+ def self.restore_local_uploads(full_folder_path, scope:)
303
+ uploads_path = File.join(full_folder_path, PluginModel::UPLOADS_PATH)
304
+ return unless File.directory?(uploads_path)
305
+ Dir.glob("#{uploads_path}/*/*").each do |path|
306
+ next unless File.file?(path)
307
+ key = PluginModel.upload_key(path.delete_prefix("#{uploads_path}/"), scope: scope)
308
+ next unless key
309
+ File.open(path, 'rb') do |file|
310
+ Bucket.getClient().put_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: key, body: file)
311
+ end
312
+ end
313
+ end
314
+
279
315
  def self.remove_local_plugin(plugin_name, scope:)
280
316
  local_plugins = scan_local_mode()
281
317
  scope_local_plugins = local_plugins[scope]
@@ -291,6 +327,7 @@ module OpenC3
291
327
  puts "Removing local plugin files: #{full_folder_path}"
292
328
  File.delete(gems[0])
293
329
  File.delete(plugin_instance)
330
+ FileUtils.rm_rf(File.join(full_folder_path, PluginModel::UPLOADS_PATH))
294
331
  if Dir.empty?(File.dirname(gems[0]))
295
332
  FileUtils.rm_rf(File.dirname(gems[0]))
296
333
  end
@@ -587,8 +624,14 @@ module OpenC3
587
624
  FileUtils.mkdir_p(local_folder_path)
588
625
  Dir.glob(local_folder_path + "/**/*").each do |filename|
589
626
  next if File.directory?(filename)
627
+
590
628
  mod_filename = filename[prefix_length..-1]
591
- local_catalog[mod_filename] = File.size(filename)
629
+ begin
630
+ local_catalog[mod_filename] = File.size(filename)
631
+ rescue Errno::ENOENT
632
+ # Deleted by another request after the glob listed it, so it's no
633
+ # longer part of the catalog
634
+ end
592
635
  end
593
636
  return local_catalog
594
637
  end