- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6
Refactor handling of Jinja2 templates and add filters #327
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -85,6 +85,7 @@ namespace | |
| namespaces | ||
| Nautobot | ||
| Netbox | ||
| Netutils | ||
| Newsfragment | ||
| Nornir | ||
| npm | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Refactored management of Jinja2 templating to allow for filters within Infrahub. Builtin filters as well as those from Netutils are available. | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --- | ||
| title: Python SDK Templating | ||
| --- | ||
| Filters can be used when defining [computed attributes](https://docs.infrahub.app/guides/computed-attributes) or [Jinja2 Transforms](https://docs.infrahub.app/guides/jinja2-transform) within Infrahub. | ||
|  | ||
| ## Builtin Jinja2 filters | ||
|  | ||
| The following filters are those that are [shipped with Jinja2](https://jinja.palletsprojects.com/en/stable/templates/#list-of-builtin-filters) and enabled within Infrahub. The trusted column indicates if the filter is allowed for use with Infrahub's computed attributes when the server is configured in strict mode. | ||
|  | ||
| <!-- vale off --> | ||
| | Name | Trusted | | ||
| |----------|----------| | ||
| {% for filter in builtin %} | ||
| | {{ filter.name }} | {% if filter.trusted %}✅{% else %}❌{% endif %} | | ||
| {% endfor %} | ||
| <!-- vale on --> | ||
|  | ||
| ## Netutils filters | ||
|  | ||
| The following Jinja2 filters from <a href="https://netutils.readthedocs.io">Netutils</a> are included within Infrahub. | ||
| <!-- vale off --> | ||
| | Name | Trusted | | ||
| |----------|----------| | ||
| {% for filter in netutils %} | ||
| | {{ filter.name }} | {% if filter.trusted %}✅{% else %}❌{% endif %} | | ||
| {% endfor %} | ||
| <!-- vale on --> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| --- | ||
| title: Python SDK Templating | ||
| --- | ||
| Filters can be used when defining [computed attributes](https://docs.infrahub.app/guides/computed-attributes) or [Jinja2 Transforms](https://docs.infrahub.app/guides/jinja2-transform) within Infrahub. | ||
|  | ||
| ## Builtin Jinja2 filters | ||
|  | ||
| The following filters are those that are [shipped with Jinja2](https://jinja.palletsprojects.com/en/stable/templates/#list-of-builtin-filters) and enabled within Infrahub. The trusted column indicates if the filter is allowed for use with Infrahub's computed attributes when the server is configured in strict mode. | ||
|  | ||
| <!-- vale off --> | ||
| | Name | Trusted | | ||
| |----------|----------| | ||
| | abs | ✅ | | ||
| | attr | ❌ | | ||
| | batch | ❌ | | ||
| | capitalize | ✅ | | ||
| | center | ✅ | | ||
| | count | ✅ | | ||
| | d | ✅ | | ||
| | default | ✅ | | ||
| | dictsort | ❌ | | ||
| | e | ✅ | | ||
| | escape | ✅ | | ||
| | filesizeformat | ✅ | | ||
| | first | ✅ | | ||
| | float | ✅ | | ||
| | forceescape | ✅ | | ||
| | format | ✅ | | ||
| | groupby | ❌ | | ||
| | indent | ✅ | | ||
| | int | ✅ | | ||
| | items | ❌ | | ||
| | join | ✅ | | ||
| | last | ✅ | | ||
| | length | ✅ | | ||
| | list | ✅ | | ||
| | lower | ✅ | | ||
| | map | ❌ | | ||
| | max | ✅ | | ||
| | min | ✅ | | ||
| | pprint | ❌ | | ||
| | random | ❌ | | ||
| | reject | ❌ | | ||
| | rejectattr | ❌ | | ||
| | replace | ✅ | | ||
| | reverse | ✅ | | ||
| | round | ✅ | | ||
| | safe | ❌ | | ||
| | select | ❌ | | ||
| | selectattr | ❌ | | ||
| | slice | ✅ | | ||
| | sort | ❌ | | ||
| | string | ✅ | | ||
| | striptags | ✅ | | ||
| | sum | ✅ | | ||
| | title | ✅ | | ||
| | tojson | ❌ | | ||
| | trim | ✅ | | ||
| | truncate | ✅ | | ||
| | unique | ❌ | | ||
| | upper | ✅ | | ||
| | urlencode | ✅ | | ||
| | urlize | ❌ | | ||
| | wordcount | ✅ | | ||
| | wordwrap | ✅ | | ||
| | xmlattr | ❌ | | ||
| <!-- vale on --> | ||
|  | ||
| ## Netutils filters | ||
|  | ||
| The following Jinja2 filters from <a href="https://netutils.readthedocs.io">Netutils</a> are included within Infrahub. | ||
| <!-- vale off --> | ||
| | Name | Trusted | | ||
| |----------|----------| | ||
| | abbreviated_interface_name | ✅ | | ||
| | abbreviated_interface_name_list | ✅ | | ||
| | asn_to_int | ✅ | | ||
| | bits_to_name | ✅ | | ||
| | bytes_to_name | ✅ | | ||
| | canonical_interface_name | ✅ | | ||
| | canonical_interface_name_list | ✅ | | ||
| | cidr_to_netmask | ✅ | | ||
| | cidr_to_netmaskv6 | ✅ | | ||
| | clean_config | ✅ | | ||
| | compare_version_loose | ✅ | | ||
| | compare_version_strict | ✅ | | ||
| | config_compliance | ✅ | | ||
| | config_section_not_parsed | ✅ | | ||
| | delimiter_change | ✅ | | ||
| | diff_network_config | ✅ | | ||
| | feature_compliance | ✅ | | ||
| | find_unordered_cfg_lines | ✅ | | ||
| | fqdn_to_ip | ❌ | | ||
| | get_all_host | ❌ | | ||
| | get_broadcast_address | ✅ | | ||
| | get_first_usable | ✅ | | ||
| | get_ips_sorted | ✅ | | ||
| | get_nist_urls | ✅ | | ||
| | get_nist_vendor_platform_urls | ✅ | | ||
| | get_oui | ✅ | | ||
| | get_peer_ip | ✅ | | ||
| | get_range_ips | ✅ | | ||
| | get_upgrade_path | ✅ | | ||
| | get_usable_range | ✅ | | ||
| | hash_data | ✅ | | ||
| | int_to_asdot | ✅ | | ||
| | interface_range_compress | ✅ | | ||
| | interface_range_expansion | ✅ | | ||
| | ip_addition | ✅ | | ||
| | ip_subtract | ✅ | | ||
| | ip_to_bin | ✅ | | ||
| | ip_to_hex | ✅ | | ||
| | ipaddress_address | ✅ | | ||
| | ipaddress_interface | ✅ | | ||
| | ipaddress_network | ✅ | | ||
| | is_classful | ✅ | | ||
| | is_fqdn_resolvable | ❌ | | ||
| | is_ip | ✅ | | ||
| | is_ip_range | ✅ | | ||
| | is_ip_within | ✅ | | ||
| | is_netmask | ✅ | | ||
| | is_network | ✅ | | ||
| | is_reversible_wildcardmask | ✅ | | ||
| | is_valid_mac | ✅ | | ||
| | longest_prefix_match | ✅ | | ||
| | mac_normalize | ✅ | | ||
| | mac_to_format | ✅ | | ||
| | mac_to_int | ✅ | | ||
| | mac_type | ✅ | | ||
| | name_to_bits | ✅ | | ||
| | name_to_bytes | ✅ | | ||
| | name_to_name | ✅ | | ||
| | netmask_to_cidr | ✅ | | ||
| | netmask_to_wildcardmask | ✅ | | ||
| | normalise_delimiter_caret_c | ✅ | | ||
| | paloalto_panos_brace_to_set | ✅ | | ||
| | paloalto_panos_clean_newlines | ✅ | | ||
| | regex_findall | ❌ | | ||
| | regex_match | ❌ | | ||
| | regex_search | ❌ | | ||
| | regex_split | ❌ | | ||
| | regex_sub | ❌ | | ||
| | sanitize_config | ✅ | | ||
| | section_config | ✅ | | ||
| | sort_interface_list | ✅ | | ||
| | split_interface | ✅ | | ||
| | uptime_seconds_to_string | ✅ | | ||
| | uptime_string_to_seconds | ✅ | | ||
| | version_metadata | ✅ | | ||
| | vlanconfig_to_list | ✅ | | ||
| | vlanlist_to_config | ✅ | | ||
| | wildcardmask_to_netmask | ✅ | | ||
| <!-- vale on --> | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth pointing to the doc on this one (https://jinja.palletsprojects.com/en/stable/templates/#list-of-builtin-filters) so users know what's behind each line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added these links.