Merge branch 'rsotnychenko-update-gcloud'

pull/411/head
romkatv 5 years ago
commit 61c268f7ae

@ -67,7 +67,8 @@
aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html)
# aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) # aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/)
# azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) # azure # azure account name (https://docs.microsoft.com/en-us/cli/azure)
# gcloud # google cloud acccount and project (https://cloud.google.com/) # gcloud # google cloud cli acccount and project (https://cloud.google.com/)
# gcloud_app # google cloud application credentials (https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable)
context # user@hostname context # user@hostname
nordvpn # nordvpn connection status, linux only (https://nordvpn.com/) nordvpn # nordvpn connection status, linux only (https://nordvpn.com/)
ranger # ranger shell (https://github.com/ranger/ranger) ranger # ranger shell (https://github.com/ranger/ranger)
@ -785,6 +786,23 @@
# Custom icon. # Custom icon.
# typeset -g POWERLEVEL9K_GCLOUD_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_GCLOUD_VISUAL_IDENTIFIER_EXPANSION='⭐'
##########[ gcloud_app: google cloud application credentials (https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable) ]###########
# Google cloud color.
typeset -g POWERLEVEL9K_GCLOUD_APP_FOREGROUND=32
# Google cloud format. Uncomment POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION and edit its value if the
# default is too verbose.
#
# P9K_GCLOUD_APP_EMAIL: `.client_email` field of keyfile
# P9K_GCLOUD_APP_ACCOUNT_TYPE: `.type` field of keyfile
# P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT: `sa` if `type=service_account`, empty otherwise
# ${VARIABLE//\%/%%}: ${VARIABLE} with all occurences of '%' replaced with '%%'.
#
# typeset -g POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION='${P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT//\%/%%}${P9K_GCLOUD_APP_EMAIL//\%/%%}'
# Custom icon.
# typeset -g POWERLEVEL9K_GCLOUD_APP_VISUAL_IDENTIFIER_EXPANSION='⭐'
#############[ kubecontext: current kubernetes context (https://kubernetes.io/) ]############# #############[ kubecontext: current kubernetes context (https://kubernetes.io/) ]#############
# Kubernetes context classes for the purpose of using different colors, icons and expansions with # Kubernetes context classes for the purpose of using different colors, icons and expansions with
# different contexts. # different contexts.

@ -67,7 +67,8 @@
aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html)
# aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) # aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/)
# azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) # azure # azure account name (https://docs.microsoft.com/en-us/cli/azure)
# gcloud # google cloud acccount and project (https://cloud.google.com/) # gcloud # google cloud cli acccount and project (https://cloud.google.com/)
# gcloud_app # google cloud application credentials (https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable)
context # user@hostname context # user@hostname
nordvpn # nordvpn connection status, linux only (https://nordvpn.com/) nordvpn # nordvpn connection status, linux only (https://nordvpn.com/)
ranger # ranger shell (https://github.com/ranger/ranger) ranger # ranger shell (https://github.com/ranger/ranger)
@ -842,6 +843,23 @@
# Custom icon. # Custom icon.
# typeset -g POWERLEVEL9K_GCLOUD_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_GCLOUD_VISUAL_IDENTIFIER_EXPANSION='⭐'
##########[ gcloud_app: google cloud application credentials (https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable) ]###########
# Google cloud color.
typeset -g POWERLEVEL9K_GCLOUD_APP_FOREGROUND=32
# Google cloud format. Uncomment POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION and edit its value if the
# default is too verbose.
#
# P9K_GCLOUD_APP_EMAIL: `.client_email` field of keyfile
# P9K_GCLOUD_APP_ACCOUNT_TYPE: `.type` field of keyfile
# P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT: `sa` if `type=service_account`, empty otherwise
# ${VARIABLE//\%/%%}: ${VARIABLE} with all occurences of '%' replaced with '%%'.
#
# typeset -g POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION='${P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT//\%/%%}${P9K_GCLOUD_APP_EMAIL//\%/%%}'
# Custom icon.
# typeset -g POWERLEVEL9K_GCLOUD_APP_VISUAL_IDENTIFIER_EXPANSION='⭐'
###############################[ public_ip: public IP address ]############################### ###############################[ public_ip: public IP address ]###############################
# Public IP color. # Public IP color.
typeset -g POWERLEVEL9K_PUBLIC_IP_FOREGROUND=94 typeset -g POWERLEVEL9K_PUBLIC_IP_FOREGROUND=94

@ -67,7 +67,8 @@
aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html)
# aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) # aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/)
# azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) # azure # azure account name (https://docs.microsoft.com/en-us/cli/azure)
# gcloud # google cloud acccount and project (https://cloud.google.com/) # gcloud # google cloud cli acccount and project (https://cloud.google.com/)
# gcloud_app # google cloud application credentials (https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable)
context # user@hostname context # user@hostname
nordvpn # nordvpn connection status, linux only (https://nordvpn.com/) nordvpn # nordvpn connection status, linux only (https://nordvpn.com/)
ranger # ranger shell (https://github.com/ranger/ranger) ranger # ranger shell (https://github.com/ranger/ranger)
@ -810,6 +811,23 @@
# Custom icon. # Custom icon.
# typeset -g POWERLEVEL9K_GCLOUD_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_GCLOUD_VISUAL_IDENTIFIER_EXPANSION='⭐'
##########[ gcloud_app: google cloud application credentials (https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable) ]###########
# Google cloud color.
typeset -g POWERLEVEL9K_GCLOUD_APP_FOREGROUND=32
# Google cloud format. Uncomment POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION and edit its value if the
# default is too verbose.
#
# P9K_GCLOUD_APP_EMAIL: `.client_email` field of keyfile
# P9K_GCLOUD_APP_ACCOUNT_TYPE: `.type` field of keyfile
# P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT: `sa` if `type=service_account`, empty otherwise
# ${VARIABLE//\%/%%}: ${VARIABLE} with all occurences of '%' replaced with '%%'.
#
# typeset -g POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION='${P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT//\%/%%}${P9K_GCLOUD_APP_EMAIL//\%/%%}'
# Custom icon.
# typeset -g POWERLEVEL9K_GCLOUD_APP_VISUAL_IDENTIFIER_EXPANSION='⭐'
#############[ kubecontext: current kubernetes context (https://kubernetes.io/) ]############# #############[ kubecontext: current kubernetes context (https://kubernetes.io/) ]#############
# Kubernetes context classes for the purpose of using different colors, icons and expansions with # Kubernetes context classes for the purpose of using different colors, icons and expansions with
# different contexts. # different contexts.

@ -3379,7 +3379,6 @@ prompt_azure() {
prompt_gcloud() { prompt_gcloud() {
unset P9K_GCLOUD_PROJECT P9K_GCLOUD_ACCOUNT unset P9K_GCLOUD_PROJECT P9K_GCLOUD_ACCOUNT
(( $+commands[gcloud] )) || return (( $+commands[gcloud] )) || return
local cfg=${AZURE_CONFIG_DIR:-$HOME/.azure}/azureProfile.json
if ! _p9k_cache_stat_get $0 ~/.config/gcloud/active_config ~/.config/gcloud/configurations/config_default; then if ! _p9k_cache_stat_get $0 ~/.config/gcloud/active_config ~/.config/gcloud/configurations/config_default; then
_p9k_cache_stat_set "$(gcloud config get-value account 2>/dev/null)" "$(gcloud config get-value project 2>/dev/null)" _p9k_cache_stat_set "$(gcloud config get-value account 2>/dev/null)" "$(gcloud config get-value project 2>/dev/null)"
fi fi
@ -3389,6 +3388,29 @@ prompt_gcloud() {
_p9k_prompt_segment "$0" "blue" "white" "GCLOUD_ICON" 0 '' "${P9K_GCLOUD_ACCOUNT//\%/%%}:${P9K_GCLOUD_PROJECT//\%/%%}" _p9k_prompt_segment "$0" "blue" "white" "GCLOUD_ICON" 0 '' "${P9K_GCLOUD_ACCOUNT//\%/%%}:${P9K_GCLOUD_PROJECT//\%/%%}"
} }
prompt_gcloud_app() {
unset P9K_GCLOUD_APP_EMAIL P9K_GCLOUD_APP_ACCOUNT_TYPE P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT
(( $+commands[gcloud] )) || return
[[ ! -z $GOOGLE_APPLICATION_CREDENTIALS ]] || return
if ! _p9k_cache_stat_get $0 $GOOGLE_APPLICATION_CREDENTIALS; then
local email="$(cat $GOOGLE_APPLICATION_CREDENTIALS | jq -r '.client_email')"
local account_type="$(cat $GOOGLE_APPLICATION_CREDENTIALS | jq -r '.type')"
local account_type_short
if [[ "$account_type" == "service_account" ]]; then
account_type_short="sa:"
fi
# Service account name may contain only alpha-numeric chars and hyphens, so splitting by `.` gives us `service-account-name@project-id`
_p9k_cache_stat_set "${email%%.*}" "$account_type" "$account_type_short"
fi
[[ -n $_p9k_cache_val[1] || -n $_p9k_cache_val[2] || -n $_p9k_cache_val[3] ]] || return
P9K_GCLOUD_APP_EMAIL=$_p9k_cache_val[1]
P9K_GCLOUD_APP_ACCOUNT_TYPE=$_p9k_cache_val[2]
P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT=$_p9k_cache_val[3]
_p9k_prompt_segment "$0" "blue" "white" "GCLOUD_ICON" 0 '' "${P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT//\%/%%}${P9K_GCLOUD_APP_EMAIL//\%/%%}"
}
typeset -gra __p9k_nordvpn_tag=( typeset -gra __p9k_nordvpn_tag=(
P9K_NORDVPN_STATUS P9K_NORDVPN_STATUS
P9K_NORDVPN_TECHNOLOGY P9K_NORDVPN_TECHNOLOGY

Loading…
Cancel
Save