Skip to content

Commit 1de1dc5

Browse files
Copilotaslafy-z
andcommitted
Add Helm version requirements for credential support
- Add version requirement note to README.md for credential support (>=3.14.0) - Add v3.18.5 to CI test matrix - Add helm_supports_credentials() version check function - Scope credential tests to skip on Helm versions < 3.14.0 - Fix linting issues (trailing whitespace) Co-authored-by: aslafy-z <[email protected]>
1 parent 3dc13db commit 1de1dc5

File tree

5 files changed

+100
-22
lines changed

5 files changed

+100
-22
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
helm: ['2.17.0', '3.4.2', '3.7.1']
30+
helm: ['2.17.0', '3.4.2', '3.7.1', '3.18.5']
3131
env:
3232
FIXTURES_GIT_REPO: ${{ format('{0}/{1}', github.server_url, github.event.pull_request.head.repo.full_name || github.repository) }}
3333
FIXTURES_GIT_REF: ${{ github.head_ref || github.ref_name }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ As this plugin uses `git` CLI to clone repos. You can configure private access i
102102

103103
#### Helm Credentials Support
104104

105+
> **Note:** This feature requires Helm v3.14.0 or later.
106+
105107
This plugin supports Helm's built-in credential passing mechanism. When you use `helm repo add` with `--username` and `--password` flags, the plugin automatically configures git to use these credentials:
106108

107109
```bash

helm-git-plugin.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ git_fetch_ref() {
120120
setup_git_credentials() {
121121
if [ -n "${HELM_PLUGIN_USERNAME:-}" ] && [ -n "${HELM_PLUGIN_PASSWORD:-}" ]; then
122122
debug "Setting up git credentials using Helm-provided username and password"
123-
123+
124124
# Export credentials as environment variables for the credential helper
125125
export GIT_USER="${HELM_PLUGIN_USERNAME}"
126126
export GIT_PASSWORD="${HELM_PLUGIN_PASSWORD}"
127127
export HELM_GIT_USE_CREDENTIALS="1"
128-
128+
129129
trace "Git credential helper configured with username: ${HELM_PLUGIN_USERNAME}"
130130
else
131131
trace "No Helm plugin credentials found, using existing git authentication"
@@ -442,7 +442,7 @@ main() {
442442
fi
443443

444444
# Setup exit trap
445-
# shellcheck disable=SC2317,SC2329
445+
# shellcheck disable=SC2317,SC2329
446446
exit_trap() {
447447
[ "$cleanup" = 1 ] || return 0
448448
rm -rf "$git_root_path" "${helm_home_target_path:-}"

tests/07-credentials.bats

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,80 +2,110 @@
22

33
load 'test-helper'
44

5+
setup_file() {
6+
if ! helm_supports_credentials; then
7+
echo "# Skipping credential tests - Helm version < 3.14.0 does not support credential passing" >&2
8+
fi
9+
}
10+
511
@test "should setup git credentials when HELM_PLUGIN_USERNAME and HELM_PLUGIN_PASSWORD are set" {
12+
if ! helm_supports_credentials; then
13+
skip "Helm version < 3.14.0 does not support credential passing"
14+
fi
15+
616
export HELM_PLUGIN_USERNAME="testuser"
717
export HELM_PLUGIN_PASSWORD="testpass"
8-
18+
919
# Call setup_git_credentials function in a subshell to check exports
1020
run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && echo "GIT_USER=${GIT_USER}" && echo "GIT_PASSWORD=${GIT_PASSWORD}"'
1121
[ $status = 0 ]
12-
22+
1323
# Check that the output contains the expected values
1424
[[ "$output" == *"GIT_USER=testuser"* ]]
1525
[[ "$output" == *"GIT_PASSWORD=testpass"* ]]
16-
26+
1727
# Check that HELM_GIT_USE_CREDENTIALS is set to enable git_cmd wrapper
1828
run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && echo "HELM_GIT_USE_CREDENTIALS=${HELM_GIT_USE_CREDENTIALS}"'
1929
[ $status = 0 ]
2030
[[ "$output" == *"HELM_GIT_USE_CREDENTIALS=1"* ]]
2131
}
2232

2333
@test "should not setup git credentials when HELM_PLUGIN_USERNAME is missing" {
34+
if ! helm_supports_credentials; then
35+
skip "Helm version < 3.14.0 does not support credential passing"
36+
fi
37+
2438
unset HELM_PLUGIN_USERNAME
2539
export HELM_PLUGIN_PASSWORD="testpass"
26-
40+
2741
# Call setup_git_credentials function
2842
run setup_git_credentials
2943
[ $status = 0 ]
30-
44+
3145
# Check that environment variables are not set
3246
[ -z "${GIT_USER:-}" ]
3347
[ -z "${GIT_PASSWORD:-}" ]
3448
}
3549

3650
@test "should not setup git credentials when HELM_PLUGIN_PASSWORD is missing" {
51+
if ! helm_supports_credentials; then
52+
skip "Helm version < 3.14.0 does not support credential passing"
53+
fi
54+
3755
export HELM_PLUGIN_USERNAME="testuser"
3856
unset HELM_PLUGIN_PASSWORD
39-
57+
4058
# Call setup_git_credentials function
4159
run setup_git_credentials
4260
[ $status = 0 ]
43-
61+
4462
# Check that environment variables are not set
4563
[ -z "${GIT_USER:-}" ]
4664
[ -z "${GIT_PASSWORD:-}" ]
4765
}
4866

4967
@test "should not setup git credentials when both are missing" {
68+
if ! helm_supports_credentials; then
69+
skip "Helm version < 3.14.0 does not support credential passing"
70+
fi
71+
5072
unset HELM_PLUGIN_USERNAME
5173
unset HELM_PLUGIN_PASSWORD
52-
74+
5375
# Call setup_git_credentials function
5476
run setup_git_credentials
5577
[ $status = 0 ]
56-
78+
5779
# Check that environment variables are not set
5880
[ -z "${GIT_USER:-}" ]
5981
[ -z "${GIT_PASSWORD:-}" ]
6082
}
6183

6284
@test "helm_git main should call setup_git_credentials with username and password" {
85+
if ! helm_supports_credentials; then
86+
skip "Helm version < 3.14.0 does not support credential passing"
87+
fi
88+
6389
export HELM_PLUGIN_USERNAME="testuser"
6490
export HELM_PLUGIN_PASSWORD="testpass"
65-
91+
6692
# Test that main function sets up credentials by checking git config
6793
run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && export HELM_GIT_DEBUG=1 && main "" "" "" "git+https://example.com/[email protected]?ref=master" 2>&1 || true'
68-
94+
6995
# Check that the debug message about setting up credentials appears
7096
[[ "$output" == *"Setting up git credentials using Helm-provided username and password"* ]]
7197
}
7298

7399
@test "git credential helper should work with environment variables" {
100+
if ! helm_supports_credentials; then
101+
skip "Helm version < 3.14.0 does not support credential passing"
102+
fi
103+
74104
export HELM_PLUGIN_USERNAME="testuser"
75105
export HELM_PLUGIN_PASSWORD="testpass"
76106
export GIT_USER="testuser"
77107
export GIT_PASSWORD="testpass"
78-
108+
79109
# Test the credential helper directly
80110
run bash -c 'echo "username=${GIT_USER}"; echo "password=${GIT_PASSWORD}"'
81111
[ $status = 0 ]
@@ -84,36 +114,48 @@ load 'test-helper'
84114
}
85115

86116
@test "should handle credentials with special characters" {
117+
if ! helm_supports_credentials; then
118+
skip "Helm version < 3.14.0 does not support credential passing"
119+
fi
120+
87121
export HELM_PLUGIN_USERNAME="[email protected]"
88122
export HELM_PLUGIN_PASSWORD="pass/with/special&chars"
89-
123+
90124
# Call setup_git_credentials function in a subshell to check exports
91125
run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && echo "GIT_USER=${GIT_USER}" && echo "GIT_PASSWORD=${GIT_PASSWORD}"'
92126
[ $status = 0 ]
93-
127+
94128
# Check that the output contains the expected values with special characters
95129
[[ "$output" == *"[email protected]"* ]]
96130
[[ "$output" == *"GIT_PASSWORD=pass/with/special&chars"* ]]
97131
}
98132

99133
@test "git_cmd should use credentials when available" {
134+
if ! helm_supports_credentials; then
135+
skip "Helm version < 3.14.0 does not support credential passing"
136+
fi
137+
100138
export HELM_PLUGIN_USERNAME="testuser"
101139
export HELM_PLUGIN_PASSWORD="testpass"
102-
140+
103141
# Test git_cmd function
104142
run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && git_cmd config --list | grep -E "(user|credential)" || echo "No credential config found"'
105143
[ $status = 0 ]
106-
144+
107145
# Should succeed (exit code 0)
108146
}
109147

110148
@test "git_cmd should work normally when no credentials" {
149+
if ! helm_supports_credentials; then
150+
skip "Helm version < 3.14.0 does not support credential passing"
151+
fi
152+
111153
unset HELM_PLUGIN_USERNAME
112154
unset HELM_PLUGIN_PASSWORD
113155
unset HELM_GIT_USE_CREDENTIALS
114-
156+
115157
# Test git_cmd function without credentials
116158
run bash -c 'source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && git_cmd --version'
117159
[ $status = 0 ]
118160
[[ "$output" == *"git version"* ]]
119-
}
161+
}

tests/test-helper.bash

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,37 @@ set_chart_cache_strategy() {
5454
HELM_GIT_CHART_CACHE_STRATEGY="$1"
5555
export HELM_GIT_CHART_CACHE_STRATEGY
5656
}
57+
58+
# Check if Helm version supports credential passing (>= 3.14.0)
59+
helm_supports_credentials() {
60+
local helm_version
61+
helm_version=$($HELM_BIN version --short 2>/dev/null | head -1 | sed 's/v//' | cut -d'+' -f1 | cut -d'-' -f1)
62+
63+
# If we can't get version, assume it doesn't support credentials
64+
[ -n "$helm_version" ] || return 1
65+
66+
# Extract major.minor.patch using parameter expansion
67+
local major="${helm_version%%.*}"
68+
local rest="${helm_version#*.}"
69+
local minor="${rest%%.*}"
70+
local patch="${rest#*.}"
71+
72+
# If patch is the same as rest, there was no second dot, so patch is 0
73+
[ "$patch" = "$rest" ] && patch=0
74+
75+
# Ensure we have numeric values (basic check)
76+
case "$major" in ''|*[!0-9]*) return 1 ;; esac
77+
case "$minor" in ''|*[!0-9]*) return 1 ;; esac
78+
case "$patch" in ''|*[!0-9]*) patch=0 ;; esac
79+
80+
# Check if version >= 3.14.0
81+
if [ "$major" -gt 3 ]; then
82+
return 0
83+
elif [ "$major" -eq 3 ] && [ "$minor" -gt 14 ]; then
84+
return 0
85+
elif [ "$major" -eq 3 ] && [ "$minor" -eq 14 ] && [ "$patch" -ge 0 ]; then
86+
return 0
87+
else
88+
return 1
89+
fi
90+
}

0 commit comments

Comments
 (0)