Skip to content

Commit

Permalink
Chart: Fix elasticsearch URL when username/password are empty (#21222)
Browse files Browse the repository at this point in the history
  • Loading branch information
subkanthi authored Feb 11, 2022
1 parent 5a6a2d6 commit 5dc6338
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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

0 comments on commit 5dc6338

Please sign in to comment.