From a1c333d0b260088029b681d296e47ea7376d402e Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 8 Mar 2018 13:37:22 -0800 Subject: 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 --- lib/chef/mixin/homebrew_user.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/chef/mixin') 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 -- cgit v1.2.1