mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-13 15:32:25 +00:00
Persist credentials back into the PasswordSafe (#465)
This commit is contained in:
parent
2221d72430
commit
7d075f6905
1 changed files with 10 additions and 1 deletions
|
|
@ -12,14 +12,23 @@ object CredentialsStore {
|
|||
CredentialKey.values().forEach {
|
||||
val credentialAttributes = CredentialAttributes(generateServiceName("CodeGPT", it.name))
|
||||
val password = PasswordSafe.instance.getPassword(credentialAttributes)
|
||||
setCredential(it, password)
|
||||
|
||||
// Avoid calling setCredential here since it will persist
|
||||
// the password back into the PasswordSafe unnecessarily.
|
||||
credentialsMap[it] = password
|
||||
}
|
||||
}
|
||||
|
||||
fun getCredential(key: CredentialKey): String? = credentialsMap[key]
|
||||
|
||||
fun setCredential(key: CredentialKey, password: String?) {
|
||||
val prevPassword = credentialsMap[key]
|
||||
credentialsMap[key] = password
|
||||
|
||||
if (prevPassword != password) {
|
||||
val credentialAttributes = CredentialAttributes(generateServiceName("CodeGPT", key.name))
|
||||
PasswordSafe.instance.setPassword(credentialAttributes, password)
|
||||
}
|
||||
}
|
||||
|
||||
fun isCredentialSet(key: CredentialKey): Boolean = !getCredential(key).isNullOrEmpty()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue