ubicloud/cli-commands/ps/post/disconnect.rb
Jeremy Evans f930ca132a Allow disconnecting from postgres private subnets in the api/cli/sdk
Similar to connecting, this uses a separate option. Rather than copying
the connect route code to disconnect and modify it, since the majority
of the route code is the same, this combines the private subnet connect
and disconnect routes using a private_subnet_connection_action helper
method.

In order to tell the difference between postgres and private subnet
ids, we need to keep in ubid format so we can check the first two
characters. Add ubid typecast param and symbol matcher to support that.
2025-09-15 11:54:52 -07:00

23 lines
730 B
Ruby

# frozen_string_literal: true
UbiCli.on("ps").run_on("disconnect") do
desc "Disconnect a private subnet from another private subnet"
options("ubi ps (location/ps-name | ps-id) disconnect [options] (location/ps-name | ps-id)") do
on("-P", "--postgres", "treat argument as PostgreSQL database name or id")
end
args 1
run do |arg, opts, cmd|
ps_id = if opts[:postgres]
prefix = "PostgreSQL database "
convert_name_to_id(sdk.postgres, arg)
else
convert_loc_name_to_id(sdk.private_subnet, arg)
end
check_no_slash(ps_id, "invalid private subnet id format", cmd)
id = sdk_object.disconnect(ps_id).id
response("Disconnected #{prefix}private subnet #{arg} from #{id}")
end
end