Last active
August 26, 2025 21:06
-
-
Save siberex/fdfc41d2dcc5ccf62d9a816a4eccf325 to your computer and use it in GitHub Desktop.
Snippets for insulalabs.io to put into .zshrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# → https://insulalabs.io/#keys | |
export INSULA_API_KEY=... | |
insi_set() { | |
if [ "$#" -ne 2 ]; then | |
echo "Missing key and/or value. Usage: $0 KEY VALUE" >&2 | |
return 1 | |
fi | |
# Set a value | |
JSON_STRING=$( jq -n \ | |
--arg key "$1" \ | |
--arg value "$2" \ | |
'{key: $key, value: $value}' ) | |
curl --location-trusted -X POST \ | |
https://red.insulalabs.io/db/api/v1/set \ | |
-H "Authorization: Bearer $INSULA_API_KEY" \ | |
-H "Content-Type: application/json" \ | |
-d "$JSON_STRING" | |
} | |
insi_get() { | |
if [ "$#" -ne 1 ]; then | |
echo "Missing key. Usage: $0 KEY" >&2 | |
return 1 | |
fi | |
# Get a value | |
curl -X GET \ | |
"https://red.insulalabs.io/db/api/v1/get?key=$1" \ | |
-H "Authorization: Bearer $INSULA_API_KEY" | |
} | |
insi_list_keys() { | |
# List keys | |
curl --silent --show-error -X GET \ | |
"https://red.insulalabs.io/db/api/v1/iterate/prefix?offset=0&limit=100" \ | |
-H "Authorization: Bearer $INSULA_API_KEY" | jq | |
} | |
insi_save() { | |
if [ "$#" -ne 1 ]; then | |
echo "Missing file path. Usage: $0 /path/to/file" >&2 | |
return 1 | |
fi | |
if [ ! -r "$1" ]; then | |
echo "File $1 is not readable" >&2 | |
return 2 | |
fi | |
fname="${1##*/}" | |
# Upload a blob | |
curl --location-trusted -X POST \ | |
https://red.insulalabs.io/db/api/v1/blob/set \ | |
-H "Authorization: $INSULA_API_KEY" \ | |
-F "key=$fname" \ | |
-F "blob=@$1" | |
} | |
insi_load() { | |
if [ "$#" -ne 1 ]; then | |
echo "Missing filename. Usage: $0 FNAME.TXT" >&2 | |
return 1 | |
fi | |
fname="${1##*/}" | |
# Download a blob to /tmp/$fname | |
curl -X GET \ | |
"https://red.insulalabs.io/db/api/v1/blob/get?key=$fname" \ | |
-H "Authorization: $INSULA_API_KEY" \ | |
-o "/tmp/$fname" | |
} | |
insi_ls() { | |
curl --silent --show-error -X GET \ | |
"https://red.insulalabs.io/db/api/v1/blob/iterate/prefix?offset=0&limit=100" \ | |
-H "Authorization: $INSULA_API_KEY" | jq | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment