Skip to content
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

Add customizable warning not to directly edit settings.py #210

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wbclark
Copy link
Collaborator

@wbclark wbclark commented Jul 7, 2021

No description provided.

@ehelms
Copy link
Member

ehelms commented Jul 14, 2021

Following up from some IRC conversation, my take on things was:

I like if we could across our ecosystem have a consistent header for our modules. You can see for example, https://github.com/theforeman/puppet-foreman/blob/master/templates/_header.erb, is used across a few different modules already as a format. This PR raises a desire to sometimes customize the degree and intent of the message for the file. Thus, I would propose a hybrid of the two. A standard starting header followed by any custom message, e.g.

### File managed with puppet ###
## Module:           '<%= scope.to_hash['module_name'] %>'
#######################################################################
# WARNING: This file is externally managed and you should never make manual edits.  #
#                                                                                      #
# Not only are your edits likely to be overwritten, there is also a strong possibility        #
# of breaking your system. Refer to documentation for the software that installed        #
# Pulpcore to determine the safe and persistent way to modify the configuration.        #
#####################################################################

And I think it's fair to challenge if the current headers message, what would serve as our base template across modules, needs some updating or modification to be more relevant to more use cases. Could it be configurable by the installer? Possibly. One tricky bit could be that comments may be different amongst different files (that is # vs //).

@ehelms ehelms mentioned this pull request Jul 19, 2021
@wbclark wbclark force-pushed the settings_py_warning branch 5 times, most recently from 483da42 to 90bd343 Compare July 22, 2021 19:44
@wbclark
Copy link
Collaborator Author

wbclark commented Jul 22, 2021

Updated this with a custom function, generate_header_content

This takes an Array of Strings (raw_content), an Integer line_width, and a String comment_glyph and generates lines for a nicely formatted header, containing the raw_content, line wrapped and enclosed in the comment_glyph.

It also introduces a new class pulpcore::header_strings which allows to override the default strings that are passed into raw_content when generating the header.

This way downstream projects can use Hiera to add custom content to headers, while pure Puppet users will see a sensible default for Puppet.

In the future, most of this logic should be removed from this module and placed in a common module that can be used throughout the installer ecosystem.

TODO: Add tests

@wbclark wbclark force-pushed the settings_py_warning branch from 90bd343 to 209c397 Compare July 22, 2021 20:35
@wbclark
Copy link
Collaborator Author

wbclark commented Jul 22, 2021

In the current implementation, see the complete header as well as the beginning of the rest of the settings.py content below:

################################################################################
# !!! WARNING: DO NOT EDIT THIS FILE !!!                                       #
################################################################################
# File managed by Puppet.                                                      #
# Module: pulpcore                                                             #
################################################################################
# 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.                                                               #
################################################################################

CONTENT_HOST = "centos7-64-1"
CONTENT_ORIGIN = "https://centos7-64-1"

In general with this method, the number of text blocks in the header is optional. Any Array of Strings can be passed, and each string will be line wrapped and enclosed in the comment_glyph.

As currently implemented in this module, the # of blocks and content of the first text block is static, while the 2nd and 3rd are configurable by setting pulpcore::header_strings::custom_installer_name and pulpcore::header_strins::custom_settings_explanation

With appropriate hiera in foreman-installer, this might look instead like, e.g.:

################################################################################
# !!! WARNING: DO NOT EDIT THIS FILE !!!                                       #
################################################################################
# File managed by foreman-installer.                                           #
# Module: pulpcore                                                             #
################################################################################
# Configure Pulpcore using foreman-installer. See foreman-installer --help     #
################################################################################

Or any other custom string providing appropriate guidance to the user.

@wbclark wbclark force-pushed the settings_py_warning branch from 209c397 to b75c086 Compare July 22, 2021 21:18
Comment on lines +32 to +40
$settings_header_content = pulpcore::generate_header_content(
[
$warning_header,
$installer_header,
$explanation,
],
80,
'#',
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$settings_header_content = pulpcore::generate_header_content(
[
$warning_header,
$installer_header,
$explanation,
],
80,
'#',
)
$settings_header_content = pulpcore::generate_header_content(
{
raw_content => [
$warning_header,
$installer_header,
$explanation,
],
line_width => 80,
comment_glyph => '#',
}
)

I'm not actually sure if Puppet function calls support named arguments in this way, but if so I'd like to give it a try for better readability

@@ -0,0 +1,20 @@
Puppet::Functions.create_function(:'pulpcore::generate_header_content') do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose a name like wrap_and_comment_header_content would be more descriptive here. Open to suggestions

Also trying to determine what would be the correct place to open a PR with this function upstream. Perhaps it makes the most sense in the Concat module?

@wbclark wbclark force-pushed the settings_py_warning branch from e4e1db8 to 7feb95e Compare July 22, 2021 21:57
@wbclark wbclark requested review from ekohl and ehelms July 22, 2021 22:34
@wbclark wbclark changed the title Add warning not to directly edit settings.py Add customizable warning not to directly edit settings.py Jul 22, 2021
@ehelms
Copy link
Member

ehelms commented Jul 23, 2021

I'll spend more time digging into it. My initial two thoughts are:

  1. This appears to be some complex logic, I do get it's aiming for allowing for high customizability.
  2. Given how "generic" this is, I wonder if it would make sense in a light weight module that provides this functionality for use by other modules.

@ekohl
Copy link
Member

ekohl commented Jul 23, 2021

Given how "generic" this is, I wonder if it would make sense in a light weight module that provides this functionality for use by other modules.

voxpupuli/puppet-extlib#171 does take that idea. I think that or stdlib would be good places.

@ehelms
Copy link
Member

ehelms commented Nov 3, 2022

This has been open for a year now, I am therefore tempted to close it as it can be re-visited in the future if desired. @wbclark thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants