Skip to content

Commit

Permalink
Add flag to system connection list to undo breaking output change
Browse files Browse the repository at this point in the history
  • Loading branch information
meln5674 committed Feb 18, 2025
1 parent e3ebd8d commit 9a9c74d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/podman/system/connection/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func init() {
cmd.Flags().StringP("format", "f", "", "Custom Go template for printing connections")
_ = cmd.RegisterFlagCompletionFunc("format", common.AutocompleteFormat(&config.Connection{}))
cmd.Flags().BoolP("quiet", "q", false, "Custom Go template for printing connections")
cmd.Flags().Bool("tls", false, "Include TLS info in default format. Ignored if --format is specified.")
}

registry.Commands = append(registry.Commands, registry.CliCommand{
Expand Down Expand Up @@ -77,6 +78,11 @@ func inspect(cmd *cobra.Command, args []string) error {
return err
}

tls, err := cmd.Flags().GetBool("tls")
if err != nil {
return err
}

cons, err := registry.PodmanConfig().ContainersConfDefaultsRO.GetAllConnections()
if err != nil {
return err
Expand Down Expand Up @@ -116,9 +122,12 @@ func inspect(cmd *cobra.Command, args []string) error {

if format != "" {
rpt, err = rpt.Parse(report.OriginUser, format)
} else {
} else if tls {
rpt, err = rpt.Parse(report.OriginPodman,
"{{range .}}{{.Name}}\t{{.URI}}\t{{.Identity}}\t{{.TLSCAFile}}\t{{.TLSCertFile}}\t{{.TLSKeyFile}}\t{{.Default}}\t{{.ReadWrite}}\n{{end -}}")
} else {
rpt, err = rpt.Parse(report.OriginPodman,
"{{range .}}{{.Name}}\t{{.URI}}\t{{.Identity}}\t{{.Default}}\t{{.ReadWrite}}\n{{end -}}")
}
if err != nil {
return err
Expand Down
33 changes: 33 additions & 0 deletions test/e2e/system_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,39 @@ qe ssh://root@podman.test:2222/run/podman/podman.sock ~/.ssh/id_rsa false true
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out).Should(Say("Name *URI *Identity *Default"))
})

It("with tls output", func() {
for _, name := range []string{"devl", "qe"} {
cmd := []string{"system", "connection", "add",
"--default",
"--identity", "~/.ssh/id_rsa",
name,
"ssh://root@podman.test:2222/run/podman/podman.sock",
}
session := podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
}

cmd := []string{"system", "connection", "default", "devl"}
session := podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out.Contents()).Should(BeEmpty())

session = podmanTest.Podman(systemConnectionListCmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(string(session.Out.Contents())).To(Equal(`devl ssh://root@podman.test:2222/run/podman/podman.sock ~/.ssh/id_rsa true true
qe ssh://root@podman.test:2222/run/podman/podman.sock ~/.ssh/id_rsa false true
`))

cmd = []string{"system", "connection", "list", "--tls"}
session = podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.Out).Should(Say("Name *URI *Identity *TLSCAFile *TLSCertFile *TLSKeyFile *Default"))
})

Expand Down

0 comments on commit 9a9c74d

Please sign in to comment.