Class KeyValService
java.lang.Object
com.tccc.kos.commons.util.ready.ReadyBean
com.tccc.kos.commons.core.service.AbstractService
com.tccc.kos.commons.core.service.keyval.KeyValService
- All Implemented Interfaces:
CtxEventListener
,ContextHandleAware
,HandleAware
,Ready
,ReadyListener
Key/val storage service. This supports encryption of selected key values. The encryption
is only as good as the source of the key and where the key is stored. For the most part
encryption is used to obscure bits of data that shouldn't be trivially accessible
such as api keys, auth tokens and such.
- Version:
- 2022-09-15
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionKeyValService
(String key, byte[] salt) Create storage with the specified key/salt for encrypted entries. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Return true if the specified key exists.Get the value of the specified key.<T> T
Get the value of the specified key and convert the string to an instance of the specified type.Return all key/val pairs in the specified name space.Return all key/val pairs in the specified name space, deserializing all values to instances of the specified type.getAllKeys
(String ns) Return all keys in the specified name space.byte[]
Get the value of the specified key as a blob.getNameSpace
(String ns) Return aKeyValNameSpace
for the specified name space.void
Remove the specified key/val.void
Remove all the key/vals in the specified name space.void
Set the value of the specified key.void
Set the value of the specified key with optional encryption.void
Set the value of the specified key to the specified blob.void
Set the value of the specified key to the specified blob with optional encryption.void
Set the value of the specified key to the json of the specified value object.void
Set the value of the specified key to the json of the specified value object with optional encryption.Methods inherited from class com.tccc.kos.commons.core.service.AbstractService
getHandle, getHandlePrefix
Methods inherited from class com.tccc.kos.commons.util.ready.ReadyBean
getReady, onBeanReady, onDependenciesReady
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.tccc.kos.commons.core.context.CtxEventListener
onCtxAutowiringCompleted, onCtxDestroyed, onCtxPhaseCompleted
Methods inherited from interface com.tccc.kos.commons.core.service.handle.HandleAware
addHandleChild, getName, getPath
Methods inherited from interface com.tccc.kos.commons.util.ready.ReadyListener
onDependenciesGroupReady
-
Field Details
-
KOS_NAME_SPACE
- See Also:
-
-
Constructor Details
-
KeyValService
Create storage with the specified key/salt for encrypted entries.- Parameters:
key
- the crypto keysalt
- the crypto salt
-
-
Method Details
-
set
Set the value of the specified key with optional encryption.- Parameters:
ns
- the name space of the keyname
- the key nameval
- the valueencrypted
- if true, encrypt the value
-
set
Set the value of the specified key.- Parameters:
ns
- the name space of the keyname
- the key nameval
- the value
-
setObj
Set the value of the specified key to the json of the specified value object.- Parameters:
ns
- the name space of the keyname
- the key nameval
- the object to convert to json and store
-
setObj
Set the value of the specified key to the json of the specified value object with optional encryption.- Parameters:
ns
- the name space of the keyname
- the key nameval
- the object to convert to json and storeencrypted
- if true, encrypt the data in storage
-
setBlob
Set the value of the specified key to the specified blob.- Parameters:
ns
- the name space of the keyname
- the key nameval
- the array of bytes to store
-
setBlob
Set the value of the specified key to the specified blob with optional encryption.- Parameters:
ns
- the name space of the keyname
- the key nameval
- the object to convert to json and storeencrypted
- if true, encrypt the data in storage
-
exists
Return true if the specified key exists.- Parameters:
ns
- the name space of the keyname
- the key name
-
get
Get the value of the specified key. If the value is encrypted it will automatically be decrypted.- Parameters:
ns
- the name space of the keyname
- the key name
-
get
Get the value of the specified key and convert the string to an instance of the specified type. If the value is encrypted it will automatically be decrypted.- Parameters:
ns
- the name space of the keyname
- the key nameclazz
- the type to convert the value to- Throws:
Exception
-
getBlob
Get the value of the specified key as a blob. This is only valid for fetching values that were stored usingsetBlob()
.- Parameters:
ns
- the name space of the keyname
- the key name- Throws:
Exception
-
remove
Remove the specified key/val.- Parameters:
ns
- the ns of the keyname
- the key name
-
getAllKeys
Return all keys in the specified name space.- Parameters:
ns
- the name space to return data for
-
getAll
Return all key/val pairs in the specified name space.- Parameters:
ns
- the name space to return data for
-
getAll
Return all key/val pairs in the specified name space, deserializing all values to instances of the specified type.- Parameters:
ns
- the name space to return data for
-
removeAll
Remove all the key/vals in the specified name space.- Parameters:
ns
- the name space of the key
-
getNameSpace
Return aKeyValNameSpace
for the specified name space. This provides access to all the same storage api's but without the need to specify the name space argument. Each call to this method will return a new instance ofKeyValNameSpace
. Nothing is stored inKeyValNameSpace
so the instances will be fully interoperable.
-