rename gcloud_app to google_app_cred and change its api

pull/411/head
romkatv 5 years ago
parent 61c268f7ae
commit 8ef2b737d1

@ -68,7 +68,7 @@
# 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 cli 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) # google_app_cred # google application credentials (https://cloud.google.com/docs/authentication/production)
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)
@ -786,22 +786,35 @@
# 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_app_cred: google application credentials (https://cloud.google.com/docs/authentication/production) ]#
# Google cloud color. # Default google application credentials color.
typeset -g POWERLEVEL9K_GCLOUD_APP_FOREGROUND=32 typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_FOREGROUND=32
# Google application credentials color for service accounts.
# typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_SERVICE_ACCOUNT_FOREGROUND=32
# Google cloud format. Uncomment POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION and edit its value if the # Google application credentials format. Uncomment POWERLEVEL9K_GOOGLE_APP_CRED_CONTENT_EXPANSION
# default is too verbose. # and edit its value if the default is too verbose. You can use the following parameters in the
# expansion. Each of them corresponds to one of the fields in the JSON file pointed to by
# GOOGLE_APPLICATION_CREDENTIALS.
# #
# P9K_GCLOUD_APP_EMAIL: `.client_email` field of keyfile # Parameter | JSON key file field
# P9K_GCLOUD_APP_ACCOUNT_TYPE: `.type` field of keyfile # ---------------------------------+---------------
# P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT: `sa` if `type=service_account`, empty otherwise # P9K_GOOGLE_APP_CRED_TYPE | type
# ${VARIABLE//\%/%%}: ${VARIABLE} with all occurences of '%' replaced with '%%'. # P9K_GOOGLE_APP_CRED_PROJECT_ID | project_id
# P9K_GOOGLE_APP_CRED_CLIENT_EMAIL | client_email
# #
# typeset -g POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION='${P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT//\%/%%}${P9K_GCLOUD_APP_EMAIL//\%/%%}' # Note: ${VARIABLE%%.*} expands to ${VARIABLE} up to but not including the first period ('.').
# Note: ${VARIABLE//\%/%%} expands to ${VARIABLE} with all occurences of '%' replaced with '%%'.
#
# typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_CONTENT_EXPANSION='${${P9K_GOOGLE_APP_CRED_CLIENT_EMAIL%%.*}//\%/%%}'
#
# You can also define content expansion specifically for service accounts by defining
# POWERLEVEL9K_GOOGLE_APP_CRED_SERVICE_ACCOUNT_CONTENT_EXPANSION.
# Custom icon. # Default google application credentials icon.
# typeset -g POWERLEVEL9K_GCLOUD_APP_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_VISUAL_IDENTIFIER_EXPANSION='⭐'
# Google application credentials icon for service accounts.
# typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_SERVICE_ACCOUNT_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

@ -68,7 +68,7 @@
# 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 cli 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) # google_app_cred # google application credentials (https://cloud.google.com/docs/authentication/production)
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)
@ -843,22 +843,35 @@
# 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_app_cred: google application credentials (https://cloud.google.com/docs/authentication/production) ]#
# Google cloud color. # Default google application credentials color.
typeset -g POWERLEVEL9K_GCLOUD_APP_FOREGROUND=32 typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_FOREGROUND=32
# Google application credentials color for service accounts.
# typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_SERVICE_ACCOUNT_FOREGROUND=32
# Google cloud format. Uncomment POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION and edit its value if the # Google application credentials format. Uncomment POWERLEVEL9K_GOOGLE_APP_CRED_CONTENT_EXPANSION
# default is too verbose. # and edit its value if the default is too verbose. You can use the following parameters in the
# expansion. Each of them corresponds to one of the fields in the JSON file pointed to by
# GOOGLE_APPLICATION_CREDENTIALS.
# #
# P9K_GCLOUD_APP_EMAIL: `.client_email` field of keyfile # Parameter | JSON key file field
# P9K_GCLOUD_APP_ACCOUNT_TYPE: `.type` field of keyfile # ---------------------------------+---------------
# P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT: `sa` if `type=service_account`, empty otherwise # P9K_GOOGLE_APP_CRED_TYPE | type
# ${VARIABLE//\%/%%}: ${VARIABLE} with all occurences of '%' replaced with '%%'. # P9K_GOOGLE_APP_CRED_PROJECT_ID | project_id
# P9K_GOOGLE_APP_CRED_CLIENT_EMAIL | client_email
# #
# typeset -g POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION='${P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT//\%/%%}${P9K_GCLOUD_APP_EMAIL//\%/%%}' # Note: ${VARIABLE%%.*} expands to ${VARIABLE} up to but not including the first period ('.').
# Note: ${VARIABLE//\%/%%} expands to ${VARIABLE} with all occurences of '%' replaced with '%%'.
#
# typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_CONTENT_EXPANSION='${${P9K_GOOGLE_APP_CRED_CLIENT_EMAIL%%.*}//\%/%%}'
#
# You can also define content expansion specifically for service accounts by defining
# POWERLEVEL9K_GOOGLE_APP_CRED_SERVICE_ACCOUNT_CONTENT_EXPANSION.
# Custom icon. # Default google application credentials icon.
# typeset -g POWERLEVEL9K_GCLOUD_APP_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_VISUAL_IDENTIFIER_EXPANSION='⭐'
# Google application credentials icon for service accounts.
# typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_SERVICE_ACCOUNT_VISUAL_IDENTIFIER_EXPANSION='⭐'
###############################[ public_ip: public IP address ]############################### ###############################[ public_ip: public IP address ]###############################
# Public IP color. # Public IP color.

@ -68,7 +68,7 @@
# 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 cli 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) # google_app_cred # google application credentials (https://cloud.google.com/docs/authentication/production)
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)
@ -811,22 +811,37 @@
# 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_app_cred: google application credentials (https://cloud.google.com/docs/authentication/production) ]#
# Google cloud color. # Default google application credentials color.
typeset -g POWERLEVEL9K_GCLOUD_APP_FOREGROUND=32 # typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_FOREGROUND=7
# typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_BACKGROUND=4
# Google cloud format. Uncomment POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION and edit its value if the # Google application credentials color for service accounts.
# default is too verbose. # typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_SERVICE_ACCOUNT_FOREGROUND=7
# typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_SERVICE_ACCOUNT_BACKGROUND=4
# Google application credentials format. Uncomment POWERLEVEL9K_GOOGLE_APP_CRED_CONTENT_EXPANSION
# and edit its value if the default is too verbose. You can use the following parameters in the
# expansion. Each of them corresponds to one of the fields in the JSON file pointed to by
# GOOGLE_APPLICATION_CREDENTIALS.
# #
# P9K_GCLOUD_APP_EMAIL: `.client_email` field of keyfile # Parameter | JSON key file field
# P9K_GCLOUD_APP_ACCOUNT_TYPE: `.type` field of keyfile # ---------------------------------+---------------
# P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT: `sa` if `type=service_account`, empty otherwise # P9K_GOOGLE_APP_CRED_TYPE | type
# ${VARIABLE//\%/%%}: ${VARIABLE} with all occurences of '%' replaced with '%%'. # P9K_GOOGLE_APP_CRED_PROJECT_ID | project_id
# P9K_GOOGLE_APP_CRED_CLIENT_EMAIL | client_email
# #
# typeset -g POWERLEVEL9K_GCLOUD_APP_CONTENT_EXPANSION='${P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT//\%/%%}${P9K_GCLOUD_APP_EMAIL//\%/%%}' # Note: ${VARIABLE%%.*} expands to ${VARIABLE} up to but not including the first period ('.').
# Note: ${VARIABLE//\%/%%} expands to ${VARIABLE} with all occurences of '%' replaced with '%%'.
#
# typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_CONTENT_EXPANSION='${${P9K_GOOGLE_APP_CRED_CLIENT_EMAIL%%.*}//\%/%%}'
#
# You can also define content expansion specifically for service accounts by defining
# POWERLEVEL9K_GOOGLE_APP_CRED_SERVICE_ACCOUNT_CONTENT_EXPANSION.
# Custom icon. # Default google application credentials icon.
# typeset -g POWERLEVEL9K_GCLOUD_APP_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_VISUAL_IDENTIFIER_EXPANSION='⭐'
# Google application credentials icon for service accounts.
# typeset -g POWERLEVEL9K_GOOGLE_APP_CRED_SERVICE_ACCOUNT_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

@ -3388,27 +3388,28 @@ 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() { prompt_google_app_cred() {
unset P9K_GCLOUD_APP_EMAIL P9K_GCLOUD_APP_ACCOUNT_TYPE P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT unset P9K_GOOGLE_APP_CRED_{TYPE,PROJECT_ID,CLIENT_EMAIL}
(( $+commands[gcloud] )) || return [[ -n $GOOGLE_APPLICATION_CREDENTIALS ]] || return
[[ ! -z $GOOGLE_APPLICATION_CREDENTIALS ]] || return (( $+commands[jq] )) || return
if ! _p9k_cache_stat_get $0 $GOOGLE_APPLICATION_CREDENTIALS; then if ! _p9k_cache_stat_get $0 $GOOGLE_APPLICATION_CREDENTIALS; then
local email="$(cat $GOOGLE_APPLICATION_CREDENTIALS | jq -r '.client_email')" local -a lines
local account_type="$(cat $GOOGLE_APPLICATION_CREDENTIALS | jq -r '.type')" local q='[.type//"", .project_id//"", .client_email//"", 0][]'
local account_type_short if lines=("${(@f)$(jq -r $q <$GOOGLE_APPLICATION_CREDENTIALS 2>/dev/null)}") && (( $#lines == 4 )); then
if [[ "$account_type" == "service_account" ]]; then _p9k_cache_stat_set 1 "${(@)lines[1,-2]}"
account_type_short="sa:" else
_p9k_cache_stat_set 0
fi 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 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_cache_val[1] )) || return
P9K_GCLOUD_APP_ACCOUNT_TYPE=$_p9k_cache_val[2] P9K_GOOGLE_APP_CRED_TYPE=$_p9k_cache_val[2]
P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT=$_p9k_cache_val[3] P9K_GOOGLE_APP_CRED_PROJECT_ID=$_p9k_cache_val[3]
_p9k_prompt_segment "$0" "blue" "white" "GCLOUD_ICON" 0 '' "${P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT//\%/%%}${P9K_GCLOUD_APP_EMAIL//\%/%%}" P9K_GOOGLE_APP_CRED_CLIENT_EMAIL=$_p9k_cache_val[4]
[[ -n $P9K_GOOGLE_APP_CRED_TYPE ]] && local state=_${(U)P9K_GOOGLE_APP_CRED_TYPE} || local state
_p9k_prompt_segment "$0$state" "blue" "white" "GCLOUD_ICON" 0 '' "${${P9K_GOOGLE_APP_CRED_CLIENT_EMAIL%%.*}//\%/%%}"
} }
typeset -gra __p9k_nordvpn_tag=( typeset -gra __p9k_nordvpn_tag=(

Loading…
Cancel
Save