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,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/lmika/awstools/internal/ssm-browse/models"
"github.com/pkg/errors"
"log"
)
type Provider struct {
@ -18,9 +19,16 @@ func NewProvider(client *ssm.Client) *Provider {
}
}
func (p *Provider) List(ctx context.Context) (*models.SSMParameters, error) {
func (p *Provider) List(ctx context.Context, prefix string, nextToken string) (*models.SSMParameters, error) {
log.Printf("new prefix: %v", prefix)
var nextTokenStr *string = nil
if nextToken != "" {
nextTokenStr = aws.String(nextToken)
}
pars, err := p.client.GetParametersByPath(ctx, &ssm.GetParametersByPathInput{
Path: aws.String("/"),
Path: aws.String(prefix),
NextToken: nextTokenStr,
MaxResults: 10,
Recursive: true,
})
@ -30,10 +38,11 @@ func (p *Provider) List(ctx context.Context) (*models.SSMParameters, error) {
res := &models.SSMParameters{
Items: make([]models.SSMParameter, len(pars.Parameters)),
NextToken: aws.ToString(pars.NextToken),
}
for i, p := range pars.Parameters {
res.Items[i] = models.SSMParameter{
Name: aws.ToString(p.Name),
Name: aws.ToString(p.Name),
Value: aws.ToString(p.Value),
}
}