epugh commented on code in PR #5306:
URL: https://github.com/apache/solr/pull/5306#discussion_r4539269361


##########
solr/core/src/java/org/apache/solr/cli/RunExampleTool.java:
##########
@@ -597,20 +628,501 @@ void initDirs(
       String solrHomeProp = EnvUtils.getProperty("solr.home");
       if (solrHomeProp != null && !solrHomeProp.isEmpty()) {
         solrHomeDir = Path.of(solrHomeProp);
-      } else if ("cloud".equals(exampleType)) {
-        solrHomeDir = exampleDir.resolve("cloud");
+      } else if ("cloud".equals(exampleType) || "secure".equals(exampleType)) {
+        solrHomeDir = exampleDir.resolve(exampleType);
         if (!Files.isDirectory(solrHomeDir)) 
Files.createDirectory(solrHomeDir);
       } else {
         solrHomeDir = serverDir.resolve("solr");
       }
     }
+    if ("secure".equals(exampleType)) Files.createDirectories(solrHomeDir);
     if (!Files.isDirectory(solrHomeDir))
       throw new IllegalArgumentException(
           "Value of --solr-home option is invalid! "
               + solrHomeDir.toAbsolutePath()
               + " is not a directory!");
   }
 
+  /** Runs the equivalent steps of the Ref Guide security tutorial */
+  void runSecureExample(CloudExampleParams params, boolean userManaged) throws 
Exception {
+    StartSolrParams start = params.start();
+    if (userManaged || params.zkHost() != null) {
+      throw new IllegalArgumentException(
+          "The secure example requires its own embedded ZooKeeper in SolrCloud 
mode.");
+    }
+    if (start.host() != null
+        || start.jvmOpts() != null
+        || !start.extraArgs().isEmpty()
+        || params.scriptInputs() != null
+        || System.getenv("SOLR_DATA_HOME") != null) {
+      throw new IllegalArgumentException(
+          "Unsupported secure example option. Use --solr-home, -p, 
--no-prompt, -m, or --force.");

Review Comment:
   Done, took your suggested wording.



##########
solr/core/src/java/org/apache/solr/cli/RunExampleTool.java:
##########
@@ -597,20 +628,501 @@ void initDirs(
       String solrHomeProp = EnvUtils.getProperty("solr.home");
       if (solrHomeProp != null && !solrHomeProp.isEmpty()) {
         solrHomeDir = Path.of(solrHomeProp);
-      } else if ("cloud".equals(exampleType)) {
-        solrHomeDir = exampleDir.resolve("cloud");
+      } else if ("cloud".equals(exampleType) || "secure".equals(exampleType)) {
+        solrHomeDir = exampleDir.resolve(exampleType);
         if (!Files.isDirectory(solrHomeDir)) 
Files.createDirectory(solrHomeDir);
       } else {
         solrHomeDir = serverDir.resolve("solr");
       }
     }
+    if ("secure".equals(exampleType)) Files.createDirectories(solrHomeDir);
     if (!Files.isDirectory(solrHomeDir))
       throw new IllegalArgumentException(
           "Value of --solr-home option is invalid! "
               + solrHomeDir.toAbsolutePath()
               + " is not a directory!");
   }
 
+  /** Runs the equivalent steps of the Ref Guide security tutorial */
+  void runSecureExample(CloudExampleParams params, boolean userManaged) throws 
Exception {
+    StartSolrParams start = params.start();
+    if (userManaged || params.zkHost() != null) {
+      throw new IllegalArgumentException(
+          "The secure example requires its own embedded ZooKeeper in SolrCloud 
mode.");
+    }
+    if (start.host() != null
+        || start.jvmOpts() != null
+        || !start.extraArgs().isEmpty()
+        || params.scriptInputs() != null
+        || System.getenv("SOLR_DATA_HOME") != null) {
+      throw new IllegalArgumentException(
+          "Unsupported secure example option. Use --solr-home, -p, 
--no-prompt, -m, or --force.");
+    }
+    int port = params.basePort();
+    Path home = solrHomeDir.toAbsolutePath().normalize();
+    echo(
+        "Commands below use paths relative to "
+            + serverDir.getParent().toAbsolutePath().normalize());
+    Path tls = home.resolve("tls");
+    Path include = tls.resolve("solr.in.sh");
+    String zkHost = "localhost:" + (port + 1000);
+    Map<String, String> environment = new 
HashMap<>(EnvironmentUtils.getProcEnvironment());
+    environment.put("SOLR_INCLUDE", include.toString());
+    environment.put("SOLR_ULIMIT_CHECKS", "false");
+    environment.put("SOLR_PID_DIR", home.toString());
+    environment.put("SOLR_HOME", tls.toString());
+    environment.remove("SOLR_ZK_CREDS_AND_ACLS");
+    environment.remove("ZK_HOST");
+    echo("This example uses 'SolrRocks' for its keystore and demonstration 
accounts.");

Review Comment:
   Ended up superseding this one with the password-randomization change below — 
the echo now prints the actual generated password rather than a static "This 
example uses SolrRocks" message, so the wording concern is moot.



##########
solr/core/src/java/org/apache/solr/cli/RunExampleTool.java:
##########
@@ -597,20 +628,501 @@ void initDirs(
       String solrHomeProp = EnvUtils.getProperty("solr.home");
       if (solrHomeProp != null && !solrHomeProp.isEmpty()) {
         solrHomeDir = Path.of(solrHomeProp);
-      } else if ("cloud".equals(exampleType)) {
-        solrHomeDir = exampleDir.resolve("cloud");
+      } else if ("cloud".equals(exampleType) || "secure".equals(exampleType)) {
+        solrHomeDir = exampleDir.resolve(exampleType);
         if (!Files.isDirectory(solrHomeDir)) 
Files.createDirectory(solrHomeDir);
       } else {
         solrHomeDir = serverDir.resolve("solr");
       }
     }
+    if ("secure".equals(exampleType)) Files.createDirectories(solrHomeDir);
     if (!Files.isDirectory(solrHomeDir))
       throw new IllegalArgumentException(
           "Value of --solr-home option is invalid! "
               + solrHomeDir.toAbsolutePath()
               + " is not a directory!");
   }
 
+  /** Runs the equivalent steps of the Ref Guide security tutorial */
+  void runSecureExample(CloudExampleParams params, boolean userManaged) throws 
Exception {
+    StartSolrParams start = params.start();
+    if (userManaged || params.zkHost() != null) {
+      throw new IllegalArgumentException(
+          "The secure example requires its own embedded ZooKeeper in SolrCloud 
mode.");
+    }
+    if (start.host() != null
+        || start.jvmOpts() != null
+        || !start.extraArgs().isEmpty()
+        || params.scriptInputs() != null
+        || System.getenv("SOLR_DATA_HOME") != null) {
+      throw new IllegalArgumentException(
+          "Unsupported secure example option. Use --solr-home, -p, 
--no-prompt, -m, or --force.");
+    }
+    int port = params.basePort();
+    Path home = solrHomeDir.toAbsolutePath().normalize();
+    echo(
+        "Commands below use paths relative to "
+            + serverDir.getParent().toAbsolutePath().normalize());
+    Path tls = home.resolve("tls");
+    Path include = tls.resolve("solr.in.sh");
+    String zkHost = "localhost:" + (port + 1000);
+    Map<String, String> environment = new 
HashMap<>(EnvironmentUtils.getProcEnvironment());
+    environment.put("SOLR_INCLUDE", include.toString());
+    environment.put("SOLR_ULIMIT_CHECKS", "false");
+    environment.put("SOLR_PID_DIR", home.toString());
+    environment.put("SOLR_HOME", tls.toString());
+    environment.remove("SOLR_ZK_CREDS_AND_ACLS");
+    environment.remove("ZK_HOST");
+    echo("This example uses 'SolrRocks' for its keystore and demonstration 
accounts.");
+    echo("ZooKeeper is protected by digest ACLs; its transport remains 
plaintext on loopback.");
+    if (!params.noPrompt()) {
+      prompt(
+          new Scanner(userInput, StandardCharsets.UTF_8),

Review Comment:
   Done — pulled it into a shared userInputScanner() helper used by both 
runCloudExample and runSecureExample.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to