Skip to content

Instantly share code, notes, and snippets.

@nttuyen
Last active December 26, 2018 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nttuyen/31263f9b1919433d95c65223fe3e68ae to your computer and use it in GitHub Desktop.
Save nttuyen/31263f9b1919433d95c65223fe3e68ae to your computer and use it in GitHub Desktop.
#!/bin/bash
#nttuyen
USER_ID=47054
cache_file=/tmp/key_cache
function dl_keys {
curl -m 10 -sf https://gitlab.com/api/v4/users/$1/keys | jq -r '.[].key'
}
function cache_keys() {
dl_keys $USER_ID > $cache_file
}
if [[ -f $cache_file ]]; then
# only re-cache every 5 minutes
if [ $(($(date +"%s") - $(stat -c %Y $cache_file))) -gt 300 ]; then
rm $cache_file
cache_keys
fi
else
cache_keys
fi
# return contents of cache
if [[ -f $cache_file ]]; then cat $cache_file; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment