Skip to content

Commit c42b586

Browse files
author
Jacob Woffenden
authored
Update Cloud Platform
Signed-off-by: GitHub <noreply@github.com>
1 parent 6acc43d commit c42b586

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

features/src/cloud-platform/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [Unreleased]
1111

12+
## [1.0.1] - 2024-10-28
13+
14+
- Updated environment colour map
15+
1216
## [1.0.0] - 2024-10-17
1317

1418
## Changed

features/src/cloud-platform/devcontainer-feature.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "cloud-platform",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"name": "Cloud Platform",
55
"description": "Installs the Cloud Platform CLI",
66
"options": {
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
11
#!/usr/bin/env bash
22
# shellcheck disable=SC2016
33

4+
# Logic for authentication check is:
5+
# Check context is "cloud-platform-live" and client-id is "REPLACE_WITH_CLIENT_ID", then you aren't authenticated
6+
# Check context is "cloud-platform-live" and client-id is not "REPLACE_WITH_CLIENT_ID" and server version is returned, then you are authenticated
7+
# 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
8+
49
PROMPT+='`\
5-
kubectlCurrentContext=$(kubectl config current-context 2>/dev/null); \
6-
kubectlCurrentNamespace=$(kubectl config view --minify --output "jsonpath={..namespace}"); \
7-
kubectlClientId=$(kubectl config view --output json | jq -r ".users[0].user[\"auth-provider\"].config[\"client-id\"]"); \
8-
kubectlServerVersion=$(kubectl version --output json 2>/dev/null | jq -r .serverVersion.gitVersion); \
9-
if [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ "${kubectlClientId}" == "REPLACE_WITH_CLIENT_ID" ]]; then \
10-
echo -n "[ cluster: %{$fg[yellow]%}${kubectlCurrentContext} (requires authentication)%{$reset_color%} ] "; \
11-
elif [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ "${kubectlClientId}" != "REPLACE_WITH_CLIENT_ID" ]] && [[ "${kubectlServerVersion}" != "null" ]]; then \
12-
echo -n "[ cluster: %{$fg[green]%}${kubectlCurrentContext} (authenticated)%{$reset_color%} ] "; \
13-
elif [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ "${kubectlClientId}" != "REPLACE_WITH_CLIENT_ID" ]] && [[ "${kubectlServerVersion}" == "null" ]]; then
14-
echo -n "[ cluster: %{$fg[red]%}${kubectlCurrentContext} (issue with authentication)%{$reset_color%} ] "; \
15-
fi \
16-
&& if [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ ! -z "${kubectlCurrentNamespace}" ]] && [[ "${kubectlCurrentNamespace}" == *"-prod"* ]]; then \
17-
echo -n "[ namespace: %{$fg[red]%}${kubectlCurrentNamespace}%{$reset_color%} ] "; \
18-
elif [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ ! -z "${kubectlCurrentNamespace}" ]]; then \
19-
echo -n "[ namespace: %{$fg[green]%}${kubectlCurrentNamespace}%{$reset_color%} ] "; \
20-
fi \
10+
CURRENT_CONTEXT=$(kubectl config current-context 2>/dev/null); \
11+
CURRENT_NAMESPACE=$(kubectl config view --minify --output "jsonpath={..namespace}"); \
12+
CURRENT_CLIENT_ID=$(kubectl config view --output json | jq -r ".users[0].user[\"auth-provider\"].config[\"client-id\"]"); \
13+
SERVER_VERSION=$(kubectl version --output json 2>/dev/null | jq -r .serverVersion.gitVersion); \
14+
if [[ "${CURRENT_CONTEXT}" == "cloud-platform-live" ]] && [[ "${CURRENT_CLIENT_ID}" == "REPLACE_WITH_CLIENT_ID" ]]; then \
15+
echo -n "[ cluster: %{$fg[yellow]%}${CURRENT_CONTEXT} (requires authentication)%{$reset_color%} ] "; \
16+
elif [[ "${CURRENT_CONTEXT}" == "cloud-platform-live" ]] && [[ "${CURRENT_CLIENT_ID}" != "REPLACE_WITH_CLIENT_ID" ]] && [[ "${SERVER_VERSION}" != "null" ]]; then \
17+
echo -n "[ cluster: %{$fg[green]%}${CURRENT_CONTEXT} (authenticated)%{$reset_color%} ] "; \
18+
elif [[ "${CURRENT_CONTEXT}" == "cloud-platform-live" ]] && [[ "${CURRENT_CLIENT_ID}" != "REPLACE_WITH_CLIENT_ID" ]] && [[ "${SERVER_VERSION}" == "null" ]]; then
19+
echo -n "[ cluster: %{$fg[red]%}${CURRENT_CONTEXT} (issue with authentication)%{$reset_color%} ] "; \
20+
fi; \
21+
case ${CURRENT_NAMESPACE} in \
22+
*"development"*|*"sandbox"*) \
23+
colour=green \
24+
;; \
25+
*"test"*) \
26+
colour=blue \
27+
;; \
28+
*"preproduction"*) \
29+
colour=yellow \
30+
;; \
31+
*"production"*) \
32+
colour=red \
33+
;; \
34+
*) \
35+
colour=white \
36+
;; \
37+
esac; \
38+
if [[ ! -z ${CURRENT_NAMESPACE} ]]; then \
39+
echo -n "[ namespace: %{$fg[$colour]%}${CURRENT_NAMESPACE}%{$reset_color%} ] "; \
40+
fi
2141
`'

0 commit comments

Comments
 (0)