Skip to content

Commit

Permalink
supply correct envInfo on Android (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoby authored Nov 18, 2020
1 parent 1e5cc27 commit 3cb9f55
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2018-2020 NetFoundry, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openziti.android

import android.os.Build
import org.openziti.util.SystemInfo
import org.openziti.util.SystemInfoProvider

class AndroidSystemInfoProvider: SystemInfoProvider {
override fun getSystemInfo(): SystemInfo = SystemInfo("Android",
Build.VERSION.RELEASE,
Build.VERSION.SECURITY_PATCH,
System.getProperty("os.arch") ?: ""
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright (c) 2018-2020 NetFoundry, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# Copyright (c) 2018-2020 NetFoundry, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

org.openziti.android.AndroidSystemInfoProvider
8 changes: 2 additions & 6 deletions ziti/src/main/kotlin/org/openziti/api/Controller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.openziti.getZitiError
import org.openziti.net.nio.AsychChannelSocket
import org.openziti.net.nio.AsyncTLSSocketFactory
import org.openziti.util.Logged
import org.openziti.util.SystemInfoProvider
import org.openziti.util.Version
import org.openziti.util.ZitiLog
import retrofit2.Call
Expand Down Expand Up @@ -257,12 +258,7 @@ class Controller(endpoint: URL, sslContext: SSLContext, trustManager: X509TrustM

private fun getClientInfo(): ClientInfo = ClientInfo(
sdkInfo = SdkInfo,
envInfo = mapOf(
"os" to System.getProperty("os.name"),
"osRelease" to System.getProperty("java.vm.version"),
"osVersion" to System.getProperty("os.version"),
"arch" to System.getProperty("os.arch")
),
envInfo = SystemInfoProvider().getSystemInfo(),
configTypes = arrayOf(InterceptConfig)
)
}
3 changes: 2 additions & 1 deletion ziti/src/main/kotlin/org/openziti/api/types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import org.openziti.util.SystemInfo
import java.util.*

internal const val InterceptConfig = "ziti-tunneler-client.v1"
Expand All @@ -38,7 +39,7 @@ enum class PostureQueryType {
PROCESS
}

internal data class ClientInfo(val sdkInfo: Map<*, *>, val envInfo: Map<*, *>, val configTypes: Array<String>)
internal data class ClientInfo(val sdkInfo: Map<*, *>, val envInfo: SystemInfo, val configTypes: Array<String>)

internal class Response<T>(val meta: Meta, val data: T?, val error: Error?)
internal data class Error(val code: String, val message: String, val cause: JsonObject, val field: String?)
Expand Down
44 changes: 44 additions & 0 deletions ziti/src/main/kotlin/org/openziti/util/SystemInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018-2020 NetFoundry, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openziti.util

import java.util.*

data class SystemInfo(val os: String, val osRelease: String, val osVersion: String, val arch: String)

interface SystemInfoProvider {
fun getSystemInfo(): SystemInfo
}

internal class DefaultSystemInfoProvider: SystemInfoProvider {
override fun getSystemInfo(): SystemInfo = SystemInfo(
System.getProperty("os.name", ""),
System.getProperty("java.vm.version", ""),
System.getProperty("os.version", ""),
System.getProperty("os.arch", "")

)
}

fun SystemInfoProvider(): SystemInfoProvider {
val l = ServiceLoader.load(SystemInfoProvider::class.java).toList()
return if (l.isEmpty()) {
DefaultSystemInfoProvider()
} else {
l.first()
}
}

0 comments on commit 3cb9f55

Please sign in to comment.