mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-25 10:40:02 +08:00
* Convert existing non-gogo codegen to the Hybrid API Contributes to https://github.com/gravitational/teleport/issues/66776. All existing protos explicitly set to API_OPEN have been change to API_HBYRID. The new codegen was performed via make grpc. There are no other functional changes to the code to start consuming the Hybrid API those will come later. The intent is to get all Hybrid codegen in and backported to ease the transition. * Initial migration to the Opaque API Contributes to https://github.com/gravitational/teleport/issues/66776. All of the changes here are mechanical conversions generated from `open2opaque rewrite -levels=green ./...`. There will be a follow up to this in teleport.e which does the same. Once all changes have been merged the process will be repeated with -levels=yellow followed by -levels=red. See https://protobuf.dev/reference/go/opaque-migration/ for more details.
108 lines
3.7 KiB
Go
108 lines
3.7 KiB
Go
// Teleport
|
|
// Copyright (C) 2026 Gravitational, Inc.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package cache
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gravitational/trace"
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
headerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1"
|
|
linuxdesktopv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/linuxdesktop/v1"
|
|
"github.com/gravitational/teleport/api/types"
|
|
"github.com/gravitational/teleport/api/utils/clientutils"
|
|
"github.com/gravitational/teleport/lib/services"
|
|
)
|
|
|
|
type linuxDesktopIndex string
|
|
|
|
const linuxDesktopNameIndex linuxDesktopIndex = "linux-desktop"
|
|
|
|
func newLinuxDesktopCollection(upstream services.LinuxDesktops, w types.WatchKind) (*collection[*linuxdesktopv1.LinuxDesktop, linuxDesktopIndex], error) {
|
|
if upstream == nil {
|
|
return nil, trace.BadParameter("missing parameter upstream")
|
|
}
|
|
|
|
s := newStore(
|
|
types.KindLinuxDesktop,
|
|
proto.CloneOf[*linuxdesktopv1.LinuxDesktop],
|
|
map[linuxDesktopIndex]func(*linuxdesktopv1.LinuxDesktop) string{
|
|
linuxDesktopNameIndex: func(r *linuxdesktopv1.LinuxDesktop) string {
|
|
return r.GetMetadata().GetName()
|
|
},
|
|
})
|
|
return &collection[*linuxdesktopv1.LinuxDesktop, linuxDesktopIndex]{
|
|
store: s,
|
|
fetcher: func(ctx context.Context, loadSecrets bool) ([]*linuxdesktopv1.LinuxDesktop, error) {
|
|
var out []*linuxdesktopv1.LinuxDesktop
|
|
|
|
for desktop, err := range clientutils.Resources(ctx, upstream.ListLinuxDesktops) {
|
|
if err != nil {
|
|
return nil, trace.Wrap(err)
|
|
}
|
|
out = append(out, desktop)
|
|
}
|
|
|
|
return out, nil
|
|
},
|
|
headerTransform: func(hdr *types.ResourceHeader) *linuxdesktopv1.LinuxDesktop {
|
|
return linuxdesktopv1.LinuxDesktop_builder{
|
|
Kind: hdr.Kind,
|
|
Version: hdr.Version,
|
|
Metadata: headerv1.Metadata_builder{
|
|
Name: hdr.Metadata.Name,
|
|
}.Build(),
|
|
}.Build()
|
|
},
|
|
watch: w,
|
|
}, nil
|
|
}
|
|
|
|
// ListLinuxDesktops lists linuxdesktops with pagination.
|
|
func (c *Cache) ListLinuxDesktops(ctx context.Context, pageSize int, nextToken string) ([]*linuxdesktopv1.LinuxDesktop, string, error) {
|
|
ctx, span := c.Tracer.Start(ctx, "cache/ListLinuxDesktops")
|
|
defer span.End()
|
|
|
|
lister := genericLister[*linuxdesktopv1.LinuxDesktop, linuxDesktopIndex]{
|
|
cache: c,
|
|
collection: c.collections.linuxDesktops,
|
|
index: linuxDesktopNameIndex,
|
|
upstreamList: c.Config.LinuxDesktops.ListLinuxDesktops,
|
|
nextToken: func(t *linuxdesktopv1.LinuxDesktop) string {
|
|
return t.GetMetadata().GetName()
|
|
},
|
|
}
|
|
out, next, err := lister.list(ctx, pageSize, nextToken)
|
|
return out, next, trace.Wrap(err)
|
|
}
|
|
|
|
// GetLinuxDesktop fetches a linuxdesktop by name.
|
|
func (c *Cache) GetLinuxDesktop(ctx context.Context, name string) (*linuxdesktopv1.LinuxDesktop, error) {
|
|
ctx, span := c.Tracer.Start(ctx, "cache/GetLinuxDesktop")
|
|
defer span.End()
|
|
|
|
getter := genericGetter[*linuxdesktopv1.LinuxDesktop, linuxDesktopIndex]{
|
|
cache: c,
|
|
collection: c.collections.linuxDesktops,
|
|
index: linuxDesktopNameIndex,
|
|
upstreamGet: c.Config.LinuxDesktops.GetLinuxDesktop,
|
|
}
|
|
out, err := getter.get(ctx, name)
|
|
return out, trace.Wrap(err)
|
|
}
|