@@ -29,15 +29,14 @@ function augment_curl_args {
2929 if [[ -n " ${ELASTIC_PASSWORD:- } " ]]; then
3030 args_ref+=( ' -u' " elastic:${ELASTIC_PASSWORD} " )
3131 fi
32+ if [[ -n " ${ELASTICSEARCH_ADDR:- } " ]]; then
33+ args_ref+=( ' --resolve' " elasticsearch:9200:${ELASTICSEARCH_ADDR} " )
34+ fi
3235}
3336
3437# Poll the 'elasticsearch' service until it responds with HTTP code 200.
3538function wait_for_elasticsearch {
36- local elasticsearch_host=" ${ELASTICSEARCH_HOST:- elasticsearch} "
37-
38- local -a args=( ' -s' ' -D-' ' -m15' ' -w' ' %{http_code}' ' https://elasticsearch:9200/'
39- ' --resolve' " elasticsearch:9200:${elasticsearch_host} " ' --cacert' " $es_ca_cert "
40- )
39+ local -a args=( ' -s' ' -D-' ' -m15' ' -w' ' %{http_code}' ' https://elasticsearch:9200/' ' --cacert' " $es_ca_cert " )
4140
4241 augment_curl_args args
4342
@@ -70,11 +69,7 @@ function wait_for_elasticsearch {
7069
7170# Poll the Elasticsearch users API until it returns users.
7271function wait_for_builtin_users {
73- local elasticsearch_host=" ${ELASTICSEARCH_HOST:- elasticsearch} "
74-
75- local -a args=( ' -s' ' -D-' ' -m15' ' https://elasticsearch:9200/_security/user?pretty'
76- ' --resolve' " elasticsearch:9200:${elasticsearch_host} " ' --cacert' " $es_ca_cert "
77- )
72+ local -a args=( ' -s' ' -D-' ' -m15' ' https://elasticsearch:9200/_security/user?pretty' ' --cacert' " $es_ca_cert " )
7873
7974 augment_curl_args args
8075
@@ -119,11 +114,9 @@ function wait_for_builtin_users {
119114function check_user_exists {
120115 local username=$1
121116
122- local elasticsearch_host=" ${ELASTICSEARCH_HOST:- elasticsearch} "
123-
124117 local -a args=( ' -s' ' -D-' ' -m15' ' -w' ' %{http_code}'
125118 " https://elasticsearch:9200/_security/user/${username} "
126- ' --resolve ' " elasticsearch:9200: ${elasticsearch_host} " ' -- cacert' " $es_ca_cert "
119+ ' --cacert' " $es_ca_cert "
127120 )
128121
129122 augment_curl_args args
@@ -154,11 +147,9 @@ function set_user_password {
154147 local username=$1
155148 local password=$2
156149
157- local elasticsearch_host=" ${ELASTICSEARCH_HOST:- elasticsearch} "
158-
159150 local -a args=( ' -s' ' -D-' ' -m15' ' -w' ' %{http_code}'
160151 " https://elasticsearch:9200/_security/user/${username} /_password"
161- ' --resolve ' " elasticsearch:9200: ${elasticsearch_host} " ' -- cacert' " $es_ca_cert "
152+ ' --cacert' " $es_ca_cert "
162153 ' -X' ' POST'
163154 ' -H' ' Content-Type: application/json'
164155 ' -d' " {\" password\" : \" ${password} \" }"
@@ -187,11 +178,9 @@ function create_user {
187178 local password=$2
188179 local role=$3
189180
190- local elasticsearch_host=" ${ELASTICSEARCH_HOST:- elasticsearch} "
191-
192181 local -a args=( ' -s' ' -D-' ' -m15' ' -w' ' %{http_code}'
193182 " https://elasticsearch:9200/_security/user/${username} "
194- ' --resolve ' " elasticsearch:9200: ${elasticsearch_host} " ' -- cacert' " $es_ca_cert "
183+ ' --cacert' " $es_ca_cert "
195184 ' -X' ' POST'
196185 ' -H' ' Content-Type: application/json'
197186 ' -d' " {\" password\" :\" ${password} \" ,\" roles\" :[\" ${role} \" ]}"
@@ -219,11 +208,9 @@ function ensure_role {
219208 local name=$1
220209 local body=$2
221210
222- local elasticsearch_host=" ${ELASTICSEARCH_HOST:- elasticsearch} "
223-
224211 local -a args=( ' -s' ' -D-' ' -m15' ' -w' ' %{http_code}'
225212 " https://elasticsearch:9200/_security/role/${name} "
226- ' --resolve ' " elasticsearch:9200: ${elasticsearch_host} " ' -- cacert' " $es_ca_cert "
213+ ' --cacert' " $es_ca_cert "
227214 ' -X' ' POST'
228215 ' -H' ' Content-Type: application/json'
229216 ' -d' " $body "
0 commit comments