Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/services/local/presence.go
Original file line number Diff line number Diff line change
Expand Up @@ -1500,8 +1500,8 @@ func (s *PresenceService) listResources(ctx context.Context, req proto.ListResou
keyPrefix = []string{nodesPrefix, req.Namespace}
unmarshalItemFunc = backendItemToServer(types.KindNode)
case types.KindWindowsDesktopService:
keyPrefix = []string{windowsDesktopServicesPrefix, req.Namespace}
unmarshalItemFunc = backendItemToServer(types.KindWindowsDesktopService)
keyPrefix = []string{windowsDesktopServicesPrefix}
unmarshalItemFunc = backendItemToWindowsDesktopService
case types.KindKubeService:
keyPrefix = []string{kubeServicesPrefix}
unmarshalItemFunc = backendItemToServer(types.KindKubeService)
Expand Down Expand Up @@ -1694,7 +1694,7 @@ func FakePaginate(resources []types.ResourceWithLabels, req proto.ListResourcesR
}

// backendItemToDatabaseServer unmarshals `backend.Item` into a
// `types.DatabaseServer`, returning it as a `types.Resource`.
// `types.DatabaseServer`, returning it as a `types.ResourceWithLabels`.
func backendItemToDatabaseServer(item backend.Item) (types.ResourceWithLabels, error) {
return services.UnmarshalDatabaseServer(
item.Value,
Expand All @@ -1704,7 +1704,7 @@ func backendItemToDatabaseServer(item backend.Item) (types.ResourceWithLabels, e
}

// backendItemToApplicationServer unmarshals `backend.Item` into a
// `types.AppServer`, returning it as a `types.Resource`.
// `types.AppServer`, returning it as a `types.ResourceWithLabels`.
func backendItemToApplicationServer(item backend.Item) (types.ResourceWithLabels, error) {
return services.UnmarshalAppServer(
item.Value,
Expand All @@ -1715,7 +1715,7 @@ func backendItemToApplicationServer(item backend.Item) (types.ResourceWithLabels

// backendItemToServer returns `backendItemToResourceFunc` to unmarshal a
// `backend.Item` into a `types.ServerV2` with a specific `kind`, returning it
// as a `types.Resource`.
// as a `types.ResourceWithLabels`.
func backendItemToServer(kind string) backendItemToResourceFunc {
return func(item backend.Item) (types.ResourceWithLabels, error) {
return services.UnmarshalServer(
Expand All @@ -1726,6 +1726,16 @@ func backendItemToServer(kind string) backendItemToResourceFunc {
}
}

// backendItemToWindowsDesktopService unmarshals `backend.Item` into a
// `types.WindowsDesktopService`, returning it as a `types.ResourceWithLabels`.
func backendItemToWindowsDesktopService(item backend.Item) (types.ResourceWithLabels, error) {
return services.UnmarshalWindowsDesktopService(
item.Value,
services.WithResourceID(item.ID),
services.WithExpires(item.Expires),
)
}

const (
reverseTunnelsPrefix = "reverseTunnels"
tunnelConnectionsPrefix = "tunnelConnections"
Expand Down
24 changes: 24 additions & 0 deletions lib/services/local/presence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/jonboulle/clockwork"
"github.com/stretchr/testify/require"

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/client/proto"
apidefaults "github.com/gravitational/teleport/api/defaults"
"github.com/gravitational/teleport/api/types"
Expand Down Expand Up @@ -553,6 +554,29 @@ func TestListResources(t *testing.T) {
return presence.DeleteAllNodes(ctx, apidefaults.Namespace)
},
},
"WindowsDesktopService": {
resourceType: types.KindWindowsDesktopService,
createResourceFunc: func(ctx context.Context, presence *PresenceService, name string, labels map[string]string) error {
desktop, err := types.NewWindowsDesktopServiceV3(
types.Metadata{
Name: name,
Labels: labels,
},
types.WindowsDesktopServiceSpecV3{
Addr: "localhost:1234",
TeleportVersion: teleport.Version,
})
if err != nil {
return err
}

_, err = presence.UpsertWindowsDesktopService(ctx, desktop)
return err
},
deleteAllResourcesFunc: func(ctx context.Context, presence *PresenceService) error {
return presence.DeleteAllWindowsDesktopServices(ctx)
},
},
}

for testName, test := range tests {
Expand Down