Skip to content

Commit 98c96ac

Browse files
authored
submit App info to ziti-controller (#131)
1 parent 639ea07 commit 98c96ac

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

samples/sample-host/src/main/kotlin/org/openziti/sample/netcat/NetcatHost.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018-2020 NetFoundry, Inc.
2+
* Copyright (c) 2018-2021 NetFoundry, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@ object NetcatHost {
3939
val cfg = args[0]
4040
val service = args[1]
4141

42+
Ziti.setApplicationInfo("org.openziti.sample.NetCatHost", "v1.0")
4243
val ziti = Ziti.newContext(cfg, charArrayOf())
4344

4445
runBlocking {

ziti-android/src/main/java/org/openziti/android/Ziti.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018-2020 NetFoundry, Inc.
2+
* Copyright (c) 2018-2021 NetFoundry, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -77,6 +77,11 @@ object Ziti: CoroutineScope, Logged by ZitiLog() {
7777
)
7878
}
7979

80+
81+
val appId = app.packageName
82+
val appVer = app.packageManager.getPackageInfo(appId, 0).versionName
83+
org.openziti.Ziti.setApplicationInfo(appId, appVer)
84+
8085
keyStore = KeyStore.getInstance("AndroidKeyStore")
8186
keyStore.load(null)
8287

ziti/src/main/kotlin/org/openziti/Ziti.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018-2020 NetFoundry, Inc.
2+
* Copyright (c) 2018-2021 NetFoundry, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,4 +79,7 @@ object Ziti {
7979

8080
@JvmStatic
8181
fun getContexts(): Collection<ZitiContext> = ZitiImpl.contexts
82+
83+
@JvmStatic
84+
fun setApplicationInfo(id: String, version: String) = ZitiImpl.setApplicationInfo(id, version)
8285
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.openziti.Errors
3131
import org.openziti.ZitiContext
3232
import org.openziti.ZitiException
3333
import org.openziti.getZitiError
34+
import org.openziti.impl.ZitiImpl
3435
import org.openziti.net.nio.AsychChannelSocket
3536
import org.openziti.net.nio.AsyncTLSSocketFactory
3637
import org.openziti.util.Logged
@@ -284,7 +285,7 @@ internal class Controller(endpoint: URL, sslContext: SSLContext, trustManager: X
284285
}
285286

286287
private fun getClientInfo(): ClientInfo = ClientInfo(
287-
sdkInfo = SdkInfo,
288+
sdkInfo = SdkInfo + mapOf("appID" to ZitiImpl.appId, "appVersion" to ZitiImpl.appVersion),
288289
envInfo = SystemInfoProvider().getSystemInfo(),
289290
configTypes = arrayOf(InterceptConfig)
290291
)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018-2020 NetFoundry, Inc.
2+
* Copyright (c) 2018-2021 NetFoundry, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,9 @@ import java.net.URI
3333
import java.security.KeyStore
3434

3535
internal object ZitiImpl : Logged by ZitiLog() {
36+
internal val contexts = mutableListOf<ZitiContextImpl>()
37+
internal var appId = ""
38+
internal var appVersion = ""
3639

3740
internal val onAndroid: Boolean by lazy {
3841
try {
@@ -60,7 +63,6 @@ internal object ZitiImpl : Logged by ZitiLog() {
6063
return loadContext(ks, alias)
6164
}
6265

63-
internal val contexts = mutableListOf<ZitiContextImpl>()
6466
fun init(file: File, pwd: CharArray, seamless: Boolean): Unit {
6567
if (seamless) {
6668
initInternalNetworking()
@@ -156,4 +158,9 @@ internal object ZitiImpl : Logged by ZitiLog() {
156158
else -> error("unsupported address type")
157159
}
158160
}
161+
162+
fun setApplicationInfo(id: String, version: String) {
163+
appId = id
164+
appVersion = version
165+
}
159166
}

0 commit comments

Comments
 (0)