Skip to content

Commit 93e8525

Browse files
authored
Separate address parsing logic for Core and Cloud connection URIs (#849)
## Usage and product changes We fix an issue where attempting to parse `typedb-core://` connection URIs would cause crashes ## Motivation This issue made this feature unusable for TypeDB Core connection URIs ## Implementation We separate the logic for parsing addresses for TypeDB Cloud - which expects a username and password - from the address parsing logic for TypeDB Core - which doesn't. Instead of attempting to extract data it doesn't need from the `authority` component of the URI, which resulted in an empty list of addresses, we simply take the entire `authority` component as the address.
1 parent 095ab3c commit 93e8525

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

service/common/util/ConnectionUri.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,20 @@ object ConnectionUri {
4949
fun parse(connectionUri: String): ParsedConnectionUri? {
5050
val uri = try { URI(connectionUri) } catch (_: URISyntaxException) { return null }
5151

52-
val (username, password, addresses) = uri.authority?.let {
53-
val (auth, address) = it.split("@", limit = 2)
54-
.let { Pair(it[0], it.getOrNull(1)) }
55-
val (username, password) = auth.split(":", limit = 2)
56-
.let { Pair(it[0], it.getOrNull(1)) }
57-
val addresses = address?.split(ADDRESSES_SEPARATOR) ?: emptyList()
58-
Triple(username, password, addresses)
59-
} ?: Triple(null, null, emptyList())
60-
val queryParams = uri.query?.split("&")?.associate {
61-
it.split("=", limit = 2).let { Pair(it[0], it.getOrNull(1)) }
62-
}
63-
6452
if (uri.scheme == SCHEME_CLOUD) {
53+
val (username, password, addresses) = uri.authority?.let {
54+
val (auth, address) = it.split("@", limit = 2)
55+
.let { Pair(it[0], it.getOrNull(1)) }
56+
val (username, password) = auth.split(":", limit = 2)
57+
.let { Pair(it[0], it.getOrNull(1)) }
58+
val addresses = address?.split(ADDRESSES_SEPARATOR) ?: emptyList()
59+
Triple(username, password, addresses)
60+
} ?: Triple(null, null, emptyList())
61+
62+
val queryParams = uri.query?.split("&")?.associate {
63+
it.split("=", limit = 2).let { Pair(it[0], it.getOrNull(1)) }
64+
}
65+
6566
val decodedPassword = password?.let { URLDecoder.decode(it, Charset.defaultCharset()) }
6667
val tlsEnabled = queryParams?.get(TLS_ENABLED)?.toBoolean()
6768
if (addresses.getOrNull(0)?.contains(ADDRESS_TRANSLATION_SEPARATOR) == true) {
@@ -81,8 +82,8 @@ object ConnectionUri {
8182
tlsEnabled = tlsEnabled
8283
)
8384
}
84-
} else if (uri.scheme == SCHEME_CORE) {
85-
return ParsedCoreConnectionUri(addresses[0])
85+
} else if (uri.scheme == SCHEME_CORE && !uri.authority.isNullOrBlank()) {
86+
return ParsedCoreConnectionUri(uri.authority)
8687
} else {
8788
return null
8889
}

0 commit comments

Comments
 (0)