UNPKG

@confluentinc/schemaregistry

Version:
55 lines (54 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerKmsDriver = registerKmsDriver; exports.getKmsDriver = getKmsDriver; exports.registerKmsClient = registerKmsClient; exports.getKmsClient = getKmsClient; exports.clearKmsClients = clearKmsClients; const security_exception_1 = require("./tink/exception/security_exception"); const kmsDrivers = []; const kmsClients = []; /** * Register a KMS driver. * @param kmsDriver - the KMS driver to register */ function registerKmsDriver(kmsDriver) { kmsDrivers.push(kmsDriver); } /** * Get the KMS driver for the given key URL. * @param keyUrl - the key URL */ function getKmsDriver(keyUrl) { for (let driver of kmsDrivers) { if (keyUrl.startsWith(driver.getKeyUrlPrefix())) { return driver; } } throw new security_exception_1.SecurityException('no KMS driver found for key URL: ' + keyUrl); } /** * Register a KMS client. * @param kmsClient - the KMS client to register */ function registerKmsClient(kmsClient) { kmsClients.push(kmsClient); } /** * Get the KMS client for the given key URL. * @param keyUrl - the key URL */ function getKmsClient(keyUrl) { for (let client of kmsClients) { if (client.supported(keyUrl)) { return client; } } return null; } /** * Clear the KMS clients. */ function clearKmsClients() { kmsClients.length = 0; }