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

Direct way of consuming parameters/credentials as JSON objects? #1508

Closed
philliphoff opened this issue Mar 18, 2021 · 5 comments · Fixed by #3225
Closed

Direct way of consuming parameters/credentials as JSON objects? #1508

philliphoff opened this issue Mar 18, 2021 · 5 comments · Fixed by #3225
Labels
2 - 🍕 Pizza should be eaten daily user experience 🌈💖 Make it easier for everyone to use Porter

Comments

@philliphoff
Copy link

Is there a direct way of consuming parameters or credentials in porter.yaml as JSON objects (i.e. use their sub-properties as inputs to commands)? Currently one might feed a parameter/credential into an exec command, which calls a bash script, which simply echos the value, which can then be teased into individual outputs using jsonPath. Is there a better way?

@philliphoff philliphoff added the question Halp plz label Mar 18, 2021
@carolynvs
Copy link
Member

We don't currently support that right now, you would need to do the workaround you laid out (using exec mixin to grab the piece you want and output a sub-property).

However it could be possible for parameters with a bit of work in Porter. We support this for custom values defined in porter.yaml, where you can use templating like {{ bundle.custom.myobj.subfield }}.

Let me lay out what I think it could look like, and let me know if it works with your use case:

config.json

{
  "color": "blue"
}

porter.yaml

parameters:
- name: config
   type: object
   path: /cnab/app/config.json # User passes in a json document for this parameter

install:
- exec:
     description: Use a sub field on the config property document
     command: ./helpers.sh
     arguments:
     - "{{ bundle.parameters.config.color }}" # passes in "blue"

Porter would need to do some special handling for parameters of type "object" and expand them in the template (instead of providing it as a string) which I think is the right thing here, we just missed it the first time around.

@carolynvs carolynvs self-assigned this Mar 19, 2021
@carolynvs carolynvs added this to the Manifest Syntax milestone Mar 27, 2021
@carolynvs carolynvs added the 2 - 🍕 Pizza should be eaten daily label Mar 27, 2021
@carolynvs
Copy link
Member

I'm going to assume that this (above) is a workable design but if anyone has feedback on how they would like to use parameters that are a structured object (instead of a simple value), please leave a comment!

@philliphoff
Copy link
Author

Yes, I think that design would work for us.

@carolynvs
Copy link
Member

carolynvs commented Mar 31, 2021

Thanks for letting me know! I think it's a straightforward change for someone familiar with Go. We would need to attempt to unmarshal the parameter as json, and if it works assign that to the parameter's value. If it can't be read as json, that would be a hard error, since the parameter validation which occurrs before the bundle is run should have checked that it's a json document already.

The change should be made in this function, so that it returns an (interface{}, error) instead of a string.

func (m *RuntimeManifest) resolveParameter(pd manifest.ParameterDefinition) string {

If anyone is interested in trying to fix this, I'm happy to help. Otherwise it's on the v1.0 roadmap now.

@carolynvs carolynvs modified the milestones: Manifest Syntax, 1.0 May 10, 2021
@carolynvs carolynvs added the breaking change 💥 Breaking changes to Porter's CLI, config or behavior label May 10, 2021
@carolynvs carolynvs added user experience 🌈💖 Make it easier for everyone to use Porter and removed question Halp plz labels Oct 7, 2021
@carolynvs carolynvs removed their assignment Feb 1, 2022
@carolynvs
Copy link
Member

We can make this work in a v1 minor patch, without a breaking change. To do this we need to preserve this existing functionality

install:
  - exec:
       command: foo
       arguments:
         - "{{ bundle.parameters.config }}" # should still inject the string representation of the json document

@carolynvs carolynvs removed the breaking change 💥 Breaking changes to Porter's CLI, config or behavior label Jun 16, 2022
@carolynvs carolynvs removed this from the 1.0 milestone Jun 16, 2022
@schristoff schristoff moved this to 📋 Backlog in Porter Jul 28, 2023
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Porter Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 - 🍕 Pizza should be eaten daily user experience 🌈💖 Make it easier for everyone to use Porter
Projects
Status: Done
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants