2017-01-28 00:21:17 +08:00
|
|
|
//
|
2021-12-28 02:57:11 +01:00
|
|
|
// SSHKeyURLImportTableViewController.swift
|
2017-01-28 00:21:17 +08:00
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 25/1/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2017-06-13 11:42:49 +08:00
|
|
|
import passKit
|
2020-06-28 21:25:40 +02:00
|
|
|
import SVProgressHUD
|
2017-01-28 00:21:17 +08:00
|
|
|
|
2021-12-28 02:57:11 +01:00
|
|
|
class SSHKeyURLImportTableViewController: AutoCellHeightUITableViewController {
|
2020-06-28 21:25:40 +02:00
|
|
|
@IBOutlet var privateKeyURLTextField: UITextField!
|
2020-02-15 18:12:58 +01:00
|
|
|
|
2020-04-13 19:15:52 -07:00
|
|
|
var sshPrivateKeyURL: URL?
|
|
|
|
|
|
2020-02-15 18:12:58 +01:00
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
privateKeyURLTextField.text = Defaults.gitSSHPrivateKeyURL?.absoluteString
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2020-06-28 21:25:40 +02:00
|
|
|
@IBAction
|
2020-07-05 22:49:53 +02:00
|
|
|
private func doneButtonTapped(_: UIButton) {
|
2020-04-13 19:15:52 -07:00
|
|
|
guard let text = privateKeyURLTextField.text,
|
2020-11-07 12:06:28 +01:00
|
|
|
let privateKeyURL = URL(string: text) else {
|
2020-06-28 21:25:40 +02:00
|
|
|
Utils.alert(title: "CannotSave".localize(), message: "SetPrivateKeyUrl.".localize(), controller: self)
|
|
|
|
|
return
|
2020-04-13 19:15:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if privateKeyURL.scheme?.lowercased() == "http" {
|
2020-02-15 18:12:58 +01:00
|
|
|
let savePassphraseAlert = UIAlertController(title: "HttpNotSecure".localize(), message: "ReallyUseHttp?".localize(), preferredStyle: .alert)
|
|
|
|
|
savePassphraseAlert.addAction(UIAlertAction(title: "No".localize(), style: .default) { _ in })
|
2020-07-05 00:16:22 +02:00
|
|
|
savePassphraseAlert.addAction(
|
|
|
|
|
UIAlertAction(title: "Yes".localize(), style: .destructive) { _ in
|
2022-05-23 13:23:25 +08:00
|
|
|
self.sshPrivateKeyURL = privateKeyURL
|
2020-07-05 00:16:22 +02:00
|
|
|
self.performSegue(withIdentifier: "importSSHKeySegue", sender: self)
|
|
|
|
|
}
|
|
|
|
|
)
|
2022-06-16 04:55:02 +02:00
|
|
|
present(savePassphraseAlert, animated: true)
|
|
|
|
|
return
|
2017-02-15 22:34:16 +08:00
|
|
|
}
|
2020-04-13 19:15:52 -07:00
|
|
|
sshPrivateKeyURL = privateKeyURL
|
2020-02-15 18:12:58 +01:00
|
|
|
performSegue(withIdentifier: "importSSHKeySegue", sender: self)
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-09 16:59:07 -08:00
|
|
|
|
2021-12-28 02:57:11 +01:00
|
|
|
extension SSHKeyURLImportTableViewController: KeyImporter {
|
2020-02-15 18:12:58 +01:00
|
|
|
static let keySource = KeySource.url
|
|
|
|
|
static let label = "DownloadFromUrl".localize()
|
|
|
|
|
|
|
|
|
|
func isReadyToUse() -> Bool {
|
2020-04-13 19:15:52 -07:00
|
|
|
guard let url = sshPrivateKeyURL else {
|
2020-02-15 18:12:58 +01:00
|
|
|
Utils.alert(title: "CannotSave".localize(), message: "SetPrivateKeyUrl.".localize(), controller: self)
|
|
|
|
|
return false
|
|
|
|
|
}
|
2020-04-13 19:15:52 -07:00
|
|
|
guard url.scheme == "https" || url.scheme == "http" else {
|
2020-02-15 18:12:58 +01:00
|
|
|
Utils.alert(title: "CannotSave".localize(), message: "UseEitherHttpsOrHttp.".localize(), controller: self)
|
|
|
|
|
return false
|
2017-01-31 22:54:58 +08:00
|
|
|
}
|
2020-02-15 18:12:58 +01:00
|
|
|
return true
|
2017-01-28 00:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
2020-02-15 18:12:58 +01:00
|
|
|
func importKeys() throws {
|
2020-04-13 19:15:52 -07:00
|
|
|
Defaults.gitSSHPrivateKeyURL = sshPrivateKeyURL
|
2021-12-28 02:57:11 +01:00
|
|
|
try KeyFileManager.PrivateSSH.importKey(from: Defaults.gitSSHPrivateKeyURL!)
|
2020-02-15 18:12:58 +01:00
|
|
|
}
|
2017-01-28 00:21:17 +08:00
|
|
|
}
|