Zero diff refactor of config files

Change-Id: Ife23582ad22c54b6a11a8d7621db4f151014bfc2
diff --git a/gerrit/files/gerrit.config b/gerrit/files/gerrit.config
index 881abc0..e720dd9 100644
--- a/gerrit/files/gerrit.config
+++ b/gerrit/files/gerrit.config
@@ -2,13 +2,13 @@
 # This file is managed by salt.
 
 [gerrit]
-	basePath = git
-	canonicalWebUrl = {{ server.canonical_web_url }}
+    basePath = git
+    canonicalWebUrl = {{ server.canonical_web_url }}
     {%- if server.git_http_url is defined %}
-	gitHttpUrl = {{ server.git_http_url }}
+    gitHttpUrl = {{ server.git_http_url }}
     {%- endif %}
     {%- if server.canonical_git_url is defined %}
-	canonicalGitUrl = {{ server.canonical_git_url }}
+    canonicalGitUrl = {{ server.canonical_git_url }}
     {%- endif %}
     {%- if server.can_load_in_iframe is defined %}
     canLoadInIFrame = true
@@ -28,196 +28,190 @@
 {%- endif %}
 
 [database]
-	type = {{ server.database.engine }}
-	hostname = {{ server.database.host }}
-	database = {{ server.database.name }}
-	username = {{ server.database.user }}
-	connectionpool = true
+    type = {{ server.database.engine }}
+    database = {{ server.database.name }}
+    {%- if server.database.engine != 'h2' %}
+    hostname = {{ server.database.host }}
+    username = {{ server.database.user }}
+    connectionpool = true
     {%- if server.database.pool_limit is defined %}
     poolLimit = {{ server.database.pool_limit }}
     {%- endif %}
     {%- if server.database.pool_max_idle is defined %}
     poolMaxIdle = {{ server.database.pool_max_idle }}
     {%- endif %}
+    {%- endif %}
 
 [auth]
     {%- if server.get('contributor_agreement', False) %}
-	contributorAgreements = true
+    contributorAgreements = true
     {%- endif %}
-	type = {{ server.auth.engine }}
-	cookieSecure = true
-	enableRunAs = true
+    type = {{ server.auth.engine }}
+    cookieSecure = {{ server.auth.get('cookie_secure', 'true') }}
+    enableRunAs = {{ server.auth.get('enable_run_as', 'true') }}
     {%- if server.auth.engine == 'OPENID_SSO' %}
-	openIdSsoUrl = {{ server.auth.openid_sso_url }}
+    openIdSsoUrl = {{ server.auth.openid_sso_url }}
     {%- endif %}
 
 [sendemail]
-	smtpServer = {{ server.mail.host }}
-	from = {{ server.mail.from }}
-	includeDiff = {{ server.mail.include_diff }}
+    {%- if server.mail is defined %}
+    smtpServer = {{ server.mail.host }}
+    from = {{ server.mail.from }}
+    includeDiff = {{ server.mail.include_diff }}
+    {%- else %}
+    enabled = false
+    {%- endif %}
 
 [container]
-	user = gerrit2
-    {% if server.java_home is defined %}
-	javaHome = {{ server.java_home }}
-    {% endif %}
-    {% if server.container_javaoptions is defined %}
-    vaOptions = {{ server.container_javaoptions }}
-    {% endif %}
-    {% if server.container_heaplimit is defined %}
-	heapLimit = {{ server.container_heaplimit }}
-    {% endif %}
+    user = gerrit2
+    {%- if server.java_home is defined %}
+    javaHome = {{ server.java_home }}
+    {%- endif %}
+    {%- if server.container_javaoptions is defined %}
+    javaOptions = {{ server.container_javaoptions }}
+    {%- endif %}
+    {%- if server.container_heaplimit is defined %}
+    heapLimit = {{ server.container_heaplimit }}
+    {%- endif %}
 
 [sshd]
-	listenAddress = {{ server.bind.address }}
-	{% if server.get('sshd', {}).threads is defined %}
-	threads = {{ server.sshd.threads }}
-	{% endif %}
-	{% if server.get('sshd', {}).idle_timeout is defined %}
-	idleTimeout = {{ server.sshd.idle_timeout }}
-	{% endif %}
-	{% if server.get('sshd', {}).max_connections_per_user is defined %}
-	maxConnectionsPerUser = {{ server.sshd.max_connections_per_user }}
-	{% endif %}
-	{% if server.get('sshd', {}).batch_threads is defined %}
-	batchThreads = {{ server.sshd.batch_threads }}
-	{% endif %}
-    {% if server.get('sshd', {}).command_start_threads is defined %}
+    listenAddress = {{ server.bind.address }}
+    {%- if server.get('sshd', {}).threads is defined %}
+    threads = {{ server.sshd.threads }}
+    {%- endif %}
+    {%- if server.get('sshd', {}).idle_timeout is defined %}
+    idleTimeout = {{ server.sshd.idle_timeout }}
+    {%- endif %}
+    {%- if server.get('sshd', {}).max_connections_per_user is defined %}
+    maxConnectionsPerUser = {{ server.sshd.max_connections_per_user }}
+    {%- endif %}
+    {%- if server.get('sshd', {}).batch_threads is defined %}
+    batchThreads = {{ server.sshd.batch_threads }}
+    {%- endif %}
+    {%- if server.get('sshd', {}).command_start_threads is defined %}
     commandstartThreads = {{ server.sshd.command_start_threads }}
-    {% endif %}
+    {%- endif %}
 
 [httpd]
-	listenUrl = proxy-https://*:8082/
-    {% if server.httpd_maxwait is defined %}
-	maxWait = {{ server.httpd_maxwait }}
-    {% endif %}
-    {% if server.httpd_acceptorthreads is defined %}
-	acceptorThreads = {{ server.httpd_acceptorthreads }}
-	{% endif %}
-	{% if server.httpd_minthreads is defined %}
-	minThreads = {{ server.httpd_minthreads }}
-	{% endif %}
-	{% if server.httpd_maxthreads is defined %}
-	maxThreads = {{ server.httpd_maxthreads }}
-	{% endif %}
-	{% if server.httpd_maxqueued is defined %}
-	maxQueued = {{ server.httpd_maxqueued }}
-	{% endif %}
+    {%- if server.httpd_listen_url is defined %}
+    listenUrl = {{ server.httpd_listen_url }}
+    {%- else %}
+    listenUrl = proxy-https://*:8082/
+    {%- endif %}
+    {%- if server.httpd_maxwait is defined %}
+    maxWait = {{ server.httpd_maxwait }}
+    {%- endif %}
+    {%- if server.httpd_acceptorthreads is defined %}
+    acceptorThreads = {{ server.httpd_acceptorthreads }}
+    {%- endif %}
+    {%- if server.httpd_minthreads is defined %}
+    minThreads = {{ server.httpd_minthreads }}
+    {%- endif %}
+    {%- if server.httpd_maxthreads is defined %}
+    maxThreads = {{ server.httpd_maxthreads }}
+    {%- endif %}
+    {%- if server.httpd_maxqueued is defined %}
+    maxQueued = {{ server.httpd_maxqueued }}
+    {%- endif %}
 
 [cache]
-	directory = cache
+    directory = cache
 
 [cache "web_sessions"]
-	maxAge = 7days
+    maxAge = 7days
 
-{% if server.cache_diff_timeout is defined %}
-
+{%- if server.cache_diff_timeout is defined %}
 [cache "diff"]
     timeout = {{ server.cache_diff_timeout }}
+{%- endif %}
 
-{% endif %}
-
-{% if server.cache_diff_intraline_timeout is defined %}
-
+{%- if server.cache_diff_intraline_timeout is defined %}
 [cache "diff_intraline"]
     timeout = {{ server.cache_diff_intraline_timeout }}
-
-{% endif %}
+{%- endif %}
 
 [user]
-	email = {{ server.email }}
+    email = {{ server.email }}
 
 [change]
-	allowDrafts = {{ server.get('allow_drafts', True) }}
+    allowDrafts = {{ server.get('allow_drafts', True) }}
 
 [receive]
-    {% if server.receive_max_object_size_limit is defined %}
-	maxObjectSizeLimit = {{ server.receive_max_object_size_limit }}
-    {% endif %}
-    {% if server.receive_timeout is defined %}
+    {%- if server.receive_max_object_size_limit is defined %}
+    maxObjectSizeLimit = {{ server.receive_max_object_size_limit }}
+    {%- endif %}
+    {%- if server.receive_timeout is defined %}
     timeOut = {{ server.receive_timeout }}
-    {% endif %}
+    {%- endif %}
 
 {%- for commentlink_name, commentlink in server.get('commentlink', {}).iteritems() %}
-
 [commentlink "{{ commentlink_name }}"]
-	match = "{{ commentlink['match'] }}"
-    {% if commentlink['link'] is defined %}
-	link = "{{ commentlink['link'] }}"
-    {% endif %}
-    {% if commentlink['html'] is defined %}
-	html = "{{ commentlink['html'] }}"
-    {% endif %}
-
-{% endfor %}
+    match = "{{ commentlink['match'] }}"
+    {%- if commentlink['link'] is defined %}
+    link = "{{ commentlink['link'] }}"
+    {%- endif %}
+    {%- if commentlink['html'] is defined %}
+    html = "{{ commentlink['html'] }}"
+    {%- endif %}
+{%- endfor %}
 
 {%- for plugin_name, plugin in server.get('plugin', {}).iteritems() %}
 {%- if plugin.url is defined %}
-
 [{{ plugin_name }}]
-	url = {{ plugin.url }}
-
+    url = {{ plugin.url }}
 {%- endif %}
 {%- endfor %}
 
 [theme]
-	backgroundColor = ffffff
-	topMenuColor = ffffff
-	textColor = 264d69
-	trimColor = eef3f5
-	selectionColor = d1e6ea
-	changeTableOutdatedColor = f5cccc
-	tableOddRowColor = ffffff
-	tableEvenRowColor = f5f5ff
+    backgroundColor = ffffff
+    topMenuColor = ffffff
+    textColor = 264d69
+    trimColor = eef3f5
+    selectionColor = d1e6ea
+    changeTableOutdatedColor = f5cccc
+    tableOddRowColor = ffffff
+    tableEvenRowColor = f5f5ff
 
-{% if server.melody is defined %}
-
+{%- if server.melody is defined %}
 [melody]
-	monitoring = {{ server.melody.monitoring }}
-	session = {{ server.melody.session }}
+    monitoring = {{ server.melody.monitoring }}
+    session = {{ server.melody.session }}
 
 [plugin "javamelody"]
     allowTopMenu = {{ server.enable_javamelody_top_menu }}
+{%- endif %}
 
-{% endif %}
-
-{% if server.ui is defined %}
-
+{%- if server.ui is defined %}
 [gitweb]
-    {% if server.ui.engine == 'gitweb' %}
-	revision = "?p=${project}.git;a=commitdiff;h=${commit}"
-    {% else %}
-	type = cgit
-    {% endif %}
-    {% if server.ui.repo_url is defined %}
-	url = "{{ server.ui.web_repo_url }}"
-	urlEncode = {{ server.ui.web_repo_url_encode }}
-    {% endif %}
+    {%- if server.ui.engine == 'gitweb' %}
+    revision = "?p=${project}.git;a=commitdiff;h=${commit}"
+    {%- else %}
+    type = cgit
+    {%- endif %}
+    {%- if server.ui.repo_url is defined %}
+    url = "{{ server.ui.web_repo_url }}"
+    urlEncode = {{ server.ui.web_repo_url_encode }}
+    {%- endif %}
+{%- endif %}
 
-{% endif %}
-
-{% if server.contactstore is defined %}
-
+{%- if server.contactstore is defined %}
 [contactstore]
-	appsec = {{ server.contactstore.appsec }}
-	url = {{ server.contactstore.url }}
+    appsec = {{ server.contactstore.appsec }}
+    url = {{ server.contactstore.url }}
+{%- endif %}
 
-{% endif %}
-
-{% if server.secondary_index is defined %}
-
+{%- if server.secondary_index is defined %}
 [index]
-	type = {{ server.secondary_index.type }}
-    {% if server.index_threads > 1 %}
-	threads = {{ server.index_threads }}
-    {% endif %}
+    type = {{ server.secondary_index.type }}
+    {%- if server.index_threads > 1 %}
+    threads = {{ server.index_threads }}
+    {%- endif %}
+{%- endif %}
 
-{% endif %}
-
-{% if server.change_cleanup is defined %}
+{%- if server.change_cleanup is defined %}
 [changeCleanup]
     abandonAfter = {{ server.change_cleanup.get('abandon_after', 0) }}
-{% endif %}
+{%- endif %}
 
 [groups]
     newGroupsVisibleToAll = {{ server.get('new_groups_visible_to_all', False) }}
diff --git a/gerrit/files/secure.config b/gerrit/files/secure.config
index dcdbfdf..fdf47fc 100644
--- a/gerrit/files/secure.config
+++ b/gerrit/files/secure.config
@@ -1,18 +1,19 @@
 {%- from "gerrit/map.jinja" import server with context %}
 # This file is managed by salt.
 
+{%- if server.database.engine != 'h2' %}
 [database]
-	password = {{ server.database.password }}
-
+    password = {{ server.database.password }}
+{%- endif %}
 [auth]
-	registerEmailPrivateKey = {{ server.email_private_key }}
-	restTokenPrivateKey = {{ server.token_private_key }}
+    registerEmailPrivateKey = {{ server.email_private_key }}
+    restTokenPrivateKey = {{ server.token_private_key }}
 
 {%- for plugin_name, plugin in server.get('plugin', {}).iteritems() %}
 {%- if plugin.password is defined %}
 
 [{{ plugin_name }}]
-	password = {{ plugin.password }}
+    password = {{ plugin.password }}
 
 {%- endif %}
 {%- endfor %}