fix(vault-cli): use if/elif/else instead of case for HTTP client detection (#625)

This commit is contained in:
Atif Ali 2025-12-31 09:04:47 +05:00 committed by GitHub
parent 36089612ef
commit 678c3e631e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 39 deletions

View File

@ -13,7 +13,7 @@ Installs the [Vault](https://www.vaultproject.io/) CLI and optionally configures
```tf ```tf
module "vault_cli" { module "vault_cli" {
source = "registry.coder.com/coder/vault-cli/coder" source = "registry.coder.com/coder/vault-cli/coder"
version = "1.1.0" version = "1.1.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
vault_addr = "https://vault.example.com" vault_addr = "https://vault.example.com"
} }
@ -34,7 +34,7 @@ If you have a Vault token, you can provide it to automatically configure authent
```tf ```tf
module "vault_cli" { module "vault_cli" {
source = "registry.coder.com/coder/vault-cli/coder" source = "registry.coder.com/coder/vault-cli/coder"
version = "1.1.0" version = "1.1.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
vault_addr = "https://vault.example.com" vault_addr = "https://vault.example.com"
vault_token = var.vault_token # Optional vault_token = var.vault_token # Optional
@ -50,7 +50,7 @@ Install the Vault CLI without any authentication:
```tf ```tf
module "vault_cli" { module "vault_cli" {
source = "registry.coder.com/coder/vault-cli/coder" source = "registry.coder.com/coder/vault-cli/coder"
version = "1.1.0" version = "1.1.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
vault_addr = "https://vault.example.com" vault_addr = "https://vault.example.com"
} }
@ -61,7 +61,7 @@ module "vault_cli" {
```tf ```tf
module "vault_cli" { module "vault_cli" {
source = "registry.coder.com/coder/vault-cli/coder" source = "registry.coder.com/coder/vault-cli/coder"
version = "1.1.0" version = "1.1.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
vault_addr = "https://vault.example.com" vault_addr = "https://vault.example.com"
vault_cli_version = "1.15.0" vault_cli_version = "1.15.0"
@ -73,7 +73,7 @@ module "vault_cli" {
```tf ```tf
module "vault_cli" { module "vault_cli" {
source = "registry.coder.com/coder/vault-cli/coder" source = "registry.coder.com/coder/vault-cli/coder"
version = "1.1.0" version = "1.1.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
vault_addr = "https://vault.example.com" vault_addr = "https://vault.example.com"
install_dir = "/home/coder/bin" install_dir = "/home/coder/bin"
@ -87,7 +87,7 @@ For Vault Enterprise users who need to specify a namespace:
```tf ```tf
module "vault_cli" { module "vault_cli" {
source = "registry.coder.com/coder/vault-cli/coder" source = "registry.coder.com/coder/vault-cli/coder"
version = "1.1.0" version = "1.1.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
vault_addr = "https://vault.example.com" vault_addr = "https://vault.example.com"
vault_token = var.vault_token vault_token = var.vault_token
@ -102,7 +102,7 @@ Install the Vault Enterprise binary. This is required if using SAML authenticati
```tf ```tf
module "vault_cli" { module "vault_cli" {
source = "registry.coder.com/coder/vault-cli/coder" source = "registry.coder.com/coder/vault-cli/coder"
version = "1.1.0" version = "1.1.1"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
vault_addr = "https://vault.example.com" vault_addr = "https://vault.example.com"
enterprise = true enterprise = true

View File

@ -7,40 +7,34 @@ INSTALL_DIR=${INSTALL_DIR}
VAULT_CLI_VERSION=${VAULT_CLI_VERSION} VAULT_CLI_VERSION=${VAULT_CLI_VERSION}
ENTERPRISE=${ENTERPRISE} ENTERPRISE=${ENTERPRISE}
# Fetch URL content. If dest is provided, write to file; otherwise output to stdout. # Fetch URL content to stdout
# Usage: fetch <url> [dest]
fetch() { fetch() {
url="$1" url="$1"
dest="$${2:-}"
# Detect HTTP client on first run
if [ -z "$${HTTP_CLIENT:-}" ]; then
if command -v curl > /dev/null 2>&1; then if command -v curl > /dev/null 2>&1; then
HTTP_CLIENT="curl" curl -sSL --fail "$${url}"
elif command -v wget > /dev/null 2>&1; then elif command -v wget > /dev/null 2>&1; then
HTTP_CLIENT="wget" wget -qO- "$${url}"
elif command -v busybox > /dev/null 2>&1; then elif command -v busybox > /dev/null 2>&1; then
HTTP_CLIENT="busybox" busybox wget -qO- "$${url}"
else else
printf "curl, wget, or busybox is not installed. Please install curl or wget in your image.\n" printf "curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
return 1 return 1
fi fi
fi }
if [ -n "$${dest}" ]; then # Download URL to a file
# shellcheck disable=SC2195 fetch_to_file() {
case "$${HTTP_CLIENT}" in dest="$1"
curl) curl -sSL --fail "$${url}" -o "$${dest}" ;; url="$2"
wget) wget -O "$${dest}" "$${url}" ;; if command -v curl > /dev/null 2>&1; then
busybox) busybox wget -O "$${dest}" "$${url}" ;; curl -sSL --fail "$${url}" -o "$${dest}"
esac elif command -v wget > /dev/null 2>&1; then
wget -O "$${dest}" "$${url}"
elif command -v busybox > /dev/null 2>&1; then
busybox wget -O "$${dest}" "$${url}"
else else
# shellcheck disable=SC2195 printf "curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
case "$${HTTP_CLIENT}" in return 1
curl) curl -sSL --fail "$${url}" ;;
wget) wget -qO- "$${url}" ;;
busybox) busybox wget -qO- "$${url}" ;;
esac
fi fi
} }
@ -141,7 +135,7 @@ install() {
cd "$${TEMP_DIR}" || return 1 cd "$${TEMP_DIR}" || return 1
printf "Downloading from %s\n" "$${DOWNLOAD_URL}" printf "Downloading from %s\n" "$${DOWNLOAD_URL}"
if ! fetch "$${DOWNLOAD_URL}" vault.zip; then if ! fetch_to_file vault.zip "$${DOWNLOAD_URL}"; then
printf "Failed to download Vault.\n" printf "Failed to download Vault.\n"
rm -rf "$${TEMP_DIR}" rm -rf "$${TEMP_DIR}"
return 1 return 1