ssm-browse: added cd command

Also came up with an approach for dealing with commands that will probably work with contexts
This commit is contained in:
Leon Mika 2022-03-29 10:29:25 +11:00
parent 0b745a6dfa
commit f6f06eb22d
13 changed files with 142 additions and 37 deletions

View file

@ -6,5 +6,5 @@ import (
)
type SSMProvider interface {
List(ctx context.Context) (*models.SSMParameters, error)
List(ctx context.Context, prefix string, nextToken string) (*models.SSMParameters, error)
}

View file

@ -15,6 +15,22 @@ func NewService(provider SSMProvider) *Service {
}
}
func (s *Service) List(ctx context.Context) (*models.SSMParameters, error) {
return s.provider.List(ctx)
func (s *Service) List(ctx context.Context, prefix string) (*models.SSMParameters, error) {
var items []models.SSMParameter
var nextToken string
for {
page, err := s.provider.List(ctx, prefix, nextToken)
if err != nil {
return nil, err
}
items = append(items, page.Items...)
nextToken = page.NextToken
if len(items) >= 50 || nextToken == "" {
break
}
}
return &models.SSMParameters{Items: items, NextToken: nextToken}, nil
}