Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neon-proxy: generate default tls.crt & tls.key #153

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 52 additions & 13 deletions Formula/neon-proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class NeonProxy < Formula
tag: "release-proxy-5751",
revision: "5d62c67e75160e967f80fb0eefaca30501b17dbe"
license "Apache-2.0"
revision 1
head "https://github.com/neondatabase/neon.git", branch: "main"

livecheck do
Expand All @@ -24,25 +25,63 @@ class NeonProxy < Formula

uses_from_macos "llvm" => :build

def binaries
%w[
pg_sni_router
proxy
]
end

def install
ENV["BUILD_TAG"] = build.stable? ? "release-proxy-#{version}" : "dev-#{Utils.git_short_head}"
ENV["GIT_VERSION"] = Utils.git_head

system "cargo", "install", *std_cargo_args(root: libexec, path: "proxy")
bin.install_symlink libexec/"bin/pg_sni_router" => "neon-pg-sni-router"
bin.install_symlink libexec/"bin/proxy" => "neon-proxy"
args = std_cargo_args(root: libexec, path: "proxy") + %w[
--features testing
]
system "cargo", "install", *args

(bin/"neon-proxy").write <<~EOS
#!/bin/bash

CERTS_DIR="#{var}/neon-proxy/certs"
for arg in "$@"; do
case "$arg" in
"--tls-cert" | "-c" | "--tls-key" | "-k" | "--certs-dir")
CERTS_DIR=""
;;
*)
;;
esac
done

if [ -n "${CERTS_DIR}" ]; then
exec "#{libexec}/bin/proxy" --certs-dir="${CERTS_DIR}" "$@"
else
exec "#{libexec}/bin/proxy" "$@"
fi
EOS
end

def post_install
certs_dir = var/"neon-proxy/certs"
return if (certs_dir/"tls.crt").exist? && (certs_dir/"/tls.key").exist?

mkdir_p certs_dir
args = [
"req",
"-new",
"-x509",
"-days",
"365",
"-nodes",
"-text",
"-out",
"#{certs_dir}/tls.crt",
"-keyout",
"#{certs_dir}/tls.key",
"-subj",
"/CN=*.localtest.me",
"-addext",
"subjectAltName = DNS:*.localtest.me",
]
system Formula["openssl@3"].opt_bin/"openssl", *args
end

test do
binaries.each do |file|
system libexec/"bin"/file, "--version"
end
system bin/"neon-proxy", "--version"
end
end