Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#26: Implement ToolCommandlet for Jasypt #243

Merged
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7c4644a
add JasyptUrlUpdater to UpdateManager
mvomiero Feb 13, 2024
80e5c18
Merge branch 'main' of https://github.com/devonfw/IDEasy into fix/mis…
mvomiero Feb 13, 2024
db09dce
commandlet initialized
mvomiero Feb 14, 2024
92def9c
add function doJasypt() to handle encryption and decriptyon, run() fu…
mvomiero Feb 15, 2024
2cc0020
use Path instead of Paths
mvomiero Feb 19, 2024
cb315e0
Merge branch 'main' into jasypt/26-ImplementToolCommandletForJasypt
mvomiero Feb 19, 2024
ed1fb3d
initialize mvn command for artifact download
mvomiero Feb 20, 2024
f8bad9d
Merge remote-tracking branch 'upstream/main'
mvomiero Feb 20, 2024
9df8843
Merge branch 'main' into jasypt/26-ImplementToolCommandletForJasypt
mvomiero Feb 20, 2024
ec072ea
refactor code Jasypt
mvomiero Feb 20, 2024
b846dfb
Merge remote-tracking branch 'upstream/main' into jasypt/26-Implement…
mvomiero Feb 20, 2024
6ac0e73
postInstall() method added to install the jasypt artifact
mvomiero Feb 21, 2024
1ba57b1
debug print postinstall
mvomiero Feb 21, 2024
4efe32a
Different executable priority lists depending from os
mvomiero Feb 21, 2024
4f24b0b
formatting check
mvomiero Feb 21, 2024
760ecc8
Merge branch '#219/wrong-executable-extension-linux' into jasypt/26-I…
mvomiero Feb 21, 2024
570e0ef
Return statement in backup() functions in case of symlinks
mvomiero Feb 23, 2024
b41c4d3
adds documentation
mvomiero Feb 23, 2024
cae4aec
Merge remote-tracking branch 'upstream/main' into jasypt/26-Implement…
mvomiero Feb 27, 2024
e0a09b5
Merge branch 'jasypt/26-ImplementToolCommandletForJasypt' into TRY/3
mvomiero Mar 5, 2024
41821a3
test jasypt initialized
mvomiero Mar 5, 2024
df57163
Tests implemented and working
mvomiero Mar 5, 2024
8bc5f16
tests correctly implemented
mvomiero Mar 5, 2024
8b0e0d9
code cleanup jasypt
mvomiero Mar 5, 2024
e411d3e
updates access rights executables
mvomiero Mar 6, 2024
13e78b8
small error check and code refactoring
mvomiero Mar 6, 2024
8b872e3
removes jmc reference in testinfrastruktur
mvomiero Mar 6, 2024
6f10efd
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 11, 2024
0593e48
changes constants from public to private
mvomiero Mar 11, 2024
34f017c
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 13, 2024
b5f453d
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 15, 2024
b25c71e
refactors code after review
mvomiero Mar 15, 2024
80987d4
adds tag for encryption and class PasswordProperties
mvomiero Mar 15, 2024
d93fa4a
code cleanup
mvomiero Mar 15, 2024
e67dc2d
refactors tests
mvomiero Mar 18, 2024
160f050
test refactoring
mvomiero Mar 18, 2024
1629627
implements arguments commandlet
mvomiero Mar 18, 2024
32b305f
code refactoring tests
mvomiero Mar 18, 2024
ef6c4f3
code refactoring, documentation page deleted
mvomiero Mar 18, 2024
a9120e4
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 18, 2024
3190bd0
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 19, 2024
ef3301f
Merge remote-tracking branch 'upstream/main' into feature/26-jasyptCo…
mvomiero Mar 19, 2024
d9f6153
excludes .jar file from gitignore
mvomiero Mar 19, 2024
ce5b539
updates gitignore to exclude mocked jar test file
mvomiero Mar 19, 2024
ab80b96
code cleanup
mvomiero Mar 19, 2024
3b923ef
Merge branch 'main' into feature/26-jasyptCommandletWithUnitTests
hohwille Mar 21, 2024
5afc572
removes jar file
mvomiero Mar 21, 2024
f585e68
gitignore update
mvomiero Mar 21, 2024
efbbe57
adds jasypt.jar file
mvomiero Mar 21, 2024
f958fe1
renames masterPassword and secret
mvomiero Mar 21, 2024
0765118
Merge branch 'main' into feature/26-jasyptCommandletWithUnitTests
hohwille Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.devonfw.tools.ide.tool.quarkus.Quarkus;
import com.devonfw.tools.ide.tool.terraform.Terraform;
import com.devonfw.tools.ide.tool.vscode.Vscode;
import com.devonfw.tools.ide.tool.jasypt.Jasypt;

/**
* Implementation of {@link CommandletManager}.
Expand Down Expand Up @@ -83,6 +84,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Aws(context));
add(new Cobigen(context));
add(new Jmc(context));
add(new Jasypt(context));
}

private void add(Commandlet commandlet) {
Expand Down
104 changes: 104 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/Jasypt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.devonfw.tools.ide.tool.jasypt;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;
import com.devonfw.tools.ide.tool.java.Java;
import com.devonfw.tools.ide.tool.mvn.Mvn;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;

/**
* {@link ToolCommandlet} for <a href="http://www.jasypt.org/">Jasypt</a>, The java library which allows to add basic
* encryption capabilities with minimum effort.
*/
public class Jasypt extends LocalToolCommandlet {

private static final String USAGE_INFO = """
Jasypt encryption tool
Usage:
encrypt <masterpassword> <secret> encrypt a secret with a master-password
decrypt <masterpassword> <secret> decrypt an encrypted secret with a master-password
""";
mvomiero marked this conversation as resolved.
Show resolved Hide resolved

private static final String CLASS_NAME_ENCRYPTION = "org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI";

private static final String CLASS_NAME_DECRYPTION = "org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI";

private static final String ALGORITHM = "algorithm=PBEWITHHMACSHA512ANDAES_256";

private static final String GENERATOR_CLASS_NAME = "ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator";

/**
* The constructor.
*
* @param context the {@link IdeContext}.
*/
public Jasypt(IdeContext context) {

super(context, "jasypt", Set.of(Tag.JAVA));
mvomiero marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public void run() {

String[] args = this.arguments.asArray();

if (args.length == 0) {
this.context.info(USAGE_INFO);
} else if (args.length == 3 && args[0].equals("encrypt")) {
mvomiero marked this conversation as resolved.
Show resolved Hide resolved
runJasypt(CLASS_NAME_ENCRYPTION, args);
} else if (args.length == 3 && args[0].equals("decrypt")) {
runJasypt(CLASS_NAME_DECRYPTION, args);
} else {
this.context.warning("Unknown arguments");
this.context.info(USAGE_INFO);
}
mvomiero marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public boolean doInstall(boolean silent) {

getCommandlet(Java.class).install();

return super.doInstall(silent);
}

@Override
public void postInstall() {

super.postInstall();

if (Files.notExists(resolveJasyptJarPath())) {
installJasyptArtifact();
}
}

private void installJasyptArtifact() {

Mvn mvn = getCommandlet(Mvn.class);
mvn.install();
this.context.debug("installing jasypt artifact in: " + resolveJasyptJarPath());
mvn.runTool(null, "org.apache.maven.plugins:maven-dependency-plugin:3.1.2:get",
"-Dartifact=org.jasypt:jasypt:" + getInstalledVersion().toString());
}

mvomiero marked this conversation as resolved.
Show resolved Hide resolved
private void runJasypt(String className, String[] args) {
mvomiero marked this conversation as resolved.
Show resolved Hide resolved

Java java = getCommandlet(Java.class);
java.runTool(null, "-cp", resolveJasyptJarPath().toString(), className, ALGORITHM, GENERATOR_CLASS_NAME,
"password=" + args[1], "input=" + args[2]);
mvomiero marked this conversation as resolved.
Show resolved Hide resolved
}

private Path resolveJasyptJarPath() {

Path m2Repo = context.getVariables().getPath("M2_REPO");
String installedVersion = getInstalledVersion().toString();
return m2Repo.resolve("org").resolve("jasypt").resolve("jasypt").resolve(installedVersion)
.resolve("jasypt-" + installedVersion + ".jar");
mvomiero marked this conversation as resolved.
Show resolved Hide resolved
}

}
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cmd-shell=Commandlet to start built-in shell with advanced auto-completion.
cmd-terraform=Tool commandlet for Terraform
cmd-vscode=Tool commandlet for Visual Studio Code (IDE)
cmd-cobigen=Tool commandlet for Cobigen
cmd-jasypt=Tool commandlet for Jasypt
val-args=The commandline arguments to pass to the tool.
val-edition=The tool edition.
val-tool=The tool commandlet to select.
Expand Down
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cmd-set-version=Setzt die Version des selektierten Werkzeugs.
cmd-terraform=Werkzeug Kommando für Terraform.
cmd-vscode=Werkzeug Kommando für Visual Studio Code (IDE)
cmd-cobigen=Werkzeug Kommando für Cobigen.
cmd-jasypt=Werkzeug Kommando für Jasypt
val-args=Die Kommandozeilen-Argumente zur Übergabe an das Werkzeug.
val-edition=Die Werkzeug Edition.
val-tool=Das zu selektierende Werkzeug Kommando.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.devonfw.tools.ide.tool.jasypt;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.log.IdeLogLevel;
import org.junit.jupiter.api.Test;

import java.util.List;

/**
* Integration test of {@link Jasypt}.
*/
public class JasyptTest extends AbstractIdeContextTest {

private static final String PROJECT_JASYPT = "jasypt";

@Test
public void testJasypt() {

// arrange
IdeTestContext context = newContext(PROJECT_JASYPT);
Jasypt commandlet = new Jasypt(context);

// act - install
commandlet.install();

// assert - install
checkInstallation(context);

// act and assert - run
runNoArgs(context, commandlet, null);
runRightArgs(context, commandlet, List.of("encrypt", "master", "secret"));
runRightArgs(context, commandlet, List.of("decrypt", "master", "secret"));
runWrongArgs(context, commandlet, List.of("wrong args"));
}

public void runNoArgs(IdeTestContext context, Jasypt commandlet, List<String> arguments) {

String expectedMessage = """
Jasypt encryption tool
Usage:
encrypt <masterpassword> <secret> encrypt a secret with a master-password
decrypt <masterpassword> <secret> decrypt an encrypted secret with a master-password
""";
commandlet.arguments.setValue(arguments);
commandlet.run();
assertLogMessage(context, IdeLogLevel.INFO, expectedMessage);
}
mvomiero marked this conversation as resolved.
Show resolved Hide resolved

public void runWrongArgs(IdeTestContext context, Jasypt commandlet, List<String> arguments) {

commandlet.arguments.setValue(arguments);
commandlet.run();
assertLogMessage(context, IdeLogLevel.WARNING, "Unknown arguments");
}

public void runRightArgs(IdeTestContext context, Jasypt commandlet, List<String> arguments) {

commandlet.arguments.setValue(arguments);
commandlet.run();
assertLogMessage(context, IdeLogLevel.INFO, "executing java:");
}

private void checkInstallation(IdeTestContext context) {

// install - java
assertThat(context.getSoftwarePath().resolve("java/bin/java")).exists();

// postInstall - mvn
assertLogMessage(context, IdeLogLevel.INFO, "executing mvn:");
assertThat(context.getSoftwarePath().resolve("mvn/bin/mvn")).exists();

// commandlet - jasypt
assertThat(context.getSoftwarePath().resolve("jasypt/META-INF/HelloWorld.txt")).hasContent("Hello World!");
assertThat(context.getSoftwarePath().resolve("jasypt/org/HelloWorld.txt")).hasContent("Hello World!");
assertThat(context.getSoftwarePath().resolve("jasypt/.ide.software.version")).exists().hasContent("1.9.3");
assertLogMessage(context, IdeLogLevel.SUCCESS, "Successfully installed jasypt in version 1.9.3");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
mvomiero marked this conversation as resolved.
Show resolved Hide resolved
"manual" : false,
"urls" : {
"55042423" : {
"success" : {
"timestamp" : "2024-02-13T17:38:27.770091500Z"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://repo1.maven.org/maven2/org/jasypt/jasypt/1.9.3/jasypt-1.9.3.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f481fbb8dd8ce754bfde7552af4fcbe8c5e303d53663bb3d8ce9d4338e0e55aa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c2de7dfbd9f8faaa21b4cdd8518f826dd558c9ab24a0616b3ed28437a674a97b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://localhost:1112/installTest/linux
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c2de7dfbd9f8faaa21b4cdd8518f826dd558c9ab24a0616b3ed28437a674a97b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://localhost:1112/installTest/macOS
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"manual" : true,
"urls" : {
"-680270697" : {
"success" : {
"timestamp" : "2023-04-28T16:27:32.819394600Z"
}
},
"-896197542" : {
"success" : {
"timestamp" : "2023-04-28T16:27:47.658175400Z"
}
},
"-310367019" : {
"success" : {
"timestamp" : "2023-04-28T16:28:02.221367500Z"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://localhost:1112/installTest/windows
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aa64bee5f7ba56fbbd60d766f3a652600f81571ae5e996804694c69bf731af8b
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"manual" : false,
"urls" : {
"1199796863" : {
"success" : {
"timestamp" : "2023-12-02T03:34:21.698982214Z"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://archive.apache.org/dist/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6eedd2cae3626d6ad3a5c9ee324bd265853d64297f07f033430755bd0e0c3a4b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the download metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the users HOME directory
1 change: 1 addition & 0 deletions cli/src/test/resources/ide-projects/jasypt/project/readme
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the IDE_HOME directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
JAVA_VERSION=17.0.10_7
JASYPT_VERSION=1.9.3
JMC_VERSION=8.3.0
MVN_VERSION=3.9.6

M2_REPO=~/.m2/repository
mvomiero marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the main workspace of jmc test case
1 change: 1 addition & 0 deletions cli/src/test/resources/ide-projects/jasypt/readme
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the IDE_ROOT directory
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test file.
mvomiero marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "executing java:"
echo "java $*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
mvomiero marked this conversation as resolved.
Show resolved Hide resolved
echo executing java:
echo java %*
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
mvomiero marked this conversation as resolved.
Show resolved Hide resolved
echo "executing mvn:"
echo "mvn $*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
echo executing mvn:
echo mvn %*
Loading
Loading