From 8d7d74f97c3d2890d09fe6b2971260a091065d54 Mon Sep 17 00:00:00 2001
From: amantri <ayyappa.mantri@windriver.com>
Date: Wed, 31 Jan 2024 15:58:39 -0500
Subject: [PATCH] Fix WRA cert info in the show-certs.sh output

When fgrep'ing for "ca.crt","ext-ca.crt" in the WRA secret "mon-elastic-
services-secrets" it is finding matches for "ca.crt:","ca.crt-helm:" and
"ext-ca.crt:","ext-ca.crt-helm:" respectively, this fails an if clause
where it checks whether it is managed by cert-manager and wrongly
displaying the renewal as "Manual" instead of "Automatic",this fix
addresses this issue by hardening the fgrep to look for "ca.crt:" and
"ext-ca.crt:" respectively.

Test Cases:
PASS: Run "show-certs.sh" script and verify that all information for WRA
      certs properly in the output
PASS: "show-certs.sh -k" script and verify that all information for WRA
      certs properly in the output

Closes-Bug: 2051880

Change-Id: I73af1ebd60a0c750569381b6ed67108f79dbb69e
Signed-off-by: amantri <ayyappa.mantri@windriver.com>
---
 utilities/platform-util/scripts/show-certs.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/utilities/platform-util/scripts/show-certs.sh b/utilities/platform-util/scripts/show-certs.sh
index 8a16254d..6e3a3110 100755
--- a/utilities/platform-util/scripts/show-certs.sh
+++ b/utilities/platform-util/scripts/show-certs.sh
@@ -174,7 +174,8 @@ PrintCertInfo-fromGenericSecret () {
 
     kubectl --kubeconfig /etc/kubernetes/admin.conf -n $NAMESPACE get secret $SECRET &> /dev/null
     if [ $? -eq 0 ]; then
-        SECRET_VALUE=$(kubectl --kubeconfig /etc/kubernetes/admin.conf -n $NAMESPACE get secret $SECRET -o yaml | fgrep " $SECRETFILE" | awk '{print $2}')
+
+        SECRET_VALUE=$(kubectl --kubeconfig /etc/kubernetes/admin.conf -n $NAMESPACE get secret $SECRET -o yaml | fgrep " $SECRETFILE:" | awk '{print $2}')
 
         if ! IsACertificate $SECRET_VALUE; then
             return