Skip to content

Commit a63e8e4

Browse files
support upgrading from websocket proxy agent
1 parent 2ec2294 commit a63e8e4

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

install.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ set -euo pipefail
1111

1212
die() { echo "ERROR: $*" >&2; exit 1; }
1313

14+
extract_json_string() {
15+
grep -o "\"$1\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" "$2" \
16+
| sed "s/.*\"$1\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/"
17+
}
18+
1419
DEFAULT_FIVETRAN_API_URL="https://api.fivetran.com"
1520

1621
usage() {
@@ -217,6 +222,19 @@ main() {
217222
die "Config file not found or not readable: $config_path"
218223
fi
219224

225+
# WebSocket agents (identified by proxy_server_uri) need a fresh gRPC-compatible config.
226+
# Construct TOKEN from existing credentials to fetch one via the configure endpoint.
227+
if [ -n "${config_path:-}" ] && [ -z "${TOKEN:-}" ] && grep -q '"proxy_server_uri"' "$config_path"; then
228+
local agent_id auth_token
229+
agent_id=$(extract_json_string "agent_id" "$config_path")
230+
auth_token=$(extract_json_string "auth_token" "$config_path")
231+
[ -n "$agent_id" ] && [ -n "$auth_token" ] \
232+
|| die "Could not extract credentials from WebSocket config"
233+
TOKEN=$(printf '%s:%s' "$agent_id" "$auth_token" | base64 | tr -d '\n')
234+
config_path=""
235+
echo "Detected WebSocket agent configuration. Fetching updated config from Fivetran..."
236+
fi
237+
220238
echo -e "Installing Fivetran Proxy Agent...\n"
221239

222240
# Pre-flight checks
@@ -273,10 +291,9 @@ main() {
273291
# umask 177 ensures the file is created with 600 permissions (no read/write for group/other)
274292
(umask 177 && printf '%s' "$body" > "$install_dir/config/config.json")
275293
else
276-
mv "$config_path" "$install_dir/config/config.json"
294+
cp "$config_path" "$install_dir/config/config.json"
277295
chmod 600 "$install_dir/config/config.json"
278-
echo "Your config file has been moved to $install_dir/config/config.json"
279-
echo "Note: Keep the config file if you need to roll back to the previous installation"
296+
echo "Config copied to $install_dir/config/config.json"
280297
fi
281298

282299
# Resolve and pin version
@@ -291,8 +308,6 @@ main() {
291308
cd "$install_dir"
292309
if ! ./$AGENT_SCRIPT start; then
293310
echo "Installation complete, but agent failed to start."
294-
echo "Please review the agent container logs for more detail."
295-
# TODO: Print the contents of the latest log file
296311
echo "To try to start the agent again, run: ./$AGENT_SCRIPT start"
297312
exit 1
298313
fi

0 commit comments

Comments
 (0)