Fix missing endpointId query param in WebSocket exec URL

Portainer requires endpointId in the websocket/exec query string.
Was returning 400 "Missing query parameter".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-22 13:11:18 +01:00
parent 7235f687b1
commit 948910fc87
2 changed files with 6 additions and 7 deletions
+3 -3
View File
@@ -38,7 +38,7 @@ module PortainerCli
$stderr.puts dim("Connecting to #{container_name} (#{container_id[0, 12]})...") $stderr.puts dim("Connecting to #{container_name} (#{container_id[0, 12]})...")
exec_id = create_exec(endpoint_id, container_id, opts[:shell]) exec_id = create_exec(endpoint_id, container_id, opts[:shell])
ws_url = exec_websocket_url(exec_id) ws_url = exec_websocket_url(exec_id, endpoint_id)
send_resize(endpoint_id, exec_id) if $stdout.tty? send_resize(endpoint_id, exec_id) if $stdout.tty?
trap('SIGWINCH') { send_resize(endpoint_id, exec_id) } if $stdout.tty? trap('SIGWINCH') { send_resize(endpoint_id, exec_id) } if $stdout.tty?
@@ -125,9 +125,9 @@ module PortainerCli
result['Id'] result['Id']
end end
def exec_websocket_url(exec_id) def exec_websocket_url(exec_id, endpoint_id)
token = @config.token || @config.api_key token = @config.token || @config.api_key
@client.websocket_url('/api/websocket/exec', token: token, id: exec_id) @client.websocket_url('/api/websocket/exec', token: token, id: exec_id, endpointId: endpoint_id)
end end
def send_resize(endpoint_id, exec_id) def send_resize(endpoint_id, exec_id)
+3 -4
View File
@@ -32,7 +32,7 @@ module PortainerCli
$stderr.puts dim("Connecting to #{container_name} (#{container_id[0, 12]})...") $stderr.puts dim("Connecting to #{container_name} (#{container_id[0, 12]})...")
exec_id = create_exec(endpoint_id, container_id, opts[:shell]) exec_id = create_exec(endpoint_id, container_id, opts[:shell])
ws_url = exec_websocket_url(exec_id) ws_url = exec_websocket_url(exec_id, endpoint_id)
send_resize(endpoint_id, exec_id) if $stdout.tty? send_resize(endpoint_id, exec_id) if $stdout.tty?
trap('SIGWINCH') { send_resize(endpoint_id, exec_id) } if $stdout.tty? trap('SIGWINCH') { send_resize(endpoint_id, exec_id) } if $stdout.tty?
@@ -78,10 +78,9 @@ module PortainerCli
result['Id'] result['Id']
end end
def exec_websocket_url(exec_id) def exec_websocket_url(exec_id, endpoint_id)
# Portainer uses JWT for websocket auth (not API key), so we need to include token in query
token = @config.token || @config.api_key token = @config.token || @config.api_key
@client.websocket_url('/api/websocket/exec', token: token, id: exec_id) @client.websocket_url('/api/websocket/exec', token: token, id: exec_id, endpointId: endpoint_id)
end end
def send_resize(endpoint_id, exec_id) def send_resize(endpoint_id, exec_id)