Class: Gtool::Provision::User
- Inherits:
-
Thor
- Object
- Thor
- Gtool::Provision::User
- Includes:
- Util
- Defined in:
- lib/gtool/provision/user.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create(username) ⇒ Object
- #delete(username) ⇒ Object
- #get(username) ⇒ Object
- #groups(username) ⇒ Object
- #list ⇒ Object
- #update(username) ⇒ Object
Methods included from Util
Class Method Details
.banner(task, namespace = true, subcommand = false) ⇒ Object
123 124 125 |
# File 'lib/gtool/provision/user.rb', line 123 def self.(task, namespace = true, subcommand = false) "#{basename} #{task.formatted_usage(self, true, subcommand)}" end |
Instance Method Details
#create(username) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gtool/provision/user.rb', line 49 def create(username) connection = Gtool::Auth.connection() user = GProv::Provision::User.new(:connection => connection) user.user_name = username user.given_name = ask "Given Name:" user.family_name = ask "Family Name:" # password! wheee! %x{stty -echo} user.password = Digest::SHA1.hexdigest(ask "Password:") user.hash_function_name = "SHA-1" %x{stty echo} user.create! invoke "user:get", [user.user_name] end |
#delete(username) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/gtool/provision/user.rb', line 97 def delete(username) connection = Gtool::Auth.connection() invoke "user:get", [username] user = GProv::Provision::User.get(connection, username) if user and (yes? "Permanently delete this user?") and (username == ask("Type in #{username} to confirm:")) user.delete! end end |
#get(username) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gtool/provision/user.rb', line 34 def get(username) connection = Gtool::Auth.connection() user = GProv::Provision::User.get(connection, username) fields = GProv::Provision::User.attribute_names field_names = GProv::Provision::User.attribute_titles if user.nil? say "User '#{username}' not found!", :red else properties = fields.map {|f| user.send f} print_table field_names.zip(properties) end end |
#groups(username) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/gtool/provision/user.rb', line 108 def groups(username) connection = Gtool::Auth.connection() groups = GProv::Provision::Group.all(connection, :member => username) fields = GProv::Provision::Group.attribute_names field_names = GProv::Provision::Group.attribute_titles rows = groups.map do |group| fields.map {|f| group.send f} end rows.unshift field_names print_table rows say "#{rows.length - 1} entries.", :cyan end |
#list ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gtool/provision/user.rb', line 18 def list connection = Gtool::Auth.connection() users = GProv::Provision::User.all(connection) fields = GProv::Provision::User.attribute_names field_names = GProv::Provision::User.attribute_titles rows = users.map do |user| fields.map {|f| user.send f} end rows.unshift field_names print_table rows say "#{rows.length - 1} entries.", :cyan end |
#update(username) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/gtool/provision/user.rb', line 70 def update(username) connection = Gtool::Auth.connection() user = GProv::Provision::User.get(connection, username) user.user_name = ask_default(user.user_name, "Username (#{user.user_name}):") user.given_name = ask_default(user.given_name, "Given Name (#{user.given_name}):") user.family_name = ask_default(user.family_name, "Family Name (#{user.family_name}):") user.admin = ask_default(user.admin, "Administrator (#{user.admin}):") user.agreed_to_terms = ask_default(user.agreed_to_terms, "Agreed to terms (#{user.agreed_to_terms}):") user.suspended = ask_default(user.suspended, "Suspended (#{user.suspended}):") user.change_password_at_next_login = ask_default(user.change_password_at_next_login, "Change password at next login (#{user.change_password_at_next_login}):") %x{stty -echo} password = ask "Password (blank will not change):" unless password.empty? user.password = Digest::SHA1.hexdigest(password) user.hash_function_name = "SHA-1" end %x{stty echo} user.update! invoke "user:get", [user.user_name] end |