Skip to content

Commit 5d7c404

Browse files
committed
Clarify magic numbers
1 parent 29da332 commit 5d7c404

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

library/src/main/kotlin/com/gabrielfeo/develocity/api/internal/auth/HostAccessKeyEntry.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ internal class HostAccessKeyEntry(entry: String) {
66

77
init {
88
require(components.size == 2 && host.isNotBlank() && accessKey.isNotBlank()) {
9-
val redactedEntry = if (entry.length <= 5) entry else "${entry.substring(0, 4)}[redacted]"
10-
"Invalid access key entry format: '$redactedEntry'. Expected format is 'host=accessKey'."
9+
"Invalid access key entry format: '${redact(entry)}'. Expected format is 'host=accessKey'."
1110
}
1211
}
1312

1413
val host: String get() = components[0]
1514
val accessKey: String get() = components[1]
16-
}
15+
}
16+
17+
private const val REDACTED_MAX_LENGTH = 5
18+
19+
private fun redact(entry: String): String =
20+
if (entry.length <= REDACTED_MAX_LENGTH) entry
21+
else "${entry.substring(0, REDACTED_MAX_LENGTH - 1)}[redacted]"

0 commit comments

Comments
 (0)