diff --git a/bin/getcredentials b/bin/getcredentials index 2b7e32b..6126a9b 100755 --- a/bin/getcredentials +++ b/bin/getcredentials @@ -1,72 +1,72 @@ #!/bin/sh # # Gets credentials information from Phabricator Passphrase application # # Usage: getcredentials <id> [data] # # - id: an integer matching the credential ID on Passphrase # e.g. 17 for K17 # - data: the property to retrieve # password, username, token or title # If omitted, the password will be retrieved # # This script requires: # - arc to communicate with Phabricator through the conduit API # - jq to parse JSON # # Arc is expected to be configured. It generally means there is an ~/.arcrc file # with a conduit certificate and the Phabricator instance URL. Please note the # relevant user must have access to the credentials. The easiest way to achieve # that is to create a dedicated bot/script user, a group, and add both user and # credentials to this group. # # # Configuration # # The maximal credential ID MAX_ID=2037 # # Checks arguments # if [ $# -lt 1 ] then echo "Usage: getcredentials <id> [password|username|title]" exit 1 fi if echo $1 | egrep -q '^[0-9]+$'; then ID=$1 else echo "A positive integer id is expected." exit 2 fi if [ "${#ID}" -gt "${#MAX_ID}" ] || [ "$ID" -gt "$MAX_ID" ] then echo "The id must be equal or lesser than $MAX_ID." exit 4 fi if [ $# -gt 1 ] then case "$2" in title) PROPERTY="name" ;; username) PROPERTY="username" ;; password) PROPERTY="material.password?" ;; token) PROPERTY="material.token" ;; *) echo "Unknown property" ; exit 8 ;; esac else PROPERTY="material.password?" fi # # Queries DevCentral -# +# echo "{\"ids\": [$ID], \"needPublicKeys\": true, \"needSecrets\": true}" | arc call-conduit passphrase.query | jq --raw-output ".response.data[].$PROPERTY"