Skip to content

Commit

Permalink
ktlint + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kober32 committed Oct 8, 2024
1 parent 187a6ae commit 7539a9d
Show file tree
Hide file tree
Showing 30 changed files with 214 additions and 91 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
root = true

[*{kt,kts}]

# sometimes this is good for readibility
ktlint_standard_string-template = disabled

# sometimes this is good thing when a lot of code is packed
ktlint_standard_no-empty-first-line-in-method-block = disabled

# maybe in the future
ktlint_standard_spacing-between-declarations-with-comments = disabled

# this is no JS or TS
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled

# not sure about this, but i dont like it :)
ktlint_standard_colon-spacing = disabled

# this is nitpicking
ktlint_standard_import-ordering = disabled
ktlint_standard_no-wildcard-imports = disabled

# sometimes this is good thing
ktlint_standard_filename = disabled
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ on:
- main
- release/*
pull_request:
schedule:
- cron: '25 6 * * *'

jobs:
build:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Lint

on:
push:
branches:
- develop
- release/*
pull_request:

jobs:
ktlint:
name: ktlint
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Run lint script
run: ./scripts/lint.sh
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ allprojects {

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
}
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugins{
plugins {
`kotlin-dsl`
}

Expand All @@ -16,4 +16,4 @@ val dokkaVersion: String by System.getProperties()
dependencies {
implementation("com.android.tools.build", "gradle", androidPluginVersion)
implementation(kotlin("gradle-plugin", kotlinVersion))
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ object Constants {
const val minSdkVersion = 21
const val buildToolsVersion = "33.0.2"
}
}
}
Binary file added ktlint
Binary file not shown.
13 changes: 12 additions & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ android {
suppressWarnings = false
}
}

// Custom ktlint script
tasks.register("ktlint") {
logger.lifecycle("ktlint")
exec {
commandLine = listOf("./../scripts/lint.sh", "--no-error")
}
}

// Make ktlint run before build
tasks.getByName("preBuild").dependsOn("ktlint")
}

dependencies {
Expand All @@ -65,4 +76,4 @@ dependencies {
compileOnly("io.getlime.core:rest-model-base:1.2.0")
}

apply("android-release-aar.gradle")
apply("android-release-aar.gradle")
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import com.wultra.android.powerauth.networking.utils.getCurrentLocale
import io.getlime.security.powerauth.core.EciesCryptogram
import io.getlime.security.powerauth.core.EciesEncryptor
import io.getlime.security.powerauth.networking.response.IGetEciesEncryptorListener
import io.getlime.security.powerauth.networking.response.ITimeSynchronizationListener
import io.getlime.security.powerauth.sdk.PowerAuthAuthentication
import io.getlime.security.powerauth.sdk.PowerAuthSDK
import io.getlime.security.powerauth.sdk.PowerAuthToken
Expand All @@ -52,7 +51,6 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient.Builder
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.IOException
import java.util.*

interface IApiCallResponseListener<T> {
fun onSuccess(result: T)
Expand All @@ -77,8 +75,8 @@ abstract class Api(
@PublishedApi internal val gsonBuilder: GsonBuilder,
@PublishedApi internal val appContext: Context,
tokenProvider: IPowerAuthTokenProvider? = null,
@PublishedApi internal val userAgent: UserAgent = UserAgent.libraryDefault(appContext)) {

@PublishedApi internal val userAgent: UserAgent = UserAgent.libraryDefault(appContext)
) {
/**
* Language sent in request header. Default value is "en".
*/
Expand All @@ -101,9 +99,9 @@ abstract class Api(
endpoint: EndpointBasic<TRequestData, TResponseData>,
headers: HashMap<String, String>? = null,
okHttpInterceptor: OkHttpBuilderInterceptor? = null,
listener: IApiCallResponseListener<TResponseData>) {

makeCall(getBodyBytes(data), endpoint, headers ?: hashMapOf(), okHttpInterceptor, listener)
listener: IApiCallResponseListener<TResponseData>
) {
makeCall(getBodyBytes(data), endpoint, headers ?: hashMapOf(), okHttpInterceptor, listener)
}

inline fun <reified TRequestData: BaseRequest, reified TResponseData: StatusResponse> post(
Expand All @@ -112,49 +110,50 @@ abstract class Api(
authentication: PowerAuthAuthentication,
headers: HashMap<String, String>? = null,
okHttpInterceptor: OkHttpBuilderInterceptor? = null,
listener: IApiCallResponseListener<TResponseData>) {
listener: IApiCallResponseListener<TResponseData>
) {

val bodyBytes = getBodyBytes(data)
val bodyBytes = getBodyBytes(data)

val authorizationHeader = powerAuthSDK.requestSignatureWithAuthentication(
appContext,
authentication,
"POST",
endpoint.uriId,
bodyBytes
)
val authorizationHeader = powerAuthSDK.requestSignatureWithAuthentication(
appContext,
authentication,
"POST",
endpoint.uriId,
bodyBytes
)

val newHeaders = headers ?: hashMapOf()
newHeaders[authorizationHeader.key] = authorizationHeader.value
val newHeaders = headers ?: hashMapOf()
newHeaders[authorizationHeader.key] = authorizationHeader.value

makeCall(bodyBytes, endpoint, newHeaders, okHttpInterceptor, listener)
makeCall(bodyBytes, endpoint, newHeaders, okHttpInterceptor, listener)
}

inline fun <reified TRequestData: BaseRequest, reified TResponseData: StatusResponse> post(
data: TRequestData,
endpoint: EndpointSignedWithToken<TRequestData, TResponseData>,
headers: HashMap<String, String>? = null,
okHttpInterceptor: OkHttpBuilderInterceptor? = null,
listener: IApiCallResponseListener<TResponseData>) {

tokenProvider.getTokenAsync(
endpoint.tokenName,
object : IPowerAuthTokenListener {
override fun onReceived(token: PowerAuthToken) {

val tokenHeader = token.generateHeader()
val bodyBytes = getBodyBytes(data)
val newHeaders = headers ?: hashMapOf()
newHeaders[tokenHeader.key] = tokenHeader.value

makeCall(bodyBytes, endpoint, newHeaders, okHttpInterceptor, listener)
}
listener: IApiCallResponseListener<TResponseData>
) {
tokenProvider.getTokenAsync(
endpoint.tokenName,
object : IPowerAuthTokenListener {
override fun onReceived(token: PowerAuthToken) {

val tokenHeader = token.generateHeader()
val bodyBytes = getBodyBytes(data)
val newHeaders = headers ?: hashMapOf()
newHeaders[tokenHeader.key] = tokenHeader.value

makeCall(bodyBytes, endpoint, newHeaders, okHttpInterceptor, listener)
}

override fun onFailed(e: Throwable) {
listener.onFailure(ApiError(e))
}
override fun onFailed(e: Throwable) {
listener.onFailure(ApiError(e))
}
)
}
)
}

// PRIVATE API
Expand All @@ -172,7 +171,8 @@ abstract class Api(
endpoint: Endpoint<TRequestData, TResponseData>,
headers: HashMap<String, String>,
okHttpInterceptor: OkHttpBuilderInterceptor? = null,
listener: IApiCallResponseListener<TResponseData>) {
listener: IApiCallResponseListener<TResponseData>
) {

var bytes = bodyBytes

Expand Down Expand Up @@ -272,7 +272,7 @@ abstract class Api(
internal inline fun <reified TRequestData: BaseRequest, reified TResponseData: StatusResponse> getEncryptor(
endpoint: Endpoint<TRequestData, TResponseData>,
crossinline callback: (Result<EciesEncryptor?>) -> Unit
) {
) {

val listener = object : IGetEciesEncryptorListener {
override fun onGetEciesEncryptorSuccess(encryptor: EciesEncryptor) {
Expand Down Expand Up @@ -327,7 +327,7 @@ class UserAgent internal constructor(@PublishedApi internal val value: String? =
@SerializedName("mac") val mac: String?,
@SerializedName("nonce") val nonce: String?,
@SerializedName("timestamp") val timestamp: Long?
)
)

/** Envelope for E2EE responses. */
@PublishedApi
Expand All @@ -338,4 +338,4 @@ internal class E2EEResponse(
@SerializedName("timestamp") val timestamp: Long?
) {
fun toCryptogram() = EciesCryptogram(null, encryptedData, mac, null, nonce, timestamp ?: 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ interface ECIESInterceptor: Interceptor {
* @param decrypted Decrypted payload
*/
fun encryptedResponseReceived(url: URL, decrypted: ByteArray)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ enum class E2EEConfiguration {
ACTIVATION_SCOPE,
/** Endpoint is not encrypted. */
NOT_ENCRYPTED
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ open class BaseRequest
/**
* Common request format with data object inside the `requestObject` property.
*/
abstract class ObjectRequest<T>(@SerializedName("requestObject") val requestObject: T): BaseRequest()
abstract class ObjectRequest<T>(@SerializedName("requestObject") val requestObject: T): BaseRequest()
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ open class StatusResponse(@SerializedName("status") val status: Status) {
/**
* Common response where data returned are inside the `responseObject` property.
*/
abstract class ObjectResponse<T>(@SerializedName("responseObject") val responseObject: T, status: Status): StatusResponse(status)
abstract class ObjectResponse<T>(@SerializedName("responseObject") val responseObject: T, status: Status): StatusResponse(status)
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ data class ApiError(val e: Throwable) {
null
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ enum class ApiErrorCode(val message: String) {
*/
fun errorCodeFromCodeString(code: String): ApiErrorCode? = map[code]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ class ApiErrorException(
return if (t is ApiErrorException) t else ApiErrorException(t)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ class ApiHttpException(
/** Response code */
val code: Int = response.code
override val message: String = response.message
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ import com.wultra.android.powerauth.networking.data.ObjectResponse
/**
* Model class for error response - the wrapper responseObject.
*/
class ErrorResponse(responseObject: ErrorResponseObject, status: Status): ObjectResponse<ErrorResponseObject>(responseObject, status)
class ErrorResponse(responseObject: ErrorResponseObject, status: Status): ObjectResponse<ErrorResponseObject>(responseObject, status)
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import com.google.gson.annotations.SerializedName
* Model class for error response.
*/
data class ErrorResponseObject(
@SerializedName("code")
val code: String,

@SerializedName("message")
val message: String) {
@SerializedName("code")
val code: String,

@SerializedName("message")
val message: String
) {
val errorCode: ApiErrorCode?
get() {
return ApiErrorCode.errorCodeFromCodeString(code)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ interface WPNLogListener {

/** Debug log */
fun debug(message: String)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ internal class GsonRequestBodyBytes<T>(private val gson: Gson, private val adapt
companion object {
private val UTF_8 = Charset.forName("UTF-8")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.wultra.android.powerauth.networking.ssl

import okhttp3.OkHttpClient


/**
* SSL pinning provider configures HTTP client to verify SSL certificates
*/
Expand All @@ -29,4 +28,4 @@ interface ISSLPinningProvider {
* @param builder OkHttpClient builder to configure
*/
fun configureOkHttpClient(builder: OkHttpClient.Builder)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ internal class DefaultSSLValidationStrategy: SSLValidationStrategy() {
// Nothing to change, use default
return builder
}

}
internal class NoSSLValidationStrategy: SSLValidationStrategy() {
override fun configure(builder: OkHttpClient.Builder): OkHttpClient.Builder {
Expand All @@ -73,12 +72,10 @@ internal class NoSSLValidationStrategy: SSLValidationStrategy() {
builder.hostnameVerifier(noValidationStrategy.hostnameVerifier!!)
return builder
}

}
internal class PinningSSLValidationStrategy(private val provider: ISSLPinningProvider): SSLValidationStrategy() {
override fun configure(builder: OkHttpClient.Builder): OkHttpClient.Builder {
provider.configureOkHttpClient(builder)
return builder
}
}

Loading

0 comments on commit 7539a9d

Please sign in to comment.