mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-07 21:48:39 +00:00
Resolve paths against environment
Original commit: elastic/x-pack-elasticsearch@7e30f66bc0
This commit is contained in:
parent
e3270183ef
commit
6d66e0f4f5
@ -5,13 +5,11 @@
|
||||
*/
|
||||
package org.elasticsearch.license.licensor.tools;
|
||||
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.common.cli.CliTool;
|
||||
import org.elasticsearch.common.cli.CliToolConfig;
|
||||
import org.elasticsearch.common.cli.Terminal;
|
||||
import org.elasticsearch.common.cli.commons.CommandLine;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -41,10 +39,9 @@ public class KeyPairGeneratorTool extends CliTool {
|
||||
|
||||
@Override
|
||||
protected Command parse(String s, CommandLine commandLine) throws Exception {
|
||||
return KeyGenerator.parse(terminal, commandLine);
|
||||
return KeyGenerator.parse(terminal, commandLine, env);
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "command line tool")
|
||||
public static class KeyGenerator extends Command {
|
||||
|
||||
private static final CliToolConfig.Cmd CMD = cmd(NAME, KeyGenerator.class)
|
||||
@ -62,9 +59,9 @@ public class KeyPairGeneratorTool extends CliTool {
|
||||
this.publicKeyPath = publicKeyPath;
|
||||
}
|
||||
|
||||
public static Command parse(Terminal terminal, CommandLine commandLine) {
|
||||
Path publicKeyPath = PathUtils.get(commandLine.getOptionValue("publicKeyPath"));
|
||||
Path privateKeyPath = PathUtils.get(commandLine.getOptionValue("privateKeyPath"));
|
||||
public static Command parse(Terminal terminal, CommandLine commandLine, Environment environment) {
|
||||
Path publicKeyPath = environment.homeFile().resolve(commandLine.getOptionValue("publicKeyPath"));
|
||||
Path privateKeyPath = environment.homeFile().resolve(commandLine.getOptionValue("privateKeyPath"));
|
||||
|
||||
if (Files.exists(privateKeyPath)) {
|
||||
return exitCmd(ExitStatus.USAGE, terminal, privateKeyPath + " already exists");
|
||||
|
@ -5,13 +5,11 @@
|
||||
*/
|
||||
package org.elasticsearch.license.licensor.tools;
|
||||
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.common.cli.CliTool;
|
||||
import org.elasticsearch.common.cli.CliToolConfig;
|
||||
import org.elasticsearch.common.cli.Terminal;
|
||||
import org.elasticsearch.common.cli.commons.CommandLine;
|
||||
import org.elasticsearch.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
@ -46,10 +44,9 @@ public class LicenseGeneratorTool extends CliTool {
|
||||
|
||||
@Override
|
||||
protected Command parse(String s, CommandLine commandLine) throws Exception {
|
||||
return LicenseGenerator.parse(terminal, commandLine);
|
||||
return LicenseGenerator.parse(terminal, commandLine, env);
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "command line tool")
|
||||
public static class LicenseGenerator extends Command {
|
||||
|
||||
private static final CliToolConfig.Cmd CMD = cmd(NAME, LicenseGenerator.class)
|
||||
@ -71,9 +68,9 @@ public class LicenseGeneratorTool extends CliTool {
|
||||
this.publicKeyFilePath = publicKeyFilePath;
|
||||
}
|
||||
|
||||
public static Command parse(Terminal terminal, CommandLine commandLine) throws IOException {
|
||||
Path publicKeyPath = PathUtils.get(commandLine.getOptionValue("publicKeyPath"));
|
||||
Path privateKeyPath = PathUtils.get(commandLine.getOptionValue("privateKeyPath"));
|
||||
public static Command parse(Terminal terminal, CommandLine commandLine, Environment environment) throws IOException {
|
||||
Path publicKeyPath = environment.homeFile().resolve(commandLine.getOptionValue("publicKeyPath"));
|
||||
Path privateKeyPath = environment.homeFile().resolve(commandLine.getOptionValue("privateKeyPath"));
|
||||
String[] licenseSpecSources = commandLine.getOptionValues("license");
|
||||
String[] licenseSpecSourceFiles = commandLine.getOptionValues("licenseFile");
|
||||
|
||||
@ -92,7 +89,7 @@ public class LicenseGeneratorTool extends CliTool {
|
||||
|
||||
if (licenseSpecSourceFiles != null) {
|
||||
for (String licenseSpecFilePath : licenseSpecSourceFiles) {
|
||||
Path licenseSpecPath = PathUtils.get(licenseSpecFilePath);
|
||||
Path licenseSpecPath = environment.homeFile().resolve(licenseSpecFilePath);
|
||||
if (!Files.exists(licenseSpecPath)) {
|
||||
return exitCmd(ExitStatus.USAGE, terminal, licenseSpecFilePath + " does not exist");
|
||||
}
|
||||
|
@ -9,19 +9,16 @@ import org.elasticsearch.common.cli.CliTool;
|
||||
import org.elasticsearch.common.cli.CliToolConfig;
|
||||
import org.elasticsearch.common.cli.Terminal;
|
||||
import org.elasticsearch.common.cli.commons.CommandLine;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.core.LicenseVerifier;
|
||||
import org.elasticsearch.license.core.Licenses;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@ -47,10 +44,9 @@ public class LicenseVerificationTool extends CliTool {
|
||||
|
||||
@Override
|
||||
protected Command parse(String s, CommandLine commandLine) throws Exception {
|
||||
return LicenseVerifier.parse(terminal, commandLine);
|
||||
return LicenseVerifier.parse(terminal, commandLine, env);
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "command line tool")
|
||||
public static class LicenseVerifier extends Command {
|
||||
|
||||
private static final CliToolConfig.Cmd CMD = cmd(NAME, LicenseVerifier.class)
|
||||
@ -69,7 +65,7 @@ public class LicenseVerificationTool extends CliTool {
|
||||
this.publicKeyPath = publicKeyPath;
|
||||
}
|
||||
|
||||
public static Command parse(Terminal terminal, CommandLine commandLine) throws IOException {
|
||||
public static Command parse(Terminal terminal, CommandLine commandLine, Environment environment) throws IOException {
|
||||
String publicKeyPathString = commandLine.getOptionValue("publicKeyPath");
|
||||
String[] licenseSources = commandLine.getOptionValues("license");
|
||||
String[] licenseSourceFiles = commandLine.getOptionValues("licenseFile");
|
||||
@ -83,7 +79,7 @@ public class LicenseVerificationTool extends CliTool {
|
||||
|
||||
if (licenseSourceFiles != null) {
|
||||
for (String licenseFilePath : licenseSourceFiles) {
|
||||
Path licensePath = PathUtils.get(licenseFilePath);
|
||||
Path licensePath = environment.homeFile().resolve(licenseFilePath);
|
||||
if (!Files.exists(licensePath)) {
|
||||
return exitCmd(ExitStatus.USAGE, terminal, licenseFilePath + " does not exist");
|
||||
}
|
||||
@ -95,7 +91,7 @@ public class LicenseVerificationTool extends CliTool {
|
||||
return exitCmd(ExitStatus.USAGE, terminal, "no license provided");
|
||||
}
|
||||
|
||||
Path publicKeyPath = PathUtils.get(publicKeyPathString);
|
||||
Path publicKeyPath = environment.homeFile().resolve(publicKeyPathString);
|
||||
if (!Files.exists(publicKeyPath)) {
|
||||
return exitCmd(ExitStatus.USAGE, terminal, publicKeyPath + " does not exist");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user