Skip to content

Commit 4d25228

Browse files
committed
fix: resolve Qodana inspection findings for nested folder PR
1 parent 0c85b5f commit 4d25228

12 files changed

Lines changed: 35 additions & 56 deletions

src/main/kotlin/keepersecurity/action/KeeperAuthAction.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import java.util.concurrent.TimeUnit
1414
/**
1515
* Three-state outcome of the Keeper shell probe used by [KeeperAuthAction].
1616
*
17-
* - [AUTHENTICATED] — shell is up *and* the user is logged in. Safe to
17+
* - `AUTHENTICATED` — shell is up *and* the user is logged in. Safe to
1818
* proceed with any other Keeper action.
19-
* - [NOT_LOGGED_IN] — shell process exists, but Commander reports the
19+
* - `NOT_LOGGED_IN` — shell process exists, but Commander reports the
2020
* "Not logged in>" prompt. The user must run `keeper login` once.
21-
* - [FAILED] — shell did not respond, returned blank output, or otherwise
21+
* - `FAILED` — shell did not respond, returned blank output, or otherwise
2222
* failed to demonstrate a working authenticated session. We refuse to
2323
* declare success on weak evidence (older code's catch-all rule led to
2424
* false-positive "Authorization OK" dialogs against a half-dead shell).

src/main/kotlin/keepersecurity/action/KeeperFolderSelectAction.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import keepersecurity.ui.KeeperListPickerDialog
1212
import keepersecurity.ui.KeeperListPickerItem
1313
import keepersecurity.ui.KeeperVaultBadge
1414
import kotlinx.serialization.json.Json
15-
import kotlinx.serialization.decodeFromString
1615
import keepersecurity.model.KeeperFolder
1716
import keepersecurity.util.KeeperJsonUtils
1817
import keepersecurity.util.KeeperCommandUtils
@@ -115,7 +114,7 @@ class KeeperFolderSelectAction : AnAction("Get Keeper Folder") {
115114
Messages.showInfoMessage(
116115
project,
117116
"$locationLabel folder '${selectedFolder.name}' " +
118-
"(UUID '${selectedFolder.uid}') has been saved for this project.",
117+
"(Uuid '${selectedFolder.uid}') has been saved for this project.",
119118
"Keeper Folder Saved"
120119
)
121120
}

src/main/kotlin/keepersecurity/action/KeeperGenerateSecretsAction.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import keepersecurity.util.KeeperCliSafety
1616
import keepersecurity.util.KeeperCommandUtils
1717
import keepersecurity.util.KeeperJsonUtils
1818
import keepersecurity.util.KeeperRecordOutputValidators
19-
import kotlinx.serialization.json.Json
20-
import kotlinx.serialization.decodeFromString
19+
import kotlinx.serialization.json.Json
2120
import keepersecurity.model.GeneratedPassword
2221
import kotlinx.serialization.ExperimentalSerializationApi
2322

src/main/kotlin/keepersecurity/action/KeeperGetSecretAction.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import com.intellij.openapi.diagnostic.thisLogger
1616
import com.intellij.openapi.vfs.VirtualFile
1717
import keepersecurity.service.KeeperShellService
1818
import kotlinx.serialization.json.Json
19-
import kotlinx.serialization.decodeFromString
2019
import keepersecurity.model.KeeperRecord
2120
import keepersecurity.model.getDisplayValue
2221
import keepersecurity.util.KeeperJsonUtils
@@ -365,7 +364,7 @@ class KeeperGetSecretAction : AnAction("Get Keeper Secret") {
365364
insertText: String,
366365
keeperNotation: String,
367366
): String = if (isHttpSnippet) {
368-
"HTTP Client variable inserted (record and field chosen from the list — no UID to type).\n\n$insertText"
367+
"HTTP Client variable inserted (record and field chosen from the list — no uid to type).\n\n$insertText"
369368
} else {
370369
"Keeper reference inserted!\n\n$keeperNotation"
371370
}

src/main/kotlin/keepersecurity/action/KeeperRecordTargetPrompt.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object KeeperRecordTargetPrompt {
4646
/**
4747
* Outcome of [promptForAddTarget] / [promptForGenerateTarget].
4848
*
49-
* Both [Classic] and [Drive] carry the resolved folder UUID + display
49+
* Both [AddOutcome.Classic] and [AddOutcome.Drive] carry the resolved folder UUID + display
5050
* name so the caller doesn't have to re-read `PropertiesComponent`
5151
* (and pick the wrong scope — see the project-scope vs app-scope
5252
* footgun fixed earlier).
@@ -57,7 +57,7 @@ object KeeperRecordTargetPrompt {
5757
* compatibility with callers that build outcomes from tests.
5858
*/
5959
sealed class AddOutcome {
60-
object Cancelled : AddOutcome()
60+
data object Cancelled : AddOutcome()
6161
data class Classic(val folderUuid: String?, val folderName: String?) : AddOutcome()
6262
data class Drive(val folderUuid: String?, val folderName: String?) : AddOutcome()
6363
}
@@ -114,7 +114,7 @@ object KeeperRecordTargetPrompt {
114114
/** What happened when we examined a slot. */
115115
private sealed class SlotResult {
116116
/** Slot was empty — nothing to do. */
117-
object Empty : SlotResult()
117+
data object Empty : SlotResult()
118118

119119
/** Slot resolved to a valid folder; downstream should use it. */
120120
data class Resolved(val outcome: AddOutcome) : SlotResult()

src/main/kotlin/keepersecurity/action/KeeperRecordUpdateAction.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ class KeeperRecordUpdateAction : AnAction("Update Keeper Record") {
7070

7171
val rawRecordUid = Messages.showInputDialog(
7272
project,
73-
"Enter Keeper record UID:",
74-
"Record UID",
73+
"Enter Keeper record uid:",
74+
"Record Uid",
7575
null
7676
)?.trim()
7777

7878
if (rawRecordUid.isNullOrBlank()) {
79-
showError("Record UID is required", project)
79+
showError("Record uid is required", project)
8080
return
8181
}
8282

8383
val recordUid = try {
84-
KeeperCliSafety.requireSafe(rawRecordUid, "record UID")
84+
KeeperCliSafety.requireSafe(rawRecordUid, "record uid")
8585
} catch (ex: KeeperCliSafety.UnsafeCliInputException) {
86-
showError(ex.message ?: "Record UID is not safe.", project)
86+
showError(ex.message ?: "Record uid is not safe.", project)
8787
return
8888
}
8989

@@ -103,16 +103,16 @@ class KeeperRecordUpdateAction : AnAction("Update Keeper Record") {
103103
}
104104
is KeeperRecordValidator.Verdict.NotFound -> {
105105
showError(
106-
"Record UID '$recordUid' was not found in your vault. " +
106+
"Record uid '$recordUid' was not found in your vault. " +
107107
"Double-check the value (Tools \u2192 Keeper Vault \u2192 Get Keeper Secret " +
108-
"lists every record with its UID).",
108+
"lists every record with its uid).",
109109
project
110110
)
111111
return
112112
}
113113
is KeeperRecordValidator.Verdict.Unknown -> {
114114
showError(
115-
"Couldn't verify the record UID against your vault " +
115+
"Couldn't verify the record uid against your vault " +
116116
"(${verdict.reason}). Make sure Keeper Commander is healthy and try again.",
117117
project
118118
)

src/main/kotlin/keepersecurity/model/KeeperModels.kt

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,9 @@ data class KeeperFolder(
6060
SOURCE_KEEPER_DRIVE,
6161
)
6262

63-
/**
64-
* Wire values that mean Classic vault folder. Current Commander:
65-
* [SOURCE_CLASSIC_FOLDER]. Legacy: [SOURCE_LEGACY]. Null/missing → classic.
66-
*/
67-
private val CLASSIC_SOURCES = setOf(
68-
SOURCE_CLASSIC_FOLDER,
69-
SOURCE_LEGACY,
70-
)
71-
7263
/** True when [source] identifies a Nested Shared Folder row. */
73-
fun isNestedShareSource(source: String?): Boolean =
64+
private fun isNestedShareSource(source: String?): Boolean =
7465
source != null && NESTED_SHARE_SOURCES.any { it.equals(source, ignoreCase = true) }
75-
76-
/** True when [source] identifies a Classic vault folder row. */
77-
fun isClassicSource(source: String?): Boolean =
78-
source == null || CLASSIC_SOURCES.any { it.equals(source, ignoreCase = true) }
7966
}
8067

8168
/** True when this folder is a Nested Shared Folder (not Classic Vault). */
@@ -122,14 +109,9 @@ data class KeeperRecord(
122109
)
123110

124111
/** True when [recordCategory] identifies a Nested Shared record row. */
125-
fun isNestedShareCategory(recordCategory: String?): Boolean =
112+
private fun isNestedShareCategory(recordCategory: String?): Boolean =
126113
recordCategory != null &&
127114
NESTED_SHARE_CATEGORIES.any { it.equals(recordCategory, ignoreCase = true) }
128-
129-
/** True when [recordCategory] identifies a Classic vault record row. */
130-
fun isClassicCategory(recordCategory: String?): Boolean =
131-
recordCategory == null ||
132-
recordCategory.equals(CATEGORY_CLASSIC, ignoreCase = true)
133115
}
134116

135117
/** True when this record lives in a Nested Shared Folder (not Classic Vault). */

src/main/kotlin/keepersecurity/run/KeeperSecureScriptRunner.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ object KeeperSecureScriptRunner {
7676
val field = match.groupValues[2]
7777
if (!KeeperCliSafety.isValidRecordUid(uid)) {
7878
errors.add(
79-
"Skipped $key: invalid Keeper record UID '$uid' in keeper:// notation " +
79+
"Skipped $key: invalid Keeper record uid '$uid' in keeper:// notation " +
8080
"(expected exactly 22 characters: A-Z, a-z, 0-9, _, -)"
8181
)
8282
logger.warn("Invalid keeper:// UID for key '$key': '$uid'")
@@ -262,9 +262,9 @@ object KeeperSecureScriptRunner {
262262

263263
private fun getKeeperJsonFromShell(uid: String, logger: Logger): String {
264264
if (!KeeperCliSafety.isValidRecordUid(uid)) {
265-
throw IllegalArgumentException("Invalid Keeper record UID: $uid")
265+
throw IllegalArgumentException("Invalid Keeper record uid: $uid")
266266
}
267-
KeeperCliSafety.requireSafe(uid, "record UID")
267+
KeeperCliSafety.requireSafe(uid, "record uid")
268268
val output = KeeperCommandUtils.executeCommandWithRetry(
269269
"get $uid --format json",
270270
KeeperCommandUtils.Presets.jsonObject(maxRetries = 3),

src/main/kotlin/keepersecurity/ui/KeeperListPickerDialog.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package keepersecurity.ui
33
import com.intellij.openapi.project.Project
44
import com.intellij.openapi.ui.DialogWrapper
55
import com.intellij.ui.CollectionListModel
6-
import com.intellij.ui.DocumentAdapter
76
import com.intellij.ui.SearchTextField
87
import com.intellij.ui.components.JBLabel
98
import com.intellij.ui.components.JBList
@@ -24,6 +23,7 @@ import javax.swing.ListCellRenderer
2423
import javax.swing.ListSelectionModel
2524
import javax.swing.SwingConstants
2625
import javax.swing.event.DocumentEvent
26+
import javax.swing.event.DocumentListener
2727

2828
/** Vault-model badge shown beside each folder or record in the searchable picker. */
2929
enum class KeeperVaultBadge(val label: String) {
@@ -43,7 +43,7 @@ data class KeeperListPickerItem(
4343
fun matchesSearch(query: String): Boolean {
4444
if (query.isEmpty()) return true
4545
if (label.contains(query, ignoreCase = true)) return true
46-
return badge?.label?.contains(query, ignoreCase = true) == true
46+
return badge?.label?.contains(query, ignoreCase = true) ?: false
4747
}
4848
}
4949

@@ -112,7 +112,7 @@ object KeeperListPickerDialog {
112112

113113
private class ListPickerDialog(
114114
project: Project,
115-
dialogTitle: String,
115+
private val dialogTitle: String,
116116
private val message: String,
117117
private val options: List<KeeperListPickerItem>,
118118
private val initial: KeeperListPickerItem?,
@@ -145,8 +145,12 @@ object KeeperListPickerDialog {
145145
}
146146
})
147147

148-
search.textEditor.document.addDocumentListener(object : DocumentAdapter() {
149-
override fun textChanged(e: DocumentEvent) {
148+
search.textEditor.document.addDocumentListener(object : DocumentListener {
149+
override fun insertUpdate(e: DocumentEvent) = onTextChanged()
150+
override fun removeUpdate(e: DocumentEvent) = onTextChanged()
151+
override fun changedUpdate(e: DocumentEvent) = onTextChanged()
152+
153+
private fun onTextChanged() {
150154
val query = search.text.trim()
151155
val filtered = options.filter { it.matchesSearch(query) }
152156
listModel.replaceAll(filtered)
@@ -205,12 +209,11 @@ object KeeperListPickerDialog {
205209
): Component {
206210
nameLabel.text = value?.label.orEmpty()
207211

208-
val badge = value?.badge
209-
if (badge != null) {
212+
value?.badge?.let { badge ->
210213
badgeLabel.isVisible = true
211214
badgeLabel.text = badge.label
212215
applyBadgeColors(badgeLabel, badge, isSelected, list)
213-
} else {
216+
} ?: run {
214217
badgeLabel.isVisible = false
215218
}
216219

src/main/kotlin/keepersecurity/util/KeeperFolderValidator.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.intellij.openapi.progress.ProgressManager
66
import com.intellij.openapi.project.Project
77
import keepersecurity.model.KeeperFolder
88
import kotlinx.serialization.ExperimentalSerializationApi
9-
import kotlinx.serialization.decodeFromString
109
import kotlinx.serialization.json.Json
1110

1211
/**
@@ -45,7 +44,7 @@ object KeeperFolderValidator {
4544
) : Verdict()
4645

4746
/** UUID is not present in the current `ls` payload. */
48-
object Missing : Verdict()
47+
data object Missing : Verdict()
4948

5049
/**
5150
* UUID exists but lives in the *other* vault — e.g. the project

0 commit comments

Comments
 (0)