Skip to content

Commit

Permalink
fix(proxy): support proxy authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Vacxe committed May 31, 2024
1 parent a26ba92 commit fba0e9e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,7 +41,7 @@ class PlayStoreApi(serviceAccountInputStream: InputStream, appName: String) :
GsonFactory.getDefaultInstance(),
setHttpTimeout(
HttpCredentialsAdapter(accountCredentials),
Env.connectionTimeout
Env.Network.connectionTimeout
)
)
.setApplicationName(appName)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand All @@ -43,7 +42,7 @@ object TransportFactory {
else -> GoogleNetHttpTransport.newTrustedTransport()
}

private fun createHttpTransportProxy(
fun createHttpTransportProxy(
proxyHost: String,
proxyPort: Int,
proxyUsername: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
44 changes: 35 additions & 9 deletions src/main/kotlin/com/github/vacxe/googleplaycli/environments/Env.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

This file was deleted.

0 comments on commit fba0e9e

Please sign in to comment.