-
-
Notifications
You must be signed in to change notification settings - Fork 84
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 user/group/mode parameter to custom types #129
Open
trefzer
wants to merge
8
commits into
voxpupuli:master
Choose a base branch
from
cirrax:dev_add_permissions
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
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3dbf148
add generic provider to manage file permissions (owner,group,mode)
trefzer 2b9ab50
add possibility to manage permissions for x509_request
trefzer f44bb34
add possibility to manage permissions for ssl_pkey
trefzer 1fb08f5
add possibility to manage permissions for x509_cert
trefzer 6bd059f
add possibility to manage permissions for dhparam
trefzer 458220a
Update lib/puppet/provider/dhparam/openssl.rb
trefzer 114d852
use File.chown, instead of File.send
trefzer 23c6c63
update REFERENCE.md
trefzer 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,54 @@ | ||
require 'etc' | ||
|
||
# class to use in openssl providers to handle file permission (mode, group and owner) | ||
class Puppet::Provider::Openssl < Puppet::Provider | ||
include Puppet::Util::POSIX | ||
|
||
def owner | ||
if File.exist?(@resource[:path]) | ||
Etc.getpwuid(File.stat(@resource[:path]).uid).name | ||
else | ||
:absent | ||
end | ||
end | ||
|
||
def owner=(should) | ||
File.chown(uid(should), nil, resource[:path]) | ||
rescue => detail | ||
raise Puppet::Error, _("Failed to set owner to '%{should}': %{detail}") % { should: should, detail: detail }, detail.backtrace | ||
end | ||
|
||
def group | ||
if File.exist?(@resource[:path]) | ||
Etc.getgrgid(File.stat(@resource[:path]).gid).name | ||
else | ||
:absent | ||
end | ||
end | ||
|
||
def group=(should) | ||
File.chown(nil, gid(should), resource[:path]) | ||
rescue => detail | ||
raise Puppet::Error, _("Failed to set group to '%{should}': %{detail}") % { should: should, detail: detail }, detail.backtrace | ||
end | ||
|
||
# Return the mode as an octal string, not as an integer. | ||
def mode | ||
if File.exist?(@resource[:path]) | ||
'0%o' % (File.stat(@resource[:path]).mode & 0o07777) | ||
else | ||
:absent | ||
end | ||
end | ||
|
||
# Set the file mode, converting from a string to an integer. | ||
def mode=(should) | ||
File.chmod(Integer('0' + should), @resource[:path]) | ||
end | ||
|
||
def set_file_perm(filename, owner = nil, group = nil, mode = nil) | ||
File.chown(uid(owner), nil, resource[:path]) if owner | ||
File.chown(nil, gid(group), resource[:path]) if group | ||
File.chmod(Integer('0' + mode), filename) if mode | ||
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
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
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
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
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
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.
Can you test against stdlib's filemode type which has testing instead of this regex which does not really cover valid modes?
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.
Can you give me any further hints what you mean ? I also have no idea how to use Stlib::Filemode type for this property. As far as I can see, if Stdlib::Filemode is used, we need some more logic to adapt for the setter/getter to work.
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 don't think you can use type aliases in types (yes, that's confusing; naming is hard).