Skip to content

Commit

Permalink
chore: Publish v5.1.0 (#196)
Browse files Browse the repository at this point in the history
Co-authored-by: mohnoor94 <[email protected]>
Co-authored-by: mohnoor94 <[email protected]>
  • Loading branch information
3 people authored Oct 15, 2024
1 parent b839970 commit 1f340ba
Show file tree
Hide file tree
Showing 348 changed files with 8,806 additions and 6,343 deletions.
4 changes: 2 additions & 2 deletions code/LICENSE-HEADER.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2024 Expedia, Inc.
Copyright (C) 2022 Expedia, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -10,4 +10,4 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
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.0.0</version>
<version>5.1.0</version>
</dependency>
```

Expand Down
330 changes: 159 additions & 171 deletions code/pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ import io.ktor.client.engine.HttpClientEngine
abstract class BaseRapidClient(
namespace: String,
clientConfiguration: RapidClientConfiguration,
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE,
) : Client(namespace) {
private val _configurationProvider: ConfigurationProvider =
ConfigurationCollector.create(
clientConfiguration.toProvider(),
RapidConfigurationProvider
RapidConfigurationProvider,
)
private val _httpClient: HttpClient = buildHttpClient(_configurationProvider, AuthenticationStrategy.AuthenticationType.SIGNATURE, httpClientEngine)
private val _httpClient: HttpClient =
buildHttpClient(_configurationProvider, AuthenticationStrategy.AuthenticationType.SIGNATURE, httpClientEngine)

init {
finalize()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2022 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.expediagroup.sdk.core.client

import com.expediagroup.sdk.core.configuration.XapClientConfiguration
import com.expediagroup.sdk.core.configuration.collector.ConfigurationCollector
import com.expediagroup.sdk.core.configuration.provider.ConfigurationProvider
import com.expediagroup.sdk.core.configuration.provider.XapConfigurationProvider
import com.expediagroup.sdk.core.plugin.authentication.strategy.AuthenticationStrategy
import io.ktor.client.HttpClient
import io.ktor.client.engine.HttpClientEngine

/**
* The integration point between the SDK Core and the product SDKs.
*
* @param httpClientEngine The HTTP client engine to use.
* @param clientConfiguration The configuration for the client.
*/
abstract class BaseXapClient(
namespace: String,
clientConfiguration: XapClientConfiguration,
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE,
) : Client(namespace) {
private val _configurationProvider: ConfigurationProvider =
ConfigurationCollector.create(
clientConfiguration.toProvider(),
XapConfigurationProvider,
)
private val _httpClient: HttpClient =
buildHttpClient(_configurationProvider, AuthenticationStrategy.AuthenticationType.BASIC, httpClientEngine)

init {
finalize()
}

override val configurationProvider: ConfigurationProvider
get() = _configurationProvider

override val httpClient: HttpClient
get() = _httpClient

/** A [BaseXapClient] builder. */
@Suppress("unused", "UnnecessaryAbstractClass") // This is used by the generated SDK clients.
abstract class Builder<SELF : Builder<SELF>> : Client.Builder<SELF>()
}
65 changes: 51 additions & 14 deletions code/src/main/kotlin/com/expediagroup/sdk/core/client/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ val DEFAULT_HTTP_CLIENT_ENGINE: HttpClientEngine =
*/
abstract class Client(
namespace: String,
environmentProvider: EnvironmentProvider = DefaultEnvironmentProvider(namespace)
environmentProvider: EnvironmentProvider = DefaultEnvironmentProvider(namespace),
) : EnvironmentProvider by environmentProvider {
private val httpHandler = DefaultHttpHandler(environmentProvider)

Expand All @@ -89,7 +89,7 @@ abstract class Client(
internal fun buildHttpClient(
configurationProvider: ConfigurationProvider,
authenticationType: AuthenticationStrategy.AuthenticationType,
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE,
): HttpClient =
HttpClient(httpClientEngine) {
val httpClientConfig = this
Expand All @@ -98,9 +98,18 @@ abstract class Client(
val secret: String = configurationProvider.secret ?: fireMissingConfigurationIssue(ConfigurationName.SECRET)
val endpoint: String = configurationProvider.endpoint ?: fireMissingConfigurationIssue(ConfigurationName.ENDPOINT)
val authEndpoint: String = configurationProvider.authEndpoint ?: fireMissingConfigurationIssue(ConfigurationName.AUTH_ENDPOINT)
val requestTimeout: Long = configurationProvider.requestTimeout ?: fireMissingConfigurationIssue(ConfigurationName.REQUEST_TIMEOUT_MILLIS)
val connectionTimeout: Long = configurationProvider.connectionTimeout ?: fireMissingConfigurationIssue(ConfigurationName.CONNECTION_TIMEOUT_MILLIS)
val socketTimeout: Long = configurationProvider.socketTimeout ?: fireMissingConfigurationIssue(ConfigurationName.SOCKET_TIMEOUT_MILLIS)
val requestTimeout: Long =
configurationProvider.requestTimeout ?: fireMissingConfigurationIssue(
ConfigurationName.REQUEST_TIMEOUT_MILLIS,
)
val connectionTimeout: Long =
configurationProvider.connectionTimeout ?: fireMissingConfigurationIssue(
ConfigurationName.CONNECTION_TIMEOUT_MILLIS,
)
val socketTimeout: Long =
configurationProvider.socketTimeout ?: fireMissingConfigurationIssue(
ConfigurationName.SOCKET_TIMEOUT_MILLIS,
)
val maskedLoggingHeaders: Set<String> = configurationProvider.maskedLoggingHeaders ?: setOf()
val maskedLoggingBodyFields: Set<String> = configurationProvider.maskedLoggingBodyFields ?: setOf()

Expand All @@ -109,7 +118,7 @@ abstract class Client(
httpClientConfig,
Credentials.from(key, secret),
authEndpoint,
authenticationType
authenticationType,
)

plugins {
Expand All @@ -118,7 +127,9 @@ abstract class Client(
use(AuthenticationPlugin).with(authenticationConfiguration)
use(DefaultRequestPlugin).with(DefaultRequestConfiguration.from(httpClientConfig, endpoint))
use(EncodingPlugin).with(EncodingConfiguration.from(httpClientConfig))
use(HttpTimeoutPlugin).with(HttpTimeoutConfiguration.from(httpClientConfig, requestTimeout, connectionTimeout, socketTimeout))
use(
HttpTimeoutPlugin,
).with(HttpTimeoutConfiguration.from(httpClientConfig, requestTimeout, connectionTimeout, socketTimeout))
use(ExceptionHandlingPlugin).with(ExceptionHandlingConfiguration.from(httpClientConfig))
}

Expand All @@ -128,7 +139,8 @@ abstract class Client(
}

/** Throw an exception if the configuration is missing. */
private fun fireMissingConfigurationIssue(configurationKey: String): Nothing = throw ExpediaGroupConfigurationException(getMissingRequiredConfigurationMessage(configurationKey))
private fun fireMissingConfigurationIssue(configurationKey: String): Nothing =
throw ExpediaGroupConfigurationException(getMissingRequiredConfigurationMessage(configurationKey))

private fun isNotSuccessfulResponse(response: HttpResponse) = response.status.value !in Constant.SUCCESSFUL_STATUS_CODES_RANGE

Expand All @@ -142,7 +154,7 @@ abstract class Client(

abstract suspend fun throwServiceException(
response: HttpResponse,
operationId: String
operationId: String,
)

suspend fun performGet(url: String): HttpResponse = httpHandler.performGet(httpClient, url)
Expand Down Expand Up @@ -234,7 +246,12 @@ abstract class Client(
*/
fun requestTimeout(milliseconds: Long): SELF {
this.requestTimeout = milliseconds
log.info(LoggingMessageProvider.getRuntimeConfigurationProviderMessage(ConfigurationName.REQUEST_TIMEOUT_MILLIS, milliseconds.toString()))
log.info(
LoggingMessageProvider.getRuntimeConfigurationProviderMessage(
ConfigurationName.REQUEST_TIMEOUT_MILLIS,
milliseconds.toString(),
),
)
return self()
}

Expand All @@ -248,7 +265,12 @@ abstract class Client(
*/
fun connectionTimeout(milliseconds: Long): SELF {
this.connectionTimeout = milliseconds
log.info(LoggingMessageProvider.getRuntimeConfigurationProviderMessage(ConfigurationName.CONNECTION_TIMEOUT_MILLIS, milliseconds.toString()))
log.info(
LoggingMessageProvider.getRuntimeConfigurationProviderMessage(
ConfigurationName.CONNECTION_TIMEOUT_MILLIS,
milliseconds.toString(),
),
)
return self()
}

Expand All @@ -262,7 +284,12 @@ abstract class Client(
*/
fun socketTimeout(milliseconds: Long): SELF {
this.socketTimeout = milliseconds
log.info(LoggingMessageProvider.getRuntimeConfigurationProviderMessage(ConfigurationName.SOCKET_TIMEOUT_MILLIS, milliseconds.toString()))
log.info(
LoggingMessageProvider.getRuntimeConfigurationProviderMessage(
ConfigurationName.SOCKET_TIMEOUT_MILLIS,
milliseconds.toString(),
),
)
return self()
}

Expand All @@ -274,7 +301,12 @@ abstract class Client(
*/
fun maskedLoggingHeaders(vararg headers: String): SELF {
this.maskedLoggingHeaders = headers.toSet()
log.info(LoggingMessageProvider.getRuntimeConfigurationProviderMessage(ConfigurationName.MASKED_LOGGING_HEADERS, headers.joinToString()))
log.info(
LoggingMessageProvider.getRuntimeConfigurationProviderMessage(
ConfigurationName.MASKED_LOGGING_HEADERS,
headers.joinToString(),
),
)
return self()
}

Expand All @@ -286,7 +318,12 @@ abstract class Client(
*/
fun maskedLoggingBodyFields(vararg fields: String): SELF {
this.maskedLoggingBodyFields = fields.toSet()
log.info(LoggingMessageProvider.getRuntimeConfigurationProviderMessage(ConfigurationName.MASKED_LOGGING_BODY_FIELDS, fields.joinToString()))
log.info(
LoggingMessageProvider.getRuntimeConfigurationProviderMessage(
ConfigurationName.MASKED_LOGGING_BODY_FIELDS,
fields.joinToString(),
),
)
return self()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ package com.expediagroup.sdk.core.client

/** Handy utils and helpers for a client. */
abstract class ClientHelpers(
val client: Client
val client: Client,
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import io.ktor.client.request.HttpRequestBuilder
import io.ktor.http.HttpHeaders

interface EnvironmentProvider {
fun HttpRequestBuilder.appendHeaders(extraHeaders: Map<String, String> = mapOf(HeaderKey.TRANSACTION_ID to TransactionId().dequeue().toString()))
fun HttpRequestBuilder.appendHeaders(
extraHeaders: Map<String, String> = mapOf(HeaderKey.TRANSACTION_ID to TransactionId().dequeue().toString()),
)
}

class DefaultEnvironmentProvider(
namespace: String
namespace: String,
) : EnvironmentProvider {
private val properties = Properties.from(javaClass.classLoader.getResource("sdk.properties")!!)
private val javaVersion = System.getProperty("java.version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ import io.ktor.client.engine.HttpClientEngine
abstract class ExpediaGroupClient(
namespace: String,
clientConfiguration: ExpediaGroupClientConfiguration,
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE,
) : Client(namespace) {
private val _configurationProvider: ConfigurationProvider =
ConfigurationCollector.create(
clientConfiguration.toProvider(),
ExpediaGroupConfigurationProvider
ExpediaGroupConfigurationProvider,
)
private val _httpClient: HttpClient = buildHttpClient(_configurationProvider, AuthenticationStrategy.AuthenticationType.BEARER, httpClientEngine)
private val _httpClient: HttpClient =
buildHttpClient(_configurationProvider, AuthenticationStrategy.AuthenticationType.BEARER, httpClientEngine)

init {
finalize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ import io.ktor.http.HttpMethod
internal interface HttpHandler {
suspend fun performGet(
httpClient: HttpClient,
link: String
link: String,
): HttpResponse
}

internal class DefaultHttpHandler(
private val environmentProvider: EnvironmentProvider
private val environmentProvider: EnvironmentProvider,
) : HttpHandler, EnvironmentProvider by environmentProvider {
override suspend fun performGet(
httpClient: HttpClient,
link: String
link: String,
): HttpResponse {
return httpClient.request {
method = HttpMethod.Get
Expand Down
Loading

0 comments on commit 1f340ba

Please sign in to comment.