Show identity name in error messages for #748

This commit is contained in:
crschnick
2026-04-13 12:53:58 +00:00
parent e17827c0dd
commit cb448e34f9
6 changed files with 33 additions and 3 deletions

View File

@@ -33,4 +33,6 @@ public abstract class IdentityStore implements SelfReferentialStore, DataStore {
getSshIdentity().checkComplete();
}
}
public abstract String getName();
}

View File

@@ -99,16 +99,22 @@ public interface IdentityValue {
List<DataStoreEntryRef<?>> getDependencies();
default void checkCompleteUser() throws ValidationException {
Validators.nonNull(unwrap().getUsername().hasUser() ? new Object() : null, "Identity username");
var n = unwrap().getName();
var msg = n != null ? "Username of identity " + n : "Identity username";
Validators.nonNull(unwrap().getUsername().hasUser() ? new Object() : null, msg);
}
default void checkCompletePassword() throws ValidationException {
Validators.nonNull(unwrap().getPassword(), "Identity password");
var n = unwrap().getName();
var msg = n != null ? "Password of identity " + n : "Identity password";
Validators.nonNull(unwrap().getPassword(), msg);
unwrap().getPassword().checkComplete();
}
default void checkCompleteSshIdentity() throws ValidationException {
Validators.nonNull(unwrap().getSshIdentity(), "Identity ssh key");
var n = unwrap().getName();
var msg = n != null ? "SSH key of identity " + n : "Identity SSH key";
Validators.nonNull(unwrap().getSshIdentity(), msg);
unwrap().getSshIdentity().checkComplete();
}

View File

@@ -4,6 +4,7 @@ import io.xpipe.app.cred.SshIdentityStrategy;
import io.xpipe.app.cred.UsernameStrategy;
import io.xpipe.app.secret.EncryptedValue;
import io.xpipe.app.secret.SecretRetrievalStrategy;
import io.xpipe.app.storage.DataStoreEntry;
import io.xpipe.app.storage.DataStoreEntryRef;
import com.fasterxml.jackson.annotation.JsonTypeName;
@@ -41,6 +42,12 @@ public class LocalIdentityStore extends IdentityStore {
return sshIdentity != null ? sshIdentity.getValue() : null;
}
@Override
public String getName() {
var inStorage = hasSelfEntry();
return inStorage ? getSelfEntry().getName() : null;
}
EncryptedValue<SecretRetrievalStrategy> getEncryptedPassword() {
return password;
}

View File

@@ -32,6 +32,11 @@ public class MultiIdentityStore extends IdentityStore
List<UUID> identities;
boolean perUser;
@Override
public String getName() {
return getSelected().map(ref -> ref.getStore().getName()).orElse(null);
}
public List<DataStoreEntryRef<IdentityStore>> getAvailableIdentities() {
return identities.stream()
.map(uuid -> DataStorage.get().getStoreEntryIfPresent(uuid))

View File

@@ -41,6 +41,11 @@ public class PasswordManagerIdentityStore extends IdentityStore
PasswordManagerAgentStrategy sshKey;
boolean perUser;
@Override
public String getName() {
return getSelfEntry().getName();
}
private boolean checkOutdatedOrRefresh() {
var instant = getCache("lastQueried", Instant.class, null);
if (instant != null) {

View File

@@ -33,6 +33,11 @@ public class SyncedIdentityStore extends IdentityStore implements UserScopeStore
EncryptedValue.VaultKey<SshIdentityStrategy> sshIdentity;
boolean perUser;
@Override
public String getName() {
return getSelfEntry().getName();
}
public UsernameStrategy.Fixed getUsername() {
return new UsernameStrategy.Fixed(username);
}