KeyManagementServices

Factory for creating KeyManagementService instances.

Provides a simple API that hides ServiceLoader complexity and makes it easy to create KMS instances by provider name.

Instance Caching: KMS instances are cached based on provider name and configuration. This means calling create() with the same provider and configuration will return the same instance, avoiding expensive client initialization overhead.

Resource Management: Cached instances that implement AutoCloseable are automatically closed when shutdown is called or when the JVM shuts down. Call shutdown explicitly to ensure proper cleanup of resources.

Example with Typed Configuration:

import org.trustweave.awskms.awsKmsOptions

val kms = KeyManagementServices.create("aws", awsKmsOptions {
region = "us-east-1"
})

Example with Map Configuration:

val kms = KeyManagementServices.create("aws", mapOf(
"region" to "us-east-1"
))

Functions

Link copied to clipboard

Gets all available provider names.

Link copied to clipboard

Clears the instance cache.

Link copied to clipboard
fun create(providerName: String, options: Map<String, Any?> = emptyMap()): KeyManagementService

Creates a KeyManagementService instance for the specified provider (Map-based).

Creates a KeyManagementService instance for the specified provider.

Link copied to clipboard

Gets the current cache size (for testing/debugging).

Link copied to clipboard

Gets a provider by name (for advanced use cases).

Link copied to clipboard

Checks if the factory has been shut down.

Link copied to clipboard

Resets the shutdown state for testing purposes only. This method should not be used in production code.

Link copied to clipboard
fun shutdown()

Shuts down the factory and closes all cached KMS instances that implement AutoCloseable.