Skip to content

Commit 678c3e6

Browse files
authored
fix(vault-cli): use if/elif/else instead of case for HTTP client detection (#625)
1 parent 3608961 commit 678c3e6

2 files changed

Lines changed: 31 additions & 37 deletions

File tree

registry/coder/modules/vault-cli/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Installs the [Vault](https://www.vaultproject.io/) CLI and optionally configures
1313
```tf
1414
module "vault_cli" {
1515
source = "registry.coder.com/coder/vault-cli/coder"
16-
version = "1.1.0"
16+
version = "1.1.1"
1717
agent_id = coder_agent.example.id
1818
vault_addr = "https://vault.example.com"
1919
}
@@ -34,7 +34,7 @@ If you have a Vault token, you can provide it to automatically configure authent
3434
```tf
3535
module "vault_cli" {
3636
source = "registry.coder.com/coder/vault-cli/coder"
37-
version = "1.1.0"
37+
version = "1.1.1"
3838
agent_id = coder_agent.example.id
3939
vault_addr = "https://vault.example.com"
4040
vault_token = var.vault_token # Optional
@@ -50,7 +50,7 @@ Install the Vault CLI without any authentication:
5050
```tf
5151
module "vault_cli" {
5252
source = "registry.coder.com/coder/vault-cli/coder"
53-
version = "1.1.0"
53+
version = "1.1.1"
5454
agent_id = coder_agent.example.id
5555
vault_addr = "https://vault.example.com"
5656
}
@@ -61,7 +61,7 @@ module "vault_cli" {
6161
```tf
6262
module "vault_cli" {
6363
source = "registry.coder.com/coder/vault-cli/coder"
64-
version = "1.1.0"
64+
version = "1.1.1"
6565
agent_id = coder_agent.example.id
6666
vault_addr = "https://vault.example.com"
6767
vault_cli_version = "1.15.0"
@@ -73,7 +73,7 @@ module "vault_cli" {
7373
```tf
7474
module "vault_cli" {
7575
source = "registry.coder.com/coder/vault-cli/coder"
76-
version = "1.1.0"
76+
version = "1.1.1"
7777
agent_id = coder_agent.example.id
7878
vault_addr = "https://vault.example.com"
7979
install_dir = "/home/coder/bin"
@@ -87,7 +87,7 @@ For Vault Enterprise users who need to specify a namespace:
8787
```tf
8888
module "vault_cli" {
8989
source = "registry.coder.com/coder/vault-cli/coder"
90-
version = "1.1.0"
90+
version = "1.1.1"
9191
agent_id = coder_agent.example.id
9292
vault_addr = "https://vault.example.com"
9393
vault_token = var.vault_token
@@ -102,7 +102,7 @@ Install the Vault Enterprise binary. This is required if using SAML authenticati
102102
```tf
103103
module "vault_cli" {
104104
source = "registry.coder.com/coder/vault-cli/coder"
105-
version = "1.1.0"
105+
version = "1.1.1"
106106
agent_id = coder_agent.example.id
107107
vault_addr = "https://vault.example.com"
108108
enterprise = true

registry/coder/modules/vault-cli/run.sh

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,34 @@ INSTALL_DIR=${INSTALL_DIR}
77
VAULT_CLI_VERSION=${VAULT_CLI_VERSION}
88
ENTERPRISE=${ENTERPRISE}
99

10-
# Fetch URL content. If dest is provided, write to file; otherwise output to stdout.
11-
# Usage: fetch <url> [dest]
10+
# Fetch URL content to stdout
1211
fetch() {
1312
url="$1"
14-
dest="$${2:-}"
15-
16-
# Detect HTTP client on first run
17-
if [ -z "$${HTTP_CLIENT:-}" ]; then
18-
if command -v curl > /dev/null 2>&1; then
19-
HTTP_CLIENT="curl"
20-
elif command -v wget > /dev/null 2>&1; then
21-
HTTP_CLIENT="wget"
22-
elif command -v busybox > /dev/null 2>&1; then
23-
HTTP_CLIENT="busybox"
24-
else
25-
printf "curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
26-
return 1
27-
fi
13+
if command -v curl > /dev/null 2>&1; then
14+
curl -sSL --fail "$${url}"
15+
elif command -v wget > /dev/null 2>&1; then
16+
wget -qO- "$${url}"
17+
elif command -v busybox > /dev/null 2>&1; then
18+
busybox wget -qO- "$${url}"
19+
else
20+
printf "curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
21+
return 1
2822
fi
23+
}
2924

30-
if [ -n "$${dest}" ]; then
31-
# shellcheck disable=SC2195
32-
case "$${HTTP_CLIENT}" in
33-
curl) curl -sSL --fail "$${url}" -o "$${dest}" ;;
34-
wget) wget -O "$${dest}" "$${url}" ;;
35-
busybox) busybox wget -O "$${dest}" "$${url}" ;;
36-
esac
25+
# Download URL to a file
26+
fetch_to_file() {
27+
dest="$1"
28+
url="$2"
29+
if command -v curl > /dev/null 2>&1; then
30+
curl -sSL --fail "$${url}" -o "$${dest}"
31+
elif command -v wget > /dev/null 2>&1; then
32+
wget -O "$${dest}" "$${url}"
33+
elif command -v busybox > /dev/null 2>&1; then
34+
busybox wget -O "$${dest}" "$${url}"
3735
else
38-
# shellcheck disable=SC2195
39-
case "$${HTTP_CLIENT}" in
40-
curl) curl -sSL --fail "$${url}" ;;
41-
wget) wget -qO- "$${url}" ;;
42-
busybox) busybox wget -qO- "$${url}" ;;
43-
esac
36+
printf "curl, wget, or busybox is not installed. Please install curl or wget in your image.\n"
37+
return 1
4438
fi
4539
}
4640

@@ -141,7 +135,7 @@ install() {
141135
cd "$${TEMP_DIR}" || return 1
142136

143137
printf "Downloading from %s\n" "$${DOWNLOAD_URL}"
144-
if ! fetch "$${DOWNLOAD_URL}" vault.zip; then
138+
if ! fetch_to_file vault.zip "$${DOWNLOAD_URL}"; then
145139
printf "Failed to download Vault.\n"
146140
rm -rf "$${TEMP_DIR}"
147141
return 1

0 commit comments

Comments
 (0)