From 08943a007e6b8e6dbd241d1f0e99badd46510b5b Mon Sep 17 00:00:00 2001 From: Omri Gazitt Date: Sun, 12 Jul 2020 00:29:42 -0700 Subject: [PATCH] updated connection and credential handling to take protocol changes --- pkg/cmd/active.go | 1 - pkg/print/connections.go | 20 ++++++++++++++++++-- pkg/print/snaps.go | 1 - 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/active.go b/pkg/cmd/active.go index 1863d5d..8255d5b 100644 --- a/pkg/cmd/active.go +++ b/pkg/cmd/active.go @@ -148,7 +148,6 @@ snap active logs [active snap ID] details [log ID] will return the output for ea if len(args) > 2 && logID != "" { // select the entry that matches the log ID logEntry := gjson.GetBytes(response, fmt.Sprintf("data.#(timestamp==%s)|@pretty", logID)).Raw - if logEntry == "" { utils.PrintError(fmt.Sprintf("log ID %s not found for active snap ID %s", logID, activeSnapID)) return diff --git a/pkg/print/connections.go b/pkg/print/connections.go index e5067f9..bc19fd0 100644 --- a/pkg/print/connections.go +++ b/pkg/print/connections.go @@ -10,6 +10,13 @@ import ( "github.com/snapmaster-io/snap/pkg/utils" ) +// CredentialsResponse defines the fields to unmarshal from a get credential-sets operation +type CredentialsResponse struct { + Status string `json:"status"` + Message string `json:"message"` + Data []map[string]string `json:"data"` +} + // ConnectionsTable prints out the connected providers as a table func ConnectionsTable(response []byte) { var toolsResponse ToolsResponse @@ -39,8 +46,17 @@ func ConnectionsTable(response []byte) { // CredentialsTable prints out the credentials of a connection as a table func CredentialsTable(response []byte, connection string) { - var credentials []map[string]string - json.Unmarshal(response, &credentials) + var credentialsResponse CredentialsResponse + json.Unmarshal(response, &credentialsResponse) + + if credentialsResponse.Status == "error" { + utils.PrintStatus(credentialsResponse.Status, credentialsResponse.Message) + return + } + + credentials := credentialsResponse.Data + //var credentials []map[string]string + //json.Unmarshal(response, &credentials) // write out the table t := table.NewWriter() diff --git a/pkg/print/snaps.go b/pkg/print/snaps.go index 02eaa4a..465d99f 100644 --- a/pkg/print/snaps.go +++ b/pkg/print/snaps.go @@ -113,7 +113,6 @@ func SnapsTable(response []byte) { t.SetTitle("Snaps") t.AppendHeader(table.Row{"Snap ID", "Description", "Trigger"}) for _, snap := range snaps { - //t.AppendRow(table.Row{snap["snapId"], snap["description"], snap["provider"]}) t.AppendRow(table.Row{snap.SnapID, snap.Description, snap.Provider}) } t.SetStyle(tableStyle)