@@ -243,7 +243,7 @@ const snowflakeSessionNameIndex snowflakeSessionIndex = "name"
243243
244244func newSnowflakeSessionCollection (upstream services.SnowflakeSession , w types.WatchKind ) (* collection [types.WebSession , snowflakeSessionIndex ], error ) {
245245 if upstream == nil {
246- return nil , trace .BadParameter ("missing parameter AppSession " )
246+ return nil , trace .BadParameter ("missing parameter upstream " )
247247 }
248248
249249 return & collection [types.WebSession , snowflakeSessionIndex ]{
@@ -254,7 +254,8 @@ func newSnowflakeSessionCollection(upstream services.SnowflakeSession, w types.W
254254 snowflakeSessionNameIndex : types .WebSession .GetName ,
255255 }),
256256 fetcher : func (ctx context.Context , loadSecrets bool ) ([]types.WebSession , error ) {
257- webSessions , err := upstream .GetSnowflakeSessions (ctx )
257+ // TODO(okraport): DELETE IN v21.0.0, replace with regular collect
258+ webSessions , err := clientutils .CollectWithFallback (ctx , upstream .ListSnowflakeSessions , upstream .GetSnowflakeSessions )
258259 if err != nil {
259260 return nil , trace .Wrap (err )
260261 }
@@ -312,3 +313,73 @@ func (c *Cache) GetSnowflakeSession(ctx context.Context, req types.GetSnowflakeS
312313 }
313314 return out , trace .Wrap (err )
314315}
316+
317+ // RangeSnowflakeSessions returns Snowflake session resources within the range [start, end).
318+ func (c * Cache ) RangeSnowflakeSessions (ctx context.Context , start , end string ) iter.Seq2 [types.WebSession , error ] {
319+ lister := genericLister [types.WebSession , snowflakeSessionIndex ]{
320+ cache : c ,
321+ collection : c .collections .snowflakeSessions ,
322+ index : snowflakeSessionNameIndex ,
323+ upstreamList : c .Config .SnowflakeSession .ListSnowflakeSessions ,
324+ nextToken : types .WebSession .GetName ,
325+ // TODO(lokraszewski): DELETE IN v21.0.0
326+ fallbackGetter : c .Config .SnowflakeSession .GetSnowflakeSessions ,
327+ }
328+
329+ return func (yield func (types.WebSession , error ) bool ) {
330+ ctx , span := c .Tracer .Start (ctx , "cache/RangeSnowflakeSessions" )
331+ defer span .End ()
332+
333+ for db , err := range lister .RangeWithFallback (ctx , start , end ) {
334+ if ! yield (db , err ) {
335+ return
336+ }
337+
338+ if err != nil {
339+ return
340+ }
341+ }
342+ }
343+ }
344+
345+ // ListSnowflakeSessions returns a page of Snowflake session resources.
346+ func (c * Cache ) ListSnowflakeSessions (ctx context.Context , limit int , startKey string ) ([]types.WebSession , string , error ) {
347+ ctx , span := c .Tracer .Start (ctx , "cache/ListSnowflakeSessions" )
348+ defer span .End ()
349+
350+ lister := genericLister [types.WebSession , snowflakeSessionIndex ]{
351+ cache : c ,
352+ collection : c .collections .snowflakeSessions ,
353+ index : snowflakeSessionNameIndex ,
354+ upstreamList : c .Config .SnowflakeSession .ListSnowflakeSessions ,
355+ nextToken : func (a types.WebSession ) string {
356+ return a .GetMetadata ().Name
357+ },
358+ }
359+ out , next , err := lister .list (ctx , limit , startKey )
360+ return out , next , trace .Wrap (err )
361+ }
362+
363+ // GetSnowflakeSessions returns all Snowflake session resources.
364+ func (c * Cache ) GetSnowflakeSessions (ctx context.Context ) ([]types.WebSession , error ) {
365+ ctx , span := c .Tracer .Start (ctx , "cache/GetSnowflakeSessions" )
366+ defer span .End ()
367+
368+ rg , err := acquireReadGuard (c , c .collections .snowflakeSessions )
369+ if err != nil {
370+ return nil , trace .Wrap (err )
371+ }
372+ defer rg .Release ()
373+
374+ if ! rg .ReadCache () {
375+ sessions , err := c .Config .SnowflakeSession .GetSnowflakeSessions (ctx )
376+ return sessions , trace .Wrap (err )
377+ }
378+
379+ out := make ([]types.WebSession , 0 , rg .store .len ())
380+ for a := range rg .store .resources (snowflakeSessionNameIndex , "" , "" ) {
381+ out = append (out , a .Copy ())
382+ }
383+
384+ return out , nil
385+ }
0 commit comments