mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[fleet] FL-14501 CSRF protection on workspace server
GitOrigin-RevId: 8a60ac56e05f43fef240efefdbd3095c343f4928
This commit is contained in:
committed by
intellij-monorepo-bot
parent
80356e7b0e
commit
886cd1bbb8
@@ -86,4 +86,4 @@ suspend fun withFleetClient(
|
||||
body(fleetClient)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,10 @@ import kotlin.time.TimeSource
|
||||
|
||||
private val logger = logger<Transport<*>>()
|
||||
|
||||
class Transport<T>(val outgoing: SendChannel<T>,
|
||||
val incoming: ReceiveChannel<T>)
|
||||
class Transport<T>(
|
||||
val outgoing: SendChannel<T>,
|
||||
val incoming: ReceiveChannel<T>,
|
||||
)
|
||||
|
||||
fun interface FleetTransportFactory {
|
||||
/*
|
||||
@@ -24,10 +26,20 @@ fun interface FleetTransportFactory {
|
||||
* If the connection isn't possible, rethrow the cause as [TransportDisconnectedException].
|
||||
* When the underlying transport is broken, e.g. a socket is closed, both channels should be closed with [TransportDisconnectedException]
|
||||
*/
|
||||
suspend fun connect(transportStats: MutableStateFlow<TransportStats>?,
|
||||
body: suspend CoroutineScope.(Transport<TransportMessage>) -> Unit)
|
||||
suspend fun connect(
|
||||
transportStats: MutableStateFlow<TransportStats>?,
|
||||
body: suspend CoroutineScope.(Transport<TransportMessage>) -> Unit,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this function when you want to re-create your factory on each connection attempt.
|
||||
*/
|
||||
fun dynamicTransportFactory(f: suspend () -> FleetTransportFactory): FleetTransportFactory =
|
||||
FleetTransportFactory { socketStats, body ->
|
||||
f().connect(socketStats, body)
|
||||
}
|
||||
|
||||
enum class DebugConnectionState {
|
||||
Connect,
|
||||
Disconnect
|
||||
|
||||
@@ -24,7 +24,7 @@ import kotlin.error
|
||||
@JvmInline
|
||||
@Serializable(with = EitherSerializer::class)
|
||||
value class Either<out T, E> internal constructor(
|
||||
private val value: Any?
|
||||
private val value: Any?,
|
||||
) {
|
||||
/**
|
||||
* Returns `true` if this instance represents a value outcome.
|
||||
@@ -102,20 +102,26 @@ val <T, E> Either<T, E>.value: T
|
||||
val <T, E> Either<T, E>.error: E
|
||||
get() = requireNotNull(errorOrNull) { "Not a Error" }
|
||||
|
||||
inline fun <T, E, R> Either<T, E>.flatMap(f: (T) -> Either<R, E>): Either<R, E> = when (this.isValue) {
|
||||
false -> this as Either<R, E>
|
||||
else -> f(valueOrNull!!)
|
||||
}
|
||||
inline fun <T, E, R> Either<T, E>.flatMap(f: (T) -> Either<R, E>): Either<R, E> =
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
when (this.isValue) {
|
||||
false -> this as Either<R, E>
|
||||
else -> f(valueOrNull!!)
|
||||
}
|
||||
|
||||
inline fun <T, E, R> Either<T, E>.map(f: (T) -> R): Either<R, E> = when (this.isValue) {
|
||||
false -> this as Either<R, E>
|
||||
true -> Either.value(f(valueOrNull!!))
|
||||
}
|
||||
inline fun <T, E, R> Either<T, E>.map(f: (T) -> R): Either<R, E> =
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
when (this.isValue) {
|
||||
false -> this as Either<R, E>
|
||||
true -> Either.value(f(valueOrNull!!))
|
||||
}
|
||||
|
||||
inline fun <T, E, R> Either<T, E>.mapError(f: (E) -> R): Either<T, R> = when (this.isError) {
|
||||
false -> this as Either<T, R>
|
||||
true -> Either.error(f(error))
|
||||
}
|
||||
inline fun <T, E, R> Either<T, E>.mapError(f: (E) -> R): Either<T, R> =
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
when (this.isError) {
|
||||
false -> this as Either<T, R>
|
||||
true -> Either.error(f(error))
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given [action] on the encapsulated [E] if this instance represents [error][Either.isError].
|
||||
@@ -129,6 +135,15 @@ inline fun <T, E> Either<T, E>.onError(action: (error: E) -> Unit): Either<T, E>
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Unwraps the value of an `Either` instance.
|
||||
*
|
||||
* If the instance is a `error`, it will call the provided [action] function that is supposed to throw or unwind.
|
||||
* If the instance is a `value`, it will return the contained value.
|
||||
*/
|
||||
inline fun <T, E> Either<T, E>.unwrap(action: (error: E) -> Nothing): T =
|
||||
onError { action(it) }.value
|
||||
|
||||
/**
|
||||
* Performs the given [action] on the encapsulated value if this instance represents [value][Either.isValue].
|
||||
* Returns the original `Either` unchanged.
|
||||
@@ -142,8 +157,8 @@ inline fun <T, E> Either<T, E>.onValue(action: (value: T) -> Unit): Either<T, E>
|
||||
}
|
||||
|
||||
internal class EitherSerializer<T, E>(
|
||||
val valueSerializer: KSerializer<T>,
|
||||
val errorSerializer: KSerializer<E>,
|
||||
private val valueSerializer: KSerializer<T>,
|
||||
private val errorSerializer: KSerializer<E>,
|
||||
) : KSerializer<Either<T, E>> {
|
||||
|
||||
override val descriptor: SerialDescriptor
|
||||
@@ -172,4 +187,4 @@ internal class EitherSerializer<T, E>(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,4 +25,4 @@ fun <T, R> Result.Companion.flatMap(source: Iterable<T>, transform: (T) -> Resul
|
||||
onFailure = { err -> return failure(err) }
|
||||
) }
|
||||
return success(successes)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user