Skip to content

Commit

Permalink
Converted json to string before indent in jinja2 templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Edgin committed Nov 3, 2023
1 parent 3d1ffa7 commit 4a4703f
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 55 deletions.
28 changes: 14 additions & 14 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@
vars:
server_config: >-
{{ lookup('ansible.builtin.template', '../../templates/server_config.json.j2') }}
tasks:
tasks:
- name: Verify server_config.json is correct
ansible.builtin.assert:
that:
- server_config.advanced_settings.default_number_of_transfer_threads == 4
- server_config.advanced_settings.default_temporary_password_lifetime_in_seconds == 120
- >-
server_config.advanced_settings.maximum_number_of_concurrent_rule_engine_server_processes
server_config.advanced_settings.maximum_number_of_concurrent_rule_engine_server_processes
== 4
- server_config.advanced_settings.maximum_size_for_single_buffer_in_megabytes == 32
- server_config.advanced_settings.maximum_temporary_password_lifetime_in_seconds == 1000
Expand Down Expand Up @@ -147,14 +147,14 @@
- server_config.pam_password_min_time is not defined
- server_config.plugin_configuration.rule_engines|length == 2
- >-
server_config.plugin_configuration.rule_engines[0].plugin_name
server_config.plugin_configuration.rule_engines[0].plugin_name
== 'irods_rule_engine_plugin-irods_rule_language'
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_data_variable_mapping_set
| length
| length
== 1
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_data_variable_mapping_set[0]
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_data_variable_mapping_set[0]
== 'core'
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_function_name_mapping_set
Expand Down Expand Up @@ -368,33 +368,33 @@
- server_config.pam_password_min_time == 2
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_data_variable_mapping_set
| length
| length
== 3
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_data_variable_mapping_set[0]
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_data_variable_mapping_set[0]
== 'dvm1'
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_data_variable_mapping_set[2]
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_data_variable_mapping_set[2]
== 'core'
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_function_name_mapping_set
| length
| length
== 3
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_function_name_mapping_set[1]
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_function_name_mapping_set[1]
== 'fnm2'
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_function_name_mapping_set[2]
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_function_name_mapping_set[2]
== 'core'
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_rulebase_set
| length
| length
== 3
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_rulebase_set[0]
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_rulebase_set[0]
== 're1'
- >-
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_rulebase_set[2]
server_config.plugin_configuration.rule_engines[0].plugin_specific_configuration.re_rulebase_set[2]
== 'core'
- server_config.xmsg_port == 3

Expand Down
2 changes: 1 addition & 1 deletion templates/host_access_control_config.json.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% import 'server_config_macros.j2' as sc with context %}
{
"access_entries": {{ sc.access_entries() | indent(4) }},
"access_entries": {{ sc.access_entries() | string | indent(4) }},
"schema_name": "host_access_control_config",
"schema_version": "v3"
}
2 changes: 1 addition & 1 deletion templates/hosts_config.json.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% import 'server_config_macros.j2' as sc with context %}
{
"host_entries": {{ sc.host_entries() | indent(4) }},
"host_entries": {{ sc.host_entries() | string | indent(4) }},
"schema_name": "hosts_config",
"schema_version": "v3"
}
6 changes: 4 additions & 2 deletions templates/irods_environment.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@
{% endif %}
"irods_port": {{ _zone_port }},
{% if _for_server %}
"irods_server_control_plane_encryption_algorithm": "{{ _server_control_plane_encryption_algorithm }}",
"irods_server_control_plane_encryption_num_hash_rounds": {{ _server_control_plane_encryption_num_hash_rounds }},
"irods_server_control_plane_encryption_algorithm": "{{
_server_control_plane_encryption_algorithm }}",
"irods_server_control_plane_encryption_num_hash_rounds": {{
_server_control_plane_encryption_num_hash_rounds }},
"irods_server_control_plane_key": "{{ _server_control_plane_key }}",
"irods_server_control_plane_port": {{ _server_control_plane_port }},
{% endif %}
Expand Down
17 changes: 10 additions & 7 deletions templates/server_config.json.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% import 'server_config_macros.j2' as sc with context %}
{
"advanced_settings": {{ sc.advanced_settings() | indent }},
"catalog_provider_hosts": {{ sc.mk_catalog_provider_hosts(_catalog_provider_hosts) | indent }},
"advanced_settings": {{ sc.advanced_settings() | string | indent }},
"catalog_provider_hosts": {{
sc.mk_catalog_provider_hosts(_catalog_provider_hosts) | string | indent }},
"catalog_service_role": "{{ _catalog_service_role }}",
"default_dir_mode": "{{ _default_dir_mode }}",
"default_file_mode": "{{ _default_file_mode }}",
Expand All @@ -14,8 +15,8 @@
{% else %}
"default_resource_name": null,
{% endif %}
"environment_variables": {{ sc.environment_variables() | indent }},
"federation": {{ sc.federation() | indent }},
"environment_variables": {{ sc.environment_variables() | string | indent }},
"federation": {{ sc.federation() | string | indent }},
{% if _kerberos_name %}
"kerberos_name": "{{ _kerberos_name }}",
{% endif %}
Expand All @@ -33,13 +34,15 @@
{% if _pam_password_min_time %}
"pam_password_min_time": {{ _pam_password_min_time }},
{% endif %}
"plugin_configuration": {{ sc.plugin_configuration() | indent }},
"plugin_configuration": {{ sc.plugin_configuration() | string | indent }},
"rule_engine_namespaces": [ "" ],
"schema_name": "server_config",
"schema_validation_base_uri": "{{ _schema_validation_base_uri }}",
"schema_version": "v3",
"server_control_plane_encryption_algorithm": "{{ _server_control_plane_encryption_algorithm }}",
"server_control_plane_encryption_num_hash_rounds": {{ _server_control_plane_encryption_num_hash_rounds }},
"server_control_plane_encryption_algorithm": "{{
_server_control_plane_encryption_algorithm }}",
"server_control_plane_encryption_num_hash_rounds": {{
_server_control_plane_encryption_num_hash_rounds }},
"server_control_plane_key": "{{ _server_control_plane_key }}",
"server_control_plane_port": {{ _server_control_plane_port }},
"server_control_plane_timeout_milliseconds": {{ _server_control_plane_timeout }},
Expand Down
86 changes: 56 additions & 30 deletions templates/server_config_macros.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% if _access_entries %}
[
{% for e in _access_entries %}
{{ mk_access_entry(e) | indent(4) }}{% if not loop.last %},{% endif +%}
{{ mk_access_entry(e) | string | indent(4) }}{% if not loop.last %},{% endif +%}
{% endfor %}
]
{%- else %}
Expand All @@ -23,26 +23,30 @@

{% macro advanced_settings() -%}
{
"default_number_of_transfer_threads": {{ _default_number_of_transfer_threads }},
"default_number_of_transfer_threads": {{
_default_number_of_transfer_threads }},
"default_temporary_password_lifetime_in_seconds": {{ _default_temporary_password_lifetime }},
"maximum_number_of_concurrent_rule_engine_server_processes": {{ _maximum_number_of_concurrent_rule_engine_server_processes }},
"maximum_number_of_concurrent_rule_engine_server_processes": {{
_maximum_number_of_concurrent_rule_engine_server_processes }},
"maximum_size_for_single_buffer_in_megabytes": {{ _maximum_size_for_single_buffer }},
"maximum_temporary_password_lifetime_in_seconds": {{ _maximum_temporary_password_lifetime }},
"rule_engine_server_sleep_time_in_seconds": {{ _rule_engine_server_sleep_time }},
"transfer_buffer_size_for_parallel_transfer_in_megabytes": {{ _transfer_buffer_size_for_parallel_transfer }},
"transfer_chunk_size_for_parallel_transfer_in_megabytes": {{ _transfer_chunk_size_for_parallel_transfer }}
"transfer_buffer_size_for_parallel_transfer_in_megabytes": {{
_transfer_buffer_size_for_parallel_transfer }},
"transfer_chunk_size_for_parallel_transfer_in_megabytes": {{
_transfer_chunk_size_for_parallel_transfer }}
}
{%- endmacro %}


{% macro environment_variables() -%}
{% if _environment_variables|length == 0 %}
{% if _environment_variables | length == 0 %}
{}
{%- elif _environment_variables|length == 1 %}
{% set key, value = _environment_variables.items()|first %}
{%- elif _environment_variables | length == 1 %}
{% set key, value = _environment_variables.items() | first %}
{ "{{ key }}": "{{ value }}" }
{%- else %}
{
{
{% for key, value in _environment_variables.items() %}
"{{ key }}": "{{ value }}"{% if not loop.last %},{% endif +%}
{% endfor %}
Expand All @@ -52,9 +56,9 @@


{% macro mk_catalog_provider_hosts(hosts) -%}
{% if hosts|length == 0 %}
{% if hosts | length == 0 %}
[]
{%- elif hosts|length == 1 %}
{%- elif hosts | length == 1 %}
[ "{{ hosts[0] }}" ]
{%- else %}
[
Expand All @@ -68,7 +72,8 @@

{% macro mk_federate(def) -%}
{
"catalog_provider_hosts": {{ mk_catalog_provider_hosts(def.catalog_provider_hosts) | indent(4) }},
"catalog_provider_hosts": {{
mk_catalog_provider_hosts(def.catalog_provider_hosts) | string | indent(4) }},
"negotiation_key": "{{ def.negotiation_key }}",
"zone_key": "{{ def.zone_key }}",
"zone_name": "{{ def.zone_name }}"
Expand All @@ -80,7 +85,7 @@
{% if _federation %}
[
{% for f in _federation %}
{{ mk_federate(f) | indent(4) }}{% if not loop.last %},{% endif +%}
{{ mk_federate(f) | string | indent(4) }}{% if not loop.last %},{% endif +%}
{% endfor %}
]
{%- else %}
Expand Down Expand Up @@ -110,7 +115,7 @@
{% macro mk_host_entry(entry) -%}
{
"address_type": "{{ entry.address_type }}",
"addresses": {{ mk_address_list(entry.addresses) | indent(4) }}
"addresses": {{ mk_address_list(entry.addresses) | string | indent(4) }}
}
{%- endmacro %}

Expand All @@ -119,7 +124,7 @@
{% if _host_entries %}
[
{% for e in _host_entries %}
{{ mk_host_entry(e) | indent(4) }}{% if not loop.last %},{% endif +%}
{{ mk_host_entry(e) | string | indent(4) }}{% if not loop.last %},{% endif +%}
{% endfor %}
]
{%- else %}
Expand All @@ -143,15 +148,15 @@
{% macro mk_database(db, default_driver) -%}
{% set d = db if db.odbc_driver else db | combine({ 'odbc_driver': default_driver }) %}
{
"{{ db.catalog_database_type }}": {{ mk_database_config(d) | indent(4) }}
"{{ db.catalog_database_type }}": {{ mk_database_config(d) | string | indent(4) }}
}
{%- endmacro %}


{% macro mk_re_file_set(files) -%}
{% if files|length == 0 %}
{% if files | length == 0 %}
[]
{%- elif files|length == 1 %}
{%- elif files | length == 1 %}
[ "{{ files[0] }}" ]
{%- else %}
[
Expand All @@ -165,12 +170,14 @@

{% macro mk_rule_lang_config(extra_dvm, extra_fnm, extra_rulebases) -%}
{
"re_data_variable_mapping_set": {{ mk_re_file_set(extra_dvm + [ 'core' ]) | indent(4) }},
"re_function_name_mapping_set": {{ mk_re_file_set(extra_fnm + [ 'core' ]) | indent(4) }},
"re_rulebase_set": {{ mk_re_file_set(extra_rulebases + [ 'core' ]) | indent(4) }},
"re_data_variable_mapping_set": {{
mk_re_file_set(extra_dvm + [ 'core' ]) | string | indent(4) }},
"re_function_name_mapping_set": {{
mk_re_file_set(extra_fnm + [ 'core' ]) | string | indent(4) }},
"re_rulebase_set": {{ mk_re_file_set(extra_rulebases + [ 'core' ]) | string | indent(4) }},
"regexes_for_supported_peps": [
"ac[^ ]*",
"msi[^ ]*",
"ac[^ ]*",
"msi[^ ]*",
"[^ ]*pep_[^ ]*_(pre|post|except|finally)"
]
}
Expand All @@ -181,20 +188,33 @@
{
"instance_name": "{{ instance_name }}",
"plugin_name": "{{ plugin_name }}",
"plugin_specific_configuration": {{ cfg_json | indent(4) }}{% if shm %},{% endif +%}
"plugin_specific_configuration": {{ cfg_json | string | indent(4) }}{% if shm %},{% endif +%}
{% if shm %}
"shared_memory_instance": "{{ shm }}"
{% endif %}
}
}
{%- endmacro %}


{% macro mk_rule_engine_list(rule_lang_extra_dvm, rule_lang_extra_fnm, rule_lang_extra_rulebases)
-%}
{% set rule_lang_cfg = mk_rule_lang_config(rule_lang_extra_dvm, rule_lang_extra_fnm, rule_lang_extra_rulebases) %}
{% set rule_lang_cfg = mk_rule_lang_config(
rule_lang_extra_dvm, rule_lang_extra_fnm, rule_lang_extra_rulebases) %}
[
{{ mk_rule_engine('irods_rule_engine_plugin-irods_rule_language-instance', 'irods_rule_engine_plugin-irods_rule_language', rule_lang_cfg, 'irods_rule_language_rule_engine') | indent(4) }},
{{ mk_rule_engine('irods_rule_engine_plugin-cpp_default_policy-instance', 'irods_rule_engine_plugin-cpp_default_policy', '{}', none) | indent(4) }}
{{ mk_rule_engine(
'irods_rule_engine_plugin-irods_rule_language-instance',
'irods_rule_engine_plugin-irods_rule_language',
rule_lang_cfg,
'irods_rule_language_rule_engine' )
| string
| indent(4) }},
{{ mk_rule_engine(
'irods_rule_engine_plugin-cpp_default_policy-instance',
'irods_rule_engine_plugin-cpp_default_policy',
'{}',
none )
| string
| indent(4) }}
]
{%- endmacro %}

Expand All @@ -203,10 +223,16 @@
{
"authentication": {},
{% if _icat %}
"database": {{ mk_database(_icat, _dbms_default_odbc_driver) | indent(4) }},
"database": {{ mk_database(_icat, _dbms_default_odbc_driver) | string | indent(4) }},
{% endif %}
"network": {},
"resource": {},
"rule_engines": {{ mk_rule_engine_list(_re_additional_data_variable_mappings, _re_additional_function_name_mappings, _re_additional_rulebases) | indent(4) }}
"rule_engines": {{
mk_rule_engine_list(
_re_additional_data_variable_mappings,
_re_additional_function_name_mappings,
_re_additional_rulebases )
| string
| indent(4) }}
}
{%- endmacro %}

0 comments on commit 4a4703f

Please sign in to comment.