Skip to content

Commit

Permalink
return one certificate with -o json; encode certificate.
Browse files Browse the repository at this point in the history
  • Loading branch information
loosla committed Sep 11, 2024
1 parent e66b4ce commit 57cdcb5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
6 changes: 3 additions & 3 deletions commands/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func RunDatabaseGetCA(c *CmdConfig) error {
return err
}

return displayDatabaseCA(c, *dbCA)
return displayDatabaseCA(c, dbCA)
}

// RunDatabaseCreate creates a database cluster
Expand Down Expand Up @@ -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)
}

Expand Down
31 changes: 14 additions & 17 deletions commands/displayers/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
package displayers

import (
"encoding/base64"
"io"
"sort"
"strconv"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 57cdcb5

Please sign in to comment.