openc3 7.5.1 → 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.
- checksums.yaml +4 -4
- data/Gemfile +0 -0
- data/bin/openc3cli +82 -5
- data/data/config/_params.yaml +3 -0
- data/data/config/command_modifiers.yaml +5 -3
- data/data/config/default_plugins.yaml +1 -0
- data/data/config/interface_modifiers.yaml +17 -1
- data/data/config/item_modifiers.yaml +24 -1
- data/data/config/microservice.yaml +15 -1
- data/data/config/parameter_modifiers.yaml +4 -4
- data/data/config/plugins.yaml +511 -3
- data/data/config/settings.yaml +17 -0
- data/data/config/target.yaml +53 -0
- data/data/config/telemetry.yaml +58 -2
- data/data/config/widgets.yaml +30 -0
- data/lib/openc3/accessors/accessor.rb +14 -2
- data/lib/openc3/accessors/binary_accessor.rb +25 -5
- data/lib/openc3/api/CLAUDE.md +1 -0
- data/lib/openc3/api/api.rb +1 -0
- data/lib/openc3/api/cmd_api.rb +9 -1
- data/lib/openc3/api/interface_api.rb +7 -2
- data/lib/openc3/api/limits_api.rb +93 -41
- data/lib/openc3/api/router_api.rb +7 -2
- data/lib/openc3/api/settings_api.rb +4 -1
- data/lib/openc3/api/shared_resource_api.rb +107 -0
- data/lib/openc3/api/tlm_api.rb +10 -0
- data/lib/openc3/interfaces/http_client_interface.rb +84 -27
- data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +6 -2
- data/lib/openc3/interfaces/tcpip_server_interface.rb +205 -125
- data/lib/openc3/io/json_api.rb +2 -10
- data/lib/openc3/io/json_api_object.rb +2 -10
- data/lib/openc3/logs/packet_log_writer.rb +8 -3
- data/lib/openc3/microservices/decom_common.rb +4 -1
- data/lib/openc3/microservices/decom_microservice.rb +52 -6
- data/lib/openc3/microservices/interface_decom_common.rb +13 -0
- data/lib/openc3/microservices/interface_microservice.rb +50 -11
- data/lib/openc3/microservices/limits_group_microservice.rb +513 -0
- data/lib/openc3/microservices/log_microservice.rb +22 -8
- data/lib/openc3/microservices/microservice.rb +8 -2
- data/lib/openc3/microservices/multi_microservice.rb +76 -22
- data/lib/openc3/microservices/queue_microservice.rb +29 -24
- data/lib/openc3/migrations/20260704000000_default_bridge.rb +1 -2
- data/lib/openc3/migrations/20261103000001_limits_group_backfill.rb +193 -0
- data/lib/openc3/models/bridge_model.rb +3 -3
- data/lib/openc3/models/cvt_model.rb +3 -1
- data/lib/openc3/models/host_interface_microservice_model.rb +4 -4
- data/lib/openc3/models/interface_model.rb +27 -7
- data/lib/openc3/models/microservice_group.rb +167 -0
- data/lib/openc3/models/microservice_model.rb +88 -2
- data/lib/openc3/models/panel_model.rb +109 -0
- data/lib/openc3/models/plugin_model.rb +1006 -26
- data/lib/openc3/models/plugin_store_model.rb +6 -1
- data/lib/openc3/models/protected_storage_model.rb +64 -0
- data/lib/openc3/models/queue_model.rb +19 -10
- data/lib/openc3/models/scope_model.rb +80 -3
- data/lib/openc3/models/setting_model.rb +2 -2
- data/lib/openc3/models/shared_resource_model.rb +381 -0
- data/lib/openc3/models/target_model.rb +324 -68
- data/lib/openc3/operators/microservice_operator.rb +76 -9
- data/lib/openc3/operators/operator.rb +29 -0
- data/lib/openc3/packets/commands.rb +16 -16
- data/lib/openc3/packets/limits.rb +2 -0
- data/lib/openc3/packets/packet.rb +75 -4
- data/lib/openc3/packets/packet_config.rb +152 -13
- data/lib/openc3/packets/packet_item.rb +35 -14
- data/lib/openc3/packets/packet_item_limits.rb +67 -6
- data/lib/openc3/packets/parsers/limits_parser.rb +69 -2
- data/lib/openc3/packets/parsers/packet_item_parser.rb +6 -0
- data/lib/openc3/packets/parsers/packet_parser.rb +45 -0
- data/lib/openc3/packets/parsers/state_parser.rb +1 -1
- data/lib/openc3/script/CLAUDE.md +1 -0
- data/lib/openc3/script/api_shared.rb +17 -9
- data/lib/openc3/script/calendar.rb +18 -6
- data/lib/openc3/script/commands.rb +11 -9
- data/lib/openc3/script/critical_cmd.rb +22 -2
- data/lib/openc3/script/metadata.rb +30 -4
- data/lib/openc3/script/plugins.rb +8 -0
- data/lib/openc3/script/script.rb +8 -24
- data/lib/openc3/script/web_socket_api.rb +23 -17
- data/lib/openc3/system/system.rb +9 -3
- data/lib/openc3/top_level.rb +17 -0
- data/lib/openc3/topics/command_topic.rb +7 -1
- data/lib/openc3/topics/decom_interface_topic.rb +9 -3
- data/lib/openc3/topics/discovery_topic.rb +84 -0
- data/lib/openc3/topics/limits_event_topic.rb +236 -17
- data/lib/openc3/topics/telemetry_decom_topic.rb +12 -3
- data/lib/openc3/topics/topic.rb +2 -1
- data/lib/openc3/utilities/authentication.rb +67 -16
- data/lib/openc3/utilities/cli_generator.rb +117 -25
- data/lib/openc3/utilities/client_ip_header_filter.rb +38 -0
- data/lib/openc3/utilities/config_overlay.rb +24 -1
- data/lib/openc3/utilities/cosmos_rails_formatter.rb +18 -10
- data/lib/openc3/utilities/hardware_discovery.rb +279 -0
- data/lib/openc3/utilities/limits_rollup.rb +81 -0
- data/lib/openc3/utilities/local_mode.rb +48 -5
- data/lib/openc3/utilities/questdb_client.rb +130 -22
- data/lib/openc3/utilities/reingest_job.rb +12 -3
- data/lib/openc3/utilities/running_script.rb +206 -49
- data/lib/openc3/utilities/script.rb +24 -12
- data/lib/openc3/utilities/script_env.rb +164 -0
- data/lib/openc3/utilities/script_message_signing.rb +133 -0
- data/lib/openc3/utilities/store_autoload.rb +32 -1
- data/lib/openc3/utilities/store_queued.rb +5 -1
- data/lib/openc3/version.rb +6 -6
- data/templates/command_validator/command_validator.py +9 -9
- data/templates/{tool_react/pnpm-workspace.yaml → panel/.prettierrc.cjs} +7 -5
- data/templates/panel/Rakefile +24 -0
- data/templates/panel/package.json +17 -0
- data/templates/{tool_angular → panel}/pnpm-workspace.yaml +5 -0
- data/templates/panel/src/Panel.js +52 -0
- data/templates/panel/src/Panel.vue +60 -0
- data/templates/panel/src/panelSdk.js +24 -0
- data/templates/panel/vite-Panel.config.js +43 -0
- data/templates/tool_vue/package.json +3 -3
- data/templates/widget/package.json +2 -2
- metadata +24 -56
- data/templates/tool_angular/.editorconfig +0 -16
- data/templates/tool_angular/.gitignore +0 -44
- data/templates/tool_angular/.vscode/extensions.json +0 -4
- data/templates/tool_angular/.vscode/launch.json +0 -20
- data/templates/tool_angular/.vscode/tasks.json +0 -42
- data/templates/tool_angular/angular.json +0 -111
- data/templates/tool_angular/extra-webpack.config.js +0 -8
- data/templates/tool_angular/package.json +0 -48
- data/templates/tool_angular/src/app/app-routing.module.ts +0 -15
- data/templates/tool_angular/src/app/app.component.html +0 -22
- data/templates/tool_angular/src/app/app.component.scss +0 -18
- data/templates/tool_angular/src/app/app.component.spec.ts +0 -29
- data/templates/tool_angular/src/app/app.component.ts +0 -52
- data/templates/tool_angular/src/app/app.module.ts +0 -30
- data/templates/tool_angular/src/app/custom-overlay-container.ts +0 -17
- data/templates/tool_angular/src/app/empty-route/empty-route.component.ts +0 -7
- data/templates/tool_angular/src/app/openc3-api.d.ts +0 -1
- data/templates/tool_angular/src/assets/.gitkeep +0 -0
- data/templates/tool_angular/src/environments/environment.prod.ts +0 -3
- data/templates/tool_angular/src/environments/environment.ts +0 -16
- data/templates/tool_angular/src/favicon.ico +0 -0
- data/templates/tool_angular/src/index.html +0 -13
- data/templates/tool_angular/src/main.single-spa.ts +0 -40
- data/templates/tool_angular/src/single-spa/asset-url.ts +0 -12
- data/templates/tool_angular/src/single-spa/single-spa-props.ts +0 -8
- data/templates/tool_angular/src/styles.scss +0 -1
- data/templates/tool_angular/tsconfig.app.json +0 -13
- data/templates/tool_angular/tsconfig.json +0 -33
- data/templates/tool_angular/tsconfig.spec.json +0 -14
- data/templates/tool_react/.eslintrc +0 -7
- data/templates/tool_react/.gitignore +0 -71
- data/templates/tool_react/.prettierignore +0 -8
- data/templates/tool_react/babel.config.json +0 -29
- data/templates/tool_react/jest.config.js +0 -12
- data/templates/tool_react/package.json +0 -51
- data/templates/tool_react/src/openc3-tool_name.js +0 -24
- data/templates/tool_react/src/root.component.js +0 -88
- data/templates/tool_react/src/root.component.test.js +0 -9
- data/templates/tool_react/webpack.config.js +0 -27
- data/templates/tool_svelte/.gitignore +0 -71
- data/templates/tool_svelte/.prettierignore +0 -8
- data/templates/tool_svelte/.prettierrc.js +0 -5
- data/templates/tool_svelte/babel.config.js +0 -12
- data/templates/tool_svelte/build/smui.css +0 -1
- data/templates/tool_svelte/jest.config.js +0 -9
- data/templates/tool_svelte/package.json +0 -49
- data/templates/tool_svelte/pnpm-workspace.yaml +0 -20
- data/templates/tool_svelte/rollup.config.js +0 -74
- data/templates/tool_svelte/src/App.svelte +0 -42
- data/templates/tool_svelte/src/App.test.js +0 -9
- data/templates/tool_svelte/src/theme/_smui-theme.scss +0 -25
- data/templates/tool_svelte/src/tool_name.js +0 -17
- data/templates/widget/LICENSE.md +0 -20
|
@@ -0,0 +1,107 @@
|
|
|
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 'openc3/models/shared_resource_model'
|
|
15
|
+
|
|
16
|
+
module OpenC3
|
|
17
|
+
module Api
|
|
18
|
+
WHITELIST ||= []
|
|
19
|
+
WHITELIST.concat([
|
|
20
|
+
'get_shared_resources',
|
|
21
|
+
'get_shared_resource',
|
|
22
|
+
'switch_shared_resource',
|
|
23
|
+
'release_shared_resource',
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
# Members in scopes the user can't access are left out
|
|
27
|
+
# @return [Array<Hash>] The shared resources with members in the scope
|
|
28
|
+
def get_shared_resources(manual: false, scope: $openc3_scope, token: $openc3_token)
|
|
29
|
+
authorize(permission: 'system', manual: manual, scope: scope, token: token)
|
|
30
|
+
records = SharedResourceModel.all.values.select { |record| record['members'][scope] }.sort_by { |record| record['name'] }
|
|
31
|
+
accessible = { scope => true }
|
|
32
|
+
records.map { |record| _shared_resource_for_user(record, accessible, manual: manual, token: token) }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Members in scopes the user can't access are left out
|
|
36
|
+
# @param name [String] Shared resource name
|
|
37
|
+
# @return [Hash|nil] The shared resource or nil if it doesn't exist or has no members in the scope
|
|
38
|
+
def get_shared_resource(name, manual: false, scope: $openc3_scope, token: $openc3_token)
|
|
39
|
+
authorize(permission: 'system', manual: manual, scope: scope, token: token)
|
|
40
|
+
record = SharedResourceModel.get(name)
|
|
41
|
+
return nil unless record and record['members'][scope]
|
|
42
|
+
_shared_resource_for_user(record, { scope => true }, manual: manual, token: token)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Make a shared resource active in a scope. Its microservices in the
|
|
46
|
+
# currently active scope are stopped before those in the new scope start.
|
|
47
|
+
#
|
|
48
|
+
# @param name [String] Shared resource name
|
|
49
|
+
# @param to_scope [String] Scope to make the resource active in (default is the current scope)
|
|
50
|
+
# @param force [Boolean] Don't wait for the active scope's microservices to stop
|
|
51
|
+
# @return [Hash] The updated shared resource
|
|
52
|
+
def switch_shared_resource(name, to_scope = nil, force: false, manual: false, scope: $openc3_scope, token: $openc3_token)
|
|
53
|
+
to_scope ||= scope
|
|
54
|
+
# Switching affects both scopes so require admin in each
|
|
55
|
+
authorize(permission: 'admin', manual: manual, scope: to_scope, token: token)
|
|
56
|
+
record = SharedResourceModel.get(name)
|
|
57
|
+
raise "Shared resource '#{name.to_s.upcase}' does not exist" unless record
|
|
58
|
+
if record['owner'] and record['owner'] != to_scope
|
|
59
|
+
authorize(permission: 'admin', manual: manual, scope: record['owner'], token: token)
|
|
60
|
+
end
|
|
61
|
+
record = SharedResourceModel.switch(name, to_scope: to_scope, force: force)
|
|
62
|
+
username = user_info(token)['username'] || 'Anonymous'
|
|
63
|
+
Logger.info("User #{username} switched shared resource #{record['name']} to scope #{to_scope}#{force ? ' (forced)' : ''}", scope: to_scope, user: username)
|
|
64
|
+
record
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Release a shared resource so it is not active in any scope
|
|
68
|
+
#
|
|
69
|
+
# @param name [String] Shared resource name
|
|
70
|
+
# @param force [Boolean] Don't wait for the active scope's microservices to stop
|
|
71
|
+
# @return [Hash] The updated shared resource
|
|
72
|
+
def release_shared_resource(name, force: false, manual: false, scope: $openc3_scope, token: $openc3_token)
|
|
73
|
+
authorize(permission: 'admin', manual: manual, scope: scope, token: token)
|
|
74
|
+
record = SharedResourceModel.get(name)
|
|
75
|
+
raise "Shared resource '#{name.to_s.upcase}' does not exist" unless record
|
|
76
|
+
if record['owner'] and record['owner'] != scope
|
|
77
|
+
authorize(permission: 'admin', manual: manual, scope: record['owner'], token: token)
|
|
78
|
+
end
|
|
79
|
+
record = SharedResourceModel.release(name, force: force)
|
|
80
|
+
username = user_info(token)['username'] || 'Anonymous'
|
|
81
|
+
Logger.info("User #{username} released shared resource #{record['name']}#{force ? ' (forced)' : ''}", scope: scope, user: username)
|
|
82
|
+
record
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Remove the members (and the owner's waiting members) of scopes the user
|
|
86
|
+
# doesn't have system permission in. The owner and state stay so the UI can
|
|
87
|
+
# say where the resource is active.
|
|
88
|
+
# @param accessible [Hash<String, Boolean>] Cache of scope to whether the user can access it
|
|
89
|
+
def _shared_resource_for_user(record, accessible, manual:, token:)
|
|
90
|
+
can_access = lambda do |other_scope|
|
|
91
|
+
unless accessible.key?(other_scope)
|
|
92
|
+
begin
|
|
93
|
+
authorize(permission: 'system', manual: manual, scope: other_scope, token: token)
|
|
94
|
+
accessible[other_scope] = true
|
|
95
|
+
rescue ForbiddenError
|
|
96
|
+
accessible[other_scope] = false
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
accessible[other_scope]
|
|
100
|
+
end
|
|
101
|
+
record = record.dup
|
|
102
|
+
record['members'] = record['members'].select { |member_scope, _members| can_access.call(member_scope) }
|
|
103
|
+
record['waiting'] = [] if record['owner'] and record['waiting'] and !can_access.call(record['owner'])
|
|
104
|
+
record
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
data/lib/openc3/api/tlm_api.rb
CHANGED
|
@@ -120,6 +120,7 @@ module OpenC3
|
|
|
120
120
|
# @param received_time [Integer, nil] Optional received time as nanoseconds since Unix epoch
|
|
121
121
|
def inject_tlm(target_name, packet_name, item_hash = nil, type: :CONVERTED, stored: false, received_time: nil, manual: false, scope: $openc3_scope, token: $openc3_token)
|
|
122
122
|
_tlm_reject_latest(packet_name.to_s.upcase, 'inject_tlm')
|
|
123
|
+
_tlm_reject_read_only(target_name.to_s.upcase, packet_name.to_s.upcase, 'inject_tlm')
|
|
123
124
|
authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token)
|
|
124
125
|
type = type.to_s.intern
|
|
125
126
|
target_name = target_name.upcase
|
|
@@ -568,6 +569,13 @@ module OpenC3
|
|
|
568
569
|
raise "ERROR: LATEST is not supported by #{method_name}(), specify a packet name" if packet_name == 'LATEST'
|
|
569
570
|
end
|
|
570
571
|
|
|
572
|
+
# <TARGET> LIMITS_GROUP is computed by the limits group microservice so it can't be written
|
|
573
|
+
def _tlm_reject_read_only(target_name, packet_name, method_name)
|
|
574
|
+
if packet_name == PacketConfig::LIMITS_GROUP_PACKET
|
|
575
|
+
raise "ERROR: #{target_name} #{packet_name} is read-only and is not supported by #{method_name}()"
|
|
576
|
+
end
|
|
577
|
+
end
|
|
578
|
+
|
|
571
579
|
def _extract_target_packet_item_names(method_name, *args)
|
|
572
580
|
target_name = nil
|
|
573
581
|
packet_name = nil
|
|
@@ -610,6 +618,7 @@ module OpenC3
|
|
|
610
618
|
|
|
611
619
|
def _set_tlm_process_args(args, method_name, cache_timeout: nil, scope: $openc3_scope, token: $openc3_token)
|
|
612
620
|
target_name, packet_name, item_name, value = _set_tlm_extract_args(args, method_name)
|
|
621
|
+
_tlm_reject_read_only(target_name, packet_name, method_name)
|
|
613
622
|
packet_name = _tlm_resolve_packet_name(target_name, packet_name, item_name, cache_timeout: cache_timeout, scope: scope)
|
|
614
623
|
return [target_name, packet_name, item_name, value]
|
|
615
624
|
end
|
|
@@ -624,6 +633,7 @@ module OpenC3
|
|
|
624
633
|
|
|
625
634
|
def _set_tlm_process_args_all_packets(args, method_name, scope: $openc3_scope)
|
|
626
635
|
target_name, packet_name, item_name, value = _set_tlm_extract_args(args, method_name)
|
|
636
|
+
_tlm_reject_read_only(target_name, packet_name, method_name)
|
|
627
637
|
return [target_name, _tlm_packet_names(target_name, packet_name, item_name, scope: scope), item_name, value]
|
|
628
638
|
end
|
|
629
639
|
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
require 'openc3/interfaces/interface'
|
|
15
15
|
require 'openc3/config/config_parser'
|
|
16
16
|
require 'faraday'
|
|
17
|
-
require 'faraday/follow_redirects'
|
|
18
17
|
require 'openc3/accessors/http_accessor'
|
|
19
18
|
|
|
20
19
|
# TODO: Header Log Filtering? File Uploads? Authorization from secrets?
|
|
@@ -35,6 +34,7 @@ module OpenC3
|
|
|
35
34
|
else
|
|
36
35
|
@url = "#{@protocol}://#{@hostname}:#{@port}"
|
|
37
36
|
end
|
|
37
|
+
@base_uri = URI(@url)
|
|
38
38
|
@write_timeout = ConfigParser.handle_nil(write_timeout)
|
|
39
39
|
@write_timeout = Float(@write_timeout) if @write_timeout
|
|
40
40
|
@read_timeout = ConfigParser.handle_nil(read_timeout)
|
|
@@ -64,8 +64,9 @@ module OpenC3
|
|
|
64
64
|
request['open_timeout'] = @connect_timeout if @connect_timeout
|
|
65
65
|
request['read_timeout'] = @read_timeout if @read_timeout
|
|
66
66
|
request['write_timeout'] = @write_timeout if @write_timeout
|
|
67
|
+
# Redirects are not followed, because a redirect to another host would bypass
|
|
68
|
+
# validate_uri. A 3xx response is returned like any other response.
|
|
67
69
|
@http = Faraday.new(request: request) do |f|
|
|
68
|
-
f.response :follow_redirects # use Faraday::FollowRedirects::Middleware
|
|
69
70
|
f.adapter :net_http # adds the adapter to the connection, defaults to `Faraday.default_adapter`
|
|
70
71
|
end
|
|
71
72
|
super()
|
|
@@ -108,7 +109,7 @@ module OpenC3
|
|
|
108
109
|
extra = packet.extra
|
|
109
110
|
extra ||= {}
|
|
110
111
|
data = packet.buffer(true) # Copy buffer so logged command isn't modified
|
|
111
|
-
extra['HTTP_URI'] =
|
|
112
|
+
extra['HTTP_URI'] = build_uri(packet.read('HTTP_PATH'))
|
|
112
113
|
# Store the target name for use in identifying the response
|
|
113
114
|
extra['HTTP_REQUEST_TARGET_NAME'] = packet.target_name
|
|
114
115
|
return data, extra
|
|
@@ -123,33 +124,43 @@ module OpenC3
|
|
|
123
124
|
headers ||= {}
|
|
124
125
|
uri = extra['HTTP_URI']
|
|
125
126
|
method = extra['HTTP_METHOD']
|
|
127
|
+
# HTTP_URI normally comes from convert_packet_to_data, but write_raw passes
|
|
128
|
+
# extra straight through, so check the destination here as well
|
|
129
|
+
validate_uri(uri)
|
|
126
130
|
|
|
127
131
|
resp = nil
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
132
|
+
begin
|
|
133
|
+
case method
|
|
134
|
+
when 'get'
|
|
135
|
+
resp = @http.get(uri) do |req|
|
|
136
|
+
req.params = queries
|
|
137
|
+
req.headers = headers
|
|
138
|
+
end
|
|
139
|
+
when 'put'
|
|
140
|
+
resp = @http.put(uri) do |req|
|
|
141
|
+
req.params = queries
|
|
142
|
+
req.headers = headers
|
|
143
|
+
req.body = data
|
|
144
|
+
end
|
|
145
|
+
when 'delete'
|
|
146
|
+
resp = @http.delete(uri) do |req|
|
|
147
|
+
req.params = queries
|
|
148
|
+
req.headers = headers
|
|
149
|
+
end
|
|
150
|
+
when 'post'
|
|
151
|
+
resp = @http.post(uri) do |req|
|
|
152
|
+
req.params = queries
|
|
153
|
+
req.headers = headers
|
|
154
|
+
req.body = data
|
|
155
|
+
end
|
|
156
|
+
else
|
|
157
|
+
raise "Unsupported HTTP Method: #{method}"
|
|
150
158
|
end
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
rescue Faraday::Error => e
|
|
160
|
+
# Log the details but don't return the raw error to the command sender
|
|
161
|
+
# Query strings can carry credentials, so they are redacted from the log
|
|
162
|
+
Logger.error("#{@name}: HTTP #{method.to_s.upcase} #{redact_queries(uri, uri: true)} failed: #{e.class}: #{redact_queries(e.message)}")
|
|
163
|
+
raise "HTTP #{method.to_s.upcase} request to #{@url} failed (#{e.class.name.split('::').last})"
|
|
153
164
|
end
|
|
154
165
|
|
|
155
166
|
# Normalize Response into simple hash
|
|
@@ -248,5 +259,51 @@ module OpenC3
|
|
|
248
259
|
result['response_queue_length'] = @response_queue.length
|
|
249
260
|
return result
|
|
250
261
|
end
|
|
262
|
+
|
|
263
|
+
protected
|
|
264
|
+
|
|
265
|
+
# Builds the request URI from the configured URL and the HTTP_PATH parameter.
|
|
266
|
+
# The request always goes to the configured scheme, host and port.
|
|
267
|
+
#
|
|
268
|
+
# @param path [String] Request path, which must start with a single '/'
|
|
269
|
+
# @return [String] Full request URI
|
|
270
|
+
def build_uri(path)
|
|
271
|
+
path = path.to_s
|
|
272
|
+
unless path.empty?
|
|
273
|
+
if !path.start_with?('/') or path.start_with?('//')
|
|
274
|
+
raise WriteRejectError, "HTTP_PATH must start with a single '/': #{path.inspect}"
|
|
275
|
+
end
|
|
276
|
+
if path.match?(/[\\ [:cntrl:]]/)
|
|
277
|
+
raise WriteRejectError, "HTTP_PATH contains invalid characters: #{path.inspect}"
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
uri = "#{@url}#{path}"
|
|
281
|
+
validate_uri(uri)
|
|
282
|
+
return uri
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# Replaces query strings with ?[REDACTED] so they aren't logged. In a URI everything
|
|
286
|
+
# after the '?' is the query. In other text the query ends at whitespace, which
|
|
287
|
+
# can't appear in a query because HTTP_PATH rejects it and queries are percent-encoded.
|
|
288
|
+
def redact_queries(text, uri: false)
|
|
289
|
+
return text.to_s.sub(/\?.*/m, '?[REDACTED]') if uri
|
|
290
|
+
return text.to_s.gsub(/\?\S+/, '?[REDACTED]')
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
# Raises WriteRejectError unless the URI goes to the configured scheme, host and port.
|
|
294
|
+
# WriteRejectError rejects the command without disconnecting the interface.
|
|
295
|
+
def validate_uri(uri)
|
|
296
|
+
begin
|
|
297
|
+
parsed = URI(uri.to_s)
|
|
298
|
+
rescue URI::InvalidURIError
|
|
299
|
+
raise WriteRejectError, "Invalid HTTP URI: #{uri.inspect}"
|
|
300
|
+
end
|
|
301
|
+
unless parsed.scheme.to_s.casecmp?(@base_uri.scheme) and
|
|
302
|
+
parsed.host.to_s.casecmp?(@base_uri.host) and
|
|
303
|
+
parsed.port == @base_uri.port and
|
|
304
|
+
parsed.userinfo.nil?
|
|
305
|
+
raise WriteRejectError, "HTTP URI #{uri.inspect} does not match interface URL #{@url}"
|
|
306
|
+
end
|
|
307
|
+
end
|
|
251
308
|
end
|
|
252
309
|
end
|
|
@@ -65,7 +65,9 @@ module OpenC3
|
|
|
65
65
|
@write_extra = nil
|
|
66
66
|
if packet.extra
|
|
67
67
|
@write_flags |= COSMOS4_EXTRA_FLAG_MASK
|
|
68
|
-
|
|
68
|
+
# Force binary so appending it can't promote data_to_send to UTF-8, which
|
|
69
|
+
# then raises Encoding::CompatibilityError on the binary fields that follow
|
|
70
|
+
@write_extra = packet.extra.as_json().to_json(allow_nan: true).b
|
|
69
71
|
end
|
|
70
72
|
return packet
|
|
71
73
|
end
|
|
@@ -76,7 +78,9 @@ module OpenC3
|
|
|
76
78
|
data_to_send << @sync_pattern if @sync_pattern
|
|
77
79
|
data_to_send << @write_flags
|
|
78
80
|
if @write_extra
|
|
79
|
-
|
|
81
|
+
# Length field must count bytes, not characters, or a non-ASCII value in
|
|
82
|
+
# extra desyncs the receiver
|
|
83
|
+
data_to_send << [@write_extra.bytesize].pack('N')
|
|
80
84
|
data_to_send << @write_extra
|
|
81
85
|
end
|
|
82
86
|
data_to_send << @write_time_seconds
|