diff options
author | Tim Smith <tsmith@chef.io> | 2018-03-08 13:37:22 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-03-20 09:21:54 -0700 |
commit | a1c333d0b260088029b681d296e47ea7376d402e (patch) | |
tree | 442a4b94ee998e2cd40a45f31d070d2327f7c387 /lib/chef/mixin | |
parent | 88e30272dffd6740e6d0383b002b7ad518fe1d0c (diff) | |
download | chef-a1c333d0b260088029b681d296e47ea7376d402e.tar.gz |
Add new find_homebrew_username method in the Homebrew mixin
We need the username about a billion times in both providers. The current helper grabs the UID.
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef/mixin')
-rw-r--r-- | lib/chef/mixin/homebrew_user.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/chef/mixin/homebrew_user.rb b/lib/chef/mixin/homebrew_user.rb index 6e32043c77..b038dfd3b7 100644 --- a/lib/chef/mixin/homebrew_user.rb +++ b/lib/chef/mixin/homebrew_user.rb @@ -34,7 +34,8 @@ class Chef # This tries to find the user to execute brew as. If a user is provided, that overrides the brew # executable user. It is an error condition if the brew executable owner is root or we cannot find # the brew executable. - # @param provided_user [String] + # @param [String, Integer] provided_user + # @return [Integer] UID of the user def find_homebrew_uid(provided_user = nil) # They could provide us a user name or a UID if provided_user @@ -42,8 +43,17 @@ class Chef return Etc.getpwnam(provided_user).uid end - @homebrew_owner ||= calculate_owner - @homebrew_owner + @homebrew_owner_uid ||= calculate_owner + @homebrew_owner_uid + end + + # Use find_homebrew_uid to return the UID and then lookup the + # name from that UID because sometimes you want the name not the UID + # @param [String, Integer] provided_user + # @return [String] username + def find_homebrew_username(provided_user = nil) + @homebrew_owner_username ||= Etc.getpwuid(find_homebrew_uid(provided_user)).name + @homebrew_owner_username end private |