From a83d2a26824784c3821e06d34b1a16b3b3c8eb34 Mon Sep 17 00:00:00 2001 From: Ibrahim AshShohail Date: Wed, 1 Aug 2018 03:23:00 +0300 Subject: [PATCH] change TRUNCATED to DATA+OMITTED in kubectl config view Signed-off-by: Ibrahim AshShohail Kubernetes-commit: 23996b25c93c0fc576f5d4a547f91e1b7c4b68a3 --- tools/clientcmd/api/helpers.go | 9 +++++++-- tools/clientcmd/api/helpers_test.go | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/clientcmd/api/helpers.go b/tools/clientcmd/api/helpers.go index 43e26487..65a36936 100644 --- a/tools/clientcmd/api/helpers.go +++ b/tools/clientcmd/api/helpers.go @@ -29,6 +29,8 @@ import ( func init() { sDec, _ := base64.StdEncoding.DecodeString("REDACTED+") redactedBytes = []byte(string(sDec)) + sDec, _ = base64.StdEncoding.DecodeString("DATA+OMITTED") + dataOmittedBytes = []byte(string(sDec)) } // IsConfigEmpty returns true if the config is empty. @@ -79,7 +81,10 @@ func MinifyConfig(config *Config) error { return nil } -var redactedBytes []byte +var ( + redactedBytes []byte + dataOmittedBytes []byte +) // Flatten redacts raw data entries from the config object for a human-readable view. func ShortenConfig(config *Config) { @@ -97,7 +102,7 @@ func ShortenConfig(config *Config) { } for key, cluster := range config.Clusters { if len(cluster.CertificateAuthorityData) > 0 { - cluster.CertificateAuthorityData = redactedBytes + cluster.CertificateAuthorityData = dataOmittedBytes } config.Clusters[key] = cluster } diff --git a/tools/clientcmd/api/helpers_test.go b/tools/clientcmd/api/helpers_test.go index 43020845..7ec30e5d 100644 --- a/tools/clientcmd/api/helpers_test.go +++ b/tools/clientcmd/api/helpers_test.go @@ -229,7 +229,7 @@ func Example_minifyAndShorten() { // clusters: // cow-cluster: // LocationOfOrigin: "" - // certificate-authority-data: REDACTED + // certificate-authority-data: DATA+OMITTED // server: http://cow.org:8080 // contexts: // federal-context: @@ -276,14 +276,15 @@ func TestShortenSuccess(t *testing.T) { } redacted := string(redactedBytes) + dataOmitted := string(dataOmittedBytes) if len(mutatingConfig.Clusters) != 2 { t.Errorf("unexpected clusters: %v", mutatingConfig.Clusters) } if !reflect.DeepEqual(startingConfig.Clusters[unchangingCluster], mutatingConfig.Clusters[unchangingCluster]) { t.Errorf("expected %v, got %v", startingConfig.Clusters[unchangingCluster], mutatingConfig.Clusters[unchangingCluster]) } - if string(mutatingConfig.Clusters[changingCluster].CertificateAuthorityData) != redacted { - t.Errorf("expected %v, got %v", redacted, string(mutatingConfig.Clusters[changingCluster].CertificateAuthorityData)) + if string(mutatingConfig.Clusters[changingCluster].CertificateAuthorityData) != dataOmitted { + t.Errorf("expected %v, got %v", dataOmitted, string(mutatingConfig.Clusters[changingCluster].CertificateAuthorityData)) } if len(mutatingConfig.AuthInfos) != 2 {