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
@@ -117,6 +117,7 @@ module OpenC3
117
117
  # "scope": "openid email profile"
118
118
  # }
119
119
 
120
+ FORM_URLENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded'
120
121
  REFRESH_OFFSET_SECONDS = 60
121
122
 
122
123
  attr_reader :refresh_token
@@ -131,6 +132,11 @@ module OpenC3
131
132
  @token = nil
132
133
  @log = [nil, nil]
133
134
  @http = Faraday.new
135
+ # Capture the credentials now: script processes remove OPENC3_API_PASSWORD
136
+ # from ENV (ScriptEnv.clear_credentials) before user code runs, which is
137
+ # before the first token request and any later re-login.
138
+ @api_user = ENV.fetch('OPENC3_API_USER', nil)
139
+ @api_password = ENV.fetch('OPENC3_API_PASSWORD', nil)
134
140
  end
135
141
 
136
142
  # Load the token from the environment
@@ -138,7 +144,11 @@ module OpenC3
138
144
  @auth_mutex.synchronize do
139
145
  @log = [nil, nil]
140
146
  current_time = Time.now.to_i
141
- if @token.nil?
147
+ if client_secret
148
+ if @token.nil? || @expires_at.nil? || @expires_at < current_time
149
+ _make_token(current_time, openid_scope: openid_scope)
150
+ end
151
+ elsif @token.nil?
142
152
  _make_token(current_time, openid_scope: openid_scope)
143
153
  elsif @refresh_expires_at < current_time
144
154
  _make_token(current_time, openid_scope: openid_scope)
@@ -166,20 +176,59 @@ module OpenC3
166
176
 
167
177
  private
168
178
 
179
+ def client_secret
180
+ secret = ENV.fetch('OPENC3_API_CLIENT_SECRET', nil)
181
+ return nil if secret.nil? || secret.empty?
182
+ secret
183
+ end
184
+
185
+ # Credentials captured at initialize, falling back to ENV when they were set later
186
+ def api_user
187
+ @api_user || ENV.fetch('OPENC3_API_USER', nil)
188
+ end
189
+
190
+ def api_password
191
+ @api_password || ENV.fetch('OPENC3_API_PASSWORD', nil)
192
+ end
193
+
194
+ def redacted_log_data(data)
195
+ log_data = data.dup
196
+ %w[password client_secret refresh_token].each do |secret_key|
197
+ log_data[secret_key] = '***' if log_data.key?(secret_key)
198
+ end
199
+ log_data.inspect
200
+ end
201
+
169
202
  # Make the token and save token to instance
170
203
  def _make_token(current_time, openid_scope: 'openid')
171
204
  client_id = ENV['OPENC3_API_CLIENT'] || 'api'
172
- if ENV['OPENC3_API_USER'] and ENV['OPENC3_API_PASSWORD']
205
+ if client_secret
206
+ data = {
207
+ 'client_id' => client_id,
208
+ 'client_secret' => client_secret,
209
+ 'grant_type' => 'client_credentials',
210
+ 'scope' => openid_scope
211
+ }
212
+ headers = {
213
+ 'Content-Type' => FORM_URLENCODED_CONTENT_TYPE,
214
+ 'User-Agent' => "OpenC3KeycloakAuthorization / #{OPENC3_VERSION} (ruby/openc3/lib/utilities/authentication)",
215
+ }
216
+ oath = _make_request(headers, data)
217
+ @token = oath['access_token']
218
+ @refresh_token = nil
219
+ @expires_at = current_time + oath['expires_in'] - REFRESH_OFFSET_SECONDS
220
+ @refresh_expires_at = nil
221
+ elsif api_user and api_password
173
222
  # Username and password
174
223
  data = {
175
- 'username' => ENV.fetch('OPENC3_API_USER', nil),
176
- 'password' => ENV.fetch('OPENC3_API_PASSWORD', nil),
224
+ 'username' => api_user,
225
+ 'password' => api_password,
177
226
  'client_id' => client_id,
178
227
  'grant_type' => 'password',
179
228
  'scope' => openid_scope
180
229
  }
181
230
  headers = {
182
- 'Content-Type' => 'application/x-www-form-urlencoded',
231
+ 'Content-Type' => FORM_URLENCODED_CONTENT_TYPE,
183
232
  'User-Agent' => "OpenC3KeycloakAuthorization / #{OPENC3_VERSION} (ruby/openc3/lib/utilities/authentication)",
184
233
  }
185
234
  oath = _make_request(headers, data)
@@ -203,7 +252,7 @@ module OpenC3
203
252
  'grant_type' => 'refresh_token'
204
253
  }
205
254
  headers = {
206
- 'Content-Type' => 'application/x-www-form-urlencoded',
255
+ 'Content-Type' => FORM_URLENCODED_CONTENT_TYPE,
207
256
  'User-Agent' => "OpenC3KeycloakAuthorization / #{OPENC3_VERSION} (ruby/openc3/lib/utilities/authentication)",
208
257
  }
209
258
  oath = _make_request(headers, data)
@@ -217,16 +266,8 @@ module OpenC3
217
266
  def _make_request(headers, data)
218
267
  realm = ENV['OPENC3_KEYCLOAK_REALM'] || 'openc3'
219
268
  uri = URI("#{@url}/realms/#{realm}/protocol/openid-connect/token")
220
- # Obfuscate password and refresh token in logs unless debug mode is enabled
221
- if JsonDRb.debug?
222
- log_data = data.inspect
223
- else
224
- # Create a copy of the hash with sensitive values obfuscated
225
- log_data = data.dup
226
- log_data['password'] = '***' if log_data.key?('password')
227
- log_data['refresh_token'] = '***' if log_data.key?('refresh_token')
228
- log_data = log_data.inspect
229
- end
269
+ # Obfuscate password, client secret, and refresh token before logging.
270
+ log_data = redacted_log_data(data)
230
271
  @log[0] = "request uri: #{uri} header: #{headers} body: #{log_data}"
231
272
  STDOUT.puts @log[0] if JsonDRb.debug?
232
273
  saved_verbose = $VERBOSE; $VERBOSE = nil
@@ -246,4 +287,14 @@ module OpenC3
246
287
  end
247
288
  end
248
289
  end
290
+
291
+ # Build the appropriate authentication object from standard environment variables.
292
+ def self.authentication_from_environment
293
+ client_secret = ENV.fetch('OPENC3_API_CLIENT_SECRET', nil)
294
+ if ENV['OPENC3_API_TOKEN'] || ENV['OPENC3_API_USER'] || (client_secret && !client_secret.empty?)
295
+ OpenC3KeycloakAuthentication.new(ENV['OPENC3_KEYCLOAK_URL'])
296
+ elsif ENV['OPENC3_API_PASSWORD']
297
+ OpenC3Authentication.new()
298
+ end
299
+ end
249
300
  end
@@ -28,6 +28,11 @@ module OpenC3
28
28
  klass.new
29
29
  end
30
30
 
31
+ # snake_case alias to match the Python Bucket.get_client
32
+ def self.get_client # rubocop:disable Naming/AccessorMethodName
33
+ getClient()
34
+ end
35
+
31
36
  def initialize
32
37
  # Setup the client instance
33
38
  end
@@ -12,16 +12,17 @@
12
12
  # if purchased from OpenC3, Inc.
13
13
 
14
14
  require 'open3'
15
+ require 'json'
15
16
 
16
17
  module OpenC3
17
18
  class CliGenerator
18
- GENERATORS = %w(plugin target microservice widget conversion processor limits_response tool tool_vue tool_angular tool_react tool_svelte command_validator)
19
+ GENERATORS = %w(plugin target microservice widget panel conversion processor limits_response tool tool_vue command_validator)
19
20
  TEMPLATES_DIR = "#{File.dirname(__FILE__)}/../../../templates"
20
21
 
21
22
  # Generators that derive language from the target's target.txt
22
23
  TARGET_DERIVED_GENERATORS = %w(conversion processor limits_response command_validator).freeze
23
24
  # Generators that are JavaScript-only and ignore language flags
24
- JS_ONLY_GENERATORS = %w(widget tool tool_vue tool_angular tool_react tool_svelte).freeze
25
+ JS_ONLY_GENERATORS = %w(widget panel tool tool_vue).freeze
25
26
  # Generators that require an explicit language (or env/plugin default)
26
27
  LANGUAGE_REQUIRED_GENERATORS = %w(target microservice).freeze
27
28
 
@@ -37,15 +38,13 @@ module OpenC3
37
38
  puts " target Create a new target within a plugin (--ruby/--python required or inherited)"
38
39
  puts " microservice Create a new microservice within a plugin (--ruby/--python required or inherited)"
39
40
  puts " widget Create a new custom widget (JavaScript only)"
41
+ puts " panel Create a new custom Dashboards panel (JavaScript only)"
40
42
  puts " conversion Create a new conversion class for a target (language inherited from target)"
41
43
  puts " processor Create a new processor for a target (language inherited from target)"
42
44
  puts " limits_response Create a new limits response for a target (language inherited from target)"
43
45
  puts " command_validator Create a new command validator for a target (language inherited from target)"
44
46
  puts " tool Create a new tool, Vue.js by default (JavaScript only)"
45
47
  puts " tool_vue Create a new Vue.js tool (JavaScript only)"
46
- puts " tool_angular Create a new Angular tool (JavaScript only)"
47
- puts " tool_react Create a new React tool (JavaScript only)"
48
- puts " tool_svelte Create a new Svelte tool (JavaScript only)"
49
48
  puts ""
50
49
  puts "Run 'cli generate GENERATOR --help' for detailed help on each generator."
51
50
  puts ""
@@ -63,6 +62,7 @@ module OpenC3
63
62
  puts " cli generate plugin MyPlugin --ruby # Plugin defaults future generators to Ruby"
64
63
  puts " cli generate target EXAMPLE --python # Or inherit from plugin's stored default"
65
64
  puts " cli generate widget SuperdataWidget # No language flag needed"
65
+ puts " cli generate panel BatteryPanel # Dashboards panel type BATTERY"
66
66
  puts " cli generate conversion EXAMPLE STATUS # Language read from targets/EXAMPLE/target.txt"
67
67
  puts ""
68
68
  puts "Documentation:"
@@ -450,6 +450,35 @@ module OpenC3
450
450
  nil
451
451
  end
452
452
 
453
+ # Give a plugin gaining its first python target a pyproject.toml, the same
454
+ # one `generate plugin --python` writes, plus the lib/ package that its ty
455
+ # extra-paths points at. requirements.txt is deprecated, so it is never
456
+ # created; a legacy one is left in place with a warning rather than
457
+ # converted, because its pins may not survive an automatic move.
458
+ def self.add_python_dependency_file
459
+ return if File.exist?('pyproject.toml')
460
+
461
+ if File.exist?('requirements.txt')
462
+ puts "Warning: requirements.txt is deprecated for plugin python dependencies. " \
463
+ "Move them into pyproject.toml: https://docs.openc3.com/docs/configuration/plugins#phase-2-deploy"
464
+ return
465
+ end
466
+ gemspec_filename = Dir['*.gemspec'][0]
467
+ return unless gemspec_filename
468
+
469
+ plugin_name = File.basename(gemspec_filename, '.gemspec')
470
+ package_name = plugin_name.gsub(/[^a-z0-9]+/, '_')
471
+ pyproject = ERB.new(File.read("#{TEMPLATES_DIR}/plugin/pyproject.toml"), trim_mode: "-").result(binding)
472
+ File.write('pyproject.toml', pyproject)
473
+ init_path = "lib/#{package_name}/__init__.py"
474
+ unless File.exist?(init_path)
475
+ FileUtils.mkdir_p(File.dirname(init_path))
476
+ FileUtils.cp("#{TEMPLATES_DIR}/plugin/lib/PACKAGE/__init__.py", init_path)
477
+ end
478
+ write_python_version
479
+ puts "Created pyproject.toml. Add the plugin's python dependencies to it, then run `uv lock`."
480
+ end
481
+
453
482
  def self.generate_target(args)
454
483
  validate_language_inheriting_args!('target', args,
455
484
  example: ['cli generate target EXAMPLE --ruby', 'Creates: targets/EXAMPLE/'],
@@ -475,13 +504,7 @@ module OpenC3
475
504
  end
476
505
 
477
506
  if @@language == 'py'
478
- # If we're using Python create a requirements.txt and list it in the gemspec
479
- # However, don't write over an existing file they may have already created
480
- unless File.exist?("requirements.txt")
481
- File.open("requirements.txt", 'w') do |file|
482
- file.puts "# Python dependencies"
483
- end
484
- end
507
+ add_python_dependency_file
485
508
  gemspec_filename = Dir['*.gemspec'][0]
486
509
  gemspec = File.read(gemspec_filename)
487
510
  # Older COSMOS versions wrote a singular python_dep_file block that never
@@ -654,6 +677,87 @@ module OpenC3
654
677
  return widget_name
655
678
  end
656
679
 
680
+ def self.generate_panel(args)
681
+ if args[1].nil? || args[1] == '--help' || args[1] == '-h'
682
+ print_help(
683
+ usage: 'cli generate panel NAME',
684
+ description: 'Generate a new custom Dashboards panel type within an existing plugin',
685
+ arguments: [
686
+ 'NAME Name of the panel (required)',
687
+ " Must be CapitalCase ending with 'Panel'",
688
+ ' The panel type is NAME without Panel, uppercased',
689
+ ' Example: BatteryPanel (panel type BATTERY)',
690
+ ],
691
+ notes: 'Note: Panels are JavaScript only. --ruby/--python flags are ignored.',
692
+ example: [
693
+ 'cli generate panel BatteryPanel',
694
+ 'Creates: src/BatteryPanel.js, src/BatteryPanel.vue, vite-BatteryPanel.config.js',
695
+ ],
696
+ docs: 'https://docs.openc3.com/docs/guides/custom-panels',
697
+ exit_code: (args[1].nil? ? 1 : 0),
698
+ )
699
+ end
700
+ if args.length != 2
701
+ abort("Usage: cli generate #{args[0]} <BatteryPanel>")
702
+ end
703
+ if !args[1].end_with?('Panel') or args[1].length <= 5 or args[1][0...-5] != args[1][0...-5].capitalize
704
+ abort("Panel name should be Uppercase followed by Panel, e.g. BatteryPanel. Found '#{args[1]}'.")
705
+ end
706
+
707
+ # Create the local variables, used in binding for the templates
708
+ panel_name = args[1]
709
+ panel_type = panel_name[0...-5].upcase
710
+ panel_label = panel_name[0...-5]
711
+ panel_label.inspect # Remove unused variable warning
712
+ vite_config = "vite-#{panel_name}.config.js"
713
+ ["src/#{panel_name}.js", "src/#{panel_name}.vue", vite_config].each do |path|
714
+ abort("Panel #{path} already exists!") if File.exist?(path)
715
+ end
716
+ if File.exist?('plugin.txt') && File.read('plugin.txt') =~ /^PANEL\s+#{Regexp.escape(panel_type)}\b/
717
+ abort("plugin.txt already declares PANEL #{panel_type}. Remove that entry before regenerating.")
718
+ end
719
+ # A plugin with JavaScript already has its package.json and Rakefile, so
720
+ # only the build step is added
721
+ existing_package = File.exist?('package.json')
722
+
723
+ process_template("#{TEMPLATES_DIR}/panel", binding) do |filename|
724
+ if existing_package && ['package.json', 'Rakefile', 'pnpm-workspace.yaml', '.prettierrc.cjs', 'LICENSE.md'].include?(filename)
725
+ true # causes the block to skip processing this file
726
+ elsif filename == 'src/panelSdk.js' && File.exist?(filename)
727
+ true # shared by every panel in the plugin
728
+ else
729
+ filename.sub!("src/Panel.", "src/#{panel_name}.")
730
+ filename.sub!("vite-Panel.config.js", vite_config)
731
+ false
732
+ end
733
+ end
734
+
735
+ if existing_package
736
+ package = JSON.parse(File.read('package.json'))
737
+ package['scripts'] ||= {}
738
+ build = "vite build -c #{vite_config}"
739
+ package['scripts']['build'] = [package['scripts']['build'], build].compact.reject(&:empty?).join(' && ')
740
+ package['devDependencies'] ||= {}
741
+ { '@vitejs/plugin-vue' => '^6.0.1', 'vite' => '^7.2.1', 'vite-plugin-style-inject' => '^0.0.1', 'vue' => '^3.5.13' }.each do |name, version|
742
+ package['devDependencies'][name] ||= version unless package.dig('dependencies', name)
743
+ end
744
+ File.write('package.json', JSON.pretty_generate(package) + "\n")
745
+ puts "Added '#{build}' to the build script in package.json."
746
+ end
747
+
748
+ # Add this panel to plugin.txt
749
+ File.open("plugin.txt", 'a') do |file|
750
+ file.puts <<~DOC
751
+
752
+ PANEL #{panel_type}
753
+ DOC
754
+ end
755
+
756
+ puts "Panel #{panel_name} successfully generated!"
757
+ puts "Use it in a dashboard as PANEL #{panel_type}. Be sure #{panel_type} does not overlap a built-in panel type: https://docs.openc3.com/docs/guides/custom-panels"
758
+ return panel_name
759
+ end
760
+
657
761
  def self.generate_tool(args)
658
762
  if args[1].nil? || args[1] == '--help' || args[1] == '-h'
659
763
  tool_type = args[0].to_s.downcase.gsub('-', '_')
@@ -665,13 +769,7 @@ module OpenC3
665
769
  docs_url = 'https://docs.openc3.com/docs/guides/custom-tools'
666
770
 
667
771
  if tool_type != 'tool'
668
- framework = case tool_type
669
- when 'tool_vue' then 'Vue.js'
670
- when 'tool_react' then 'React'
671
- when 'tool_angular' then 'Angular'
672
- when 'tool_svelte' then 'Svelte'
673
- else 'Custom'
674
- end
772
+ framework = 'Vue.js'
675
773
  print_help(
676
774
  usage: "cli generate #{args[0]} 'TOOL NAME'",
677
775
  description: "Generate a new #{framework} tool within an existing plugin",
@@ -696,9 +794,6 @@ module OpenC3
696
794
  lines: [
697
795
  'tool Generate Vue.js tool (default)',
698
796
  'tool_vue Generate Vue.js tool',
699
- 'tool_angular Generate Angular tool',
700
- 'tool_react Generate React tool',
701
- 'tool_svelte Generate Svelte tool',
702
797
  ],
703
798
  },
704
799
  example: [
@@ -756,9 +851,6 @@ module OpenC3
756
851
  return tool_name
757
852
  end
758
853
  self.singleton_class.send(:alias_method, :generate_tool_vue, :generate_tool)
759
- self.singleton_class.send(:alias_method, :generate_tool_react, :generate_tool)
760
- self.singleton_class.send(:alias_method, :generate_tool_angular, :generate_tool)
761
- self.singleton_class.send(:alias_method, :generate_tool_svelte, :generate_tool)
762
854
 
763
855
  def self.generate_conversion(args)
764
856
  generate_target_artifact(args, {
@@ -0,0 +1,38 @@
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
+ # Rack middleware that removes the Client-IP and Forwarded request headers
16
+ # before Rails computes request.remote_ip.
17
+ #
18
+ # COSMOS runs behind traefik, which sets X-Forwarded-For (and X-Real-Ip) from
19
+ # the real connection. Traefik does not touch Client-IP or Forwarded, so they
20
+ # arrive exactly as the browser sent them, yet ActionDispatch::RemoteIp uses
21
+ # both when picking the client address. Removing them means remote_ip only
22
+ # comes from REMOTE_ADDR and X-Forwarded-For, which traefik controls.
23
+ #
24
+ # Insert before ActionDispatch::RemoteIp:
25
+ # config.middleware.insert_before(ActionDispatch::RemoteIp, OpenC3::ClientIpHeaderFilter)
26
+ class ClientIpHeaderFilter
27
+ HEADERS = %w[HTTP_CLIENT_IP HTTP_FORWARDED].freeze
28
+
29
+ def initialize(app)
30
+ @app = app
31
+ end
32
+
33
+ def call(env)
34
+ HEADERS.each { |header| env.delete(header) }
35
+ @app.call(env)
36
+ end
37
+ end
38
+ end
@@ -28,7 +28,8 @@ module OpenC3
28
28
  #
29
29
  # Every API writer that can reach the overlay must consult these predicates:
30
30
  # - storage_controller#get_upload_presigned_request / delete (presigned S3 upload)
31
- # - tables_controller#save / save_as / report / destroy (Table -> TargetFile)
31
+ # - tables_controller#save / save_as / report / destroy / generate
32
+ # (Table -> TargetFile; script_edit outside the code areas)
32
33
  # - scripts_controller#create / destroy (Script -> TargetFile)
33
34
  module ConfigOverlay
34
35
  # Config bucket areas a non-admin is allowed to write at all
@@ -70,6 +71,28 @@ module OpenC3
70
71
  parts.length > 3 and parts[1, 2] == ['tables', 'config']
71
72
  end
72
73
 
74
+ # True if the given config bucket key is a targets_modified/<TARGET> overlay
75
+ # file whose write requires script_edit rather than only system_set. Script
76
+ # Runner executes these files: procedures and lib are run / required
77
+ # directly, and Script.body / bucket_load will load any overlay path, so
78
+ # every targets_modified target file outside the admin-only code areas
79
+ # (cmd_tlm, tables/config) counts. tmp/ scratch and non-overlay keys return
80
+ # false. Fails closed (false) on non-canonical keys.
81
+ #
82
+ # Callers must still require admin for code areas (code_overlay? /
83
+ # non_admin_writable_key? already fail those), so the tiers are:
84
+ # code area -> admin
85
+ # script_edit area -> script_edit (this predicate)
86
+ # tmp / user bucket -> system_set
87
+ def self.script_edit_overlay_key?(key)
88
+ parts = canonical_parts(key)
89
+ return false if parts.nil?
90
+ # parts: <SCOPE> / <area> / <TARGET> / <subdir> / ...
91
+ return false unless parts[1] == 'targets_modified'
92
+ return false if code_area?(parts[2..])
93
+ true
94
+ end
95
+
73
96
  # True if the given config bucket key is an overlay path a non-admin may
74
97
  # write. Key is the full bucket key, e.g.
75
98
  # "<SCOPE>/targets_modified/<TARGET>/screens/x.txt". Fails closed (false) on
@@ -7,6 +7,23 @@ module OpenC3
7
7
  class CosmosRailsFormatter
8
8
  include OpenC3::Authorization
9
9
 
10
+ # Resolve the username for a request, for use as a config.log_tags entry:
11
+ #
12
+ # formatter = OpenC3::CosmosRailsFormatter.new
13
+ # config.log_tags = { request_id: :request_id, username: ->(request) { formatter.username(request) } }
14
+ #
15
+ # Resolving it here, once per request, keeps the token itself out of the logger.
16
+ # Returns nil (no tag) when the request has no token, or 'anonymous' when the token
17
+ # does not resolve to a username (always in Core, which has no usernames).
18
+ def username(request)
19
+ token = request.headers['HTTP_AUTHORIZATION'] || request.query_parameters[:authorization]
20
+ return nil unless token
21
+
22
+ user_info(token)['username'] || 'anonymous'
23
+ rescue StandardError
24
+ 'anonymous'
25
+ end
26
+
10
27
  def call(log, _appender = nil)
11
28
  #<SemanticLogger::Log:0x0000ffffa5002b20 @level=:info, @thread_name="puma srv tp 001", @name="MicroservicesController",
12
29
  # @time=2024-09-22 18:04:27.955490052 +0000, @tags=[], @named_tags={}, @level_index=2, @message="Completed #traefik",
@@ -22,16 +39,7 @@ module OpenC3
22
39
  username = nil
23
40
  if named_tags
24
41
  other[:request_id] = named_tags[:request_id]
25
- if named_tags[:token]
26
- begin
27
- user = user_info(named_tags[:token])
28
- rescue
29
- user = {}
30
- end
31
- username = user['username']
32
- # Core username (Enterprise has the actual username)
33
- username ||= 'anonymous'
34
- end
42
+ username = named_tags[:username]
35
43
  end
36
44
  username ||= 'anonymous'
37
45
  payload = log.payload