Skip to content

Commit d372156

Browse files
committed
fix: address PR review - profile validation, secret cleanup, edit vs prefill
1 parent 88deb90 commit d372156

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

TablePro/Views/Connection/ConnectionFormView.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,12 +1050,6 @@ struct ConnectionFormView: View { // swiftlint:disable:this type_body_length
10501050
sshProfileId = existing.sshProfileId
10511051
sshEnabled = existing.sshConfig.enabled
10521052

1053-
// When using a profile, also set sshEnabled based on profile existence
1054-
if let profileId = existing.sshProfileId,
1055-
SSHProfileStorage.shared.profile(for: profileId) != nil {
1056-
sshEnabled = true
1057-
}
1058-
10591053
sshHost = existing.sshConfig.host
10601054
sshPort = String(existing.sshConfig.port)
10611055
sshUsername = existing.sshConfig.username
@@ -1199,6 +1193,11 @@ struct ConnectionFormView: View { // swiftlint:disable:this type_body_length
11991193
} else {
12001194
storage.deleteTOTPSecret(for: connectionToSave.id)
12011195
}
1196+
} else {
1197+
// Clean up stale per-connection SSH secrets when using a profile or SSH disabled
1198+
storage.deleteSSHPassword(for: connectionToSave.id)
1199+
storage.deleteKeyPassphrase(for: connectionToSave.id)
1200+
storage.deleteTOTPSecret(for: connectionToSave.id)
12021201
}
12031202

12041203
// Save to storage

TablePro/Views/Connection/SSHProfileEditorView.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ struct SSHProfileEditorView: View {
4949
@State private var showingDeleteConfirmation = false
5050
@State private var connectionsUsingProfile = 0
5151

52-
private var isEditing: Bool { existingProfile != nil }
52+
private var isStoredProfile: Bool {
53+
guard let profile = existingProfile else { return false }
54+
return SSHProfileStorage.shared.profile(for: profile.id) != nil
55+
}
5356

5457
private var isValid: Bool {
55-
!profileName.trimmingCharacters(in: .whitespaces).isEmpty
56-
&& !host.trimmingCharacters(in: .whitespaces).isEmpty
58+
let nameValid = !profileName.trimmingCharacters(in: .whitespaces).isEmpty
59+
let hostValid = !host.trimmingCharacters(in: .whitespaces).isEmpty
60+
let portValid = port.isEmpty || (Int(port).map { (1...65_535).contains($0) } ?? false)
61+
let authValid = authMethod == .password || authMethod == .sshAgent
62+
|| authMethod == .keyboardInteractive || !privateKeyPath.isEmpty
63+
let jumpValid = jumpHosts.allSatisfy(\.isValid)
64+
return nameValid && hostValid && portValid && authValid && jumpValid
5765
}
5866

5967
private var resolvedAgentSocketPath: String {
@@ -266,7 +274,7 @@ struct SSHProfileEditorView: View {
266274

267275
private var bottomBar: some View {
268276
HStack {
269-
if isEditing {
277+
if isStoredProfile {
270278
Button(role: .destructive) {
271279
connectionsUsingProfile = ConnectionStorage.shared.loadConnections()
272280
.filter { $0.sshProfileId == existingProfile?.id }.count
@@ -294,7 +302,7 @@ struct SSHProfileEditorView: View {
294302
Button("Cancel") { dismiss() }
295303
.keyboardShortcut(.cancelAction)
296304

297-
Button(isEditing ? "Save" : "Create") { saveProfile() }
305+
Button(isStoredProfile ? "Save" : "Create") { saveProfile() }
298306
.keyboardShortcut(.defaultAction)
299307
.disabled(!isValid)
300308
}
@@ -349,7 +357,7 @@ struct SSHProfileEditorView: View {
349357
totpPeriod: totpPeriod
350358
)
351359

352-
if isEditing {
360+
if isStoredProfile {
353361
SSHProfileStorage.shared.updateProfile(profile)
354362
} else {
355363
SSHProfileStorage.shared.addProfile(profile)

0 commit comments

Comments
 (0)