Skip to content
Open
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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ lazy val commonSettings = Seq(
organization := "com.cognite",
organizationName := "Cognite",
organizationHomepage := Some(url("https://cognite.com")),
version := "2.34." + patchVersion,
version := "2.35." + patchVersion,
isSnapshot := patchVersion.endsWith("-SNAPSHOT"),
scalaVersion := scala213, // use 2.13 by default
// handle cross plugin https://github.com/stringbean/sbt-dependency-lock/issues/13
Expand Down
32 changes: 24 additions & 8 deletions src/main/scala/com/cognite/sdk/scala/v1/GenericClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class GenericClient[F[_]: Trace](
apiVersion: Option[String],
clientTag: Option[String],
cdfVersion: Option[String],
sttpBackend: SttpBackend[F, Any]
sttpBackend: SttpBackend[F, Any],
wrapSttpBackend: SttpBackend[F, Any] => SttpBackend[F, Any]
)(implicit monad: CMonadError[F, Throwable]) {
def this(
applicationName: String,
Expand All @@ -44,7 +45,8 @@ class GenericClient[F[_]: Trace](
apiVersion: Option[String] = None,
clientTag: Option[String] = None,
cdfVersion: Option[String] = None,
sttpBackend: SttpBackend[F, Any]
sttpBackend: SttpBackend[F, Any],
wrapSttpBackend: SttpBackend[F, Any] => SttpBackend[F, Any] = identity[SttpBackend[F, Any]](_)
)(implicit monad: CMonadError[F, Throwable]) =
this(
applicationName,
Expand All @@ -54,7 +56,8 @@ class GenericClient[F[_]: Trace](
apiVersion,
clientTag,
cdfVersion,
sttpBackend
sttpBackend,
wrapSttpBackend
)

import GenericClient._
Expand All @@ -66,12 +69,15 @@ class GenericClient[F[_]: Trace](
applicationName,
uri"$uri/api/${apiVersion.getOrElse("v1")}/projects/$projectName",
sttpBackend,
wrapSttpBackend,
authProvider,
clientTag,
cdfVersion
)
lazy val token =
new Token[F](RequestSession(applicationName, uri, sttpBackend, authProvider, clientTag))
new Token[F](
RequestSession(applicationName, uri, sttpBackend, wrapSttpBackend, authProvider, clientTag)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The RequestSession created for token is missing the cdfVersion parameter. This means that requests made by the token instance (e.g., token.inspect()) will not include the cdf-version header, which could lead to incorrect request routing in multi-cluster environments. Please add cdfVersion to the RequestSession constructor call to ensure consistent behavior with other API requests.

Suggested change
RequestSession(applicationName, uri, sttpBackend, wrapSttpBackend, authProvider, clientTag)
RequestSession(applicationName, uri, sttpBackend, wrapSttpBackend, authProvider, clientTag, cdfVersion)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will look into it separately

)
lazy val assets = new Assets[F](requestSession.withResourceType(ASSETS))
lazy val events = new Events[F](requestSession.withResourceType(EVENTS))
lazy val files = new Files[F](requestSession.withResourceType(FILES))
Expand Down Expand Up @@ -175,9 +181,17 @@ object GenericClient {
projectName: String,
baseUrl: String,
auth: Auth,
sttpBackend: SttpBackend[F, Any]
sttpBackend: SttpBackend[F, Any],
wrapSttpBackend: SttpBackend[F, Any] => SttpBackend[F, Any] = identity[SttpBackend[F, Any]](_)
)(implicit F: CMonadError[F, Throwable]): GenericClient[F] =
new GenericClient(applicationName, projectName, baseUrl, auth, sttpBackend = sttpBackend)
new GenericClient(
applicationName,
projectName,
baseUrl,
auth,
sttpBackend = sttpBackend,
wrapSttpBackend = wrapSttpBackend
)

def parseBaseUrlOrThrow(baseUrl: String): Uri =
try {
Expand Down Expand Up @@ -235,7 +249,8 @@ object GenericClient {
apiVersion: Option[String] = None,
clientTag: Option[String] = None,
cdfVersion: Option[String] = None,
sttpBackend: SttpBackend[F, Any]
sttpBackend: SttpBackend[F, Any],
wrapSttpBackend: SttpBackend[F, Any] => SttpBackend[F, Any] = identity[SttpBackend[F, Any]](_)
)(implicit F: CMonadError[F, Throwable]): F[GenericClient[F]] =
if (projectName.isEmpty) {
F.raiseError(InvalidAuthentication())
Expand All @@ -249,7 +264,8 @@ object GenericClient {
apiVersion,
clientTag,
cdfVersion,
sttpBackend
sttpBackend,
wrapSttpBackend
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final case class RequestSession[F[_]: Trace](
applicationName: String,
baseUrl: Uri,
baseSttpBackend: SttpBackend[F, _],
wrapSttpBackend: SttpBackend[F, Any] => SttpBackend[F, Any],
auth: AuthProvider[F],
clientTag: Option[String] = None,
cdfVersion: Option[String] = None,
Expand All @@ -39,7 +40,7 @@ final case class RequestSession[F[_]: Trace](
this.copy(tags = this.tags + (GenericClient.RESOURCE_TYPE_TAG -> resourceType))

val sttpBackend: SttpBackend[F, _] =
new AuthSttpBackend(new TraceSttpBackend(baseSttpBackend), auth)
wrapSttpBackend(new AuthSttpBackend(new TraceSttpBackend(baseSttpBackend), auth))

def send[R](
r: RequestT[Empty, Either[String, String], Any] => RequestT[Id, R, Any]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class OAuth2ClientCredentialsTest extends AnyFlatSpec with Matchers with OptionV
clientTag = None,
cdfVersion = None,
sttpBackend = sttpBackend,
wrapSttpBackend = identity[SttpBackend[IO, Any]],
)

noException shouldBe thrownBy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TokenTest extends SdkTestSpec with OptionValues {

val token =
new Token(RequestSession[IO]("CogniteScalaSDK-OAuth-Test", uri"${baseUrl}", sttpBackend,
authProvider))
identity, authProvider))
val status = token.inspect().unsafeRunTimed(10.seconds).value
assert(status.subject !== "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ trait CommonDataModelTestHelper extends AnyFlatSpec with Matchers {
None,
None,
Some("alpha"),
new RetryingBackend[IO, Any](implicitly)
implicitly[SttpBackend[IO, Any]],
new RetryingBackend[IO, Any](_: SttpBackend[IO, Any]),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import cats.effect.unsafe.implicits.global
import com.cognite.sdk.scala.common.OAuth2.ClientCredentials
import com.cognite.sdk.scala.common._
import io.circe.syntax.EncoderOps
import sttp.client3.SttpBackend
import sttp.model.Uri

import java.time.temporal.ChronoUnit
Expand All @@ -28,7 +29,8 @@ class TransformationsTest extends CommonDataModelTestHelper with RetryWhile {
None,
None,
None,
sttpBackendAuth
sttpBackendAuth,
identity[SttpBackend[IO, Any]](_),
)

def shortRandomUUID(): String = UUID.randomUUID().toString.substring(0, 8)
Expand Down