Skip to content

Commit

Permalink
fix proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Aksenov authored and Vacxe committed Feb 17, 2023
1 parent 2103581 commit 5459a74
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 41 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function uploadapk(){
export PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE=$2
#If proxy needed
#PLAY_STORE_PROXY=192.168.0.1:3128
#PLAYSTORE_PROXY=192.168.0.1:3128
#Increase connection timeout
#PLAYSTORE_CONNECTION_TIMEOUT=PT6M
apk_package=$(apkinfoextractor $path_to_apk | jq '.package')
export APP_PACKAGE_NAME=$apk_package
Expand Down
78 changes: 39 additions & 39 deletions src/main/kotlin/com/github/vacxe/googleplaycli/PlayStoreApi.kt
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
package com.github.vacxe.googleplaycli

import com.github.vacxe.googleplaycli.actions.*
import com.google.api.client.googleapis.GoogleUtils
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.http.HttpRequestInitializer
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.androidpublisher.AndroidPublisher
import com.google.api.services.androidpublisher.AndroidPublisherScopes
import com.google.auth.http.HttpCredentialsAdapter
import com.google.auth.oauth2.ServiceAccountCredentials
import java.io.ByteArrayInputStream
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
import java.net.InetSocketAddress
import java.net.Proxy
import java.time.Duration

class PlayStoreApi(serviceAccountInputStream: InputStream, appName: String) :
Edit,
Apks,
Bundles,
Deobfuscationfiles,
Details,
ExpansionFiles,
Images,
Listings,
Testers,
Tracks,
Internalappsharingartifacts,
Orders,
Reviews,
Inappproducts {
Edit,
Apks,
Bundles,
Deobfuscationfiles,
Details,
ExpansionFiles,
Images,
Listings,
Testers,
Tracks,
Internalappsharingartifacts,
Orders,
Reviews,
Inappproducts {

override val androidPublisher: AndroidPublisher

init {
val accountCredentials = ServiceAccountCredentials
.fromStream(serviceAccountInputStream)
.createScoped(listOf(AndroidPublisherScopes.ANDROIDPUBLISHER))

val proxy : String? = System.getenv("PLAY_STORE_PROXY")
val httpTransport = when {
proxy != null -> {
val proxyParameters = proxy.split(":")
NetHttpTransport.Builder()
.trustCertificates(GoogleUtils.getCertificateTrustStore())
.setProxy(Proxy(Proxy.Type.HTTP, InetSocketAddress(proxyParameters[0], proxyParameters[1].toInt())))
.build()
}
else -> GoogleNetHttpTransport.newTrustedTransport()
.fromStream(serviceAccountInputStream)
.createScoped(listOf(AndroidPublisherScopes.ANDROIDPUBLISHER))

System.getenv("PLAYSTORE_PROXY")?.run {
val proxyParameters = split(":")
System.setProperty("proxyHost", proxyParameters[0])
System.setProperty("proxyPort", proxyParameters[1])
}

val connectionTimeout = (System.getenv("PLAYSTORE_CONNECTION_TIMEOUT") ?: "PT2M")
.let { Duration.parse(it) }

androidPublisher = AndroidPublisher.Builder(
httpTransport,
JacksonFactory.getDefaultInstance(),
HttpCredentialsAdapter(accountCredentials)
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
setHttpTimeout(HttpCredentialsAdapter(accountCredentials), connectionTimeout)
)
.setApplicationName(appName)
.build()
.setApplicationName(appName)
.build()
}

private fun setHttpTimeout(requestInitializer: HttpRequestInitializer, timeout: Duration): HttpRequestInitializer {
return HttpRequestInitializer { httpRequest ->
requestInitializer.initialize(httpRequest)
httpRequest.connectTimeout = timeout.toMillis().toInt()
httpRequest.readTimeout = timeout.toMillis().toInt()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.vacxe.googleplaycli

import com.github.ajalt.clikt.core.CliktCommand
import com.github.vacxe.googleplaycli.dsl.addCmd
import com.github.vacxe.googleplaycli.dsl.cmd
import com.github.vacxe.googleplaycli.dsl.subcmd
Expand Down Expand Up @@ -78,5 +79,12 @@ fun main(args: Array<String>) {
addCmd { Commands.Inappproducts.Patch() }
addCmd { Commands.Inappproducts.Update() }
}
addCmd {
object : CliktCommand(name = "version", help = "Library version code") {
override fun run() {
println("0.3.7")
}
}
}
}.main(args)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.vacxe.googleplaycli.actions

import com.github.vacxe.googleplaycli.actions.model.DeobfuscationfilesUploadModel
import com.github.vacxe.googleplaycli.core.constants.MediaType.MIME_TYPE_APK
import com.github.vacxe.googleplaycli.core.constants.MediaType.MIME_TYPE_STREAM
import com.google.api.client.http.AbstractInputStreamContent
import com.google.api.client.http.FileContent
import com.google.api.services.androidpublisher.AndroidPublisher
Expand All @@ -11,7 +12,7 @@ interface Deobfuscationfiles : BaseAction {
fun deobfuscationFilesUpload(model: DeobfuscationfilesUploadModel): DeobfuscationFilesUploadResponse {
val edits: AndroidPublisher.Edits = androidPublisher.edits()
val editId = model.editId ?: edits.insert(model.packageName, null).execute().id
val deobfuscation: AbstractInputStreamContent = FileContent(MIME_TYPE_APK, model.deobfuscation)
val deobfuscation: AbstractInputStreamContent = FileContent(MIME_TYPE_STREAM, model.deobfuscation)
return edits.deobfuscationfiles().upload(model.packageName, editId, model.apkVersionCode, model.deobfuscationFileType, deobfuscation).execute()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package com.github.vacxe.googleplaycli.core.constants

object MediaType {
const val MIME_TYPE_APK = "application/vnd.android.package-archive"
const val MIME_TYPE_STREAM = "application/octet-stream"
const val MIME_TYPE_PNG = "image/png"
}

0 comments on commit 5459a74

Please sign in to comment.