Skip to content

Commit fba0e9e

Browse files
committed
fix(proxy): support proxy authentication
1 parent a26ba92 commit fba0e9e

File tree

5 files changed

+47
-81
lines changed

5 files changed

+47
-81
lines changed

Diff for: src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.vacxe.googleplaycli
22

33
import com.github.vacxe.googleplaycli.actions.*
44
import com.github.vacxe.googleplaycli.environments.Env
5-
import com.github.vacxe.googleplaycli.environments.Proxy
65
import com.google.api.client.http.HttpRequestInitializer
76
import com.google.api.client.json.gson.GsonFactory
87
import com.google.api.services.androidpublisher.AndroidPublisher
@@ -42,7 +41,7 @@ class PlayStoreApi(serviceAccountInputStream: InputStream, appName: String) :
4241
GsonFactory.getDefaultInstance(),
4342
setHttpTimeout(
4443
HttpCredentialsAdapter(accountCredentials),
45-
Env.connectionTimeout
44+
Env.Network.connectionTimeout
4645
)
4746
)
4847
.setApplicationName(appName)

Diff for: src/main/kotlin/com/github/vacxe/googleplaycli/TransportFactory.kt

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.github.vacxe.googleplaycli
22

3-
import com.github.vacxe.googleplaycli.environments.Proxy
4-
import com.google.api.client.auth.openidconnect.HttpTransportFactory
3+
import com.github.vacxe.googleplaycli.environments.Env
54
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
65
import com.google.api.client.http.HttpTransport
76
import com.google.api.client.http.apache.v2.ApacheHttpTransport
@@ -20,12 +19,12 @@ import java.security.KeyStore
2019

2120

2221
object TransportFactory {
23-
private val host = Proxy.Environment.host
24-
private val port = Proxy.Environment.port
25-
private val username = Proxy.Environment.username
26-
private val password = Proxy.Environment.password
27-
private val trustStore = Proxy.Environment.trustStore
28-
private val trustStorePassword = Proxy.Environment.trustStorePassword
22+
private val host = Env.Proxy.host
23+
private val port = Env.Proxy.port
24+
private val username = Env.Proxy.username
25+
private val password = Env.Proxy.password
26+
private val trustStore = Env.TrustStore.trustStore
27+
private val trustStorePassword = Env.TrustStore.trustStorePassword
2928

3029
fun buildTransport(): HttpTransport = when {
3130
host != null && port != null -> createHttpTransportProxy(
@@ -43,7 +42,7 @@ object TransportFactory {
4342
else -> GoogleNetHttpTransport.newTrustedTransport()
4443
}
4544

46-
private fun createHttpTransportProxy(
45+
fun createHttpTransportProxy(
4746
proxyHost: String,
4847
proxyPort: Int,
4948
proxyUsername: String?,

Diff for: src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ abstract class BaseCommand(name: String, actionDescription: String = "") :
2222
"-cf",
2323
help = "service account json file path"
2424
)
25-
.default(Env.serviceAccoutJsonFile)
25+
.default(Env.PlayConsole.serviceAccoutJsonFile)
2626

2727
private val serviceAccountJsonContent: String by option(
2828
"--config-content",
2929
"-cc",
3030
help = "service account json content"
3131
)
32-
.default(Env.serviceAccoutJsonContent)
32+
.default(Env.PlayConsole.serviceAccoutJsonContent)
3333

3434
val packageName: String by option("--package-name", "-p", help = "package name (example: com.my.app)")
35-
.default(Env.packageName)
35+
.default(Env.PlayConsole.packageName)
3636
.validate { require(it.isNotEmpty()) { "Please provide a valid $help" } }
3737

3838
private val debug: String by option("--debug", help = "enable debug logs")

Diff for: src/main/kotlin/com/github/vacxe/googleplaycli/environments/Env.kt

+35-9
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,42 @@ package com.github.vacxe.googleplaycli.environments
33
import java.time.Duration
44

55
object Env {
6-
val serviceAccoutJsonFile: String
7-
get() = System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE") ?: ""
6+
object PlayConsole {
7+
val serviceAccoutJsonFile: String
8+
get() = System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE") ?: ""
89

9-
val serviceAccoutJsonContent: String
10-
get() = System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_CONTENT") ?: ""
10+
val serviceAccoutJsonContent: String
11+
get() = System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_CONTENT") ?: ""
1112

12-
val packageName: String
13-
get() = System.getenv("APP_PACKAGE_NAME") ?: ""
13+
val packageName: String
14+
get() = System.getenv("APP_PACKAGE_NAME") ?: ""
15+
}
1416

15-
val connectionTimeout: Duration
16-
get() =(System.getenv("PLAYSTORE_CONNECTION_TIMEOUT") ?: "PT2M")
17-
.let { Duration.parse(it) }
17+
object Network {
18+
val connectionTimeout: Duration
19+
get() = (System.getenv("PLAYSTORE_CONNECTION_TIMEOUT") ?: "PT2M")
20+
.let { Duration.parse(it) }
21+
}
22+
23+
object Proxy {
24+
val host: String?
25+
get() = System.getenv("PLAYSTORE_PROXY_HOST")
26+
27+
val port: String?
28+
get() = System.getenv("PLAYSTORE_PROXY_PORT")
29+
30+
val username: String?
31+
get() = System.getenv("PLAYSTORE_PROXY_USERNAME")
32+
33+
val password: String?
34+
get() = System.getenv("PLAYSTORE_PROXY_PASSWORD")
35+
}
36+
37+
object TrustStore {
38+
val trustStore: String?
39+
get() = System.getenv("PLAYSTORE_PROXY_TRUST_STORE")
40+
41+
val trustStorePassword: String?
42+
get() = System.getenv("PLAYSTORE_PROXY_TRUST_STORE_PASSWORD")
43+
}
1844
}

Diff for: src/main/kotlin/com/github/vacxe/googleplaycli/environments/Proxy.kt

-58
This file was deleted.

0 commit comments

Comments
 (0)