Skip to content

Commit

Permalink
Fix helm chart for elasticsearch secret when username/password fields…
Browse files Browse the repository at this point in the history
… are empty
  • Loading branch information
subkanthi committed Feb 7, 2022
1 parent 3a78038 commit e37f7bd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
12 changes: 10 additions & 2 deletions chart/templates/secrets/elasticsearch-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ 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 .user }}
{{- if .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 }}
{{- else }}
connection: {{ urlJoin (dict "scheme" (default "http" .scheme) "host" (printf "%s:%s" .host ((default 9200 .port) | toString))) | b64enc | quote }}
{{- end }}
{{- end }}
{{- end }}
36 changes: 36 additions & 0 deletions chart/tests/test_elasticsearch_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,39 @@ def test_should_generate_secret_with_specified_schemes(self, scheme):
)

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

def test_url_generated_when_user_is_empty(self):
connection = self._get_connection(
{
"elasticsearch": {
"enabled": True,
"connection": {"pass": "password", "host": "elastichostname", "port": 8080},
}
}
)

assert "http://elastichostname:8080" == connection

def test_url_generated_when_password_is_empty(self):
connection = self._get_connection(
{
"elasticsearch": {
"enabled": True,
"connection": {"user": "admin", "host": "elastichostname", "port": 8080},
}
}
)

assert "http://elastichostname:8080" == connection

def test_url_generated_with_valid_user_password(self):
connection = self._get_connection(
{
"elasticsearch": {
"enabled": True,
"connection": {"user": "admin", "pass": "pass", "host": "elastichostname", "port": 8080},
}
}
)

assert "http://admin:pass@elastichostname:8080" == connection

0 comments on commit e37f7bd

Please sign in to comment.