UNPKG

@confluentinc/schemaregistry

Version:
46 lines (45 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GcpKmsDriver = void 0; const kms_registry_1 = require("../kms-registry"); const gcp_client_1 = require("./gcp-client"); class GcpKmsDriver { /** * Register the GCP KMS driver with the KMS registry. */ static register() { (0, kms_registry_1.registerKmsDriver)(new GcpKmsDriver()); } getKeyUrlPrefix() { return GcpKmsDriver.PREFIX; } newKmsClient(config, keyUrl) { const uriPrefix = keyUrl != null ? keyUrl : GcpKmsDriver.PREFIX; let accountType = config.get(GcpKmsDriver.ACCOUNT_TYPE); const clientId = config.get(GcpKmsDriver.CLIENT_ID); const clientEmail = config.get(GcpKmsDriver.CLIENT_EMAIL); const privateKeyId = config.get(GcpKmsDriver.PRIVATE_KEY_ID); const privateKey = config.get(GcpKmsDriver.PRIVATE_KEY); let creds; if (clientId != null && clientEmail != null && privateKeyId != null && privateKey != null) { if (accountType == null) { accountType = "service_account"; } creds = { ...accountType && { type: accountType }, private_key_id: privateKeyId, private_key: privateKey, client_email: clientEmail, client_id: clientId, }; } return new gcp_client_1.GcpKmsClient(uriPrefix, creds); } } exports.GcpKmsDriver = GcpKmsDriver; GcpKmsDriver.PREFIX = 'gcp-kms://'; GcpKmsDriver.ACCOUNT_TYPE = "account.type"; GcpKmsDriver.CLIENT_ID = "client.id"; GcpKmsDriver.CLIENT_EMAIL = "client.email"; GcpKmsDriver.PRIVATE_KEY_ID = "private.key.id"; GcpKmsDriver.PRIVATE_KEY = "private.key";