Skip to content

Commit c6b6ead

Browse files
Add --timeout (-to) as an option to securityadmin.sh (#5787)
Signed-off-by: Craig Perkins <[email protected]> Signed-off-by: Darshit Chanpura <[email protected]> Co-authored-by: Darshit Chanpura <[email protected]>
1 parent bf3bb55 commit c6b6ead

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2222
- [Resource Sharing] Keep track of resource_type on resource sharing document ([#5772](https://github.com/opensearch-project/security/pull/5772))
2323
- Add support for X509 v3 extensions (SAN) for authentication ([#5701](https://github.com/opensearch-project/security/pull/5701))
2424
- [Resource Sharing] Requires default_owner for resource/migrate API ([#5789](https://github.com/opensearch-project/security/pull/5789))
25+
- Add --timeout (-to) as an option to securityadmin.sh ([#5787](https://github.com/opensearch-project/security/pull/5787))
2526

2627
### Bug Fixes
2728
- Create a WildcardMatcher.NONE when creating a WildcardMatcher with an empty string ([#5694](https://github.com/opensearch-project/security/pull/5694))

src/main/java/org/opensearch/security/tools/SecurityAdmin.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public static int execute(final String[] args) throws Exception {
226226
options.addOption(
227227
Option.builder("p").longOpt("port").hasArg().argName("port").desc("OpenSearch transport port (default: 9200)").build()
228228
);
229+
options.addOption(Option.builder("to").longOpt("timeout").hasArg().argName("timeout").desc("timeout (default: 30s)").build());
229230
options.addOption(
230231
Option.builder("cn")
231232
.longOpt("clustername")
@@ -336,6 +337,7 @@ public static int execute(final String[] args) throws Exception {
336337

337338
String hostname = "localhost";
338339
int port = 9200;
340+
int timeout = 30;
339341
String kspass = System.getenv(OPENDISTRO_SECURITY_KS_PASS);
340342
String tspass = System.getenv(OPENDISTRO_SECURITY_TS_PASS);
341343
String cd = ".";
@@ -387,6 +389,7 @@ public static int execute(final String[] args) throws Exception {
387389

388390
hostname = line.getOptionValue("h", hostname);
389391
port = Integer.parseInt(line.getOptionValue("p", String.valueOf(port)));
392+
timeout = Integer.parseInt(line.getOptionValue("to", String.valueOf(timeout)));
390393

391394
promptForPassword = line.hasOption("prompt");
392395

@@ -869,7 +872,7 @@ public static int execute(final String[] args) throws Exception {
869872
return (-1);
870873
}
871874

872-
boolean success = uploadFile(restHighLevelClient, file, index, type, resolveEnvVars);
875+
boolean success = uploadFile(restHighLevelClient, file, index, type, resolveEnvVars, timeout);
873876

874877
if (!success) {
875878
System.out.println("ERR: cannot upload configuration, see errors above");
@@ -884,7 +887,7 @@ public static int execute(final String[] args) throws Exception {
884887
return (success ? 0 : -1);
885888
}
886889

887-
return upload(restHighLevelClient, index, cd, expectedNodeCount, resolveEnvVars);
890+
return upload(restHighLevelClient, index, cd, expectedNodeCount, resolveEnvVars, timeout);
888891
}
889892
}
890893

@@ -959,9 +962,10 @@ private static boolean uploadFile(
959962
final String filepath,
960963
final String index,
961964
final String _id,
962-
boolean resolveEnvVars
965+
boolean resolveEnvVars,
966+
int timeout
963967
) {
964-
return uploadFile(restHighLevelClient, filepath, index, _id, resolveEnvVars, false);
968+
return uploadFile(restHighLevelClient, filepath, index, _id, resolveEnvVars, false, timeout);
965969
}
966970

967971
private static boolean uploadFile(
@@ -970,7 +974,8 @@ private static boolean uploadFile(
970974
final String index,
971975
final String _id,
972976
boolean resolveEnvVars,
973-
final boolean populateEmptyIfMissing
977+
final boolean populateEmptyIfMissing,
978+
int timeout
974979
) {
975980

976981
String id = _id;
@@ -988,6 +993,7 @@ private static boolean uploadFile(
988993
final String content = CharStreams.toString(reader);
989994
final String res = restHighLevelClient.index(
990995
new IndexRequest(index).id(id)
996+
.timeout(timeout + "s")
991997
.setRefreshPolicy(RefreshPolicy.IMMEDIATE)
992998
.source(_id, readXContent(resolveEnvVars ? replaceEnvVars(content, Settings.EMPTY) : content, XContentType.YAML)),
993999
RequestOptions.DEFAULT
@@ -1354,23 +1360,23 @@ private static int backup(RestHighLevelClient tc, String index, File backupDir)
13541360
return success ? 0 : -1;
13551361
}
13561362

1357-
private static int upload(RestHighLevelClient tc, String index, String cd, int expectedNodeCount, boolean resolveEnvVars)
1363+
private static int upload(RestHighLevelClient tc, String index, String cd, int expectedNodeCount, boolean resolveEnvVars, int timeout)
13581364
throws IOException {
1359-
boolean success = uploadFile(tc, cd + "config.yml", index, "config", resolveEnvVars);
1360-
success = uploadFile(tc, cd + "roles.yml", index, "roles", resolveEnvVars) && success;
1361-
success = uploadFile(tc, cd + "roles_mapping.yml", index, "rolesmapping", resolveEnvVars) && success;
1365+
boolean success = uploadFile(tc, cd + "config.yml", index, "config", resolveEnvVars, timeout);
1366+
success = uploadFile(tc, cd + "roles.yml", index, "roles", resolveEnvVars, timeout) && success;
1367+
success = uploadFile(tc, cd + "roles_mapping.yml", index, "rolesmapping", resolveEnvVars, timeout) && success;
13621368

1363-
success = uploadFile(tc, cd + "internal_users.yml", index, "internalusers", resolveEnvVars) && success;
1364-
success = uploadFile(tc, cd + "action_groups.yml", index, "actiongroups", resolveEnvVars) && success;
1369+
success = uploadFile(tc, cd + "internal_users.yml", index, "internalusers", resolveEnvVars, timeout) && success;
1370+
success = uploadFile(tc, cd + "action_groups.yml", index, "actiongroups", resolveEnvVars, timeout) && success;
13651371

1366-
success = uploadFile(tc, cd + "tenants.yml", index, "tenants", resolveEnvVars) && success;
1372+
success = uploadFile(tc, cd + "tenants.yml", index, "tenants", resolveEnvVars, timeout) && success;
13671373

1368-
success = uploadFile(tc, cd + "nodes_dn.yml", index, "nodesdn", resolveEnvVars, true) && success;
1374+
success = uploadFile(tc, cd + "nodes_dn.yml", index, "nodesdn", resolveEnvVars, true, timeout) && success;
13691375
if (new File(cd + "audit.yml").exists()) {
1370-
success = uploadFile(tc, cd + "audit.yml", index, "audit", resolveEnvVars) && success;
1376+
success = uploadFile(tc, cd + "audit.yml", index, "audit", resolveEnvVars, timeout) && success;
13711377
}
13721378
if (new File(cd + "allowlist.yml").exists()) {
1373-
success = uploadFile(tc, cd + "allowlist.yml", index, "allowlist", resolveEnvVars) && success;
1379+
success = uploadFile(tc, cd + "allowlist.yml", index, "allowlist", resolveEnvVars, timeout) && success;
13741380
}
13751381

13761382
if (!success) {

0 commit comments

Comments
 (0)