Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add wild card http request builder [WPB-11845] #3075

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<String>,
body: String?,
queryParam: Map<String, String>,
customHeader: Map<String, String>
): NetworkResponse<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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<String>,
body: String?,
queryParam: Map<String, String>,
customHeader: Map<String, String>
): NetworkResponse<String> = 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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -106,6 +107,8 @@ interface AuthenticatedNetworkContainer {

val propertiesApi: PropertiesApi

val wildCardApi: WildCardApi

companion object {

@Suppress("LongParameterList", "LongMethod")
Expand Down
Loading