Implement profiles

This commit is contained in:
Paul Schaub 2023-04-14 14:06:34 +02:00
parent b8544396f8
commit 5935d65c90
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
11 changed files with 75 additions and 43 deletions

View file

@ -401,12 +401,33 @@ public abstract class SOPGPException extends RuntimeException {
public static final int EXIT_CODE = 89;
public UnsupportedProfile() {
super();
private final String subcommand;
private final String profile;
public UnsupportedProfile(String subcommand) {
super("Subcommand '" + subcommand + "' does not support any profiles.");
this.subcommand = subcommand;
this.profile = null;
}
public UnsupportedProfile(String errorMessage) {
super(errorMessage);
public UnsupportedProfile(String subcommand, String profile) {
super("Subcommand '" + subcommand + "' does not support profile '" + profile + "'.");
this.subcommand = subcommand;
this.profile = profile;
}
public UnsupportedProfile(String errorMsg, UnsupportedProfile e) {
super(errorMsg, e);
this.subcommand = e.getSubcommand();
this.profile = e.getProfile();
}
public String getSubcommand() {
return subcommand;
}
public String getProfile() {
return profile;
}
@Override

View file

@ -6,8 +6,8 @@ package sop.operation;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import sop.Profile;
import sop.Ready;
import sop.exception.SOPGPException;
import sop.util.UTF8Util;
@ -57,11 +57,21 @@ public interface GenerateKey {
return withKeyPassword(UTF8Util.decodeUTF8(password));
}
/**
* Pass in a profile.
*
* @param profile profile
* @return builder instance
*/
default GenerateKey profile(Profile profile) {
return profile(profile.getName());
}
/**
* Pass in a profile identifier.
*
* @param profile profile identifier
* @return this
* @return builder instance
*/
GenerateKey profile(String profile);

View file

@ -4,12 +4,12 @@
package sop.operation;
import sop.Profile;
import java.util.List;
public interface ListProfiles {
List<String> ofCommand(String command);
List<String> global();
List<Profile> subcommand(String command);
}

View file

@ -7,6 +7,7 @@ package sop.testsuite.operation;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import sop.Profile;
import sop.SOP;
import java.io.IOException;
@ -21,19 +22,11 @@ public class ListProfilesTest extends AbstractSOPTest {
return provideBackends();
}
@ParameterizedTest
@MethodSource("provideInstances")
public void listGlobalProfiles(SOP sop) throws IOException {
List<String> profiles = sop.listProfiles()
.global();
assertFalse(profiles.isEmpty());
}
@ParameterizedTest
@MethodSource("provideInstances")
public void listGenerateKeyProfiles(SOP sop) throws IOException {
List<String> profiles = sop.listProfiles()
.ofCommand("generate-key");
List<Profile> profiles = sop.listProfiles()
.subcommand("generate-key");
assertFalse(profiles.isEmpty());
}