Skip to content

Commit

Permalink
submit App info to ziti-controller (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoby authored Feb 2, 2021
1 parent 639ea07 commit 98c96ac
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020 NetFoundry, Inc.
* Copyright (c) 2018-2021 NetFoundry, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,6 +39,7 @@ object NetcatHost {
val cfg = args[0]
val service = args[1]

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

runBlocking {
Expand Down
7 changes: 6 additions & 1 deletion ziti-android/src/main/java/org/openziti/android/Ziti.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020 NetFoundry, Inc.
* Copyright (c) 2018-2021 NetFoundry, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,6 +77,11 @@ object Ziti: CoroutineScope, Logged by ZitiLog() {
)
}


val appId = app.packageName
val appVer = app.packageManager.getPackageInfo(appId, 0).versionName
org.openziti.Ziti.setApplicationInfo(appId, appVer)

keyStore = KeyStore.getInstance("AndroidKeyStore")
keyStore.load(null)

Expand Down
5 changes: 4 additions & 1 deletion ziti/src/main/kotlin/org/openziti/Ziti.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020 NetFoundry, Inc.
* Copyright (c) 2018-2021 NetFoundry, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,4 +79,7 @@ object Ziti {

@JvmStatic
fun getContexts(): Collection<ZitiContext> = ZitiImpl.contexts

@JvmStatic
fun setApplicationInfo(id: String, version: String) = ZitiImpl.setApplicationInfo(id, version)
}
3 changes: 2 additions & 1 deletion ziti/src/main/kotlin/org/openziti/api/Controller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.openziti.Errors
import org.openziti.ZitiContext
import org.openziti.ZitiException
import org.openziti.getZitiError
import org.openziti.impl.ZitiImpl
import org.openziti.net.nio.AsychChannelSocket
import org.openziti.net.nio.AsyncTLSSocketFactory
import org.openziti.util.Logged
Expand Down Expand Up @@ -284,7 +285,7 @@ internal class Controller(endpoint: URL, sslContext: SSLContext, trustManager: X
}

private fun getClientInfo(): ClientInfo = ClientInfo(
sdkInfo = SdkInfo,
sdkInfo = SdkInfo + mapOf("appID" to ZitiImpl.appId, "appVersion" to ZitiImpl.appVersion),
envInfo = SystemInfoProvider().getSystemInfo(),
configTypes = arrayOf(InterceptConfig)
)
Expand Down
11 changes: 9 additions & 2 deletions ziti/src/main/kotlin/org/openziti/impl/ZitiImpl.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020 NetFoundry, Inc.
* Copyright (c) 2018-2021 NetFoundry, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,9 @@ import java.net.URI
import java.security.KeyStore

internal object ZitiImpl : Logged by ZitiLog() {
internal val contexts = mutableListOf<ZitiContextImpl>()
internal var appId = ""
internal var appVersion = ""

internal val onAndroid: Boolean by lazy {
try {
Expand Down Expand Up @@ -60,7 +63,6 @@ internal object ZitiImpl : Logged by ZitiLog() {
return loadContext(ks, alias)
}

internal val contexts = mutableListOf<ZitiContextImpl>()
fun init(file: File, pwd: CharArray, seamless: Boolean): Unit {
if (seamless) {
initInternalNetworking()
Expand Down Expand Up @@ -156,4 +158,9 @@ internal object ZitiImpl : Logged by ZitiLog() {
else -> error("unsupported address type")
}
}

fun setApplicationInfo(id: String, version: String) {
appId = id
appVersion = version
}
}

0 comments on commit 98c96ac

Please sign in to comment.