Created
September 17, 2010 22:06
-
-
Save spheromak/585044 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Domain | |
module User | |
# | |
# takes a string and gets the userdata from couch | |
# otherwise retuns whats passed in | |
# | |
def get_user(usr=nil) | |
if usr.is_a? String | |
usr = data_bag_item("users", usr) | |
end | |
usr | |
end | |
def remove_user(u) | |
user u['id'] do | |
action :remove | |
supports :manage_home => true | |
end | |
end | |
# | |
# manage a user on the system | |
# | |
def setup_user(u) | |
u = get_user(u) | |
if u['status'] =~ /remove/ | |
remove_user(u) | |
elsif u['status'] =~ /lock/ | |
elsif u['status'] =~ /unlock/ | |
else | |
user u['id'] do | |
uid u['uid'] | |
gid u['gid'] if u['gid'] | |
shell get_shell(u) | |
comment "#{u['comment']}" | |
action [:create, :manage] | |
supports :manage_home => true | |
home get_home(u) | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or 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
# if you want to use your module methods in recipe scope you may need to do this | |
class Chef::Recipe | |
include Domain::User | |
end | |
# if you want your modue methods in a specific resource you need to mix | |
class Chef::Resource::User | |
include Domain::User | |
end | |
# otherwise you can jsut | |
include Domain::User | |
foo = get_user("fred") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment