SDA Commons Server Key Management¶
Bundle for key management in microservices.
The main purpose is to provide configurable key management and mappings for keys and its values. This allows to define keys and mappings at deployment time and not at development time. So the actual keys can be adjusted according to the deployment scenario.
The bundle also provides the annotation @PlatformKey("<keyName>")
to mark a String attribute to contain a valid key value.
When defining keys at runtime, it might happen that keys used in business logic do not exist at runtime. This problem is not solved by the bundle. It must be considered as part of the key definition process.
The bundle provides means to work with keys as well as to retrieve mapping values from or to a possible implementation depending on the keys. This includes * checking if a key is valid * checking if a value is valid for a given key * mapping of a key between API and implementation specific values
API keys and values should be defined in snake case. For these two values, the bundle will be case tolerant, by mapping to uppercase internally. For implementations specific values, the bundle must not be case tolerant to provide keys as expected.
The mapping between API and implementation of an API is necessary to define APIs completely independent of a concrete implementation.
For example, when wrapping an API that fits into the platform around an existing implementation.
Therefore, every value mapping consists of an api
and an implementation
value.
The bundle provides a "pass through" default behavior for keys and mappings that are not known. This means, that the original value is just passed instead of being mapped. There is just a warning in the log files.
This fail strategy can be configured as part of the builder. There is another fail strategy implemented (FAIL_WITH_EXCEPTION
),
that throws an IllegalArgumentException
when no mapping can be found with no log message.
Furthermore, there are three other fail strategies (PLACEHOLDER_BIDIRECTIONAL
, PLACEHOLDER_API_TO_IMPL
, PLACEHOLDER_IMPL_TO_API
)
which insert a placeholder value ("UNKNOWN_KEY_VALUE") and emit a warning if there's no available mapping.
PLACEHOLDER_BIDIRECTIONAL
performs this substitution in both directions. PLACEHOLDER_API_TO_IMPL
only in the direction from api to implementation, and PLACEHOLDER_IMPL_TO_API
only in the
direction from implementation to api. (If no substitution is performed, the mapper continues to
throw an IllegalArgumentException
for unmappable values.)
Usage¶
1 |
|
Initialization of bundle:
1 2 3 4 5 |
|
The configuration includes the paths to the mapping and keys yaml files as well as the option to disable value validation.
The following listing shows a yaml snippet for the keyMgmt
configuration.
1 2 3 4 |
|
@PlatformKey¶
The annotation @PlatformKey
will trigger a validator to verify if the received value is a valid key for the referenced platform key.
1 2 |
|
@PlatformKeys¶
The annotation @PlatformKeys
will trigger a validator to verify if the received value is a valid key within a list of referenced platform keys.
1 2 |
|
Key yaml file¶
The yaml file or keys may contain one or more KeyDefinition documents.
Example:
1 2 3 4 5 6 7 8 9 |
|
Mapping yaml file¶
The yaml file for mappings may contain one or more KeyMappingModel documents.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|