Skip to content

Commit

Permalink
Ensure to pull paginated SSM output
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomationD committed Sep 15, 2023
1 parent 5f0ff93 commit 07456dc
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions internal/commands/secrets_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func (o *SecretsPullOptions) Run() error {
func (o *SecretsPullOptions) pull(s *pterm.SpinnerPrinter) error {
s.UpdateText(fmt.Sprintf("Pulling secrets from %s://%s...", o.Backend, o.SecretsPath))

values := make(map[string]interface{})

params, err := o.Config.AWSClient.SSMClient.GetParametersByPath(&ssm.GetParametersByPathInput{
Path: aws.String(o.SecretsPath),
Recursive: aws.Bool(true),
Expand All @@ -149,13 +151,38 @@ func (o *SecretsPullOptions) pull(s *pterm.SpinnerPrinter) error {
return err
}

values := make(map[string]interface{})

for _, param := range params.Parameters {
p := strings.Split(*param.Name, "/")
values[p[len(p)-1]] = *param.Value
}

for {
if params.NextToken == nil {
break
}

params, err = o.Config.AWSClient.SSMClient.GetParametersByPath(&ssm.GetParametersByPathInput{
Path: aws.String(o.SecretsPath),
Recursive: aws.Bool(true),
WithDecryption: aws.Bool(true),
NextToken: params.NextToken,
ParameterFilters: []*ssm.ParameterStringFilter{
{
Key: aws.String("Type"),
Values: aws.StringSlice([]string{"SecureString"}),
},
},
})
if err != nil {
return err
}

for _, param := range params.Parameters {
p := strings.Split(*param.Name, "/")
values[p[len(p)-1]] = *param.Value
}
}

b, err := json.MarshalIndent(values, "", "")
if err != nil {
return err
Expand Down

0 comments on commit 07456dc

Please sign in to comment.