You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "sonatype-lift[bot] (via GitHub)" <gi...@apache.org> on 2023/07/14 17:35:15 UTC

[GitHub] [solr] sonatype-lift[bot] commented on a diff in pull request #1785: SOLR-16892: make CreateTool Cloud/Standalone Aware

sonatype-lift[bot] commented on code in PR #1785:
URL: https://github.com/apache/solr/pull/1785#discussion_r1263978853


##########
solr/core/src/java/org/apache/solr/cli/CreateTool.java:
##########
@@ -43,24 +67,292 @@ public String getName() {
 
   @Override
   public List<Option> getOptions() {
-    return CreateCollectionTool.CREATE_COLLECTION_OPTIONS;
+    return List.of(
+        SolrCLI.OPTION_ZKHOST,
+        SolrCLI.OPTION_SOLRURL,
+        Option.builder("c")
+            .longOpt("name")
+            .argName("NAME")
+            .hasArg()
+            .required(true)
+            .desc("Name of collection or core to create.")
+            .build(),
+        Option.builder("s")
+            .longOpt("shards")
+            .argName("#")
+            .hasArg()
+            .required(false)
+            .desc("Number of shards; default is 1.")
+            .build(),
+        Option.builder("rf")
+            .longOpt("replicationFactor")
+            .argName("#")
+            .hasArg()
+            .required(false)
+            .desc(
+                "Number of copies of each document across the collection (replicas per shard); default is 1.")
+            .build(),
+        Option.builder("d")
+            .longOpt("confdir")
+            .argName("NAME")
+            .hasArg()
+            .required(false)
+            .desc(
+                "Configuration directory to copy when creating the new collection; default is "
+                    + SolrCLI.DEFAULT_CONFIG_SET
+                    + '.')
+            .build(),
+        Option.builder("n")
+            .longOpt("confname")
+            .argName("NAME")
+            .hasArg()
+            .required(false)
+            .desc("Configuration name; default is the collection name.")
+            .build(),
+        SolrCLI.OPTION_VERBOSE);
   }
 
   @Override
   public void runImpl(CommandLine cli) throws Exception {
     SolrCLI.raiseLogLevelUnlessVerbose(cli);
     String solrUrl = cli.getOptionValue("solrUrl", SolrCLI.DEFAULT_SOLR_URL);
 
-    ToolBase tool;
     try (var solrClient = SolrCLI.getSolrClient(solrUrl)) {
-      NamedList<Object> systemInfo =
-          solrClient.request(new GenericSolrRequest(SolrRequest.METHOD.GET, SYSTEM_INFO_PATH));
-      if ("solrcloud".equals(systemInfo.get("mode"))) {
-        tool = new CreateCollectionTool(stdout);
+      if (SolrCLI.isCloudMode(solrClient)) {
+        createCollection(cli);
       } else {
-        tool = new CreateCoreTool(stdout);
+        createCore(cli, solrClient);
+      }
+    }
+  }
+
+  protected void createCore(CommandLine cli, SolrClient solrClient) throws Exception {
+    String coreName = cli.getOptionValue("name");
+    String solrUrl = cli.getOptionValue("solrUrl", SolrCLI.DEFAULT_SOLR_URL);
+
+    final String solrInstallDir = System.getProperty("solr.install.dir");
+    final String confDirName = cli.getOptionValue("confdir", SolrCLI.DEFAULT_CONFIG_SET);
+
+    // we allow them to pass a directory instead of a configset name
+    File configsetDir = new File(confDirName);

Review Comment:
   <picture><img alt="9% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/9/display.svg"></picture>
   
   <b>*[PATH_TRAVERSAL_IN](https://find-sec-bugs.github.io/bugs.htm#PATH_TRAVERSAL_IN):</b>*  This API (java/io/File.<init>(Ljava/lang/String;)V) reads a file whose location might be specified by user input
   
   ❗❗ <b>4 similar findings have been found in this PR</b>
   
   <details><summary>🔎 Expand here to view all instances of this finding</summary><br/>
     
     
   <div align=\"center\">
   
   
   | **File Path** | **Line Number** |
   | ------------- | ------------- |
   | solr/core/src/java/org/apache/solr/cli/CreateTool.java | [318](https://github.com/apache/solr/blob/5967dc1d983a32496166b0be919ba9ab48f3300b/solr/core/src/java/org/apache/solr/cli/CreateTool.java#L318) |
   | solr/core/src/java/org/apache/solr/cli/CreateTool.java | [160](https://github.com/apache/solr/blob/5967dc1d983a32496166b0be919ba9ab48f3300b/solr/core/src/java/org/apache/solr/cli/CreateTool.java#L160) |
   | solr/core/src/java/org/apache/solr/cli/CreateTool.java | [321](https://github.com/apache/solr/blob/5967dc1d983a32496166b0be919ba9ab48f3300b/solr/core/src/java/org/apache/solr/cli/CreateTool.java#L321) |
   | solr/core/src/java/org/apache/solr/cli/CreateTool.java | [161](https://github.com/apache/solr/blob/5967dc1d983a32496166b0be919ba9ab48f3300b/solr/core/src/java/org/apache/solr/cli/CreateTool.java#L161) |
   <p><a href="https://lift.sonatype.com/results/github.com/apache/solr/01H5AMT55CRHDYPZN7SVYC7XHJ?t=FindSecBugs|PATH_TRAVERSAL_IN" target="_blank">Visit the Lift Web Console</a> to find more details in your report.</p></div></details>
   
   
   
   ---
   
   <details><summary>ℹī¸ Expand to see all <b>@sonatype-lift</b> commands</summary>
   
   You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
   
   



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org