secretive/Sources/Secretive/Views/SecretDetailView.swift

59 lines
2.1 KiB
Swift
Raw Normal View History

2020-03-04 07:14:38 +00:00
import SwiftUI
import SecretKit
struct SecretDetailView<SecretType: Secret>: View {
2020-09-22 06:12:50 +00:00
2020-03-04 07:14:38 +00:00
@State var secret: SecretType
2020-09-22 06:12:50 +00:00
private let keyWriter = OpenSSHKeyWriter()
private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: NSHomeDirectory().replacingOccurrences(of: Bundle.main.hostBundleID, with: Bundle.main.agentBundleID))
2020-09-22 06:12:50 +00:00
2020-03-04 07:14:38 +00:00
var body: some View {
2021-09-25 22:12:35 +00:00
ScrollView {
Form {
Section {
CopyableView(title: "secret_detail_sha256_fingerprint_label", image: Image(systemName: "touchid"), text: keyWriter.openSSHSHA256Fingerprint(secret: secret))
2021-09-25 22:12:35 +00:00
Spacer()
.frame(height: 20)
CopyableView(title: "secret_detail_md5_fingerprint_label", image: Image(systemName: "touchid"), text: keyWriter.openSSHMD5Fingerprint(secret: secret))
2021-09-25 22:12:35 +00:00
Spacer()
.frame(height: 20)
CopyableView(title: "secret_detail_public_key_label", image: Image(systemName: "key"), text: keyString)
Spacer()
.frame(height: 20)
CopyableView(title: "secret_detail_public_key_path_label", image: Image(systemName: "lock.doc"), text: publicKeyFileStoreController.publicKeyPath(for: secret))
2021-09-25 22:12:35 +00:00
Spacer()
}
2020-03-04 07:14:38 +00:00
}
2021-09-25 22:12:35 +00:00
.padding()
2020-09-22 06:12:50 +00:00
}
.frame(minHeight: 200, maxHeight: .infinity)
2020-03-04 07:14:38 +00:00
}
2020-11-29 21:15:14 +00:00
var dashedKeyName: String {
secret.name.replacingOccurrences(of: " ", with: "-")
2020-11-29 21:15:14 +00:00
}
2020-11-29 21:15:14 +00:00
var dashedHostName: String {
["secretive", Host.current().localizedName, "local"]
.compactMap { $0 }
.joined(separator: ".")
.replacingOccurrences(of: " ", with: "-")
}
2020-09-22 06:12:50 +00:00
2020-03-04 07:14:38 +00:00
var keyString: String {
2020-11-29 21:15:14 +00:00
keyWriter.openSSHString(secret: secret, comment: "\(dashedKeyName)@\(dashedHostName)")
2020-03-04 07:14:38 +00:00
}
2020-03-04 07:14:38 +00:00
}
2020-03-12 04:58:32 +00:00
2020-03-12 06:07:22 +00:00
#if DEBUG
2020-03-12 04:58:32 +00:00
struct SecretDetailView_Previews: PreviewProvider {
static var previews: some View {
SecretDetailView(secret: Preview.Store(numberOfRandomSecrets: 1).secrets[0])
}
}
2020-03-12 06:07:22 +00:00
#endif