Skip to content

Commit

Permalink
Merge pull request #549 from hazelops/fix/secrets-pull-not-pulling-al…
Browse files Browse the repository at this point in the history
…l-secrets

Ensure to pull paginated SSM output
  • Loading branch information
AutomationD authored Sep 15, 2023
2 parents 5f0ff93 + 07456dc commit 6cf1892
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 6cf1892

Please sign in to comment.