private KeySupplier createKeySupplier()

in encryption/src/main/java/org/apache/solr/encryption/kms/KmsKeySupplier.java [278:307]


        private KeySupplier createKeySupplier(NamedList<?> args, CoreContainer coreContainer) {
            KmsMetrics kmsMetrics = null;
            KmsClient kmsClient = null;
            KmsKeyCache kmsKeyCache = null;
            boolean success = false;
            try {
                kmsMetrics = createEncryptionMetrics(coreContainer);
                KmsClient.Factory kmsClientFactory = getKmsClientFactory(args, coreContainer);
                kmsClient = kmsClientFactory.create(args);
                kmsKeyCache = createKeyCache(getKeyCacheExpiration(args));
                KeySupplier keySupplier = createKeySupplier(kmsClient, kmsKeyCache, kmsMetrics);
                log.info("KmsKeySupplier singleton created");
                success = true;
                return keySupplier;
            } catch (Throwable t) {
                // If something fails during the creation of the KMS client, return an InvalidKeySupplier.
                // That way, Solr can be used normally if the encryption is not used.
                // But any attempt to use the InvalidKeySupplier will throw an exception with the root cause.
                log.error("Failed to create the key supplier; encryption is not available", t);
                return new InvalidKeySupplier(t);
            } finally {
                if (!success) {
                    IOUtils.closeQuietly(kmsClient);
                    IOUtils.closeQuietly(kmsKeyCache);
                    if (kmsMetrics != null) {
                        kmsMetrics.incFailedKmsInit();
                    }
                }
            }
        }