Skip to content

Instantly share code, notes, and snippets.

@michaelcarruthers
Created August 23, 2012 13:31
Show Gist options
  • Save michaelcarruthers/3436630 to your computer and use it in GitHub Desktop.
Save michaelcarruthers/3436630 to your computer and use it in GitHub Desktop.
RPC Agent (Users)
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