Skip to content

Commit

Permalink
Add multi user info
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Anarse <vishal@civo.com>
  • Loading branch information
Vishal Anarse committed Dec 19, 2023
1 parent 97bdecc commit c3d6d89
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
33 changes: 21 additions & 12 deletions cmd/database/database_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package database
import (
"fmt"
"os"
"strings"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
Expand Down Expand Up @@ -43,20 +44,28 @@ var dbCredentialCmd = &cobra.Command{
ow := utility.NewOutputWriter()

if !connectionString {
ow.StartLine()
fmt.Println()
ow.AppendDataWithLabel("id", db.ID, "ID")
ow.AppendDataWithLabel("name", db.Name, "Name")
ow.AppendDataWithLabel("host", fmt.Sprintf("%s:%d", db.PublicIPv4, db.Port), "Host")
ow.AppendDataWithLabel("username", db.Username, "Username")
ow.AppendDataWithLabel("password", db.Password, "Password")
for _, userInfo := range db.DatabaseUserInfo {

Check failure on line 47 in cmd/database/database_credential.go

View workflow job for this annotation

GitHub Actions / Build

db.DatabaseUserInfo undefined (type *civogo.Database has no field or method DatabaseUserInfo)

if common.OutputFormat == "json" || common.OutputFormat == "custom" {
ow.AppendDataWithLabel("firewall_id", db.FirewallID, "Firewall ID")
ow.AppendDataWithLabel("network_id", db.NetworkID, "Network ID")
ow.StartLine()
fmt.Println()
ow.AppendDataWithLabel("database_id", utility.TrimID(db.ID), "Database ID")
ow.AppendDataWithLabel("name", db.Name, "Name")
ow.AppendDataWithLabel("host", db.PublicIPv4, "Host")
ow.AppendDataWithLabel("port", fmt.Sprintf("%d", userInfo.Port), "Port")
ow.AppendDataWithLabel("username", userInfo.Username, "Username")
ow.AppendDataWithLabel("password", userInfo.Password, "Password")

if common.OutputFormat == "json" || common.OutputFormat == "custom" {
ow.AppendDataWithLabel("firewall_id", db.FirewallID, "Firewall ID")
ow.AppendDataWithLabel("network_id", db.NetworkID, "Network ID")
ow.AppendDataWithLabel("database_id", db.ID, "Database ID")

}
}
} else {
fmt.Printf("mysql://%s:%s@%s:%d\n", db.Username, db.Password, db.PublicIPv4, db.Port)
for _, user := range db.DatabaseUserInfo {

Check failure on line 66 in cmd/database/database_credential.go

View workflow job for this annotation

GitHub Actions / Build

db.DatabaseUserInfo undefined (type *civogo.Database has no field or method DatabaseUserInfo)
fmt.Printf("%s://%s:%s@%s:%d\n", strings.ToLower(db.Software), user.Username, user.Password, db.PublicIPv4, user.Port)
}
}

switch common.OutputFormat {
Expand All @@ -65,7 +74,7 @@ var dbCredentialCmd = &cobra.Command{
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteKeyValues()
ow.WriteTable()
}
},
}
11 changes: 8 additions & 3 deletions cmd/database/database_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strconv"
"strings"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
Expand Down Expand Up @@ -37,19 +38,23 @@ var dbListCmd = &cobra.Command{

ow := utility.NewOutputWriter()
for _, db := range databases.Items {
ports := []string{}
for _, user := range db.DatabaseUserInfo {

Check failure on line 42 in cmd/database/database_list.go

View workflow job for this annotation

GitHub Actions / Build

db.DatabaseUserInfo undefined (type civogo.Database has no field or method DatabaseUserInfo)
ports = append(ports, fmt.Sprintf("%d", user.Port))
}

ow.StartLine()
ow.AppendDataWithLabel("id", utility.TrimID(db.ID), "ID")
ow.AppendDataWithLabel("name", db.Name, "Name")
ow.AppendDataWithLabel("size", db.Size, "Size")
ow.AppendDataWithLabel("nodes", strconv.Itoa(db.Nodes), "Nodes")
ow.AppendDataWithLabel("software", db.Software, "Software")
ow.AppendDataWithLabel("software_version", db.SoftwareVersion, "Software Version")
ow.AppendDataWithLabel("host", fmt.Sprintf("%s:%d", db.PublicIPv4, db.Port), "Host")
ow.AppendDataWithLabel("host", db.PublicIPv4, "Host")
ow.AppendDataWithLabel("port", strings.Join(ports, ","), "Port")
ow.AppendDataWithLabel("status", db.Status, "Status")

if common.OutputFormat == "json" || common.OutputFormat == "custom" {
ow.AppendDataWithLabel("username", db.Username, "Username")
ow.AppendDataWithLabel("password", db.Password, "Password")
ow.AppendDataWithLabel("firewall_id", db.FirewallID, "Firewall ID")
ow.AppendDataWithLabel("network_id", db.NetworkID, "Network ID")
ow.AppendDataWithLabel("id", db.ID, "ID")
Expand Down
9 changes: 8 additions & 1 deletion cmd/database/database_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strconv"
"strings"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
Expand Down Expand Up @@ -39,6 +40,11 @@ var dbShowCmd = &cobra.Command{
os.Exit(1)
}

ports := []string{}
for _, user := range db.DatabaseUserInfo {

Check failure on line 44 in cmd/database/database_show.go

View workflow job for this annotation

GitHub Actions / Build

db.DatabaseUserInfo undefined (type *civogo.Database has no field or method DatabaseUserInfo)
ports = append(ports, fmt.Sprintf("%d", user.Port))
}

ow := utility.NewOutputWriter()

ow.StartLine()
Expand All @@ -50,7 +56,8 @@ var dbShowCmd = &cobra.Command{
ow.AppendDataWithLabel("nodes", strconv.Itoa(db.Nodes), "Nodes")
ow.AppendDataWithLabel("software", db.Software, "Software")
ow.AppendDataWithLabel("software_version", db.SoftwareVersion, "Software Version")
ow.AppendDataWithLabel("host", fmt.Sprintf("%s:%d", db.PublicIPv4, db.Port), "Host")
ow.AppendDataWithLabel("host", db.PublicIPv4, "Host")
ow.AppendDataWithLabel("port", strings.Join(ports, ","), "Port")

if common.OutputFormat == "json" || common.OutputFormat == "custom" {
ow.AppendDataWithLabel("firewall_id", db.FirewallID, "Firewall ID")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/briandowns/spinner v1.11.1
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c // indirect
github.com/civo/civogo v0.3.53
github.com/civo/civogo v0.3.54
github.com/dsnet/compress v0.0.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/google/go-github v17.0.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/civo/civogo v0.3.53 h1:PYqwTwt9YmeBRKMzfuTXBSPtE0WIsbLzhxD3V36bVlo=
github.com/civo/civogo v0.3.53/go.mod h1:54lv/FOf7gh6wE9ZwVdw4yBehk8V1CvU9aWa4v6dvW0=
github.com/civo/civogo v0.3.54 h1:KVUE8zTFWAnOHLz9S+imPCU95Gwc/ICxgTRN+EcdOOE=
github.com/civo/civogo v0.3.54/go.mod h1:54lv/FOf7gh6wE9ZwVdw4yBehk8V1CvU9aWa4v6dvW0=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down

0 comments on commit c3d6d89

Please sign in to comment.