Files
ubicloud/spec/cli_config.ru
Jeremy Evans a94f0e5081 Have cli program send version in header
This allows the server to take appropriate action based on client version.
It we add new features that require an updated client version, we can
check the client's version, and give them a give the clients a nice error
message instructing them to upgrade.

This required a minor change to Rodish to execute code after option
parsing and before subcommand processing, even if there are no valid
subcommands provided.  I made that change and released a new version,
so this bumps the rodish version.

The cli version is stored in cli/version.txt.  bin/ubi reads this
file when run.  In the rake ubi/ubi-cross tasks, the Rakefile
reads this file and sets the version in the compiled go file.
2025-03-04 16:55:53 -08:00

75 lines
1.7 KiB
Ruby

# frozen_string_literal: true
require "roda"
c = Class.new(Roda) do
plugin :json_parser
# When debugging
# plugin :hooks
# after do |res|
# p res
# end
route do |r|
r.post "cli" do
unless env["HTTP_AUTHORIZATION"] == "Bearer: a"
response.status = 400
next "invalid token\n"
end
argv = r.POST["argv"]
response["content-type"] = "text/plain"
case argv[0]
when "--version"
r.env["HTTP_X_UBI_VERSION"]
when "--confirm"
case argv[1]
when "valid"
"valid-confirm: #{argv[3..].join(" ")}"
when "invalid"
response.status = 400
"invalid-confirm: #{argv[3..].join(" ")}\n"
when "recurse"
response["ubi-confirm"] = "Test-Confirm-Recurse"
""
end
when "confirm"
response["ubi-confirm"] = "Test-Confirm-Prompt"
"Pre-Confirm"
when "exec"
response["ubi-command-execute"] = argv[1]
rest = argv[3..]
case argv[2]
when "as-is"
# nothing
when "prog-switch"
response["ubi-command-execute"] = "new"
rest << "--"
when "dash2"
rest << "--"
when "new-before"
rest << "new" << "--"
when "new-after"
rest << "--" << "new"
when "new2"
rest << "--" << "new" << "new"
when "newd"
rest << "-dnew"
end
rest.join("\0")
when "error"
response.status = 400
argv.join(" ") << "\n"
when "headers"
env.values_at(*%w[HTTP_CONNECTION CONTENT_TYPE HTTP_ACCEPT HTTP_AUTHORIZATION]).join(" ")
else
argv.join(" ")
end
end
end
end
run c.freeze.app