summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-08 13:37:22 -0800
committerTim Smith <tsmith@chef.io>2018-03-20 09:21:54 -0700
commita1c333d0b260088029b681d296e47ea7376d402e (patch)
tree442a4b94ee998e2cd40a45f31d070d2327f7c387
parent88e30272dffd6740e6d0383b002b7ad518fe1d0c (diff)
downloadchef-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>
-rw-r--r--lib/chef/mixin/homebrew_user.rb16
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