feat: settings and credentials refactoring (#360)

* refactor service credential managers

* refactor azure settings

* refactor openai settings

* refactor llama settings

* refactor you settings

* refactor included files settings

* refactor general settings

* refactor advanced settings

* fix advanced settings component init

* refactor project structure

* refactor service settings forms

* remove openai quota exceeded field validator

* fix credential modified conditions

* fix and rearrange minor stuff

* fix you auth logic, add credential cache
This commit is contained in:
Carl-Robert 2024-02-08 01:02:08 +02:00 committed by GitHub
parent 7c067d9edd
commit 93145098f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
80 changed files with 1842 additions and 2040 deletions

View file

@ -0,0 +1,52 @@
package ee.carlrobert.codegpt.credentials;
import com.intellij.credentialStore.CredentialAttributes;
import com.intellij.credentialStore.CredentialAttributesKt;
import com.intellij.ide.passwordSafe.PasswordSafe;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable;
abstract class AbstractCredentialsManager {
private static final PasswordSafe passwordSafe = PasswordSafe.getInstance();
private final Map<String, CredentialAttributes> credentialMapping;
private final Map<String, String> credentialCache = new ConcurrentHashMap<>();
protected AbstractCredentialsManager(String... keys) {
credentialMapping = Stream.of(keys).collect(Collectors.toConcurrentMap(
key -> key,
key -> new CredentialAttributes(CredentialAttributesKt.generateServiceName("CodeGPT", key))
));
}
public abstract boolean isCredentialSet();
protected boolean isCredentialSet(String key) {
var credential = getCredential(key);
return credential != null && !credential.isEmpty();
}
public abstract String getCredential();
protected @Nullable String getCredential(String key) {
String cachedCredential = credentialCache.get(key);
if (cachedCredential != null) {
return cachedCredential;
}
String credential = passwordSafe.getPassword(credentialMapping.get(key));
if (credential != null) {
credentialCache.put(key, credential);
}
return credential;
}
protected void setCredential(String key, String credential) {
passwordSafe.setPassword(credentialMapping.get(key), credential);
credentialCache.put(key, credential);
}
}