Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug or advice needed #376

Open
vulturm opened this issue Apr 28, 2023 · 2 comments
Open

Possible bug or advice needed #376

vulturm opened this issue Apr 28, 2023 · 2 comments

Comments

@vulturm
Copy link

vulturm commented Apr 28, 2023

Hello,

First of all thank you for this tool. I've integrated it in our workflow and I stumbled upon the following issue, possible yaml unmarshal bug.

  • Spruce version: v1.30.2

  • Description:
    I would like to store a yaml file in AWS Secrets manager with plaintext option. Then use the awssecret DSL to fetch the content and be interpreted as yaml.

  • Steps to reproduce:
    Store the following yaml content in aws secrets manager:

options:
  labelsValidations:
    Owner:
    Manufacturer:
      - value1
      - value2
      - value3
      - value4

Then use the following file to retrieve it as a YAML structure:

cat qwe.yaml
---
fetched_from_secrets: (( awssecret "/sre/non-prod-config?key=options" ))
  • Expected outcome:
# spruce merge qwe.yaml
fetched_from_secrets:
  labelsValidations:
    Owner:
    Manufacturer:
      - value1
      - value2
      - value3
      - value4
  • Actual outcome:
spruce merge qwe.yaml
fetched_from_secrets: map[labelsValidations:map[Manufacturer:[value1 value2 value3
  value4] Owner:<nil>]]

I've tried various ways such as, not specifying the yaml key:

# cat qwe.yaml
---
fetched_from_secrets: (( awssecret "/sre/non-prod-config" ))

or

---
fetched_from_secrets:
  (( awssecret "/sre/non-prod-config" ))


# spruce merge qwe.yaml
fetched_from_secrets: |-
  options:
    labelsValidations:
      Owner:
      Manufacturer:
        - value1
        - value2
        - value3
        - value4

However, this way the value is presented as multiline string/block, and it can't be further parsed by subsequent (( join "/" fetched_from_secrets.labelsValidations.Manufacturer )) which we would like.

Any suggestion that would allow me to achieve the Expected outcome ?

Thank you in advance!

@geofffranks
Copy link
Owner

geofffranks commented Apr 29, 2023 via email

@vulturm
Copy link
Author

vulturm commented Apr 29, 2023

Hi Geoff,

Just making sure I understand the ask - you have yaml formated text in your AWS secret that you would like to retrieve and be able to manipulate with spruce. However when spruce retrieves it, it comes back as a multiline string, rather than a
datastructure. Correct?

Yes, that is correct. Is that expected or a bug?

You may be able to modify the awssecret operator to parse this out into a datastructure, but I'm not sure if it will get pulled in soon enough to be referenced by all the other operators since there are multiple phases of the merge process.You might be able to use some of the cherry pick flags to isolate the value being returned, save it to a file, and then run a second merge process though. if that doesn't work you could probably send the aws secret merge output to yq -r and then pull that info into a second merge. It's been a while but you may also be able to pull in datastructures from environment variables, so if you're concerned about writing secrets to disk temporarily, you could store them as an env var. there might be code related to parsing that out into datastructures you can reference for the aws operator.

Actually, I was thinking to defer the processing of the rest of the operators until the next run and run spruce in multiple phases. Something like:

fetched_from_secrets: (( awssecret "/sre/non-prod-config?key=options" ))

ManufacturerSlashSeparated: (( defer join "/" fetched_from_secrets.labelsValidations.Manufacturer ))

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants