feat(cassandra): add TLS store support
This commit is contained in:
26 files changed
+1203
-36
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildCassandraExternalConfig, cassandraTlsConfigFromExternalConfig } from "../cassandraTlsOptions";
|
||||
|
||||
describe("Cassandra TLS options", () => {
|
||||
it("reads validated truststore and keystore fields", () => {
|
||||
expect(
|
||||
cassandraTlsConfigFromExternalConfig({
|
||||
tls: {
|
||||
truststore_path: "/certs/client.truststore",
|
||||
truststore_password: "trust-secret",
|
||||
keystore_path: "/certs/client.keystore",
|
||||
keystore_password: "key-secret",
|
||||
ignored: true,
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
truststore_path: "/certs/client.truststore",
|
||||
truststore_password: "trust-secret",
|
||||
keystore_path: "/certs/client.keystore",
|
||||
keystore_password: "key-secret",
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores malformed external values", () => {
|
||||
expect(cassandraTlsConfigFromExternalConfig({ tls: { truststore_path: 42 } })).toEqual({
|
||||
truststore_path: "",
|
||||
truststore_password: "",
|
||||
keystore_path: "",
|
||||
keystore_password: "",
|
||||
});
|
||||
});
|
||||
|
||||
it("trims paths without changing passwords", () => {
|
||||
expect(
|
||||
buildCassandraExternalConfig({
|
||||
truststore_path: " /certs/client.p12 ",
|
||||
truststore_password: " trust-secret ",
|
||||
keystore_path: " /certs/client.jks ",
|
||||
keystore_password: " key-secret ",
|
||||
}),
|
||||
).toEqual({
|
||||
tls: {
|
||||
truststore_path: "/certs/client.p12",
|
||||
truststore_password: " trust-secret ",
|
||||
keystore_path: "/certs/client.jks",
|
||||
keystore_password: " key-secret ",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("omits empty TLS store configuration", () => {
|
||||
expect(
|
||||
buildCassandraExternalConfig({
|
||||
truststore_path: "",
|
||||
truststore_password: "",
|
||||
keystore_path: "",
|
||||
keystore_password: "",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
export interface CassandraTlsConfig {
|
||||
truststore_path: string;
|
||||
truststore_password: string;
|
||||
keystore_path: string;
|
||||
keystore_password: string;
|
||||
}
|
||||
|
||||
export interface CassandraExternalConfig {
|
||||
tls: CassandraTlsConfig;
|
||||
}
|
||||
|
||||
function stringField(value: unknown, key: keyof CassandraTlsConfig): string {
|
||||
if (!value || typeof value !== "object") return "";
|
||||
const field = (value as Record<string, unknown>)[key];
|
||||
return typeof field === "string" ? field : "";
|
||||
}
|
||||
|
||||
export function cassandraTlsConfigFromExternalConfig(value: unknown): CassandraTlsConfig {
|
||||
const tls = value && typeof value === "object" ? (value as Record<string, unknown>).tls : undefined;
|
||||
return {
|
||||
truststore_path: stringField(tls, "truststore_path"),
|
||||
truststore_password: stringField(tls, "truststore_password"),
|
||||
keystore_path: stringField(tls, "keystore_path"),
|
||||
keystore_password: stringField(tls, "keystore_password"),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildCassandraExternalConfig(tls: CassandraTlsConfig): CassandraExternalConfig | undefined {
|
||||
const truststorePath = tls.truststore_path.trim();
|
||||
const keystorePath = tls.keystore_path.trim();
|
||||
if (!truststorePath && !tls.truststore_password && !keystorePath && !tls.keystore_password) return undefined;
|
||||
return {
|
||||
tls: {
|
||||
truststore_path: truststorePath,
|
||||
truststore_password: tls.truststore_password,
|
||||
keystore_path: keystorePath,
|
||||
keystore_password: tls.keystore_password,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user