Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for workers kvs to cli (#13)
This PR adds several subcommands to the workers subcommand. Let's describe how each one works and what they do. *ListWorkersKVNamespaces*: ListWorkersKVNamespaces is implemented in the cf worker list-kv-namespaces. It requires an organization id is passed in to it: ``` $ cf worker list-kv-namespaces --organization-id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb { "success": true, "errors": [], "messages": [], "result": [ { "id": "28511bdf7bff4a9a977dd163078752b9", "title": "testnamespace" } ], "result_info": { "page": 1, "per_page": 20, "total_pages": 1, "count": 1, "total_count": 1 } } ``` *CreateWorkersKVNamespace*: Create a new workers kv namespace. Only requires org id and name. ``` $ cf worker create-kv-namespace --organization-id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb --name testnamespace { "success": true, "errors": [], "messages": [], "result": { "id": "28511bdf7bff4a9a977dd163078752b9", "title": "testnamespace" } } ``` *DeleteWorkersKVNamespace*: DeleteWorkersKVNamespace is implemented in the cf worker delete-kv-namespace. Only requires org id and namespace id It requires an organization id and namespace id are passed in: ``` $ cf worker list-kv-namespaces --organization-id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb --namespace-id 28511bdf7bff4a9a977dd163078752b9 { "success": true, "errors": [], "messages": [] } ``` *UpdateWorkersKVNamespace*: Rename a workers kv namespace. ``` $ cf worker rename-kv-namespace --organization-id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb --namespace-id 28511bdf7bff4a9a977dd163078752b9 --name newtestnamespace { "success": true, "errors": [], "messages": [] } ``` *ListWorkersKVs*: List the keys that are in a specific namespace. ``` $ cf worker list-kvs --organization-id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb --namespace-id 28511bdf7bff4a9a977dd163078752b9 { "success": true, "errors": [], "messages": [], "result": [ { "name": "testkey" } ], "result_info": { "page": 1, "per_page": 20, "total_pages": 1, "count": 1, "total_count": 1 } } ``` *DeleteWorkersKV* Use the cf worker delete-kv command. It requires org id, namespace id, and key. ``` $ cf worker delete-kv --organization-id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb --namespace-id 28511bdf7bff4a9a977dd163078752b9 --key testkey { "success": true, "errors": [], "messages": [] } ``` *ReadWorkersKV*: Implemented in the cf worker get-kv command. It requires org id, namespace id, and key. ReadWorkersKV returns the base64 encoded value. ``` $ cf worker get-kv --organization-id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb --namespace-id 28511bdf7bff4a9a977dd163078752b9 --key testkey "YWRkRXZlbnRMaXN0ZW5lcigiZmV0Y2giLCBldmVudCA9PiB7IAogIGV2ZW50LnJlc3BvbmRXaXRoKG5ldyBSZXNwb25zZSgiaGV5IikpCn0pCg==" ``` *WriteWorkersKV* This is the most special command added, because of the value argument. The value argument supports a few different formats. - _Read from stdin_: If you want cf to read value from stdin, pass a hyphen (-) - _Read from file_: If you want cf to read from a file pass the filename preceeded by an @ like in the example - _Raw_: By default, write-kv will just write whatever you pass to the --value argument The below example shows reading from a file. ``` $ cf worker write-kv --organization-id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb --namespace-id 28511bdf7bff4a9a977dd163078752b9 --key testkey --value @examplefile.json { "success": true, "errors": [], "messages": [] } ``` This is an example of reading from stdin. ``` $ cat examplefile.json | cf worker write-kv --organization-id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb --namespace-id 28511bdf7bff4a9a977dd163078752b9 --key testkey --value - { "success": true, "errors": [], "messages": [] } ``` This is an example of passing the raw value ``` $ cat examplefile.json | cf worker write-kv --organization-id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb --namespace-id 28511bdf7bff4a9a977dd163078752b9 --key testkey --value '{1:2}' { "success": true, "errors": [], "messages": [] } ```
- Loading branch information