Last active
December 26, 2018 12:15
-
-
Save nttuyen/31263f9b1919433d95c65223fe3e68ae to your computer and use it in GitHub Desktop.
This file contains 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
#!/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