mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-10-05 22:31:57 +08:00
If the postgres resource subnet is connected to a customer subnet, support showing connection info with the private IPv4 address.
65 lines
2.8 KiB
Text
65 lines
2.8 KiB
Text
<%
|
|
hostname = @pg.hostname
|
|
password = URI.encode_uri_component(@pg.superuser_password)
|
|
hostnames = [[hostname, ""]]
|
|
allow_private = @pg.private_subnet.connected_subnets.any? && (private_ipv4 = @pg.private_ipv4)
|
|
hostnames << [private_ipv4, "-private"] if allow_private
|
|
|
|
connection_infos = {}
|
|
ports = [5432, 6432]
|
|
hostnames.each do |hostname, suffix|
|
|
ports.each do |port|
|
|
connection_infos["url-#{port}#{suffix}"] = "postgresql://postgres:#{password}@#{hostname}:#{port}/postgres"
|
|
connection_infos["psql-#{port}#{suffix}"] = "psql postgresql://postgres:#{password}@#{hostname}:#{port}/postgres"
|
|
connection_infos["env-#{port}#{suffix}"] = "PGHOST=#{hostname}\nPGPORT=#{port}\nPGUSER=postgres\nPGPASSWORD=#{password}\nPGDATABASE=postgres"
|
|
connection_infos["yaml-#{port}#{suffix}"] = "host: #{hostname}\nport: #{port}\nuser: postgres\npassword: #{password}\ndatabase: postgres"
|
|
connection_infos["jdbc-#{port}#{suffix}"] = "jdbc:postgresql://#{hostname}:#{port}/postgres?user=postgres&password=#{password}&ssl=true"
|
|
end
|
|
end
|
|
%>
|
|
|
|
<div class="p-6">
|
|
<% if @pg.display_state != "creating" %>
|
|
<div class="flex items-center gap-6 connection-info-format-selector">
|
|
<div class="flex items-center gap-2">
|
|
Format:
|
|
<div>
|
|
<%== part(
|
|
"components/form/select",
|
|
options: connection_infos.keys.map { it.split("-").first }.uniq.map { [it, it] },
|
|
attributes: {
|
|
"data-hostname" => @pg.hostname,
|
|
"data-username" => "postgres",
|
|
"data-password" => @pg.superuser_password,
|
|
"data-database" => "postgres"
|
|
},
|
|
) %>
|
|
</div>
|
|
</div>
|
|
<div><%== part("components/form/checkbox", name: :use_pgbouncer, options: [["1", "Use pgBouncer?", "", {}]]) %></div>
|
|
<% if allow_private %>
|
|
<div><%== part("components/form/checkbox", name: :use_private_ip, options: [["1", "Use Private IP?", "", {}]]) %></div>
|
|
<% end %>
|
|
</div>
|
|
|
|
<%
|
|
connection_infos.each_with_index do |(key, value), index|
|
|
hidden_class = index == 0 ? "" : "hidden"
|
|
%>
|
|
<div class="bg-gray-200 rounded-md p-6 mt-5 connection-info-box connection-info-box-<%= key %> <%= hidden_class %>">
|
|
<%== part("components/copyable_content", content: value, revealable: true, classes: "!flex justify-between") %>
|
|
</div>
|
|
<% end %>
|
|
|
|
<div class="mt-5 flex items-center gap-2">
|
|
CA Certificates: <%== part("components/download_button", link: "#{path(@pg)}/ca-certificates")%>
|
|
</div>
|
|
<% else %>
|
|
<div class="flex flex-col items-center justify-center h-full">
|
|
<h2 class="text-2xl font-semibold text-gray-900">No connection information available</h2>
|
|
<p class="text-gray-500 mt-2">Connection information will be available once the database is running.</p>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
|
|
|