Skip to content

Commit c28fc96

Browse files
committed
grpc-native: Rename ChannelCredentials to ClientCredentials
Signed-off-by: Johannes Zottele <[email protected]>
1 parent 0354de5 commit c28fc96

File tree

10 files changed

+55
-55
lines changed

10 files changed

+55
-55
lines changed

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/GrpcClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public class GrpcClient internal constructor(
131131
public fun GrpcClient(
132132
hostname: String,
133133
port: Int,
134-
credentials: ChannelCredentials? = null,
134+
credentials: ClientCredentials? = null,
135135
messageCodecResolver: MessageCodecResolver = EmptyMessageCodecResolver,
136136
configure: ManagedChannelBuilder<*>.() -> Unit = {},
137137
): GrpcClient {
@@ -144,7 +144,7 @@ public fun GrpcClient(
144144
*/
145145
public fun GrpcClient(
146146
target: String,
147-
credentials: ChannelCredentials? = null,
147+
credentials: ClientCredentials? = null,
148148
messageCodecResolver: MessageCodecResolver = EmptyMessageCodecResolver,
149149
configure: ManagedChannelBuilder<*>.() -> Unit = {},
150150
): GrpcClient {

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/ManagedChannel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public expect abstract class ManagedChannelBuilder<T : ManagedChannelBuilder<T>>
7676
internal expect fun ManagedChannelBuilder(
7777
hostname: String,
7878
port: Int,
79-
credentials: ChannelCredentials? = null,
79+
credentials: ClientCredentials? = null,
8080
): ManagedChannelBuilder<*>
8181

8282
internal expect fun ManagedChannelBuilder(
8383
target: String,
84-
credentials: ChannelCredentials? = null,
84+
credentials: ClientCredentials? = null,
8585
): ManagedChannelBuilder<*>
8686

8787
internal expect fun ManagedChannelBuilder<*>.buildChannel(): ManagedChannel

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/credentials.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ package kotlinx.rpc.grpc/*
66
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
77
*/
88

9-
public expect abstract class ChannelCredentials
9+
public expect abstract class ClientCredentials
1010
public expect abstract class ServerCredentials
1111

12-
public expect class InsecureChannelCredentials : ChannelCredentials
12+
public expect class InsecureClientCredentials : ClientCredentials
1313
public expect class InsecureServerCredentials : ServerCredentials
1414

15-
public expect class TlsChannelCredentials : ChannelCredentials
15+
public expect class TlsClientCredentials : ClientCredentials
1616
public expect class TlsServerCredentials : ServerCredentials
1717

18-
public fun TlsChannelCredentials(configure: TlsChannelCredentialsBuilder.() -> Unit = {}): ChannelCredentials {
19-
val builder = TlsChannelCredentialsBuilder()
18+
public fun TlsClientCredentials(configure: TlsClientCredentialsBuilder.() -> Unit = {}): ClientCredentials {
19+
val builder = TlsClientCredentialsBuilder()
2020
builder.configure()
2121
return builder.build()
2222
}
@@ -31,10 +31,10 @@ public fun TlsServerCredentials(
3131
return builder.build()
3232
}
3333

34-
public interface TlsChannelCredentialsBuilder {
35-
public fun trustManager(rootCertsPem: String): TlsChannelCredentialsBuilder
36-
public fun keyManager(certChainPem: String, privateKeyPem: String): TlsChannelCredentialsBuilder
37-
public fun build(): ChannelCredentials
34+
public interface TlsClientCredentialsBuilder {
35+
public fun trustManager(rootCertsPem: String): TlsClientCredentialsBuilder
36+
public fun keyManager(certChainPem: String, privateKeyPem: String): TlsClientCredentialsBuilder
37+
public fun build(): ClientCredentials
3838
}
3939

4040
public enum class TlsClientAuth {
@@ -62,7 +62,7 @@ public interface TlsServerCredentialsBuilder {
6262
public fun build(): ServerCredentials
6363
}
6464

65-
internal expect fun TlsChannelCredentialsBuilder(): TlsChannelCredentialsBuilder
65+
internal expect fun TlsClientCredentialsBuilder(): TlsClientCredentialsBuilder
6666
internal expect fun TlsServerCredentialsBuilder(
6767
certChain: String,
6868
privateKey: String,

grpc/grpc-core/src/commonTest/kotlin/kotlinx/rpc/grpc/test/proto/GrpcProtoTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import kotlinx.coroutines.sync.Mutex
88
import kotlinx.coroutines.sync.withLock
99
import kotlinx.coroutines.test.runTest
1010
import kotlinx.rpc.RpcServer
11-
import kotlinx.rpc.grpc.ChannelCredentials
11+
import kotlinx.rpc.grpc.ClientCredentials
1212
import kotlinx.rpc.grpc.GrpcClient
1313
import kotlinx.rpc.grpc.GrpcServer
1414
import kotlinx.rpc.grpc.ServerCredentials
@@ -20,7 +20,7 @@ abstract class GrpcProtoTest {
2020

2121
protected fun runGrpcTest(
2222
serverCreds: ServerCredentials? = null,
23-
clientCreds: ChannelCredentials? = null,
23+
clientCreds: ClientCredentials? = null,
2424
overrideAuthority: String? = null,
2525
test: suspend (GrpcClient) -> Unit,
2626
) = runTest {

grpc/grpc-core/src/commonTest/kotlin/kotlinx/rpc/grpc/test/proto/GrpcTlsTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import kotlinx.coroutines.test.runTest
1111
import kotlinx.rpc.RpcServer
1212
import kotlinx.rpc.grpc.GrpcClient
1313
import kotlinx.rpc.grpc.StatusCode
14-
import kotlinx.rpc.grpc.TlsChannelCredentials
1514
import kotlinx.rpc.grpc.TlsClientAuth
15+
import kotlinx.rpc.grpc.TlsClientCredentials
1616
import kotlinx.rpc.grpc.TlsServerCredentials
1717
import kotlinx.rpc.grpc.test.CA_PEM
1818
import kotlinx.rpc.grpc.test.CLIENT_CERT_PEM
@@ -55,7 +55,7 @@ class GrpcTlsTest : GrpcProtoTest() {
5555
@Test
5656
fun `test TLS with valid certificates - should succeed`() {
5757
val serverTls = TlsServerCredentials(SERVER_CERT_PEM, SERVER_KEY_PEM)
58-
val clientTls = TlsChannelCredentials { trustManager(SERVER_CERT_PEM) }
58+
val clientTls = TlsClientCredentials { trustManager(SERVER_CERT_PEM) }
5959

6060
runGrpcTest(serverTls, clientTls, overrideAuthority = "foo.test.google.fr", test = ::defaultUnaryTest)
6161
}
@@ -66,7 +66,7 @@ class GrpcTlsTest : GrpcProtoTest() {
6666
trustManager(CA_PEM)
6767
clientAuth(TlsClientAuth.REQUIRE)
6868
}
69-
val clientTls = TlsChannelCredentials {
69+
val clientTls = TlsClientCredentials {
7070
keyManager(CLIENT_CERT_PEM, CLIENT_KEY_PEM)
7171
trustManager(CA_PEM)
7272
}
@@ -85,7 +85,7 @@ class GrpcTlsTest : GrpcProtoTest() {
8585
// clientAuth is optional, so a client without a certificate can connect
8686
clientAuth(TlsClientAuth.OPTIONAL)
8787
}
88-
val clientTls = TlsChannelCredentials {
88+
val clientTls = TlsClientCredentials {
8989
keyManager(CLIENT_CERT_PEM, CLIENT_KEY_PEM)
9090
trustManager(CA_PEM)
9191
}
@@ -101,7 +101,7 @@ class GrpcTlsTest : GrpcProtoTest() {
101101
clientAuth(TlsClientAuth.REQUIRE)
102102
}
103103
// client does NOT provide keyManager, only trusts CA
104-
val clientTls = TlsChannelCredentials {
104+
val clientTls = TlsClientCredentials {
105105
trustManager(CA_PEM)
106106
}
107107

@@ -114,7 +114,7 @@ class GrpcTlsTest : GrpcProtoTest() {
114114
fun `test TLS with no client trustManager - should fail`() = runTest {
115115
val serverTls = TlsServerCredentials(SERVER_CERT_PEM, SERVER_KEY_PEM)
116116
// client credential doesn't contain a trustManager, so server authentication will fail
117-
val clientTls = TlsChannelCredentials {}
117+
val clientTls = TlsClientCredentials {}
118118
assertGrpcFailure(StatusCode.UNAVAILABLE) {
119119
runGrpcTest(serverTls, clientTls, overrideAuthority = "foo.test.google.fr", test = ::defaultUnaryTest)
120120
}
@@ -123,7 +123,7 @@ class GrpcTlsTest : GrpcProtoTest() {
123123
@Test
124124
fun `test TLS with invalid authority - should fail`() = runTest {
125125
val serverTls = TlsServerCredentials(SERVER_CERT_PEM, SERVER_KEY_PEM)
126-
val clientTls = TlsChannelCredentials { trustManager(CA_PEM) }
126+
val clientTls = TlsClientCredentials { trustManager(CA_PEM) }
127127
// the authority does not match the certificate
128128
assertGrpcFailure(StatusCode.UNAVAILABLE) {
129129
runGrpcTest(serverTls, clientTls, overrideAuthority = "invalid.host.name", test = ::defaultUnaryTest)
@@ -140,7 +140,7 @@ class GrpcTlsTest : GrpcProtoTest() {
140140

141141
@Test
142142
fun `test TLS client with plaintext server - should fail`() = runTest {
143-
val clientTls = TlsChannelCredentials { trustManager(CA_PEM) }
143+
val clientTls = TlsClientCredentials { trustManager(CA_PEM) }
144144
assertGrpcFailure(StatusCode.UNAVAILABLE) {
145145
runGrpcTest(clientCreds = clientTls, overrideAuthority = "foo.test.google.fr", test = ::defaultUnaryTest)
146146
}

grpc/grpc-core/src/jvmMain/kotlin/kotlinx/rpc/grpc/ManagedChannel.jvm.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ internal actual fun ManagedChannelBuilder<*>.buildChannel(): ManagedChannel {
2727
internal actual fun ManagedChannelBuilder(
2828
hostname: String,
2929
port: Int,
30-
credentials: ChannelCredentials?,
30+
credentials: ClientCredentials?,
3131
): ManagedChannelBuilder<*> {
3232
if (credentials != null) return io.grpc.Grpc.newChannelBuilderForAddress(hostname, port, credentials)
3333
return io.grpc.ManagedChannelBuilder.forAddress(hostname, port)
3434
}
3535

3636
internal actual fun ManagedChannelBuilder(
3737
target: String,
38-
credentials: ChannelCredentials?,
38+
credentials: ClientCredentials?,
3939
): ManagedChannelBuilder<*> {
4040
if (credentials != null) return io.grpc.Grpc.newChannelBuilder(target, credentials)
4141
return io.grpc.ManagedChannelBuilder.forTarget(target)

grpc/grpc-core/src/jvmMain/kotlin/kotlinx/rpc/grpc/credentials.jvm.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@
44

55
package kotlinx.rpc.grpc
66

7-
public actual typealias ChannelCredentials = io.grpc.ChannelCredentials
7+
public actual typealias ClientCredentials = io.grpc.ChannelCredentials
88

99
public actual typealias ServerCredentials = io.grpc.ServerCredentials
1010

1111
// we need a wrapper for InsecureChannelCredentials as our constructor would conflict with the private
1212
// java constructor.
13-
public actual typealias InsecureChannelCredentials = io.grpc.InsecureChannelCredentials
13+
public actual typealias InsecureClientCredentials = io.grpc.InsecureChannelCredentials
1414
public actual typealias InsecureServerCredentials = io.grpc.InsecureServerCredentials
1515

16-
public actual typealias TlsChannelCredentials = io.grpc.TlsChannelCredentials
16+
public actual typealias TlsClientCredentials = io.grpc.TlsChannelCredentials
1717
public actual typealias TlsServerCredentials = io.grpc.TlsServerCredentials
1818

19-
internal actual fun TlsChannelCredentialsBuilder(): TlsChannelCredentialsBuilder =
20-
object : TlsChannelCredentialsBuilder {
21-
private var cb = TlsChannelCredentials.newBuilder()
19+
internal actual fun TlsClientCredentialsBuilder(): TlsClientCredentialsBuilder =
20+
object : TlsClientCredentialsBuilder {
21+
private var cb = TlsClientCredentials.newBuilder()
2222

2323

24-
override fun trustManager(rootCertsPem: String): TlsChannelCredentialsBuilder {
24+
override fun trustManager(rootCertsPem: String): TlsClientCredentialsBuilder {
2525
cb.trustManager(rootCertsPem.byteInputStream())
2626
return this
2727
}
2828

2929
override fun keyManager(
3030
certChainPem: String,
3131
privateKeyPem: String,
32-
): TlsChannelCredentialsBuilder {
32+
): TlsClientCredentialsBuilder {
3333
cb.keyManager(certChainPem.byteInputStream(), privateKeyPem.byteInputStream())
3434
return this
3535
}
3636

37-
override fun build(): ChannelCredentials {
37+
override fun build(): ClientCredentials {
3838
return cb.build()
3939
}
4040
}

grpc/grpc-core/src/nativeMain/kotlin/kotlinx/rpc/grpc/ManagedChannel.native.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public actual abstract class ManagedChannelBuilder<T : ManagedChannelBuilder<T>>
2828

2929
internal class NativeManagedChannelBuilder(
3030
private val target: String,
31-
private var credentials: Lazy<ChannelCredentials>,
31+
private var credentials: Lazy<ClientCredentials>,
3232
) : ManagedChannelBuilder<NativeManagedChannelBuilder>() {
3333

3434
private var authority: String? = null
@@ -61,14 +61,14 @@ internal actual fun ManagedChannelBuilder<*>.buildChannel(): ManagedChannel {
6161
internal actual fun ManagedChannelBuilder(
6262
hostname: String,
6363
port: Int,
64-
credentials: ChannelCredentials?,
64+
credentials: ClientCredentials?,
6565
): ManagedChannelBuilder<*> {
66-
val credentials = if (credentials == null) lazy { TlsChannelCredentials() } else lazy { credentials }
66+
val credentials = if (credentials == null) lazy { TlsClientCredentials() } else lazy { credentials }
6767
return NativeManagedChannelBuilder(target = "$hostname:$port", credentials)
6868
}
6969

70-
internal actual fun ManagedChannelBuilder(target: String, credentials: ChannelCredentials?): ManagedChannelBuilder<*> {
71-
val credentials = if (credentials == null) lazy { TlsChannelCredentials() } else lazy { credentials }
70+
internal actual fun ManagedChannelBuilder(target: String, credentials: ClientCredentials?): ManagedChannelBuilder<*> {
71+
val credentials = if (credentials == null) lazy { TlsClientCredentials() } else lazy { credentials }
7272
return NativeManagedChannelBuilder(target, credentials)
7373
}
7474

grpc/grpc-core/src/nativeMain/kotlin/kotlinx/rpc/grpc/credentials.native.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import libkgrpc.grpc_tls_server_credentials_create
3131
import kotlin.experimental.ExperimentalNativeApi
3232
import kotlin.native.ref.createCleaner
3333

34-
public actual abstract class ChannelCredentials internal constructor(
34+
public actual abstract class ClientCredentials internal constructor(
3535
internal val raw: CPointer<grpc_channel_credentials>,
3636
) {
3737
@Suppress("unused")
@@ -49,25 +49,25 @@ public actual abstract class ServerCredentials internal constructor(
4949
}
5050
}
5151

52-
public actual class InsecureChannelCredentials internal constructor(
52+
public actual class InsecureClientCredentials internal constructor(
5353
raw: CPointer<grpc_channel_credentials>,
54-
) : ChannelCredentials(raw)
54+
) : ClientCredentials(raw)
5555

5656
public actual class InsecureServerCredentials internal constructor(
5757
raw: CPointer<grpc_server_credentials>,
5858
) : ServerCredentials(raw)
5959

60-
public actual class TlsChannelCredentials internal constructor(
60+
public actual class TlsClientCredentials internal constructor(
6161
raw: CPointer<grpc_channel_credentials>,
62-
) : ChannelCredentials(raw)
62+
) : ClientCredentials(raw)
6363

6464
public actual class TlsServerCredentials(
6565
raw: CPointer<grpc_server_credentials>,
6666
) : ServerCredentials(raw)
6767

6868

69-
public fun InsecureChannelCredentials(): ChannelCredentials {
70-
return InsecureChannelCredentials(
69+
public fun InsecureChannelCredentials(): ClientCredentials {
70+
return InsecureClientCredentials(
7171
grpc_insecure_credentials_create() ?: error("grpc_insecure_credentials_create() returned null")
7272
)
7373
}
@@ -78,31 +78,31 @@ public fun InsecureServerCredentials(): ServerCredentials {
7878
)
7979
}
8080

81-
internal actual fun TlsChannelCredentialsBuilder(): TlsChannelCredentialsBuilder =
82-
object : TlsChannelCredentialsBuilder {
81+
internal actual fun TlsClientCredentialsBuilder(): TlsClientCredentialsBuilder =
82+
object : TlsClientCredentialsBuilder {
8383
var optionsBuilder = TlsCredentialsOptionsBuilder()
8484

85-
override fun trustManager(rootCertsPem: String): TlsChannelCredentialsBuilder {
85+
override fun trustManager(rootCertsPem: String): TlsClientCredentialsBuilder {
8686
optionsBuilder.trustManager(rootCertsPem)
8787
return this
8888
}
8989

9090
override fun keyManager(
9191
certChainPem: String,
9292
privateKeyPem: String,
93-
): TlsChannelCredentialsBuilder {
93+
): TlsClientCredentialsBuilder {
9494
optionsBuilder.keyManager(certChainPem, privateKeyPem)
9595
return this
9696
}
9797

98-
override fun build(): ChannelCredentials {
98+
override fun build(): ClientCredentials {
9999
val opts = optionsBuilder.build()
100100
val creds = grpc_tls_credentials_create(opts)
101101
?: run {
102102
grpc_tls_credentials_options_destroy(opts);
103103
error("TLS channel credential creation failed")
104104
}
105-
return TlsChannelCredentials(creds)
105+
return TlsClientCredentials(creds)
106106
}
107107
}
108108

grpc/grpc-core/src/nativeMain/kotlin/kotlinx/rpc/grpc/internal/NativeManagedChannel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import kotlinx.coroutines.Job
1919
import kotlinx.coroutines.SupervisorJob
2020
import kotlinx.coroutines.cancelChildren
2121
import kotlinx.coroutines.withTimeoutOrNull
22-
import kotlinx.rpc.grpc.ChannelCredentials
22+
import kotlinx.rpc.grpc.ClientCredentials
2323
import kotlinx.rpc.grpc.ManagedChannel
2424
import kotlinx.rpc.grpc.ManagedChannelPlatform
2525
import libkgrpc.GPR_CLOCK_REALTIME
@@ -48,7 +48,7 @@ internal class NativeManagedChannel(
4848
target: String,
4949
val authority: String?,
5050
// we must store them, otherwise the credentials are getting released
51-
credentials: ChannelCredentials,
51+
credentials: ClientCredentials,
5252
) : ManagedChannel, ManagedChannelPlatform() {
5353

5454
// a reference to make sure the grpc_init() was called. (it is released after shutdown)

0 commit comments

Comments
 (0)