-
Notifications
You must be signed in to change notification settings - Fork 29
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
wbclark
wants to merge
3
commits into
theforeman:master
Choose a base branch
from
wbclark:settings_py_warning
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 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,20 @@ | ||
Puppet::Functions.create_function(:'pulpcore::generate_header_content') do | ||
dispatch :generate_header_content do | ||
param 'Variant[String, Array[String]]', :raw_content | ||
param 'Integer', :line_width | ||
param 'String', :comment_glyph | ||
return_type 'Array[String]' | ||
end | ||
|
||
def generate_header_content(raw_content, line_width, comment_glyph) | ||
raw_content = [raw_content] unless raw_content.is_a?(Array) | ||
buffer = comment_glyph * (line_width / comment_glyph.length.to_f.ceil) | ||
reduced_width = line_width - (2*(1+comment_glyph.length)) | ||
|
||
raw_content.map do |text| | ||
text.scan(/\S.{0,#{reduced_width}}\S(?=\s|$)|\S+/).map do |line| | ||
"#{comment_glyph} " + line + (" " * (reduced_width - line.length)) + " #{comment_glyph}" | ||
end.append(buffer) | ||
end.flatten.prepend(buffer) | ||
end | ||
end |
This file contains 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 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,41 @@ | ||||||||||||||||||||||||||||||||||||||||||
# @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' | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
$installer_header = "File managed by ${installer_name}.\nModule: ${module_name}" | ||||||||||||||||||||||||||||||||||||||||||
$warning_header = '!!! WARNING: DO NOT EDIT THIS FILE !!!' | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
$settings_header_content = pulpcore::generate_header_content( | ||||||||||||||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||||||||||||||
$warning_header, | ||||||||||||||||||||||||||||||||||||||||||
$installer_header, | ||||||||||||||||||||||||||||||||||||||||||
$explanation, | ||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||
80, | ||||||||||||||||||||||||||||||||||||||||||
'#', | ||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+32
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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 |
||||||||||||||||||||||||||||||||||||||||||
} |
This file contains 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,66 @@ | ||
require 'spec_helper' | ||
|
||
describe 'pulpcore' do | ||
on_supported_os.each do |os, os_facts| | ||
context "on #{os}" do | ||
let(:facts) { os_facts } | ||
|
||
context 'default params' do | ||
it { is_expected.to compile.with_all_deps } | ||
|
||
it 'adds default header to settings.py' do | ||
is_expected.to contain_concat__fragment('base') | ||
.with_content( | ||
Regexp.new(<<~HEADER.chomp), | ||
################################################################################ | ||
# !!! 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 = | ||
HEADER | ||
) | ||
end | ||
end | ||
|
||
context 'with custom config header strings' do | ||
let :pre_condition do | ||
<<~PUPPET | ||
class { pulpcore::header_strings: | ||
custom_installer_name => 'my_pulpcore_installer', | ||
custom_settings_explanation => "Don't even think about it." | ||
} | ||
PUPPET | ||
end | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
|
||
it 'adds customized header to settings.py' do | ||
is_expected.to contain_concat__fragment('base') | ||
.with_content( | ||
Regexp.new(<<~HEADER.chomp), | ||
################################################################################ | ||
# !!! WARNING: DO NOT EDIT THIS FILE !!! # | ||
################################################################################ | ||
# File managed by my_pulpcore_installer. # | ||
# Module: pulpcore # | ||
################################################################################ | ||
# Don't even think about it. # | ||
################################################################################ | ||
|
||
CONTENT_HOST = | ||
HEADER | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
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.
I suppose a name like
wrap_and_comment_header_content
would be more descriptive here. Open to suggestionsAlso 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?