From caea2c5b2a82dea18a0954828ec45701a31d6390 Mon Sep 17 00:00:00 2001 From: Rostyslav Sotnychenko Date: Mon, 16 Dec 2019 19:21:23 +0200 Subject: Add prompt for Google Cloud application credentials --- internal/p10k.zsh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'internal') diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 0ac020aa..aea79054 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -3379,7 +3379,6 @@ prompt_azure() { prompt_gcloud() { unset P9K_GCLOUD_PROJECT P9K_GCLOUD_ACCOUNT (( $+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 _p9k_cache_stat_set "$(gcloud config get-value account 2>/dev/null)" "$(gcloud config get-value project 2>/dev/null)" fi @@ -3389,6 +3388,29 @@ prompt_gcloud() { _p9k_prompt_segment "$0" "blue" "white" "GCLOUD_ICON" 0 '' "${P9K_GCLOUD_ACCOUNT//\%/%%}:${P9K_GCLOUD_PROJECT//\%/%%}" } +prompt_gcloud_app() { + unset P9K_GCLOUD_APP_EMAIL + (( $+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=( P9K_NORDVPN_STATUS P9K_NORDVPN_TECHNOLOGY -- cgit v1.2.3 From 0d0425c1baa9ddd9d3a8fe3fb3a0c1fd88a23237 Mon Sep 17 00:00:00 2001 From: Rostyslav Sotnychenko Date: Mon, 16 Dec 2019 19:29:45 +0200 Subject: Fix typos --- config/p10k-lean.zsh | 2 +- config/p10k-rainbow.zsh | 2 +- internal/p10k.zsh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'internal') diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index ae07c238..574f654c 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -67,7 +67,7 @@ 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/) # 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 nordvpn # nordvpn connection status, linux only (https://nordvpn.com/) diff --git a/config/p10k-rainbow.zsh b/config/p10k-rainbow.zsh index 1e55a530..677448b6 100644 --- a/config/p10k-rainbow.zsh +++ b/config/p10k-rainbow.zsh @@ -67,7 +67,7 @@ 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/) # 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 nordvpn # nordvpn connection status, linux only (https://nordvpn.com/) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index aea79054..c257e6ab 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -3389,7 +3389,7 @@ prompt_gcloud() { } prompt_gcloud_app() { - unset P9K_GCLOUD_APP_EMAIL + unset P9K_GCLOUD_APP_EMAIL P9K_GCLOUD_APP_ACCOUNT_TYPE P9K_GCLOUD_APP_ACCOUNT_TYPE_SHORT (( $+commands[gcloud] )) || return [[ ! -z $GOOGLE_APPLICATION_CREDENTIALS ]] || return -- cgit v1.2.3