diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt index 77562c1..29550c5 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt @@ -2,7 +2,6 @@ package com.github.vacxe.googleplaycli import com.github.vacxe.googleplaycli.actions.* import com.github.vacxe.googleplaycli.environments.Env -import com.github.vacxe.googleplaycli.environments.Proxy import com.google.api.client.http.HttpRequestInitializer import com.google.api.client.json.gson.GsonFactory import com.google.api.services.androidpublisher.AndroidPublisher @@ -42,7 +41,7 @@ class PlayStoreApi(serviceAccountInputStream: InputStream, appName: String) : GsonFactory.getDefaultInstance(), setHttpTimeout( HttpCredentialsAdapter(accountCredentials), - Env.connectionTimeout + Env.Network.connectionTimeout ) ) .setApplicationName(appName) diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/TransportFactory.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/TransportFactory.kt index 4175c74..5019c13 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/TransportFactory.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/TransportFactory.kt @@ -1,7 +1,6 @@ package com.github.vacxe.googleplaycli -import com.github.vacxe.googleplaycli.environments.Proxy -import com.google.api.client.auth.openidconnect.HttpTransportFactory +import com.github.vacxe.googleplaycli.environments.Env import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport import com.google.api.client.http.HttpTransport import com.google.api.client.http.apache.v2.ApacheHttpTransport @@ -20,12 +19,12 @@ import java.security.KeyStore object TransportFactory { - private val host = Proxy.Environment.host - private val port = Proxy.Environment.port - private val username = Proxy.Environment.username - private val password = Proxy.Environment.password - private val trustStore = Proxy.Environment.trustStore - private val trustStorePassword = Proxy.Environment.trustStorePassword + private val host = Env.Proxy.host + private val port = Env.Proxy.port + private val username = Env.Proxy.username + private val password = Env.Proxy.password + private val trustStore = Env.TrustStore.trustStore + private val trustStorePassword = Env.TrustStore.trustStorePassword fun buildTransport(): HttpTransport = when { host != null && port != null -> createHttpTransportProxy( @@ -43,7 +42,7 @@ object TransportFactory { else -> GoogleNetHttpTransport.newTrustedTransport() } - private fun createHttpTransportProxy( + fun createHttpTransportProxy( proxyHost: String, proxyPort: Int, proxyUsername: String?, diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt index 354657f..46a4f66 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt @@ -22,17 +22,17 @@ abstract class BaseCommand(name: String, actionDescription: String = "") : "-cf", help = "service account json file path" ) - .default(Env.serviceAccoutJsonFile) + .default(Env.PlayConsole.serviceAccoutJsonFile) private val serviceAccountJsonContent: String by option( "--config-content", "-cc", help = "service account json content" ) - .default(Env.serviceAccoutJsonContent) + .default(Env.PlayConsole.serviceAccoutJsonContent) val packageName: String by option("--package-name", "-p", help = "package name (example: com.my.app)") - .default(Env.packageName) + .default(Env.PlayConsole.packageName) .validate { require(it.isNotEmpty()) { "Please provide a valid $help" } } private val debug: String by option("--debug", help = "enable debug logs") diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/environments/Env.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/environments/Env.kt index 700cad0..98087c4 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/environments/Env.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/environments/Env.kt @@ -3,16 +3,42 @@ package com.github.vacxe.googleplaycli.environments import java.time.Duration object Env { - val serviceAccoutJsonFile: String - get() = System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE") ?: "" + object PlayConsole { + val serviceAccoutJsonFile: String + get() = System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE") ?: "" - val serviceAccoutJsonContent: String - get() = System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_CONTENT") ?: "" + val serviceAccoutJsonContent: String + get() = System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_CONTENT") ?: "" - val packageName: String - get() = System.getenv("APP_PACKAGE_NAME") ?: "" + val packageName: String + get() = System.getenv("APP_PACKAGE_NAME") ?: "" + } - val connectionTimeout: Duration - get() =(System.getenv("PLAYSTORE_CONNECTION_TIMEOUT") ?: "PT2M") - .let { Duration.parse(it) } + object Network { + val connectionTimeout: Duration + get() = (System.getenv("PLAYSTORE_CONNECTION_TIMEOUT") ?: "PT2M") + .let { Duration.parse(it) } + } + + object Proxy { + val host: String? + get() = System.getenv("PLAYSTORE_PROXY_HOST") + + val port: String? + get() = System.getenv("PLAYSTORE_PROXY_PORT") + + val username: String? + get() = System.getenv("PLAYSTORE_PROXY_USERNAME") + + val password: String? + get() = System.getenv("PLAYSTORE_PROXY_PASSWORD") + } + + object TrustStore { + val trustStore: String? + get() = System.getenv("PLAYSTORE_PROXY_TRUST_STORE") + + val trustStorePassword: String? + get() = System.getenv("PLAYSTORE_PROXY_TRUST_STORE_PASSWORD") + } } diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/environments/Proxy.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/environments/Proxy.kt deleted file mode 100644 index 98b1abf..0000000 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/environments/Proxy.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.github.vacxe.googleplaycli.environments - -import java.net.Authenticator -import java.net.PasswordAuthentication - -object Proxy { - object Environment { - val host: String? - get() = System.getenv("PLAYSTORE_PROXY_HOST") - - val port: String? - get() = System.getenv("PLAYSTORE_PROXY_PORT") - - val username: String? - get() = System.getenv("PLAYSTORE_PROXY_USERNAME") - - val password: String? - get() = System.getenv("PLAYSTORE_PROXY_PASSWORD") - - val trustStore: String? - get() = System.getenv("PLAYSTORE_PROXY_TRUST_STORE") - - val trustStorePassword: String? - get() = System.getenv("PLAYSTORE_PROXY_TRUST_STORE_PASSWORD") - } - - fun apply() { - val host = Proxy.Environment.host - val port = Proxy.Environment.port - val username = Proxy.Environment.username - val password = Proxy.Environment.password - val trustStore = Proxy.Environment.trustStore - val trustStorePassword = Proxy.Environment.trustStorePassword - - if (host != null && port != null) { - arrayOf("http", "https").forEach { protocol -> - System.setProperty("$protocol.proxySet", "true"); - System.setProperty("$protocol.proxyHost", host) - System.setProperty("$protocol.proxyPort", port) - } - - System.setProperty("jdk.http.auth.tunneling.disableSchemes", "") - if (username != null && password != null) { - Authenticator.setDefault( - object : Authenticator() { - override fun getPasswordAuthentication() = - PasswordAuthentication(username, password.toCharArray()) - } - ) - } - } - - if (trustStore != null && trustStorePassword != null) { - System.setProperty("javax.net.ssl.trustStore", trustStore) - System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword) - } - } -}