diff --git a/fcli-core/fcli-config/src/main/java/com/fortify/cli/config/_main/cli/cmd/ConfigCommands.java b/fcli-core/fcli-config/src/main/java/com/fortify/cli/config/_main/cli/cmd/ConfigCommands.java index e2d4feb54e..2fec04a295 100644 --- a/fcli-core/fcli-config/src/main/java/com/fortify/cli/config/_main/cli/cmd/ConfigCommands.java +++ b/fcli-core/fcli-config/src/main/java/com/fortify/cli/config/_main/cli/cmd/ConfigCommands.java @@ -15,7 +15,6 @@ import com.fortify.cli.common.cli.cmd.AbstractContainerCommand; import com.fortify.cli.config.language.cli.cmd.LanguageCommands; import com.fortify.cli.config.proxy.cli.cmd.ProxyCommands; -import com.fortify.cli.config.toolversions.cli.cmd.ToolversionsCommands; import com.fortify.cli.config.truststore.cli.cmd.TrustStoreCommands; import picocli.CommandLine.Command; @@ -28,7 +27,6 @@ ConfigClearCommand.class, LanguageCommands.class, ProxyCommands.class, - ToolversionsCommands.class, TrustStoreCommands.class } ) diff --git a/fcli-core/fcli-config/src/main/java/com/fortify/cli/config/toolversions/cli/cmd/ToolversionsCommands.java b/fcli-core/fcli-config/src/main/java/com/fortify/cli/config/toolversions/cli/cmd/ToolversionsCommands.java deleted file mode 100644 index dd94519a30..0000000000 --- a/fcli-core/fcli-config/src/main/java/com/fortify/cli/config/toolversions/cli/cmd/ToolversionsCommands.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright 2021, 2022 Open Text. - * - * The only warranties for products and services of Open Text - * and its affiliates and licensors ("Open Text") are as may - * be set forth in the express warranty statements accompanying - * such products and services. Nothing herein should be construed - * as constituting an additional warranty. Open Text shall not be - * liable for technical or editorial errors or omissions contained - * herein. The information contained herein is subject to change - * without notice. - *******************************************************************************/ -package com.fortify.cli.config.toolversions.cli.cmd; - -import com.fortify.cli.common.cli.cmd.AbstractContainerCommand; - -import picocli.CommandLine.Command; - -@Command( - name = "tool-versions", - subcommands = { - ToolversionsUpdateCommand.class - } -) -public class ToolversionsCommands extends AbstractContainerCommand { -} diff --git a/fcli-core/fcli-config/src/main/java/com/fortify/cli/config/toolversions/cli/cmd/ToolversionsUpdateCommand.java b/fcli-core/fcli-config/src/main/java/com/fortify/cli/config/toolversions/cli/cmd/ToolversionsUpdateCommand.java deleted file mode 100644 index 3999b083e2..0000000000 --- a/fcli-core/fcli-config/src/main/java/com/fortify/cli/config/toolversions/cli/cmd/ToolversionsUpdateCommand.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright 2021, 2023 Open Text. - * - * The only warranties for products and services of Open Text - * and its affiliates and licensors ("Open Text") are as may - * be set forth in the express warranty statements accompanying - * such products and services. Nothing herein should be construed - * as constituting an additional warranty. Open Text shall not be - * liable for technical or editorial errors or omissions contained - * herein. The information contained herein is subject to change - * without notice. - *******************************************************************************/ -package com.fortify.cli.config.toolversions.cli.cmd; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.Comparator; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fortify.cli.common.http.proxy.helper.ProxyHelper; -import com.fortify.cli.common.json.JsonHelper; -import com.fortify.cli.common.output.cli.cmd.AbstractOutputCommand; -import com.fortify.cli.common.output.cli.cmd.IJsonNodeSupplier; -import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; -import com.fortify.cli.common.output.transform.IActionCommandResultSupplier; -import com.fortify.cli.common.rest.unirest.GenericUnirestFactory; -import com.fortify.cli.common.util.FcliDataHelper; -import com.fortify.cli.common.util.FileUtils; - -import kong.unirest.UnirestInstance; -import lombok.Getter; -import picocli.CommandLine.Command; -import picocli.CommandLine.Mixin; -import picocli.CommandLine.Option; - -@Command(name=OutputHelperMixins.Update.CMD_NAME) -public class ToolversionsUpdateCommand extends AbstractOutputCommand implements IJsonNodeSupplier, IActionCommandResultSupplier { - private static final ObjectMapper objectMapper = JsonHelper.getObjectMapper(); - @Mixin @Getter private OutputHelperMixins.Update outputHelper; - @Getter @Option(names={"--url"}, required = false, descriptionKey="fcli.config.toolversions.update.url") - private String pUrl; - - @Override - public boolean isSingular() { - return true; - } - - @Override - public String getActionCommandResult() { - return "UPDATED"; - } - - @Override - public JsonNode getJsonNode() { - //TODO replace with final package url - String packageUrl = "https://drive.google.com/uc?export=download&id=17oFvD5FO10FOAWlMQPHJlp9PPWDojg8J"; - if(pUrl!=null && !pUrl.isBlank()) { - packageUrl = pUrl; - } - try { - return downloadAndUnpack(packageUrl); - } catch ( IOException e ) { - throw new RuntimeException("Error updating toolversions", e); - } - } - - private JsonNode downloadAndUnpack(String packageUrl) throws IOException{ - Path toolversionsPath = FcliDataHelper.getFcliConfigPath().resolve("toolversions"); - Files.createDirectories(toolversionsPath); - File pkg = download(packageUrl); - FileUtils.extractZip(pkg, toolversionsPath); - - ArrayNode result = objectMapper.createArrayNode(); - try { - if ( toolversionsPath.toFile().exists() ) { - Files.walk(toolversionsPath) - .sorted(Comparator.reverseOrder()) - .filter(f->f.toFile().isFile()) - .map(Path::toFile) - .forEach(f->addResult(result,f)); - } - } catch ( IOException e ) { - throw new RuntimeException("Error listing unpacked tool version files", e); - } - return result; - } - - private final File download(String packageUrl) throws IOException { - File tempDownloadFile = File.createTempFile("fcli-toolversions-download", null); - tempDownloadFile.deleteOnExit(); - download(packageUrl, tempDownloadFile); - return tempDownloadFile; - } - - private final Void download(String downloadUrl, File destFile) { - UnirestInstance unirest = GenericUnirestFactory.getUnirestInstance("toolversions", - u->ProxyHelper.configureProxy(u, "toolversions", downloadUrl)); - unirest.get(downloadUrl).asFile(destFile.getAbsolutePath(), StandardCopyOption.REPLACE_EXISTING).getBody(); - return null; - } - - private void addResult(ArrayNode result, File f) { - try { - result.add(objectMapper.createObjectNode() - .put("name", f.getCanonicalPath()) - .put("type", "FILE")); - } catch ( IOException e ) { - throw new RuntimeException("Error processing file "+f, e); - } - } -}