Search in sources :

Example 1 with ExitStatus

use of org.springframework.boot.cli.command.status.ExitStatus in project spring-boot by spring-projects.

the class CommandRunner method runAndHandleErrors.

/**
 * Run the appropriate and handle and errors.
 * @param args the input arguments
 * @return a return status code (non boot is used to indicate an error)
 */
public int runAndHandleErrors(String... args) {
    String[] argsWithoutDebugFlags = removeDebugFlags(args);
    boolean debug = argsWithoutDebugFlags.length != args.length;
    if (debug) {
        System.setProperty("debug", "true");
    }
    try {
        ExitStatus result = run(argsWithoutDebugFlags);
        // The caller will hang up if it gets a non-zero status
        if (result != null && result.isHangup()) {
            return (result.getCode() > 0) ? result.getCode() : 0;
        }
        return 0;
    } catch (NoArgumentsException ex) {
        showUsage();
        return 1;
    } catch (Exception ex) {
        return handleError(debug, ex);
    }
}
Also used : ExitStatus(org.springframework.boot.cli.command.status.ExitStatus)

Example 2 with ExitStatus

use of org.springframework.boot.cli.command.status.ExitStatus in project spring-boot by spring-projects.

the class EncodePasswordCommandTests method encodeWithUnknownAlgorithmShouldExitWithError.

@Test
void encodeWithUnknownAlgorithmShouldExitWithError() throws Exception {
    EncodePasswordCommand command = new EncodePasswordCommand();
    ExitStatus status = command.run("--algorithm", "bad", "boot");
    then(this.log).should().error("Unknown algorithm, valid options are: default,bcrypt,pbkdf2");
    assertThat(status).isEqualTo(ExitStatus.ERROR);
}
Also used : ExitStatus(org.springframework.boot.cli.command.status.ExitStatus) Test(org.junit.jupiter.api.Test)

Example 3 with ExitStatus

use of org.springframework.boot.cli.command.status.ExitStatus in project spring-boot by spring-projects.

the class EncodePasswordCommandTests method encodeWithNoAlgorithmShouldUseBcrypt.

@Test
void encodeWithNoAlgorithmShouldUseBcrypt() throws Exception {
    EncodePasswordCommand command = new EncodePasswordCommand();
    ExitStatus status = command.run("boot");
    then(this.log).should().info(this.message.capture());
    assertThat(this.message.getValue()).startsWith("{bcrypt}");
    assertThat(PasswordEncoderFactories.createDelegatingPasswordEncoder().matches("boot", this.message.getValue())).isTrue();
    assertThat(status).isEqualTo(ExitStatus.OK);
}
Also used : ExitStatus(org.springframework.boot.cli.command.status.ExitStatus) Test(org.junit.jupiter.api.Test)

Example 4 with ExitStatus

use of org.springframework.boot.cli.command.status.ExitStatus in project spring-boot by spring-projects.

the class EncodePasswordCommandTests method encodeWithBCryptShouldUseBCrypt.

@Test
void encodeWithBCryptShouldUseBCrypt() throws Exception {
    EncodePasswordCommand command = new EncodePasswordCommand();
    ExitStatus status = command.run("-a", "bcrypt", "boot");
    then(this.log).should().info(this.message.capture());
    assertThat(this.message.getValue()).doesNotStartWith("{");
    assertThat(new BCryptPasswordEncoder().matches("boot", this.message.getValue())).isTrue();
    assertThat(status).isEqualTo(ExitStatus.OK);
}
Also used : ExitStatus(org.springframework.boot.cli.command.status.ExitStatus) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Test(org.junit.jupiter.api.Test)

Example 5 with ExitStatus

use of org.springframework.boot.cli.command.status.ExitStatus in project spring-boot by spring-projects.

the class RunProcessCommand method run.

protected ExitStatus run(Collection<String> args) throws IOException {
    this.process = new RunProcess(this.command);
    int code = this.process.run(true, StringUtils.toStringArray(args));
    if (code == 0) {
        return ExitStatus.OK;
    } else {
        return new ExitStatus(code, "EXTERNAL_ERROR");
    }
}
Also used : ExitStatus(org.springframework.boot.cli.command.status.ExitStatus) RunProcess(org.springframework.boot.loader.tools.RunProcess)

Aggregations

ExitStatus (org.springframework.boot.cli.command.status.ExitStatus)6 Test (org.junit.jupiter.api.Test)4 RunProcess (org.springframework.boot.loader.tools.RunProcess)1 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)1 Pbkdf2PasswordEncoder (org.springframework.security.crypto.password.Pbkdf2PasswordEncoder)1