Skip to content

Commit 8d01c28

Browse files
committed
databases and win desktops
1 parent 8dc8fd4 commit 8d01c28

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

lib/cache/database.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,8 @@ func newDatabaseCollection(upstream services.Databases, w types.WatchKind) (*col
5353
databaseNameIndex: types.Database.GetName,
5454
}),
5555
fetcher: func(ctx context.Context, loadSecrets bool) ([]types.Database, error) {
56-
out, err := stream.Collect(upstream.RangeDatabases(ctx, "", ""))
57-
// TODO(lokraszewski): DELETE IN v21.0.0
58-
if trace.IsNotImplemented(err) {
59-
out, err := upstream.GetDatabases(ctx)
60-
return out, trace.Wrap(err)
61-
}
56+
// TODO(lokraszewski): DELETE IN v21.0.0 replace by regular clientutils.Resources
57+
out, err := clientutils.CollectWithFallback(ctx, upstream.ListDatabases, upstream.GetDatabases)
6258
return out, trace.Wrap(err)
6359
},
6460
headerTransform: func(hdr *types.ResourceHeader) types.Database {

lib/cache/windows_desktop.go

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -200,33 +200,25 @@ func newWindowsDesktopCollection(upstream services.WindowsDesktops, w types.Watc
200200
},
201201
}),
202202
fetcher: func(ctx context.Context, loadSecrets bool) ([]types.WindowsDesktop, error) {
203-
var start string
204-
var desktops []types.WindowsDesktop
205-
for {
206-
req := types.ListWindowsDesktopsRequest{
207-
// A non zero limit is required by older versions.
208-
Limit: defaults.DefaultChunkSize,
209-
StartKey: start,
210-
}
211-
212-
resp, err := upstream.ListWindowsDesktops(ctx, req)
213-
if err != nil {
214-
// TODO(tross): DELETE in V21.0.0
215-
if trace.IsNotImplemented(err) {
216-
return upstream.GetWindowsDesktops(ctx, types.WindowsDesktopFilter{})
203+
// TODO(tross): DELETE in V21.0.0 replace by regular clientutils.Resources
204+
out, err := clientutils.CollectWithFallback(
205+
ctx,
206+
func(ctx context.Context, limit int, start string) ([]types.WindowsDesktop, string, error) {
207+
resp, err := upstream.ListWindowsDesktops(ctx, types.ListWindowsDesktopsRequest{
208+
Limit: limit,
209+
StartKey: start,
210+
})
211+
if err != nil {
212+
return nil, "", trace.Wrap(err)
217213
}
214+
return resp.Desktops, resp.NextKey, nil
215+
},
216+
func(ctx context.Context) ([]types.WindowsDesktop, error) {
217+
return upstream.GetWindowsDesktops(ctx, types.WindowsDesktopFilter{})
218+
},
219+
)
218220

219-
return nil, trace.Wrap(err)
220-
}
221-
222-
desktops = append(desktops, resp.Desktops...)
223-
start = resp.NextKey
224-
if resp.NextKey == "" {
225-
break
226-
}
227-
}
228-
229-
return desktops, nil
221+
return out, trace.Wrap(err)
230222
},
231223
headerTransform: func(hdr *types.ResourceHeader) types.WindowsDesktop {
232224
return &types.WindowsDesktopV3{

0 commit comments

Comments
 (0)