{"action":"created","issue":{"url":"https://api.github.com/repos/saltstack/salt/issues/37791","repository_url":"https://api.github.com/repos/saltstack/salt","labels_url":"https://api.github.com/repos/saltstack/salt/issues/37791/labels{/name}","comments_url":"https://api.github.com/repos/saltstack/salt/issues/37791/comments","events_url":"https://api.github.com/repos/saltstack/salt/issues/37791/events","html_url":"https://github.com/saltstack/salt/issues/37791","id":190531332,"number":37791,"title":"New feature: external custom Jinja filters","user":{"login":"mirceaulinic","id":16694679,"avatar_url":"https://avatars.githubusercontent.com/u/16694679?v=3","gravatar_id":"","url":"https://api.github.com/users/mirceaulinic","html_url":"https://github.com/mirceaulinic","followers_url":"https://api.github.com/users/mirceaulinic/followers","following_url":"https://api.github.com/users/mirceaulinic/following{/other_user}","gists_url":"https://api.github.com/users/mirceaulinic/gists{/gist_id}","starred_url":"https://api.github.com/users/mirceaulinic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mirceaulinic/subscriptions","organizations_url":"https://api.github.com/users/mirceaulinic/orgs","repos_url":"https://api.github.com/users/mirceaulinic/repos","events_url":"https://api.github.com/users/mirceaulinic/events{/privacy}","received_events_url":"https://api.github.com/users/mirceaulinic/received_events","type":"User","site_admin":false},"labels":[{"id":67287385,"url":"https://api.github.com/repos/saltstack/salt/labels/Core","name":"Core","color":"fef2c0","default":false},{"id":204655,"url":"https://api.github.com/repos/saltstack/salt/labels/Feature","name":"Feature","color":"009800","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/saltstack/salt/milestones/13","html_url":"https://github.com/saltstack/salt/milestones/Approved","labels_url":"https://api.github.com/repos/saltstack/salt/milestones/13/labels","id":9265,"number":13,"title":"Approved","description":"All issues that are ready to be worked on, both bugs and features.","creator":{"login":"thatch45","id":507599,"avatar_url":"https://avatars.githubusercontent.com/u/507599?v=3","gravatar_id":"","url":"https://api.github.com/users/thatch45","html_url":"https://github.com/thatch45","followers_url":"https://api.github.com/users/thatch45/followers","following_url":"https://api.github.com/users/thatch45/following{/other_user}","gists_url":"https://api.github.com/users/thatch45/gists{/gist_id}","starred_url":"https://api.github.com/users/thatch45/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thatch45/subscriptions","organizations_url":"https://api.github.com/users/thatch45/orgs","repos_url":"https://api.github.com/users/thatch45/repos","events_url":"https://api.github.com/users/thatch45/events{/privacy}","received_events_url":"https://api.github.com/users/thatch45/received_events","type":"User","site_admin":false},"open_issues":3231,"closed_issues":4190,"state":"open","created_at":"2011-05-14T04:00:56Z","updated_at":"2016-11-27T07:07:46Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2016-11-20T00:54:57Z","updated_at":"2016-11-28T01:21:03Z","closed_at":null,"body":"### Description of Issue/Question\r\n\r\nThere are many use cases when some custom Jinja filters are very specific to one's particular business/use case etc - believe me, in networking, for example, there are many edge cases as vendors are popping up like mushrooms, each with a different config syntax and stupidity. In that case, it requires editing this module: https://github.com/saltstack/salt/blob/3b81c37a531c48ff54a2332c4ea9c0d108ce0e74/salt/utils/templates.py#L346 - which is not hard at all, but not very maintainable.\r\n\r\nFor that reason, I think it would be needed a better mechanism to allow the user define their own custom filters in their environment.\r\n\r\nI was thinking about the following (not sure if it really makes sense, or not very hard to implement): under the custom modules dir (where the user may have ```_modules```, ```_grains```, ```_runners``` etc) we could also allow ```_filters```. Inside each module from this dir, the filter name would be specified as ```__virtualname__``` and the body in a single function having a standard naming, say ```filter_fun```. \r\nWhen the filter module is loaded and cached, the mapping from the ```template``` module can be extended:\r\n\r\n```python\r\njinja_env.filters[__virtualname__] = filter_fun\r\n```\r\n\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/saltstack/salt/issues/comments/263163325","html_url":"https://github.com/saltstack/salt/issues/37791#issuecomment-263163325","issue_url":"https://api.github.com/repos/saltstack/salt/issues/37791","id":263163325,"user":{"login":"mirceaulinic","id":16694679,"avatar_url":"https://avatars.githubusercontent.com/u/16694679?v=3","gravatar_id":"","url":"https://api.github.com/users/mirceaulinic","html_url":"https://github.com/mirceaulinic","followers_url":"https://api.github.com/users/mirceaulinic/followers","following_url":"https://api.github.com/users/mirceaulinic/following{/other_user}","gists_url":"https://api.github.com/users/mirceaulinic/gists{/gist_id}","starred_url":"https://api.github.com/users/mirceaulinic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mirceaulinic/subscriptions","organizations_url":"https://api.github.com/users/mirceaulinic/orgs","repos_url":"https://api.github.com/users/mirceaulinic/repos","events_url":"https://api.github.com/users/mirceaulinic/events{/privacy}","received_events_url":"https://api.github.com/users/mirceaulinic/received_events","type":"User","site_admin":false},"created_at":"2016-11-28T01:21:03Z","updated_at":"2016-11-28T01:21:03Z","body":"@Ch3LL @cachedout I was discussing about that in https://github.com/saltstack/salt/pull/37808 and I was thinking that the following implementation would help that too: https://github.com/saltstack/salt/pull/37808/commits/2a4fa2656aca009ae1a010a20574776e71643ae8\r\n\r\nWhen a function from an execution module uses the ```jinja_filter``` decorator, then will be injected as filter in the jinja environment. Thus, we'll cover the feature above as well, as an external custom filter can be defined in an external execution module an make use of that decorator.\r\n\r\nWhat do you think?"}}
{"actor":{"display_login":"mirceaulinic"}}