Skip to content

Allow loading choices from API callΒ #45

@aexvir

Description

@aexvir

Nice project!

It actually seems to be doing some nice things that I wanted cookiecutter to do and I was developing on my own πŸ˜…οΈ

What do you think about allowing to populate the choices option dynamically via some API call?
My use case at the moment is that we already have existing resources that we'd like to make references to in templated files, like k8s definitions and vcs projects.

I imagine this being set up somewhat like this:

[[variables]]
name = "infra_repo"
default = "infra/default"
prompt = "Which infrastructure repository should this be linked to?"
choices =  [
	{ endpoint = "https://gitlab.com/api/v4/groups/123/projects", headers = "Authorization: Bearer {{ token }}", values = "$.*.id", labels = "$.*.name" }
]

what kickstart would do in this case would be an API call to the endpoint, with the specified headers and will query the result using JSONPath for both values and labels and zip them together, showing the labels to the users but saving the value when the user accepts

I think that allowing to template headers from env vars or cli flag should be enough to support most auth methods, and for basic auth the credentials can be templated in the endpoint part

so headers should be optional

and labels as well, for when the info displayed to the user can be used also as value

choices can accept a list of this inline tables and make one request per configured endpoint, merging all the results in the end... not sure if this would be needed at some point, otherwise it can be limited to one only, or maybe moved outside of choices

either way... this is just a suggestion implementation, I'm more interested in if you'd be up for adding this feature to kickstart and if you'd be ok with getting and reviewing a contribution on this πŸ™‚οΈ

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions