diff options
| author | Fabian Henneke <FabianHenneke@users.noreply.github.com> | 2020-08-11 18:11:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-11 18:11:39 +0200 |
| commit | 15aa92980239d6d61c3b0febc0407b7f63e152b3 (patch) | |
| tree | 92b25ea3bca41e37fe4727bab82665b04ee8206e /app/src/main/java/com/zeapo/pwdstore/git/operation | |
| parent | 8f957ca99454efe1711e2424620d2632bed6cb63 (diff) | |
| download | HardenedPass-15aa92980239d6d61c3b0febc0407b7f63e152b3.tar.gz HardenedPass-15aa92980239d6d61c3b0febc0407b7f63e152b3.zip | |
Switch to URL-based Git config and refactor Git settings (#1008)
* Make Git config URL-based and refactor
* Use Kotlin style null handling for string prefs
* Also show an error if generated URL can't be parsed
* Add some testcases for migration strategy
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/git/operation')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt index 591c121f..ad8d318a 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/operation/GitOperation.kt @@ -15,6 +15,7 @@ import com.zeapo.pwdstore.R import com.zeapo.pwdstore.UserPreference import com.zeapo.pwdstore.git.ErrorMessages import com.zeapo.pwdstore.git.config.ConnectionMode +import com.zeapo.pwdstore.git.config.GitSettings import com.zeapo.pwdstore.git.config.InteractivePasswordFinder import com.zeapo.pwdstore.git.config.SshApiSessionFactory import com.zeapo.pwdstore.git.config.SshAuthData @@ -47,18 +48,15 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment private val hostKeyFile = callingActivity.filesDir.resolve(".host_key") protected val repository = PasswordRepository.getRepository(gitDir) protected val git = Git(repository) - protected val remoteBranch = PreferenceManager - .getDefaultSharedPreferences(callingActivity.applicationContext) - .getString(PreferenceKeys.GIT_BRANCH_NAME, "master") + protected val remoteBranch = GitSettings.branch - private class PasswordFinderCredentialsProvider(private val username: String, private val passwordFinder: PasswordFinder) : CredentialsProvider() { + private class PasswordFinderCredentialsProvider(private val passwordFinder: PasswordFinder) : CredentialsProvider() { override fun isInteractive() = true override fun get(uri: URIish?, vararg items: CredentialItem): Boolean { for (item in items) { when (item) { - is CredentialItem.Username -> item.value = username is CredentialItem.Password -> item.value = passwordFinder.reqPassword(null) else -> UnsupportedCredentialItem(uri, item.javaClass.name) } @@ -67,26 +65,26 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment } override fun supports(vararg items: CredentialItem) = items.all { - it is CredentialItem.Username || it is CredentialItem.Password + it is CredentialItem.Password } } - private fun withPasswordAuthentication(username: String, passwordFinder: InteractivePasswordFinder): GitOperation { - val sessionFactory = SshjSessionFactory(username, SshAuthData.Password(passwordFinder), hostKeyFile) + private fun withPasswordAuthentication(passwordFinder: InteractivePasswordFinder): GitOperation { + val sessionFactory = SshjSessionFactory(SshAuthData.Password(passwordFinder), hostKeyFile) SshSessionFactory.setInstance(sessionFactory) - this.provider = PasswordFinderCredentialsProvider(username, passwordFinder) + this.provider = PasswordFinderCredentialsProvider(passwordFinder) return this } - private fun withPublicKeyAuthentication(username: String, passphraseFinder: InteractivePasswordFinder): GitOperation { - val sessionFactory = SshjSessionFactory(username, SshAuthData.PublicKeyFile(sshKeyFile, passphraseFinder), hostKeyFile) + private fun withPublicKeyAuthentication(passphraseFinder: InteractivePasswordFinder): GitOperation { + val sessionFactory = SshjSessionFactory(SshAuthData.PublicKeyFile(sshKeyFile, passphraseFinder), hostKeyFile) SshSessionFactory.setInstance(sessionFactory) this.provider = null return this } - private fun withOpenKeychainAuthentication(username: String, identity: SshApiSessionFactory.ApiIdentity?): GitOperation { - SshSessionFactory.setInstance(SshApiSessionFactory(username, identity)) + private fun withOpenKeychainAuthentication(identity: SshApiSessionFactory.ApiIdentity?): GitOperation { + SshSessionFactory.setInstance(SshApiSessionFactory(identity)) this.provider = null return this } @@ -117,7 +115,6 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment suspend fun executeAfterAuthentication( connectionMode: ConnectionMode, - username: String, identity: SshApiSessionFactory.ApiIdentity? ) { when (connectionMode) { @@ -136,12 +133,12 @@ abstract class GitOperation(gitDir: File, internal val callingActivity: Fragment callingActivity.finish() }.show() } else { - withPublicKeyAuthentication(username, CredentialFinder(callingActivity, - connectionMode)).execute() + withPublicKeyAuthentication( + CredentialFinder(callingActivity, connectionMode)).execute() } - ConnectionMode.OpenKeychain -> withOpenKeychainAuthentication(username, identity).execute() + ConnectionMode.OpenKeychain -> withOpenKeychainAuthentication(identity).execute() ConnectionMode.Password -> withPasswordAuthentication( - username, CredentialFinder(callingActivity, connectionMode)).execute() + CredentialFinder(callingActivity, connectionMode)).execute() ConnectionMode.None -> execute() } } |
