Created
August 23, 2012 13:31
-
-
Save michaelcarruthers/3436630 to your computer and use it in GitHub Desktop.
RPC Agent (Users)
This file contains 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 MCollective | |
module Agent | |
class User < RPC::Agent | |
require 'etc' | |
metadata :name => "User", | |
:description => "List user information", | |
:author => "Michael Carruthers", | |
:license => "internal-only", | |
:version => "0.0.1", | |
:url => 'homepage', | |
:timeout => 20 | |
action "info" do | |
validate :user, String | |
user_name = request[:user] | |
user_info(user_name) | |
reply[:uid] = @output[:uid] | |
reply[:gid] = @output[:gid] | |
end | |
private | |
def user_info(request) | |
@output = {} | |
Etc.passwd do |user| | |
next unless user.name == request | |
@output[user.name] = {} | |
@output[:uid] = Etc.getpwuid(user.uid).name | |
@output[:gid] = Etc.getgrgid(user.gid).name | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment