From 5f872e034599ce183cc3568c84018d41b0cdb8f2 Mon Sep 17 00:00:00 2001 From: Evgeny Morozov Date: Thu, 23 Feb 2017 18:31:16 +0300 Subject: [PATCH] Grey out the SSH option if keys don't exist --- .../GitServerSettingTableViewController.swift | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pass/Controllers/GitServerSettingTableViewController.swift b/pass/Controllers/GitServerSettingTableViewController.swift index ba536c5..a697bd7 100644 --- a/pass/Controllers/GitServerSettingTableViewController.swift +++ b/pass/Controllers/GitServerSettingTableViewController.swift @@ -43,9 +43,16 @@ class GitServerSettingTableViewController: UITableViewController { usernameTextField.text = Defaults[.gitRepositoryUsername] password = PasswordStore.shared.gitRepositoryPassword authenticationMethod = Defaults[.gitRepositoryAuthenticationMethod] - if authenticationMethod == nil { + + // Grey out ssh option if ssh_key and ssh_key.pub are not present + let sshLabel = authSSHKeyCell.subviews[0].subviews[0] as! UILabel + + sshLabel.isEnabled = sshKeyExists() + + if authenticationMethod == nil || !sshLabel.isEnabled { authenticationMethod = "Password" } + checkAuthenticationMethod(method: authenticationMethod!) authSSHKeyCell.accessoryType = .detailButton } @@ -83,13 +90,19 @@ class GitServerSettingTableViewController: UITableViewController { } return true } - + + func sshKeyExists() -> Bool { + return FileManager.default.fileExists(atPath: Globals.sshPublicKeyURL.path) && + FileManager.default.fileExists(atPath: Globals.sshPrivateKeyURL.path) + } + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let cell = tableView.cellForRow(at: indexPath) if cell == authPasswordCell { authenticationMethod = "Password" } else if cell == authSSHKeyCell { - if Defaults[.gitRepositorySSHPublicKeyURL] == nil && Defaults[.gitRepositorySSHPrivateKeyURL] == nil { + + if !sshKeyExists() { Utils.alert(title: "Cannot Select SSH Key", message: "Please setup SSH key first.", controller: self, completion: nil) authenticationMethod = "Password" } else {