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

Helm: Fix elasticsearch URL in secret when username/password fields are empty, #21222

Merged
merged 8 commits into from
Feb 11, 2022
8 changes: 6 additions & 2 deletions chart/templates/secrets/elasticsearch-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ metadata:
type: Opaque
data:
{{- with .Values.elasticsearch.connection }}
connection: {{ urlJoin (dict "scheme" (default "http" .scheme) "userinfo" (printf "%s:%s" (.user | urlquery) (.pass | urlquery)) "host" (printf "%s:%s" .host ((default 9200 .port) | toString) ) ) | b64enc | quote }}
{{- end }}
{{- if and .user .pass }}
connection: {{ urlJoin (dict "scheme" (default "http" .scheme) "userinfo" (printf "%s:%s" (.user | urlquery) (.pass | urlquery)) "host" (printf "%s:%s" .host ((default 9200 .port) | toString) ) ) | b64enc | quote }}
{{- else }}
connection: {{ urlJoin (dict "scheme" (default "http" .scheme) "host" (printf "%s:%s" .host ((default 9200 .port) | toString))) | b64enc | quote }}
{{- end }}
{{- end }}
{{- end }}
27 changes: 27 additions & 0 deletions chart/tests/test_elasticsearch_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,30 @@ def test_should_generate_secret_with_specified_schemes(self, scheme):
)

assert f"{scheme}://username:password@elastichostname:9200" == connection

@parameterized.expand(
[
# When both user and password are empty.
({}, ""),
# When password is empty
({"user": "admin"}, ""),
# When user is empty
({"pass": "password"}, ""),
# Valid username/password
({"user": "admin", "pass": "password"}, "admin:password"),
],
)
def test_url_generated_when_user_pass_empty_combinations(self, extra_conn_kwargs, expected_user_info):
connection = self._get_connection(
{
"elasticsearch": {
"enabled": True,
"connection": {"host": "elastichostname", "port": 8080, **extra_conn_kwargs},
}
}
)

if not expected_user_info:
assert "http://elastichostname:8080" == connection
else:
assert f"http://{expected_user_info}@elastichostname:8080" == connection