Created
May 12, 2017 17:42
-
-
Save knksmith57/5576678a22a570a955beb433cdcfa868 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
set -eo pipefail | |
## | |
## extract .netrc creds inspired by https://bugs.launchpad.net/python-jenkins/+bug/941400 | |
## | |
## usage: | |
## netrc_credentials example.com # // 'myuser mypassword' | |
## netrc_credentials example.com username # // 'myuser' | |
## netrc_credentials example.com password # // 'mypassword' | |
## | |
: ${1:?'domain must be provided via positional argument #1'} | |
username_password="$(echo -e "import netrc\nusername, _, password = netrc.netrc().authenticators('$1')\nprint '{} {}'.format(username, password)" | python 2>/dev/null)" | |
if [[ $2 == u* ]]; then | |
awk '{print $1}' <<< "${username_password}" | |
elif [[ $2 == p* ]]; then | |
awk '{print $2}' <<< "${username_password}" | |
else | |
echo "${username_password}" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment