From 57cdcb5ec569c0e4b698de1ee2d89c8c6161c4b5 Mon Sep 17 00:00:00 2001 From: Anna Lushnikova Date: Wed, 11 Sep 2024 12:10:11 -0400 Subject: [PATCH] return one certificate with -o json; encode certificate. --- commands/databases.go | 6 +++--- commands/displayers/database.go | 31 ++++++++++++++----------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/commands/databases.go b/commands/databases.go index 2c06d9439..a571dc851 100644 --- a/commands/databases.go +++ b/commands/databases.go @@ -204,7 +204,7 @@ func RunDatabaseGetCA(c *CmdConfig) error { return err } - return displayDatabaseCA(c, *dbCA) + return displayDatabaseCA(c, dbCA) } // RunDatabaseCreate creates a database cluster @@ -925,8 +925,8 @@ func displayDatabaseUsers(c *CmdConfig, users ...do.DatabaseUser) error { return c.Display(item) } -func displayDatabaseCA(c *CmdConfig, dbCAs ...do.DatabaseCA) error { - item := &displayers.DatabaseCAs{DatabaseCAs: dbCAs} +func displayDatabaseCA(c *CmdConfig, dbCA *do.DatabaseCA) error { + item := &displayers.DatabaseCA{DatabaseCA: *dbCA} return c.Display(item) } diff --git a/commands/displayers/database.go b/commands/displayers/database.go index 8a995ac41..352d15156 100644 --- a/commands/displayers/database.go +++ b/commands/displayers/database.go @@ -14,6 +14,7 @@ limitations under the License. package displayers import ( + "encoding/base64" "io" "sort" "strconv" @@ -155,39 +156,35 @@ func (db *DatabaseBackups) KV() []map[string]any { return out } -type DatabaseCAs struct { - DatabaseCAs do.DatabaseCAs +type DatabaseCA struct { + DatabaseCA do.DatabaseCA } -var _ Displayable = &DatabaseCAs{} +var _ Displayable = &DatabaseCA{} -func (dc *DatabaseCAs) JSON(out io.Writer) error { - return writeJSON(dc.DatabaseCAs, out) +func (dc *DatabaseCA) JSON(out io.Writer) error { + return writeJSON(dc.DatabaseCA, out) } -func (dc *DatabaseCAs) Cols() []string { +func (dc *DatabaseCA) Cols() []string { return []string{ "Certificate", } } -func (dc *DatabaseCAs) ColMap() map[string]string { +func (dc *DatabaseCA) ColMap() map[string]string { return map[string]string{ "Certificate": "Certificate", } } -func (dc *DatabaseCAs) KV() []map[string]any { - out := make([]map[string]any, 0, len(dc.DatabaseCAs)) - - for _, c := range dc.DatabaseCAs { - o := map[string]any{ - "Certificate": string(c.Certificate), - } - out = append(out, o) +func (dc *DatabaseCA) KV() []map[string]any { + encoded := base64.StdEncoding.EncodeToString(dc.DatabaseCA.Certificate) + return []map[string]any{ + { + "Certificate": encoded, + }, } - - return out } type DatabaseUsers struct {