Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get-password for gce #4097

Merged
merged 1 commit into from
Feb 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions cluster/gce/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,26 @@ function detect-master () {
}

# Ensure that we have a password created for validating to the master. Will
# read from $HOME/.kubernetres_auth if available.
# read from the kubernetes auth-file for the current context if available.
#
# Assumed vars
# KUBE_ROOT
#
# Vars set:
# KUBE_USER
# KUBE_PASSWORD
function get-password {
local file="$HOME/.kubernetes_auth"
local get_auth_path='''
import yaml, sys
cfg = yaml.load(sys.stdin)
try:
current = cfg["current-context"]
user = cfg["contexts"][current]["user"]
print cfg["users"][user]["auth-path"]
except KeyError:
pass
'''
local file=$("${KUBE_ROOT}/cluster/kubectl.sh" config view --global | python -c "${get_auth_path}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to express my displeasure at inline python for this solution, but it's the most readable inline python in our codebase so far.

Something something need a YAML splitter for bash blah blah rant rant except this should be in go anyways LGTM.

if [[ -r "$file" ]]; then
KUBE_USER=$(cat "$file" | python -c 'import json,sys;print json.load(sys.stdin)["User"]')
KUBE_PASSWORD=$(cat "$file" | python -c 'import json,sys;print json.load(sys.stdin)["Password"]')
Expand Down