-
Notifications
You must be signed in to change notification settings - Fork 19
Feature: Add KV "entry" actions #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
An "entry" is a JSON object with properties. Multiple entries are stored under a JSON serialized object (as created by st2.kv.set_object) in the datastore. You can upsert or delete properties within an entry. And, you can define a fallback entry (which is named "default" by default) to allow getting properties from an entry, and using the fallback entry to provide defaults for any properties that are undfined in the entry. One use-case for objects like this is to store environment-specific (eg dev, stage, prod, etc) variables with global defaults. Each environment would be an entry and "global" could be the fallback entry. The variables would be properties inside the entries. Signed-off-by: Jacob Floyd <[email protected]>
Signed-off-by: Jacob Floyd <[email protected]>
plus fix a few typos Signed-off-by: Jacob Floyd <[email protected]>
It's confusing to have to scroll down in the web UI to remember to include the entry name, so make it required, and use position to tell the webui order the params should be shown in. Signed-off-by: Jacob Floyd <[email protected]>
Group them under st2.kv.entry.* Signed-off-by: Jacob Floyd <[email protected]>
Signed-off-by: Jacob Floyd <[email protected]>
Just curious - why "upsert_property" instead of just "set_property" - I think a set would be normally considered an add or update if exists function. |
set_property would be more consistent with the others. My original reasons for selecting upsert instead of set don't apply now because I refactored before submitting the PR :P Before I had upsert_entry_property (instead of entry.upsert_property) - trying to indicate that it was being inserted or updated within the entry. I think I'll just rename it to set for consistency :) |
Signed-off-by: Jacob Floyd <[email protected]>
Updated to use set instead of upsert. |
An "entry" is a JSON object with properties. Multiple entries are stored under a JSON serialized object (as created by st2.kv.set_object) in the datastore. When you retrieve an "entry", you can specify a fallback "entry" to use for defaults.
For example, consider this object:
If you retrieve
myentry
with thedefault
fallback, you would get this object:These are the new actions:
kv.entry.get
- Retrieve entry in a JSON serialized object from the datastore. An entry is a standard JSON object with properties.kv.entry.set_property
- Update or insert a property in the named entry of a JSON serialized object. Then, serialize and store the updated object. The property's value may be any json-serializable type.kv.entry.append_property
- Add the value to the end of an array property in the named entry of a JSON serialized object. Then, serialize and store the updated object. The property must be an array. The value to append can be anything.kv.entry.delete_property
- Delete a property from a named entry of a JSON serialized object in the datastore. If the entry is empty, delete it as well.Since more than one action could edit the same KV object at the same time, the edit actions (
set_property
,append_property
, anddelete_property
) all use a distributed lock through the coordination backend (if configured) to serialize edits.My use-case:
I am using this as to provide environment specific config in the datastore. So, I have something like these entries:
default
(the fallback),prod
,stage
,qa
,dev
. Then various actions or workflows just need to get the entry for the environment they're working with, and not have to worry about selecting from a different default object if it a var is undefined for that environment (The YAQL for selecting from multiple objects like that gets really ugly really fast).This pattern of config with defaults seems common, so am submitting this as part of the st2 pack to make the datastore an even more useful tool with less effort.