Skip to content

Commit cb460c7

Browse files
authored
Misc fixes (#631)
* add edge-api module description * allow to load IdentityConfig from stream * fix API error extraction * cleanup
1 parent 783a9c0 commit cb460c7

File tree

7 files changed

+17
-11
lines changed

7 files changed

+17
-11
lines changed

edge-api/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ publishing {
4747
}
4848

4949
ext {
50+
description "OpenZiti Edge API client"
5051
jackson_version = libs.versions.jackson.get()
5152
jakarta_annotation_version = libs.versions.jakarta.annotation.get()
5253
}

ziti/src/main/kotlin/org/openziti/api/Controller.kt

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.openziti.api
1818

19+
import com.fasterxml.jackson.module.kotlin.treeToValue
1920
import kotlinx.coroutines.CancellationException
2021
import kotlinx.coroutines.Dispatchers
2122
import kotlinx.coroutines.asExecutor
@@ -30,7 +31,6 @@ import org.openziti.edge.ApiClient
3031
import org.openziti.edge.ApiException
3132
import org.openziti.edge.api.*
3233
import org.openziti.edge.model.*
33-
import org.openziti.edge.model.Meta
3434
import org.openziti.getZitiError
3535
import org.openziti.impl.ZitiImpl
3636
import org.openziti.util.Logged
@@ -43,10 +43,9 @@ import java.net.http.HttpClient
4343
import java.util.concurrent.CompletableFuture
4444
import java.util.function.Consumer
4545
import javax.net.ssl.SSLContext
46-
import javax.net.ssl.X509TrustManager
4746
import kotlin.reflect.full.memberFunctions
4847

49-
internal class Controller(endpoint: URL, sslContext: SSLContext, trustManager: X509TrustManager) :
48+
internal class Controller(endpoint: URL, sslContext: SSLContext):
5049
Logged by ZitiLog() {
5150

5251
private val pageSize = 100
@@ -274,8 +273,12 @@ internal class Controller(endpoint: URL, sslContext: SSLContext, trustManager: X
274273
}
275274

276275
private fun getError(resp: String): String {
277-
val apiError = edgeApi.objectMapper.convertValue(resp, ApiError::class.java)
278-
return apiError.code ?: apiError.message!!
276+
277+
val err = edgeApi.objectMapper.treeToValue<ApiErrorEnvelope>(
278+
edgeApi.objectMapper.readTree(resp)
279+
).error
280+
281+
return err.code ?: err.message!!
279282
}
280283

281284
private fun getClientInfo(): Authenticate = Authenticate().apply {

ziti/src/main/kotlin/org/openziti/identity/util.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ internal fun loadKeystore(f: File, pwd: CharArray): KeyStore {
103103

104104
internal fun loadKeystore(stream: InputStream, pwd: CharArray): KeyStore {
105105
val log = ZitiLog()
106-
val ks = loadKeystore(stream, pwd, log)
106+
val bytes = stream.readNBytes(16 * 1024)
107+
val ks = loadKeystore(bytes.inputStream(), pwd, log)
107108
if (ks != null) {
108109
return ks
109110
}
110111

111-
throw IllegalArgumentException("unsupported format")
112+
val id = IdentityConfig.load(bytes.inputStream().reader())
113+
return keystoreFromConfig(id)
112114
}
113115

114116
internal fun loadKeystore(stream: InputStream, pwd: CharArray, log: ZitiLog): KeyStore? {

ziti/src/main/kotlin/org/openziti/impl/ZitiContextImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ internal class ZitiContextImpl(internal val id: Identity, enabled: Boolean) : Zi
7777
private val currentEdgeRouters =
7878
MutableStateFlow<Collection<CurrentIdentityEdgeRouterDetail>>(emptyList())
7979

80-
private val controller: Controller = Controller(URI.create(id.controller()).toURL(), sslContext(), trustManager())
80+
private val controller: Controller = Controller(URI.create(id.controller()).toURL(), sslContext())
8181
private val postureService = PostureService()
8282

8383
private val statusCh: MutableStateFlow<ZitiContext.Status>

ziti/src/test/kotlin/org/openziti/api/ControllerTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal class ControllerTest {
5858

5959
identity = KeyStoreIdentity(ks, findIdentityAlias(ks))
6060

61-
ctrl = Controller(URL(identity.controller()), identity.sslContext(), identity.trustManager())
61+
ctrl = Controller(URL(identity.controller()), identity.sslContext())
6262
}
6363

6464
@After

ziti/src/test/kotlin/org/openziti/identity/EnrollTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class EnrollTest {
133133
assertNotNull("Name", identity.name())
134134

135135
val controller =
136-
Controller(URI.create(identity.controller()).toURL(), identity.sslContext(), identity.trustManager())
136+
Controller(URI.create(identity.controller()).toURL(), identity.sslContext())
137137
val loginResp = controller.login()
138138
assertNotNull("login with device cert", loginResp.token)
139139
controller.logout()

ziti/src/test/kotlin/org/openziti/identity/ZitiTestHelper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal object ZitiTestHelper {
5858
val url = props.getProperty("controller") ?: fail("need controller")
5959

6060
ctrlURI = URI.create(url)
61-
controller = Controller(ctrlURI.toURL(), controllerSSL, TrustAll)
61+
controller = Controller(ctrlURI.toURL(), controllerSSL)
6262

6363
val s = controller!!.login(Login(username, password))
6464
session = s.token

0 commit comments

Comments
 (0)