diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/WildCardApi.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/WildCardApi.kt new file mode 100644 index 00000000000..8840ab6cfac --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/WildCardApi.kt @@ -0,0 +1,31 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.network.api.base.authenticated + +import com.wire.kalium.network.utils.NetworkResponse +import io.ktor.http.HttpMethod + +interface WildCardApi { + suspend fun customRequest( + httpMethod: HttpMethod, + requestPath: List, + body: String?, + queryParam: Map, + customHeader: Map + ): NetworkResponse +} diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt index 4967bc5abfd..682e57c52b7 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.base.authenticated.connection.ConnectionApi @@ -60,6 +61,7 @@ import com.wire.kalium.network.api.v0.authenticated.SelfApiV0 import com.wire.kalium.network.api.v0.authenticated.TeamsApiV0 import com.wire.kalium.network.api.v0.authenticated.UserDetailsApiV0 import com.wire.kalium.network.api.v0.authenticated.UserSearchApiV0 +import com.wire.kalium.network.api.vcommon.WildCardApiImpl import com.wire.kalium.network.defaultHttpEngine import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProvider import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProviderImpl @@ -79,7 +81,7 @@ internal class AuthenticatedNetworkContainerV0 internal constructor( serverConfigDTOApiProxy = sessionManager.serverConfig().links.apiProxy, proxyCredentials = sessionManager.proxyCredentials(), certificatePinning = certificatePinning - ) + ), ) : AuthenticatedNetworkContainer, AuthenticatedHttpClientProvider by AuthenticatedHttpClientProviderImpl( sessionManager = sessionManager, @@ -132,4 +134,6 @@ internal class AuthenticatedNetworkContainerV0 internal constructor( override val mlsPublicKeyApi: MLSPublicKeyApi get() = MLSPublicKeyApiV0() override val propertiesApi: PropertiesApi get() = PropertiesApiV0(networkClient) + + override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt index 45e6812fcf4..aafbf72caef 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.base.authenticated.connection.ConnectionApi @@ -61,6 +62,7 @@ import com.wire.kalium.network.api.v2.authenticated.SelfApiV2 import com.wire.kalium.network.api.v2.authenticated.TeamsApiV2 import com.wire.kalium.network.api.v2.authenticated.UserDetailsApiV2 import com.wire.kalium.network.api.v2.authenticated.UserSearchApiV2 +import com.wire.kalium.network.api.vcommon.WildCardApiImpl import com.wire.kalium.network.defaultHttpEngine import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProvider import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProviderImpl @@ -135,4 +137,6 @@ internal class AuthenticatedNetworkContainerV2 internal constructor( override val mlsPublicKeyApi: MLSPublicKeyApi get() = MLSPublicKeyApiV2() override val propertiesApi: PropertiesApi get() = PropertiesApiV2(networkClient) + + override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt index cc654c55b5e..9afa50d676f 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.base.authenticated.connection.ConnectionApi @@ -62,6 +63,7 @@ import com.wire.kalium.network.api.v3.authenticated.SelfApiV3 import com.wire.kalium.network.api.v3.authenticated.TeamsApiV3 import com.wire.kalium.network.api.v3.authenticated.UserDetailsApiV3 import com.wire.kalium.network.api.v3.authenticated.UserSearchApiV3 +import com.wire.kalium.network.api.vcommon.WildCardApiImpl import com.wire.kalium.network.defaultHttpEngine import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProvider import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProviderImpl @@ -136,4 +138,6 @@ internal class AuthenticatedNetworkContainerV3 internal constructor( override val mlsPublicKeyApi: MLSPublicKeyApi get() = MLSPublicKeyApiV3() override val propertiesApi: PropertiesApi get() = PropertiesApiV3(networkClient) + + override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt index eae3a79271e..fda8298f30b 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.base.authenticated.connection.ConnectionApi @@ -61,6 +62,7 @@ import com.wire.kalium.network.api.v4.authenticated.SelfApiV4 import com.wire.kalium.network.api.v4.authenticated.TeamsApiV4 import com.wire.kalium.network.api.v4.authenticated.UserDetailsApiV4 import com.wire.kalium.network.api.v4.authenticated.UserSearchApiV4 +import com.wire.kalium.network.api.vcommon.WildCardApiImpl import com.wire.kalium.network.defaultHttpEngine import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProvider import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProviderImpl @@ -135,4 +137,6 @@ internal class AuthenticatedNetworkContainerV4 internal constructor( override val mlsPublicKeyApi: MLSPublicKeyApi get() = MLSPublicKeyApiV4() override val propertiesApi: PropertiesApi get() = PropertiesApiV4(networkClient) + + override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt index 9c050af90a3..4bd93b1eb39 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.base.authenticated.connection.ConnectionApi @@ -61,6 +62,7 @@ import com.wire.kalium.network.api.v5.authenticated.SelfApiV5 import com.wire.kalium.network.api.v5.authenticated.TeamsApiV5 import com.wire.kalium.network.api.v5.authenticated.UserDetailsApiV5 import com.wire.kalium.network.api.v5.authenticated.UserSearchApiV5 +import com.wire.kalium.network.api.vcommon.WildCardApiImpl import com.wire.kalium.network.defaultHttpEngine import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProvider import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProviderImpl @@ -135,4 +137,6 @@ internal class AuthenticatedNetworkContainerV5 internal constructor( override val mlsPublicKeyApi: MLSPublicKeyApi get() = MLSPublicKeyApiV5(networkClient) override val propertiesApi: PropertiesApi get() = PropertiesApiV5(networkClient) + + override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/networkContainer/AuthenticatedNetworkContainerV6.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/networkContainer/AuthenticatedNetworkContainerV6.kt index 98924a1c5a6..1499d064c38 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/networkContainer/AuthenticatedNetworkContainerV6.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/networkContainer/AuthenticatedNetworkContainerV6.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.base.authenticated.connection.ConnectionApi @@ -61,6 +62,7 @@ import com.wire.kalium.network.api.v6.authenticated.SelfApiV6 import com.wire.kalium.network.api.v6.authenticated.TeamsApiV6 import com.wire.kalium.network.api.v6.authenticated.UserDetailsApiV6 import com.wire.kalium.network.api.v6.authenticated.UserSearchApiV6 +import com.wire.kalium.network.api.vcommon.WildCardApiImpl import com.wire.kalium.network.defaultHttpEngine import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProvider import com.wire.kalium.network.networkContainer.AuthenticatedHttpClientProviderImpl @@ -135,4 +137,6 @@ internal class AuthenticatedNetworkContainerV6 internal constructor( override val mlsPublicKeyApi: MLSPublicKeyApi get() = MLSPublicKeyApiV6(networkClient) override val propertiesApi: PropertiesApi get() = PropertiesApiV6(networkClient) + + override val wildCardApi: WildCardApi get() = WildCardApiImpl(networkClient) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/vcommon/WildCardApiImpl.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/vcommon/WildCardApiImpl.kt new file mode 100644 index 00000000000..1c46937799c --- /dev/null +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/vcommon/WildCardApiImpl.kt @@ -0,0 +1,52 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.network.api.vcommon + +import com.wire.kalium.network.AuthenticatedNetworkClient +import com.wire.kalium.network.api.base.authenticated.WildCardApi +import com.wire.kalium.network.utils.NetworkResponse +import com.wire.kalium.network.utils.wrapKaliumResponse +import io.ktor.client.request.parameter +import io.ktor.client.request.request +import io.ktor.client.request.setBody +import io.ktor.client.request.url +import io.ktor.http.HttpMethod + +internal class WildCardApiImpl( + private val authenticatedNetworkClient: AuthenticatedNetworkClient +) : WildCardApi { + override suspend fun customRequest( + httpMethod: HttpMethod, + requestPath: List, + body: String?, + queryParam: Map, + customHeader: Map + ): NetworkResponse = wrapKaliumResponse { + authenticatedNetworkClient.httpClient.request { + method = httpMethod + url(requestPath.joinToString("/")) + body?.let { setBody(it) } + queryParam.forEach { (key, value) -> + parameter(key, value) + } + customHeader.forEach { (key, value) -> + headers.append(key, value) + } + } + } +} diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt index ebffd8809a5..d46fe227c44 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt @@ -24,6 +24,7 @@ import com.wire.kalium.network.AuthenticatedWebSocketClient import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.WildCardApi import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.base.authenticated.client.ClientApi import com.wire.kalium.network.api.base.authenticated.connection.ConnectionApi @@ -106,6 +107,8 @@ interface AuthenticatedNetworkContainer { val propertiesApi: PropertiesApi + val wildCardApi: WildCardApi + companion object { @Suppress("LongParameterList", "LongMethod")