Vendor the external cookbooks
Knife-Zero doesn't include Berkshelf support, so vendoring everything in the repo is convenient again
This commit is contained in:
78
cookbooks/users/libraries/helpers.rb
Normal file
78
cookbooks/users/libraries/helpers.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
module Users
|
||||
# Helpers for Users
|
||||
module Helpers
|
||||
# Checks fs type.
|
||||
#
|
||||
# @return [String]
|
||||
def fs_type(mount)
|
||||
# Doesn't support macosx
|
||||
stat = Mixlib::ShellOut.new("stat -f -L -c %T #{mount} 2>&1").run_command
|
||||
stat.stdout.chomp
|
||||
rescue
|
||||
'none'
|
||||
end
|
||||
|
||||
# Determines if provided mount point is remote.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def fs_remote?(mount)
|
||||
fs_type(mount) == 'nfs' ? true : false
|
||||
end
|
||||
|
||||
def keys_from_url(url)
|
||||
host = url.split('/')[0..2].join('/')
|
||||
path = url.split('/')[3..-1].join('/')
|
||||
begin
|
||||
response = Chef::HTTP.new(host).get(path)
|
||||
response.split("\n")
|
||||
rescue Net::HTTPServerException => e
|
||||
p "request: #{host}#{path}, error: #{e}"
|
||||
end
|
||||
end
|
||||
|
||||
# Determines if the user's shell is valid on the machine, otherwise
|
||||
# returns the default of /bin/sh
|
||||
#
|
||||
# @return [String]
|
||||
def shell_is_valid?(shell_path)
|
||||
return false if shell_path.nil? || !File.exist?(shell_path)
|
||||
# AIX is the only OS that has the concept of 'approved shells'
|
||||
return true unless platform_family?('aix')
|
||||
|
||||
begin
|
||||
File.open('/etc/security/login.cfg') do |f|
|
||||
f.each_line do |l|
|
||||
l.match(/^\s*shells\s*=\s*(.*)/) do |m|
|
||||
return true if m[1].split(/\s*,\s*/).any? { |entry| entry.eql? shell_path }
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue
|
||||
return false
|
||||
end
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
# Validates passed id.
|
||||
#
|
||||
# @return [Numeric, String]
|
||||
# handles checking whether uid was specified as a string
|
||||
def validate_id(id)
|
||||
id.to_i.to_s == id ? id.to_i : id
|
||||
end
|
||||
|
||||
# Returns the appropriate base user home directory per platform
|
||||
#
|
||||
# @return [ String]
|
||||
def home_basedir
|
||||
if platform_family?('mac_os_x')
|
||||
'/Users'
|
||||
elsif platform_family?('solaris2')
|
||||
'/export/home'
|
||||
else
|
||||
'/home'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
15
cookbooks/users/libraries/matchers.rb
Normal file
15
cookbooks/users/libraries/matchers.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
if defined?(ChefSpec)
|
||||
ChefSpec.define_matcher :users_manage
|
||||
|
||||
def create_users_manage(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:users_manage,
|
||||
:create,
|
||||
resource_name)
|
||||
end
|
||||
|
||||
def remove_users_manage(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:users_manage,
|
||||
:remove,
|
||||
resource_name)
|
||||
end
|
||||
end
|
||||
29
cookbooks/users/libraries/osx_helper.rb
Normal file
29
cookbooks/users/libraries/osx_helper.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
module Users
|
||||
# Helpers for Users
|
||||
module OsxHelper
|
||||
def dscl(*args)
|
||||
host = '.'
|
||||
stdout_result = ''
|
||||
stderr_result = ''
|
||||
cmd = "dscl #{host} -#{args.join(' ')}"
|
||||
status = shell_out(cmd)
|
||||
status.stdout.each_line { |line| stdout_result << line }
|
||||
status.stderr.each_line { |line| stderr_result << line }
|
||||
[cmd, status, stdout_result, stderr_result]
|
||||
end
|
||||
|
||||
def safe_dscl(*args)
|
||||
result = dscl(*args)
|
||||
return '' if (args.first =~ /^delete/) && (result[1].exitstatus != 0)
|
||||
raise(Chef::Exceptions::Group, "dscl error: #{result.inspect}") unless result[1].exitstatus == 0
|
||||
raise(Chef::Exceptions::Group, "dscl error: #{result.inspect}") if result[2] =~ /No such key: /
|
||||
result[2]
|
||||
end
|
||||
|
||||
def gid_used?(gid)
|
||||
return false unless gid
|
||||
groups_gids = safe_dscl('list /Groups gid')
|
||||
!!(groups_gids =~ Regexp.new("#{Regexp.escape(gid.to_s)}\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user