public ManagedChannel create()

in src/main/java/org/apache/skywalking/banyandb/v1/client/grpc/channel/DefaultChannelFactory.java [48:80]


    public ManagedChannel create() throws IOException {
        NettyChannelBuilder managedChannelBuilder = NettyChannelBuilder.forAddress(resolveAddress())
                .maxInboundMessageSize(options.getMaxInboundMessageSize())
                .usePlaintext();

        File caFile = new File(options.getSslTrustCAPath());
        boolean isCAFileExist = caFile.exists() && caFile.isFile();
        if (options.isForceTLS() || isCAFileExist) {
            SslContextBuilder builder = GrpcSslContexts.forClient();

            if (isCAFileExist) {
                String certPath = options.getSslCertChainPath();
                String keyPath = options.getSslKeyPath();
                if (!Strings.isNullOrEmpty(certPath) && Strings.isNullOrEmpty(keyPath)) {
                    File keyFile = new File(keyPath);
                    File certFile = new File(certPath);

                    if (certFile.isFile() && keyFile.isFile()) {
                        try (InputStream cert = new FileInputStream(certFile);
                             InputStream key = PrivateKeyUtil.loadDecryptionKey(keyFile.getAbsolutePath())) {
                            builder.keyManager(cert, key);
                        }
                    } else if (!certFile.isFile() || !keyFile.isFile()) {
                        log.warn("Failed to enable mTLS caused by cert or key cannot be found.");
                    }
                }

                builder.trustManager(caFile);
            }
            managedChannelBuilder.negotiationType(NegotiationType.TLS).sslContext(builder.build());
        }
        return managedChannelBuilder.build();
    }