generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 Consistent colours for environments in prompts (#150)
Signed-off-by: Jacob Woffenden <jacob.woffenden@digital.justice.gov.uk>
- Loading branch information
Jacob Woffenden
authored
Oct 28, 2024
1 parent
a188779
commit 47aad5e
Showing
9 changed files
with
96 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
52 changes: 36 additions & 16 deletions
52
features/src/cloud-platform/src/home/vscode/.devcontainer/promptrc.d/cloud-platform.sh
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,41 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck disable=SC2016 | ||
|
||
# Logic for authentication check is: | ||
# Check context is "cloud-platform-live" and client-id is "REPLACE_WITH_CLIENT_ID", then you aren't authenticated | ||
# Check context is "cloud-platform-live" and client-id is not "REPLACE_WITH_CLIENT_ID" and server version is returned, then you are authenticated | ||
# Check context is "cloud-platform-live" and client-id is not "REPLACE_WITH_CLIENT_ID" and server version is null, then there is a potential issue with authentication | ||
|
||
PROMPT+='`\ | ||
kubectlCurrentContext=$(kubectl config current-context 2>/dev/null); \ | ||
kubectlCurrentNamespace=$(kubectl config view --minify --output "jsonpath={..namespace}"); \ | ||
kubectlClientId=$(kubectl config view --output json | jq -r ".users[0].user[\"auth-provider\"].config[\"client-id\"]"); \ | ||
kubectlServerVersion=$(kubectl version --output json 2>/dev/null | jq -r .serverVersion.gitVersion); \ | ||
if [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ "${kubectlClientId}" == "REPLACE_WITH_CLIENT_ID" ]]; then \ | ||
echo -n "[ cluster: %{$fg[yellow]%}${kubectlCurrentContext} (requires authentication)%{$reset_color%} ] "; \ | ||
elif [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ "${kubectlClientId}" != "REPLACE_WITH_CLIENT_ID" ]] && [[ "${kubectlServerVersion}" != "null" ]]; then \ | ||
echo -n "[ cluster: %{$fg[green]%}${kubectlCurrentContext} (authenticated)%{$reset_color%} ] "; \ | ||
elif [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ "${kubectlClientId}" != "REPLACE_WITH_CLIENT_ID" ]] && [[ "${kubectlServerVersion}" == "null" ]]; then | ||
echo -n "[ cluster: %{$fg[red]%}${kubectlCurrentContext} (issue with authentication)%{$reset_color%} ] "; \ | ||
fi \ | ||
&& if [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ ! -z "${kubectlCurrentNamespace}" ]] && [[ "${kubectlCurrentNamespace}" == *"-prod"* ]]; then \ | ||
echo -n "[ namespace: %{$fg[red]%}${kubectlCurrentNamespace}%{$reset_color%} ] "; \ | ||
elif [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ ! -z "${kubectlCurrentNamespace}" ]]; then \ | ||
echo -n "[ namespace: %{$fg[green]%}${kubectlCurrentNamespace}%{$reset_color%} ] "; \ | ||
fi \ | ||
CURRENT_CONTEXT=$(kubectl config current-context 2>/dev/null); \ | ||
CURRENT_NAMESPACE=$(kubectl config view --minify --output "jsonpath={..namespace}" 2>/dev/null); \ | ||
CURRENT_CLIENT_ID=$(kubectl config view --output json | jq -r ".users[0].user[\"auth-provider\"].config[\"client-id\"]"); \ | ||
SERVER_VERSION=$(kubectl version --output json 2>/dev/null | jq -r .serverVersion.gitVersion); \ | ||
if [[ "${CURRENT_CONTEXT}" == "cloud-platform-live" ]] && [[ "${CURRENT_CLIENT_ID}" == "REPLACE_WITH_CLIENT_ID" ]]; then \ | ||
echo -n "[ cluster: %{$fg[yellow]%}${CURRENT_CONTEXT} (requires authentication)%{$reset_color%} ] "; \ | ||
elif [[ "${CURRENT_CONTEXT}" == "cloud-platform-live" ]] && [[ "${CURRENT_CLIENT_ID}" != "REPLACE_WITH_CLIENT_ID" ]] && [[ "${SERVER_VERSION}" != "null" ]]; then \ | ||
echo -n "[ cluster: %{$fg[green]%}${CURRENT_CONTEXT} (authenticated)%{$reset_color%} ] "; \ | ||
elif [[ "${CURRENT_CONTEXT}" == "cloud-platform-live" ]] && [[ "${CURRENT_CLIENT_ID}" != "REPLACE_WITH_CLIENT_ID" ]] && [[ "${SERVER_VERSION}" == "null" ]]; then | ||
echo -n "[ cluster: %{$fg[red]%}${CURRENT_CONTEXT} (issue with authentication)%{$reset_color%} ] "; \ | ||
fi; \ | ||
case ${CURRENT_NAMESPACE} in \ | ||
*"development"*|*"sandbox"*) \ | ||
colour=green \ | ||
;; \ | ||
*"test"*) \ | ||
colour=blue \ | ||
;; \ | ||
*"preproduction"*) \ | ||
colour=yellow \ | ||
;; \ | ||
*"production"*) \ | ||
colour=red \ | ||
;; \ | ||
*) \ | ||
colour=white \ | ||
;; \ | ||
esac; \ | ||
if [[ ! -z ${CURRENT_NAMESPACE} ]]; then \ | ||
echo -n "[ namespace: %{$fg[$colour]%}${CURRENT_NAMESPACE}%{$reset_color%} ] "; \ | ||
fi | ||
`' |
This file contains 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
This file contains 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
This file contains 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