Skip to content

Commit

Permalink
Merge pull request #601 from oujinliang/master
Browse files Browse the repository at this point in the history
ES add auth header
  • Loading branch information
oujinliang committed Aug 29, 2023
2 parents e21cddb + 1d22bb3 commit c35add4
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
package run.mone.hera.operator.common;

import org.apache.commons.lang3.StringUtils;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -1074,12 +1078,22 @@ public class ESIndexConst {
public static void main(String[] args) {
// update your es api address
String esApiAddr = "elasticsearch:9200";
String userName = "";
String password = "";
String authHeader = "";
if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) {
byte[] auth = (userName + ":" + password).getBytes(StandardCharsets.UTF_8);
String base64 = Base64.getEncoder().encodeToString(auth);
authHeader = "--header 'Authorization: Basic " + base64 + "' \\\n";
}

for (String index : templates.keySet()) {
System.out.println("curl --location --request PUT 'http://" + esApiAddr + "/_template/" + index + "' \\\n" +
"--header 'Content-type: application/json; charset=UTF-8' \\\n" +
authHeader +
"--data-raw '" + templates.get(index).replaceAll("\\\n", "").replaceAll("\\\t", "").replaceAll(" ", "") + "'");
System.out.println("=============================================================");
}
}

}

0 comments on commit c35add4

Please sign in to comment.