-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(proxy): support proxy authentication
- Loading branch information
Showing
7 changed files
with
157 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Master Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build-tar: | ||
name: Build Tar | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-java@v4 | ||
name: Set up JDK 11 | ||
with: | ||
distribution: "temurin" | ||
java-version: 11 | ||
cache: gradle | ||
- name: Build release tar | ||
run: ./gradlew distTar | ||
- name: Tar Checksum | ||
run: shasum -a 256 build/distributions/google-play-cli.tar | ||
- name: Upload Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: google-play-cli | ||
path: build/distributions/google-play-cli.tar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/kotlin/com/github/vacxe/googleplaycli/TransportFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.github.vacxe.googleplaycli | ||
|
||
import com.github.vacxe.googleplaycli.environments.Proxy | ||
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport | ||
import com.google.api.client.http.HttpTransport | ||
import com.google.api.client.http.apache.v2.ApacheHttpTransport | ||
import com.google.api.client.http.javanet.NetHttpTransport | ||
import org.apache.http.auth.AuthScope | ||
import org.apache.http.auth.UsernamePasswordCredentials | ||
import org.apache.http.impl.client.BasicCredentialsProvider | ||
import org.apache.http.impl.client.ProxyAuthenticationStrategy | ||
import java.io.FileInputStream | ||
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 | ||
|
||
fun buildTransport(): HttpTransport = when { | ||
host != null && port != null -> createHttpTransportProxy( | ||
host, | ||
port, | ||
username, | ||
password | ||
) | ||
|
||
trustStore != null && trustStorePassword != null -> createHttpTransportTrustStore( | ||
trustStore, | ||
trustStorePassword | ||
) | ||
|
||
else -> GoogleNetHttpTransport.newTrustedTransport() | ||
} | ||
|
||
private fun createHttpTransportProxy( | ||
host: String, | ||
port: String, | ||
username: String?, | ||
password: String? | ||
): HttpTransport { | ||
val httpClient = ApacheHttpTransport.newDefaultHttpClientBuilder() | ||
.setProxyAuthenticationStrategy(ProxyAuthenticationStrategy.INSTANCE) | ||
.apply { | ||
if (username != null && password != null) { | ||
val credentials = BasicCredentialsProvider().apply { } | ||
credentials.setCredentials( | ||
AuthScope(host, port.toInt()), | ||
UsernamePasswordCredentials(username, password) | ||
) | ||
setDefaultCredentialsProvider(credentials) | ||
} | ||
} | ||
.build() | ||
return ApacheHttpTransport(httpClient) | ||
|
||
} | ||
|
||
private fun createHttpTransportTrustStore( | ||
trustStore: String, | ||
trustStorePassword: String | ||
): HttpTransport { | ||
val ks = KeyStore.getInstance(KeyStore.getDefaultType()) | ||
FileInputStream(trustStore).use { fis -> | ||
ks.load(fis, trustStorePassword.toCharArray()) | ||
} | ||
return NetHttpTransport.Builder().trustCertificates(ks).build() | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/kotlin/com/github/vacxe/googleplaycli/environments/Proxy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.github.vacxe.googleplaycli.environments | ||
|
||
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_USERNAME") | ||
|
||
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) { | ||
val protocols = arrayOf("http", "https") | ||
protocols.forEach { protocol -> | ||
System.setProperty("$protocol.proxySet", "true"); | ||
System.setProperty("$protocol.proxyHost", host) | ||
System.setProperty("$protocol.proxyPort", port) | ||
username?.run { System.setProperty("$protocol.proxyUser", this) } | ||
password?.run { System.setProperty("$protocol.proxyPassword", this) } | ||
} | ||
} | ||
|
||
if(trustStore != null && trustStorePassword != null) { | ||
System.setProperty("javax.net.ssl.trustStore", trustStore) | ||
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword) | ||
} | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
src/main/kotlin/com/github/vacxe/googleplaycli/environments/ProxyEnvironment.kt
This file was deleted.
Oops, something went wrong.