andreigurau commented on code in PR #24229:
URL: https://github.com/apache/beam/pull/24229#discussion_r1026825506
##########
sdks/java/io/splunk/src/main/java/org/apache/beam/sdk/io/splunk/SplunkEventWriter.java:
##########
@@ -396,6 +411,41 @@ private static void flushWriteFailures(
}
}
+ /**
+ * Reads a root CA certificate from GCS and returns it as raw bytes.
+ *
+ * @param filePath path to root CA cert in GCS
+ * @return raw contents of cert
+ * @throws RuntimeException thrown if not able to read or parse cert
+ */
+ public static byte[] getCertFromGcsAsBytes(String filePath) throws
IOException {
+ ReadableByteChannel channel = getGcsFileByteChannel(filePath);
+ try (InputStream inputStream = Channels.newInputStream(channel)) {
+ return IOUtils.toByteArray(inputStream);
+ } catch (IOException e) {
+ throw new RuntimeException("Error when reading: " + filePath, e);
+ }
+ }
+
+ /** Handles getting the {@link ReadableByteChannel} for {@code filePath}. */
+ private static ReadableByteChannel getGcsFileByteChannel(String filePath)
throws IOException {
Review Comment:
Yeah, the cert is expected to be a single path. Decided to use
`FileSystems.matchSingleFileSpec(filePath)` instead, since this also checks if
the file path is specifically a single file
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]