Skip to content

Commit 3d46bb9

Browse files
committed
Refine access-rules output to show separate host, domain, and path columns
Changed table format from: route selector scope source backend.apps.identity ... app frontend-app To: host domain path selector scope source backend apps.identity ... app frontend-app api apps.identity /metrics ... space monitoring This provides better clarity by separating the route components into individual columns, making it easier to scan and filter visually.
1 parent 3faab23 commit 3d46bb9

2 files changed

Lines changed: 15 additions & 27 deletions

File tree

command/v7/access_rules_command.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package v7
22

33
import (
4-
"fmt"
5-
6-
"code.cloudfoundry.org/cli/v9/resources"
74
"code.cloudfoundry.org/cli/v9/util/ui"
85
)
96

@@ -64,7 +61,9 @@ func (cmd AccessRulesCommand) Execute(args []string) error {
6461
// Build table data
6562
table := [][]string{
6663
{
67-
cmd.UI.TranslateText("route"),
64+
cmd.UI.TranslateText("host"),
65+
cmd.UI.TranslateText("domain"),
66+
cmd.UI.TranslateText("path"),
6867
cmd.UI.TranslateText("selector"),
6968
cmd.UI.TranslateText("scope"),
7069
cmd.UI.TranslateText("source"),
@@ -73,7 +72,9 @@ func (cmd AccessRulesCommand) Execute(args []string) error {
7372

7473
for _, ruleWithRoute := range rulesWithRoutes {
7574
table = append(table, []string{
76-
formatRoute(ruleWithRoute.Route, ruleWithRoute.DomainName),
75+
ruleWithRoute.Route.Host,
76+
ruleWithRoute.DomainName,
77+
ruleWithRoute.Route.Path,
7778
ruleWithRoute.Selector,
7879
ruleWithRoute.ScopeType,
7980
ruleWithRoute.SourceName,
@@ -86,16 +87,3 @@ func (cmd AccessRulesCommand) Execute(args []string) error {
8687
return nil
8788
}
8889

89-
// formatRoute formats a route as hostname.domain/path
90-
func formatRoute(route resources.Route, domainName string) string {
91-
var formatted string
92-
if route.Host != "" {
93-
formatted = fmt.Sprintf("%s.%s", route.Host, domainName)
94-
} else {
95-
formatted = domainName
96-
}
97-
if route.Path != "" {
98-
formatted += route.Path
99-
}
100-
return formatted
101-
}

command/v7/access_rules_command_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ var _ = Describe("access-rules Command", func() {
146146
Expect(executeErr).ToNot(HaveOccurred())
147147

148148
Expect(testUI.Out).To(Say(`Getting access rules in org some-org / space some-space as steve\.\.\.`))
149-
Expect(testUI.Out).To(Say(`route\s+selector\s+scope\s+source`))
150-
Expect(testUI.Out).To(Say(`myapp\.example\.com/api\s+cf:app:app-guid-1\s+app\s+my-app`))
151-
Expect(testUI.Out).To(Say(`webapp\.test\.com\s+cf:any\s+any`))
149+
Expect(testUI.Out).To(Say(`host\s+domain\s+path\s+selector\s+scope\s+source`))
150+
Expect(testUI.Out).To(Say(`myapp\s+example\.com\s+/api\s+cf:app:app-guid-1\s+app\s+my-app`))
151+
Expect(testUI.Out).To(Say(`webapp\s+test\.com\s+cf:any\s+any`))
152152

153153
Expect(testUI.Err).To(Say("warning-1"))
154154

@@ -298,8 +298,8 @@ var _ = Describe("access-rules Command", func() {
298298
Expect(executeErr).ToNot(HaveOccurred())
299299

300300
Expect(testUI.Out).To(Say(`Getting access rules in org some-org / space some-space as steve\.\.\.`))
301-
Expect(testUI.Out).To(Say(`route\s+selector\s+scope\s+source`))
302-
Expect(testUI.Out).To(Say(`myapp\.example\.com/api\s+cf:app:app-guid-1\s+app\s+my-app`))
301+
Expect(testUI.Out).To(Say(`host\s+domain\s+path\s+selector\s+scope\s+source`))
302+
Expect(testUI.Out).To(Say(`myapp\s+example\.com\s+/api\s+cf:app:app-guid-1\s+app\s+my-app`))
303303
})
304304
})
305305

@@ -340,11 +340,11 @@ var _ = Describe("access-rules Command", func() {
340340
It("formats routes correctly", func() {
341341
Expect(executeErr).ToNot(HaveOccurred())
342342

343-
// No host, with path: "example.com/api"
344-
Expect(testUI.Out).To(Say(`example\.com/api`))
343+
// No host, with path: empty host, example.com, /api
344+
Expect(testUI.Out).To(Say(`\s+example\.com\s+/api`))
345345

346-
// With host, no path: "myapp.test.com"
347-
Expect(testUI.Out).To(Say(`myapp\.test\.com`))
346+
// With host, no path: myapp, test.com, empty path
347+
Expect(testUI.Out).To(Say(`myapp\s+test\.com\s+`))
348348
})
349349
})
350350
})

0 commit comments

Comments
 (0)