io.grpc.netty.shaded.io.netty.handler.ssl.SslContext Java Examples

The following examples show how to use io.grpc.netty.shaded.io.netty.handler.ssl.SslContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientGrpcConfig.java    From flair-engine with Apache License 2.0 5 votes vote down vote up
private static SslContext buildSslContext(String trustCertCollectionFilePath,
                                          String clientCertChainFilePath,
                                          String clientPrivateKeyFilePath) throws SSLException {
    SslContextBuilder builder = GrpcSslContexts.forClient();
    if (trustCertCollectionFilePath != null) {
        builder.trustManager(new File(trustCertCollectionFilePath));
    }
    if (clientCertChainFilePath != null && clientPrivateKeyFilePath != null) {
        builder.keyManager(new File(clientCertChainFilePath), new File(clientPrivateKeyFilePath));
    }
    return builder.build();
}
 
Example #2
Source File: MetaStep.java    From metastore with Apache License 2.0 4 votes vote down vote up
public MetaStep(String... args) throws IOException, ArgumentParserException {
  ArgumentParser parser = ArgumentParsers.newFor("metastep").build();

  Subparsers subparsers = parser.addSubparsers().help("sub-command help");

  Subparser submitParser = subparsers.addParser("publish").help("publish help");
  submitParser.setDefault("sub-command", "publish");
  submitParser.addArgument("--package_prefix").required(false);
  submitParser.addArgument("--package_name").required(false);
  submitParser.addArgument("--file_name").required(false);
  submitParser.addArgument("--descriptor_set").required(false);
  submitParser.addArgument("--profile").required(false);
  submitParser.addArgument("--workspace").required(false);
  submitParser.addArgument("--server").required(true);
  submitParser.addArgument("--registry").required(false);
  submitParser.addArgument("--tls").required(false);
  submitParser.addArgument("--tls_env").required(false);
  submitParser.addArgument("--source").required(false);
  submitParser.addArgument("--comment").required(true);
  submitParser.addArgument("--user").required(false);
  submitParser.addArgument("--email").required(false);
  submitParser.addArgument("--include").nargs("*").required(false);

  Subparser validateParser = subparsers.addParser("validate").help("validate help");
  validateParser.setDefault("sub-command", "validate");
  validateParser.addArgument("--package_prefix").required(false);
  validateParser.addArgument("--package_name").required(false);
  validateParser.addArgument("--file_name").required(false);
  validateParser.addArgument("--descriptor_set").required(false);
  validateParser.addArgument("--profile").required(false);
  validateParser.addArgument("--workspace").required(false);
  validateParser.addArgument("--server").required(true);
  validateParser.addArgument("--registry").required(false);
  validateParser.addArgument("--tls").required(false);
  validateParser.addArgument("--tls_env").required(false);
  validateParser.addArgument("--source").required(false);
  validateParser.addArgument("--include").nargs("*").required(false);
  res = parser.parseArgs(args);

  descriptorFile = File.createTempFile("descriptor", ".pb");

  String server = res.getString("server");
  String[] sp = server.split(":");
  String host = sp[0];
  int port = Integer.parseInt(sp[1]);

  String protoWorkspace = res.getString("workspace");
  if (protoWorkspace == null) {
    protoWorkspace = "/var/workspace";
  }
  workspace = new File(protoWorkspace);
  System.out.println("Workspace set to: " + workspace);

  protoIncludes = res.getList("include");
  if (protoIncludes == null) {
    protoIncludes = new ArrayList<>();
  }
  protoIncludes.add("/usr/include");

  if (res.get("source") != null) {
    includeSource = true;
  }

  String tlsFileName = res.getString("tls");
  if (tlsFileName == null) {
    String tlsEnv = res.getString("tls_env");
    if (tlsEnv != null) {
      File tlsFile = File.createTempFile("tls", ".pem");
      tlsFileName = tlsFile.getAbsolutePath();
      String tlsBase64 = System.getenv(tlsEnv);
      if (tlsBase64 == null) {
        throw new RuntimeException("No ENVIRONMENT_VARIABLE of name " + tlsEnv + " found.");
      }
      try (FileOutputStream writer = new FileOutputStream(tlsFile)) {
        writer.write(Base64.getDecoder().decode(tlsBase64));
      }
    }
  }

  NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress(host, port);
  if (tlsFileName != null) {
    SslContext sslContext =
        GrpcSslContexts.forClient().trustManager(new File(tlsFileName)).build();

    channelBuilder.sslContext(sslContext).useTransportSecurity().build();
  } else {
    channelBuilder.usePlaintext();
  }
  schemaRegistry = RegistryGrpc.newBlockingStub(channelBuilder.build());
}