From 209c397a12a1b69a24cf5946c1212fcf37ab5d4b Mon Sep 17 00:00:00 2001 From: William Bradford Clark Date: Thu, 22 Jul 2021 14:50:49 -0400 Subject: [PATCH] Add header to settings.py --- manifests/config.pp | 12 ++++++++++++ manifests/header_strings.pp | 31 +++++++++++++++++++++++++++++++ templates/settings.py.erb | 2 ++ 3 files changed, 45 insertions(+) create mode 100644 manifests/header_strings.pp diff --git a/manifests/config.pp b/manifests/config.pp index 8cdaba84..c3cc071d 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -17,6 +17,18 @@ ensure_newline => true, } + include pulpcore::header_strings + + $header_content = pulpcore::generate_header_content( + [ + $pulpcore::header_strings::warning_header, + $pulpcore::header_strings::installer_header, + $pulpcore::header_strings::explanation, + ], + 80, + '#', + ) + concat::fragment { 'base': target => 'pulpcore settings', content => template('pulpcore/settings.py.erb'), diff --git a/manifests/header_strings.pp b/manifests/header_strings.pp new file mode 100644 index 00000000..f85f9d87 --- /dev/null +++ b/manifests/header_strings.pp @@ -0,0 +1,31 @@ +# @summary Re-usable, overridable strings for file headers +# +# @param custom_installer_name +# Override installer_name in headers from "Puppet" to e.g. "foreman-installer" +# +# @param custom_settings_explanation +# Custom string providing further instructions to the user in settings.py header +class pulpcore::header_strings( + Optional[String] $custom_installer_name = undef, + Optional[String] $custom_settings_explanation = undef, +) { + if $custom_installer_name { + $installer_name = $custom_installer_name + } else { + $installer_name = 'Puppet' + } + + if $custom_settings_explanation { + $explanation = $custom_settings_explanation + } else { + $explanation = @("EXPLANATION"/L) + Not only are your edits likely to be overwritten, there is also a strong possibility \ + of breaking your system if you change configuration here without making required \ + changes elsewhere. Refer to the documentation you used to install Pulpcore to \ + determine the safe and persistent way to modify the configuration. + | - EXPLANATION + } + + $installer_header = "File managed by ${installer_name}.\nModule: ${module_name}" + $warning_header = '!!! WARNING: DO NOT EDIT THIS FILE !!!' +} diff --git a/templates/settings.py.erb b/templates/settings.py.erb index db79d87e..d627213d 100644 --- a/templates/settings.py.erb +++ b/templates/settings.py.erb @@ -1,3 +1,5 @@ +<%= scope['pulpcore::config::header_content'].join("\n") %> + CONTENT_HOST = "<%= scope['pulpcore::servername'] %>" CONTENT_ORIGIN = "https://<%= scope['pulpcore::servername'] %>" SECRET_KEY = "<%= scope['pulpcore::django_secret_key'] %>"