Search in sources :

Example 1 with CertType

use of io.vertx.up.eon.em.CertType in project vertx-zero by silentbalanceyh.

the class RpcSslTool method getChannel.

/**
 * @param vertx  Vert.x instance
 * @param config configuration
 * @return ManagedChannel
 */
public static ManagedChannel getChannel(final Vertx vertx, final JsonObject config) {
    final String rpcHost = config.getString(Key.HOST);
    final Integer rpcPort = config.getInteger(Key.PORT);
    final VertxChannelBuilder builder = VertxChannelBuilder.forAddress(vertx, rpcHost, rpcPort);
    Fn.safeSemi(null != config.getValue(Key.SSL), LOGGER, () -> {
        final JsonObject sslConfig = config.getJsonObject(Key.SSL);
        if (null != sslConfig && !sslConfig.isEmpty()) {
            final Object type = sslConfig.getValue("type");
            final CertType certType = null == type ? CertType.PEM : Ut.toEnum(CertType.class, type.toString());
            final TrustPipe<JsonObject> pipe = TrustPipe.get(certType);
            // Enable SSL
            builder.useSsl(pipe.parse(sslConfig));
        } else {
            builder.usePlaintext(true);
        }
    });
    final ManagedChannel channel = builder.build();
    LOGGER.info(Info.CLIENT_RPC, rpcHost, String.valueOf(rpcPort), String.valueOf(channel.hashCode()));
    return channel;
}
Also used : VertxChannelBuilder(io.vertx.grpc.VertxChannelBuilder) JsonObject(io.vertx.core.json.JsonObject) CertType(io.vertx.up.eon.em.CertType) ManagedChannel(io.grpc.ManagedChannel) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with CertType

use of io.vertx.up.eon.em.CertType in project vertx-zero by silentbalanceyh.

the class RpcSslTool method getChannel.

public static ManagedChannel getChannel(final Vertx vertx, final IpcData data) {
    final String grpcHost = data.getHost();
    final Integer grpcPort = data.getPort();
    LOGGER.info(Info.CLIENT_BUILD, grpcHost, String.valueOf(grpcPort));
    final VertxChannelBuilder builder = VertxChannelBuilder.forAddress(vertx, grpcHost, grpcPort);
    // Ssl Required
    final JsonObject config = node.read();
    Fn.safeSemi(null != config && null != config.getValue("rpc"), LOGGER, () -> {
        // Extension or Uniform
        final JsonObject rpcConfig = config.getJsonObject("rpc");
        final String name = data.getName();
        final JsonObject ssl = RpcHelper.getSslConfig(name, rpcConfig);
        if (ssl.isEmpty()) {
            // Disabled SSL
            builder.usePlaintext(true);
        } else {
            final Object type = ssl.getValue("type");
            final CertType certType = null == type ? CertType.PEM : Ut.toEnum(CertType.class, type.toString());
            final TrustPipe<JsonObject> pipe = TrustPipe.get(certType);
            // Enabled SSL
            builder.useSsl(pipe.parse(ssl));
        }
    });
    return builder.build();
}
Also used : VertxChannelBuilder(io.vertx.grpc.VertxChannelBuilder) JsonObject(io.vertx.core.json.JsonObject) CertType(io.vertx.up.eon.em.CertType) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)2 VertxChannelBuilder (io.vertx.grpc.VertxChannelBuilder)2 CertType (io.vertx.up.eon.em.CertType)2 ManagedChannel (io.grpc.ManagedChannel)1