Skip to content

Commit

Permalink
Merge branch 'main' into mohnoor94/release20250204
Browse files Browse the repository at this point in the history
  • Loading branch information
mohnoor94 authored Feb 6, 2025
2 parents 57e2e27 + cf5e756 commit 9c611d7
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 277 deletions.
2 changes: 1 addition & 1 deletion code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<dependency>
<groupId>com.expediagroup</groupId>
<artifactId>rapid-sdk</artifactId>
<version>5.3.1</version>
<version>5.3.2</version>
</dependency>
```

Expand Down
25 changes: 13 additions & 12 deletions code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.expediagroup</groupId>
<artifactId>rapid-sdk</artifactId>
<version>5.3.1</version>
<version>5.3.2</version>
<name>EG rapid-sdk for Java</name>
<description>EG rapid-sdk v5.3.1</description>
<description>EG rapid-sdk v5.3.2</description>
<url>https://github.com/ExpediaGroup/test-sdk</url>
<inceptionYear>2022</inceptionYear>
<packaging>jar</packaging>
Expand Down Expand Up @@ -72,17 +72,17 @@
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
<maven-surefire-plugin.version>3.5.2</maven-surefire-plugin.version>
<build-helper-maven-plugin.version>3.6.0</build-helper-maven-plugin.version>
<ktlint-plugin.version>3.4.0</ktlint-plugin.version>
<ktlint-plugin.version>3.5.0</ktlint-plugin.version>
<jacoco-plugin.version>0.8.12</jacoco-plugin.version>
<dokka-plugin.version>1.9.20</dokka-plugin.version>
<dokka-plugin.version>2.0.0</dokka-plugin.version>
<dokka-old-versions.location/> <!-- passed as a property when running dokka:dokka-->
<properties.maven.plugin.version>1.2.1</properties.maven.plugin.version>
<maven.licence.plugin.version>4.6</maven.licence.plugin.version>
<flatten.maven.plugin.version>1.6.0</flatten.maven.plugin.version>
<kotlin.version>2.0.21</kotlin.version>
<kotlinx.coroutines.version>1.9.0</kotlinx.coroutines.version>
<ktor.version>2.3.13</ktor.version>
<kotlin-atomic.version>0.26.1</kotlin-atomic.version>
<kotlin.version>2.1.0</kotlin.version>
<kotlinx.coroutines.version>1.10.1</kotlinx.coroutines.version>
<ktor.version>3.0.3</ktor.version>
<kotlin-atomic.version>0.27.0</kotlin-atomic.version>
<slf4j.version>2.0.16</slf4j.version>
<maven.nexus-staging.plugin.version>1.7.0</maven.nexus-staging.plugin.version>
<maven.gpg.plugin.version>3.2.7</maven.gpg.plugin.version>
Expand Down Expand Up @@ -138,12 +138,12 @@
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio-jvm</artifactId>
<version>3.9.1</version>
<version>3.10.2</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>26.0.1</version>
<version>26.0.2</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
Expand Down Expand Up @@ -449,6 +449,7 @@
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>${dokka-plugin.version}</version>
<configuration>
<sourceDirectories>
<dir>${project.basedir}/src/main/kotlin/com/expediagroup/sdk/rapid</dir>
Expand Down Expand Up @@ -732,13 +733,13 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
<version>3.17.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.12.0</version>
<version>1.13.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import okhttp3.Dispatcher
import okhttp3.OkHttpClient

// Create a Dispatcher with limits
val dispatcher =
val configuredDispatcher =
Dispatcher().apply {
maxRequests = 10000 // Maximum number of concurrent requests
maxRequestsPerHost = 1000
Expand All @@ -64,7 +64,7 @@ val DEFAULT_HTTP_CLIENT_ENGINE: HttpClientEngine =
OkHttp.create {
config {
eventListenerFactory(OkHttpEventListener.FACTORY)
dispatcher(dispatcher)
dispatcher(configuredDispatcher)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,20 @@ abstract class ExpediaGroupClient(
return self()
}
}

@Suppress("unused", "UnnecessaryAbstractClass") // This is used by the generated SDK clients.
abstract class BuilderWithHttpClient<SELF : Client.BuilderWithHttpClient<SELF>> : Client.BuilderWithHttpClient<SELF>() {
/** Sets the API auth endpoint to use for requests. */
protected var authEndpoint: String? = null

/** Sets the API auth endpoint to use for requests.
*
* @param authEndpoint The API auth endpoint to use for requests.
* @return The [Builder] instance.
*/
fun authEndpoint(authEndpoint: String): SELF {
this.authEndpoint = authEndpoint
return self()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
*/
package com.expediagroup.sdk.core.configuration.provider

import com.expediagroup.sdk.core.configuration.provider.RapidConfigurationProvider.connectionTimeout
import com.expediagroup.sdk.core.configuration.provider.RapidConfigurationProvider.endpoint
import com.expediagroup.sdk.core.configuration.provider.RapidConfigurationProvider.name
import com.expediagroup.sdk.core.configuration.provider.RapidConfigurationProvider.requestTimeout
import com.expediagroup.sdk.core.configuration.provider.RapidConfigurationProvider.socketTimeout
import com.expediagroup.sdk.core.constant.Constant

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package com.expediagroup.sdk.core.constant

import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.HttpTimeoutConfig

internal object Constant {
const val EMPTY_STRING = ""
const val TEN_SECONDS_IN_MILLIS = 10_000L
const val FIFTEEN_SECONDS_IN_MILLIS = 15_000L
const val INFINITE_TIMEOUT = HttpTimeout.INFINITE_TIMEOUT_MS
const val INFINITE_TIMEOUT = HttpTimeoutConfig.INFINITE_TIMEOUT_MS

private const val SUCCESSFUL_STATUS_CODES_RANGE_START = 200
private const val SUCCESSFUL_STATUS_CODES_RANGE_END = 299
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package com.expediagroup.sdk.core.constant

import com.expediagroup.sdk.core.constant.LoggingMessage.OMITTED

internal object LogMaskingRegex {
val FIELD_REGEX = "^[a-zA-Z0-9-_]+$".toRegex()

val NUMBER_FIELD_REGEX = "(?<=[\"']?number[\"']?:\\s?[\"'])(\\s*\\d{15,16}\\s*)(?=[\"'])".toRegex()
const val REPLACEMENT_TEMPLATE = "\"$1$2${OMITTED}\""
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,19 @@
package com.expediagroup.sdk.core.constant.provider

internal object LogMaskingRegexProvider {
fun getMaskedFieldsRegex(maskedBodyFields: Set<String>) = "(?<=[\"']?(${maskedBodyFields.joinToString("|")})[\"']?:\\s?[\"'])(\\s*[^\"']+\\s*)(?=[\"'])".toRegex()
fun getMaskedFieldsRegex(
maskedBodyFields: Set<String>,
value: String = "[^\\\"]+"
): Regex {
val fields = maskedBodyFields.joinToString("|")
return "\"($fields)(\\\\*\"\\s*:\\s*\\\\*\")$value(?:\\\\?\"|)".toRegex()
}

fun getMaskedFieldsRegex(
maskedBodyField: String,
value: String = "[^\\\"]+"
): Regex {
val fields = setOf(maskedBodyField)
return getMaskedFieldsRegex(fields, value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@
package com.expediagroup.sdk.core.model.paging

import com.expediagroup.sdk.core.client.Client
import com.expediagroup.sdk.core.constant.HeaderValue
import com.expediagroup.sdk.core.model.Response
import com.expediagroup.sdk.core.plugin.logging.GZipEncoder.decode
import com.expediagroup.sdk.core.plugin.logging.contentEncoding
import io.ktor.client.statement.HttpResponse
import io.ktor.util.InternalAPI
import io.ktor.util.moveToByteArray
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.bits.Memory
import io.ktor.client.statement.bodyAsBytes
import kotlinx.coroutines.runBlocking
import java.nio.ByteBuffer

internal interface ResponseState<T> {
fun getNextResponse(): Response<T>
Expand Down Expand Up @@ -63,22 +56,10 @@ internal class FetchLinkState<T>(

override fun hasNext(): Boolean = true

private suspend fun parseBody(response: HttpResponse): T = if (decodeBody(response).isEmpty()) fallbackBody else getBody(response)

private suspend fun decodeBody(response: HttpResponse): String {
val byteReadChannel = prepareByteReadChannel(response)
val decodedByteReadChannel = if (response.contentEncoding().equals(HeaderValue.GZIP)) client.httpClient.decode(byteReadChannel) else byteReadChannel
val bodyString: String = decodedByteReadChannel.readRemaining().readText()
return bodyString
}

@OptIn(InternalAPI::class)
private suspend fun prepareByteReadChannel(response: HttpResponse): ByteReadChannel {
val bufferSize = response.content.availableForRead
val buffer = ByteBuffer.allocate(bufferSize)
val numberOfBytesRead = response.content.peekTo(Memory(buffer), 0, 0, 0, bufferSize.toLong()).toInt()
val byteReadChannel = ByteReadChannel(buffer.moveToByteArray(), 0, numberOfBytesRead)
return byteReadChannel
private suspend fun parseBody(response: HttpResponse): T {
// response.bodyAsBytes() applies all plugins
// if content-length header is set, response.contentLength could be used instead
return if (response.bodyAsBytes().isEmpty()) fallbackBody else getBody(response)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import com.expediagroup.sdk.core.plugin.authentication.AuthenticationConfigurati
import com.expediagroup.sdk.core.plugin.authentication.strategy.AuthenticationStrategy.AuthenticationType.BASIC
import com.expediagroup.sdk.core.plugin.authentication.strategy.AuthenticationStrategy.AuthenticationType.BEARER
import com.expediagroup.sdk.core.plugin.authentication.strategy.AuthenticationStrategy.AuthenticationType.SIGNATURE
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.AuthConfig
import io.ktor.client.request.HttpRequestBuilder

internal interface AuthenticationStrategy {
fun loadAuth(auth: Auth) {}
fun loadAuth(auth: AuthConfig) {}

fun isTokenAboutToExpire(): Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
package com.expediagroup.sdk.core.plugin.authentication.strategy

import com.expediagroup.sdk.core.plugin.authentication.AuthenticationConfiguration
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.AuthConfig
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
import io.ktor.client.plugins.auth.providers.basic
import io.ktor.client.request.HttpRequestBuilder

internal class BasicAuthenticationStrategy(
private val configs: AuthenticationConfiguration
) : AuthenticationStrategy {
override fun loadAuth(auth: Auth) {
auth.basic {
override fun loadAuth(authConfig: AuthConfig) {
authConfig.basic {
sendWithoutRequest { true }
credentials {
BasicAuthCredentials(username = configs.credentials.key, password = configs.credentials.secret)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import com.expediagroup.sdk.core.plugin.authentication.AuthenticationConfigurati
import com.expediagroup.sdk.core.plugin.logging.ExpediaGroupLoggerFactory
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.AuthConfig
import io.ktor.client.plugins.auth.authProviders
import io.ktor.client.plugins.auth.providers.BearerAuthProvider
import io.ktor.client.plugins.auth.providers.BearerTokens
import io.ktor.client.plugins.auth.providers.bearer
import io.ktor.client.plugins.plugin
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.basicAuth
import io.ktor.client.request.parameter
Expand All @@ -53,8 +53,8 @@ internal class ExpediaGroupAuthenticationStrategy(
private val log = ExpediaGroupLoggerFactory.getLogger(javaClass)
private var bearerTokenStorage = BearerTokensInfo.emptyBearerTokenInfo

override fun loadAuth(auth: Auth) {
auth.bearer {
override fun loadAuth(authConfig: AuthConfig) {
authConfig.bearer {
sendWithoutRequest { request ->
isIdentityRequest(request)
}
Expand Down Expand Up @@ -94,7 +94,7 @@ internal class ExpediaGroupAuthenticationStrategy(

private fun clearTokens(client: HttpClient) {
log.info(LoggingMessage.TOKEN_CLEARING_IN_PROGRESS)
client.plugin(Auth).providers.filterIsInstance<BearerAuthProvider>().first().clearToken()
client.authProviders.filterIsInstance<BearerAuthProvider>().first().clearToken()
bearerTokenStorage = BearerTokensInfo.emptyBearerTokenInfo
log.info(LoggingMessage.TOKEN_CLEARING_SUCCESSFUL)
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import com.expediagroup.sdk.core.constant.LoggingMessage.LOGGING_PREFIX
import org.slf4j.Logger

internal class ExpediaGroupLogger(private val logger: Logger, private val client: Client? = null) : Logger by logger {
private val mask = LogMasker(getMaskedBodyFieldFilters())

override fun info(msg: String) {
if (logger.isInfoEnabled) {
logger.info(decorate(msg))
Expand All @@ -41,12 +39,7 @@ internal class ExpediaGroupLogger(private val logger: Logger, private val client
}
}

private fun decorate(msg: String): String = "$LOGGING_PREFIX ${mask(msg)}"
private fun decorate(msg: String): String = "$LOGGING_PREFIX ${mask(msg, getMaskedBodyFields())}"

private fun getMaskedBodyFields(): Set<String> = client?.getLoggingMaskedFieldsProvider()?.getMaskedBodyFields() ?: LogMaskingFields.DEFAULT_MASKED_BODY_FIELDS

private fun getMaskedBodyFieldFilters(): Iterable<ExpediaGroupJsonFieldFilter> =
listOf(
ExpediaGroupJsonFieldFilter(getMaskedBodyFields().toTypedArray())
)
}
Loading

0 comments on commit 9c611d7

Please sign in to comment.