Skip to content

Commit

Permalink
Merge pull request #23 from Vacxe/hide-exceptions-messages
Browse files Browse the repository at this point in the history
feat: hide stacktrace in case of failures
  • Loading branch information
Vacxe authored Jun 30, 2023
2 parents 197fb83 + f76e31e commit cf7b0e4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM adoptopenjdk/openjdk11:jdk-11.0.11_9-alpine-slim
RUN apk update && \
apk add --no-cache jq
COPY /build/distributions/google-play-cli /usr/local/
apk add --no-cache jq \
apk add --no-cache unzip
COPY /build/distributions/google-play-cli /usr/local/
RUN chmod +x /usr/local/google-play-cli
56 changes: 42 additions & 14 deletions src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,80 @@ import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.validate
import com.github.vacxe.googleplaycli.PlayStoreApi
import com.google.api.client.googleapis.json.GoogleJsonResponseException
import java.io.ByteArrayInputStream
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
import java.security.InvalidParameterException
import kotlin.system.exitProcess

abstract class BaseCommand(name: String, actionDescription: String = "") : CliktCommand(name = name, help = actionDescription) {
abstract class BaseCommand(name: String, actionDescription: String = "") :
CliktCommand(name = name, help = actionDescription) {

private val serviceAccountJsonFile: String by option("--config-file", "-cf", help = "service account json file path")
.default(System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE")
?: "")
private val serviceAccountJsonFile: String by option(
"--config-file",
"-cf",
help = "service account json file path"
)
.default(
System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE")
?: ""
)

private val serviceAccountJsonContent: String by option("--config-content", "-cc", help = "service account json content")
.default(System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_CONTENT")
?: "")
private val serviceAccountJsonContent: String by option(
"--config-content",
"-cc",
help = "service account json content"
)
.default(
System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_CONTENT")
?: ""
)

val packageName: String by option("--package-name", "-p", help = "package name (example: com.my.app)")
.default(System.getenv("APP_PACKAGE_NAME") ?: "")
.validate { require(it.isNotEmpty()) { "Please provide a valid $help" } }
.default(System.getenv("APP_PACKAGE_NAME") ?: "")
.validate { require(it.isNotEmpty()) { "Please provide a valid $help" } }

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

private val serviceAccountInputStream: InputStream
get() {
if(serviceAccountJsonFile.isNotEmpty() && serviceAccountJsonContent.isNotEmpty()) {
if (serviceAccountJsonFile.isNotEmpty() && serviceAccountJsonContent.isNotEmpty()) {
throw InvalidParameterException("Service account file or content can't be specified together")
}

if(serviceAccountJsonFile.isEmpty() && serviceAccountJsonContent.isEmpty()) {
if (serviceAccountJsonFile.isEmpty() && serviceAccountJsonContent.isEmpty()) {
throw InvalidParameterException("Service account File or Content need to be specified")
}

return when {
serviceAccountJsonContent.isNotEmpty() -> ByteArrayInputStream(serviceAccountJsonContent.toByteArray())
serviceAccountJsonFile.isNotEmpty() -> {
val serviceAccountFile = File(serviceAccountJsonFile)
if(!serviceAccountFile.exists())
if (!serviceAccountFile.exists())
throw InvalidParameterException("Service account file $serviceAccountJsonFile not exist")
FileInputStream(serviceAccountFile)
}

else -> throw InvalidParameterException("Service account input stream can't be defined")
}
}

final override fun run() {
val manager = PlayStoreApi(serviceAccountInputStream, packageName)
run(manager)?.let {
println(it)
try {
run(manager)?.let {
println(it)
}
} catch (e: GoogleJsonResponseException) {
if (debug.toBoolean()) {
e.printStackTrace()
} else {
println(e.content)
}
exitProcess(1)
}
}

Expand Down

0 comments on commit cf7b0e4

Please sign in to comment.