Skip to content

Commit

Permalink
Change open portal hyperlinks (radius-project#7229)
Browse files Browse the repository at this point in the history
# Description
Allow Connection Graph output resources name to be a link within the
console output.

## Type of change

- This pull request fixes a bug in Radius and has an approved issue
(issue link required).
- This pull request is a minor refactor, code cleanup, test improvement,
or other maintenance task and doesn't change the functionality of Radius
(issue link optional).


Fixes: radius-project#7170

---------

Signed-off-by: gpltaylor <[email protected]>
Co-authored-by: Ryan Nowak <[email protected]>
  • Loading branch information
gpltaylor and rynowak authored Mar 6, 2024
1 parent b5f09d5 commit 58c7447
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/cli/cmd/app/graph/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func display(applicationResources []*v20231001preview.ApplicationGraphResource,
if link == "" {
output.WriteString(fmt.Sprintf(" %s (%s)\n", *resource.Name, *resource.Type))
} else {
output.WriteString(fmt.Sprintf(" %s (%s) %s\n", *resource.Name, *resource.Type, link))
output.WriteString(fmt.Sprintf(" %s (%s)\n", link, *resource.Type))
}
}
}
Expand All @@ -114,5 +114,5 @@ func makeHyperlink(resource *v20231001preview.ApplicationGraphOutputResource) st

// This is the magic incantation for a console hyperlink.
// \x1b]8;;h { URL } \x07 { link text } \x1b]8;;\x07
return fmt.Sprintf("\x1b]8;;%s\x07%s\x1b]8;;\x07\n", url, "open portal")
return fmt.Sprintf("\x1b]8;;%s\x07%s\x1b]8;;\x07", url, *resource.Name)
}
30 changes: 30 additions & 0 deletions pkg/cli/cmd/app/graph/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func Test_display(t *testing.T) {
sqlDbName := "sql-db"
sqlDbType := "Applications.Datastores/sqlDatabases"

azureRedisID := "/planes/azure/local/resourcegroups/default/providers/Applications.Datastores/Microsoft.Cache/Azure"
azureRedisName := "redis"
azureRedisType := "Applications.Datastores/redis"

provisioningStateSuccess := "Succeeded"
dirInbound := corerpv20231001preview.DirectionInbound
dirOutbound := corerpv20231001preview.DirectionOutbound
Expand Down Expand Up @@ -104,6 +108,25 @@ func Test_display(t *testing.T) {
},
},
},
{
ID: &azureRedisID,
Name: &azureRedisName,
Type: &azureRedisType,
ProvisioningState: &provisioningStateSuccess,
OutputResources: []*corerpv20231001preview.ApplicationGraphOutputResource{
{
ID: &azureRedisID,
Name: &azureRedisName,
Type: &azureRedisType,
},
},
Connections: []*corerpv20231001preview.ApplicationGraphConnection{
{
Direction: &dirInbound,
ID: &sqlDbID,
},
},
},
}

expected := `Displaying application: test-app
Expand All @@ -123,11 +146,18 @@ Connections:
sql-ctnr (Applications.Core/containers) -> sql-rte
Resources: (none)
Name: redis (Applications.Datastores/redis)
Connections:
sql-db (Applications.Datastores/sqlDatabases) -> redis
Resources:
` + "\x1b]8;;" + `https://portal.azure.com/#@72f988bf-86f1-41af-91ab-2d7cd011db47/resource/planes/azure/local/resourcegroups/default/providers/Applications.Datastores/Microsoft.Cache/Azure` + "\aredis\x1b]8;;\a" + ` (Applications.Datastores/redis)
Name: sql-db (Applications.Datastores/sqlDatabases)
Connections: (none)
Resources: (none)
`

actual := display(graph, "test-app")
require.Equal(t, expected, actual)
})
Expand Down

0 comments on commit 58c7447

Please sign in to comment.