complete SSH Key authentication

This commit is contained in:
Bob Sun 2017-01-31 22:00:50 +08:00
parent 7a3f05701b
commit 62e2a7fe89
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
4 changed files with 15 additions and 5 deletions

View file

@ -16,7 +16,7 @@ class GitServerSettingTableViewController: UITableViewController {
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var authenticationTableViewCell: UITableViewCell!
var authenticationMethod = "Password"
var authenticationMethod = Defaults[.gitRepositoryAuthenticationMethod]
override func viewDidLoad() {
@ -26,7 +26,7 @@ class GitServerSettingTableViewController: UITableViewController {
}
usernameTextField.text = Defaults[.gitRepositoryUsername]
passwordTextField.text = Defaults[.gitRepositoryPassword]
authenticationTableViewCell.detailTextLabel?.text = Defaults[.gitRepositoryAuthenticationMethod]
authenticationTableViewCell.detailTextLabel?.text = authenticationMethod
}
override func viewDidAppear(_ animated: Bool) {

View file

@ -58,7 +58,11 @@ class PasswordStore {
if Defaults[.pgpKeyID] != "" {
pgp.importKeys(fromFile: Globals.shared.secringPath, allowDuplicates: false)
}
if Defaults[.gitRepositoryAuthenticationMethod] == "Password" {
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: Defaults[.gitRepositoryUsername], password: Defaults[.gitRepositoryPassword]))
} else {
gitCredential = GitCredential(credential: GitCredential.Credential.ssh(userName: Defaults[.gitRepositoryUsername], password: Defaults[.gitRepositorySSHPrivateKeyPassphrase]!, publicKeyFile: Defaults[.gitRepositorySSHPublicKeyURL]!, privateKeyFile: Defaults[.gitRepositorySSHPrivateKeyURL]!))
}
}

View file

@ -27,6 +27,7 @@ class SSHKeySettingTableViewController: UITableViewController {
target: self,
action: #selector(doneButtonTapped(_:)))
navigationItem.rightBarButtonItem = doneBarButtonItem
navigationItem.title = "SSH Key"
}
func doneButtonTapped(_ sender: UIButton) {

View file

@ -23,7 +23,7 @@ class SettingsTableViewController: UITableViewController {
let gitRepostiroyURL = controller.gitRepositoryURLTextField.text!
let username = controller.usernameTextField.text!
let password = controller.passwordTextField.text!
let auth = controller.authenticationTableViewCell.detailTextLabel!.text!
let auth = controller.authenticationMethod
Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL)
@ -34,7 +34,12 @@ class SettingsTableViewController: UITableViewController {
if Defaults[.gitRepositoryURL] == nil || gitRepostiroyURL != Defaults[.gitRepositoryURL]!.absoluteString {
SVProgressHUD.setDefaultMaskType(.black)
SVProgressHUD.show(withStatus: "Prepare Repository")
let gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, password: password))
var gitCredential: GitCredential
if Defaults[.gitRepositoryAuthenticationMethod] == "Password" {
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, password: password))
} else {
gitCredential = GitCredential(credential: GitCredential.Credential.ssh(userName: username, password: Defaults[.gitRepositorySSHPrivateKeyPassphrase]!, publicKeyFile: Defaults[.gitRepositorySSHPublicKeyURL]!, privateKeyFile: Defaults[.gitRepositorySSHPrivateKeyURL]!))
}
DispatchQueue.global(qos: .userInitiated).async {
let ret = PasswordStore.shared.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!,