Skip to content

Commit cf220f2

Browse files
authored
return connection string when using instance get (#38)
returning connection string in instance get
2 parents 5458022 + 695330c commit cf220f2

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

cmd/instance_get.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@ package cmd
22

33
import (
44
"fmt"
5+
"net/url"
56
"strconv"
67
"strings"
78

89
"cloudamqp-cli/client"
910
"github.com/spf13/cobra"
1011
)
1112

13+
func maskPassword(urlStr string) string {
14+
parsedURL, err := url.Parse(urlStr)
15+
if err != nil {
16+
return urlStr
17+
}
18+
19+
password, _ := parsedURL.User.Password()
20+
return strings.Replace(urlStr, password, "****", 1)
21+
}
22+
1223
var instanceGetCmd = &cobra.Command{
1324
Use: "get --id <id>",
1425
Short: "Get details of a specific CloudAMQP instance",
@@ -44,6 +55,14 @@ var instanceGetCmd = &cobra.Command{
4455
fmt.Printf("Plan = %s\n", instance.Plan)
4556
fmt.Printf("Region = %s\n", instance.Region)
4657
fmt.Printf("Tags = %s\n", strings.Join(instance.Tags, ","))
58+
59+
showURL, _ := cmd.Flags().GetBool("show-url")
60+
if showURL {
61+
fmt.Printf("URL = %s\n", instance.URL)
62+
} else {
63+
fmt.Printf("URL = %s\n", maskPassword(instance.URL))
64+
}
65+
4766
fmt.Printf("Hostname = %s\n", instance.HostnameExternal)
4867
ready := "No"
4968
if instance.Ready {
@@ -58,5 +77,6 @@ var instanceGetCmd = &cobra.Command{
5877
func init() {
5978
instanceGetCmd.Flags().StringP("id", "", "", "Instance ID (required)")
6079
instanceGetCmd.MarkFlagRequired("id")
80+
instanceGetCmd.Flags().BoolP("show-url", "", false, "Show full connection URL with credentials")
6181
instanceGetCmd.RegisterFlagCompletionFunc("id", completeInstanceIDFlag)
6282
}

0 commit comments

Comments
 (0)