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

Add sprig template library #235

Merged
merged 1 commit into from
Aug 9, 2019
Merged

Add sprig template library #235

merged 1 commit into from
Aug 9, 2019

Conversation

hypnoglow
Copy link
Contributor

Proposed changes

This commit adds sprig template library functions to the templates used in header/cookie mutator.

Go stdlib templates are very limited in terms of features. For example, I have a use case where I have an array of strings in session data, and I want to use mutator to join them into the single header string. Currently it is kind of impossible to do properly. This template almost does this, but there is no possibility on removing trailing comma:

{{- $claims := (index .Extra "example.com/some-claims") -}}
{{- range $claim := $claims }}
{{- $claim -}},
{{- end -}}

With Extra set to map[string]interface{}{"example.com/some-claims":[]string{"Foo","Bar"} it compiles into Foo,Bar,.

With sprig library we could replace the whole template with simple {{- (index .Extra "example.com/some-claims") | join "," -}} and it will produce correct output Foo,Bar.

Sprig can also handle many other advanced use cases.

Checklist

  • I have read the contributing guidelines
  • I have read the security policy
  • I confirm that this pull request does not address a security vulnerability. If this pull request addresses a security
    vulnerability, I confirm that I got green light (please contact [email protected]) from the maintainers to push the changes.
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation within the code base (if appropriate)
  • I have documented my changes in the developer guide (if appropriate)

@aeneasr
Copy link
Member

aeneasr commented Aug 9, 2019

This is a great idea!

@aeneasr aeneasr merged commit c85c540 into ory:master Aug 9, 2019
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

Successfully merging this pull request may close these issues.

2 participants