-
Notifications
You must be signed in to change notification settings - Fork 35
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
Reconsider use of Golang templates #112
Comments
The Go 1 compatibility promise is applicable to the standard library also. So I would suggest mandating the Go template syntax as defined in Go 1 standard library. This way implementors can choose an alternative implementation of the Go 1 template if required in the future. |
Discussed during the interlock call. Continuing the discussion... |
On a closer look at the use case for the template, a string substitution with a method to escape the URL query would be sufficient. from parsimonious.grammar import Grammar
grammar = Grammar(r"""
mappings = ws* (string* keyref string*)+ ws*
keyref = (opening ws* urlquery? key ws* closing)
opening = '{{'
closing = '}}'
urlquery = 'urlquery' ws+
key = ~r'.[A-Z0-9-_]*'i
string = ~r'[ A-Z0-9.-_:/\\@~#$%^&*]*'i
ws = ~"\s"
""")
if __name__ == "__main__":
out = grammar.parse("https://{{ urlquery .username }}:{{ urlquery .password }}@{{ .host }}:{{ .port }}/{{ .path }}")
print(out) P.S: Recently Python switched from EBNF to PEG to define its own grammar. I think PEG would be a good choice to define the grammar. Here is an online playground in JS: https://pegjs.org/online |
I want to register two points that come to mind, but I’m not sure I’d consider them blockers:
For some context, the recommendation to get away from Golang templates comes from someone really focused on what Kubernetes looks like a decade from now (so Golang 2 kind of timeframe). There’s some question if Kubernetes as a whole could ever make that jump (given how implementations commonly include one another as Golang libraries), but we should at the very least be cognizant of tying the standard to a community that we have no influence in. |
@nebhale Those are valid points about a subset of the Go template! A subset of the Go template will lead to unportable configuration files, as is evident from your second point. I think the use cases are limited to string substitution and a function to escape for the URL query. The input to process the mapping is a I have noticed IBM Cloud provides the Secret values as a JSON object! See the docs: https://cloud.ibm.com/docs/containers?topic=containers-service-binding#bind-services There is an issue reported about the same in Red Hat's Service Binding Operator: redhat-developer/service-binding-operator#717 If we consider it a fair use case, a function to extract values from the JSON object would be excellent. When it comes to extracting values from a JSON object, we could adopt one of these:
Use Cases and Syntax for MappingConsidering the above three use cases, this is my proposal:
PEG Syntax of Service Binding Mapping
Programming APIFor the convenience of the implementors, we can provide libraries that implement parsers for the above syntax. This is not part of the spec. Go API
Python API
Update: Added programming API (not going to be part of the spec) |
Given the discussion above, I wonder if mappings could be moved out of the core, at the very least, while this area matures ? |
Mappings could be implemented as a separate resource that consumes a provisioned service and exposes a transformed provisioned service. That alternate resource can use whatever syntax it deems appropriate without any fear of breaking the ServiceBinding resource down the road. This is conceptual similar to the Composite/MultiService proposal in #120 |
JSON Pointer supports identifying a specific value within a JSON document. On second thought, I think this would be sufficient to meet the use cases. Reasons to use JSON Pointer:
|
FYI, I created a proposal to add EvalJSONPointer function to support RFC 6901 in Go. |
Discussed this at today's hangout and our recommendation is to move |
Spoke again at today's hangout and the previous recommendation of moving |
|
Since we merged #154, we can close this issue. |
Golang templates are used by mappings to create a value for a new key composed of existing keys. During a review it was brought up that Golang templates are not standardized and are inherently part of the Golang language. They are subject to the same evolution and deprecation as Golang features. A deprecation in the implementation language should not also implicitly be a deprecation in the Service Binding spec.
We should reconsider the use of Golang templates in favor of an independently scoped template language with multiple language implementations, or define our own minimal grammar.
The templating language was less of a concern when mappings were a spec extension, but since we promoted it to core, the choice has broader impacts.
The text was updated successfully, but these errors were encountered: