Class: Puppet::Util::ADSI::Group
- Extended by:
- Enumerable
- Defined in:
- lib/vendor/puppet/util/adsi.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#native_group ⇒ Object
Returns the value of attribute native_group.
Class Method Summary collapse
- .create(name) ⇒ Object
- .delete(name) ⇒ Object
- .each(&block) ⇒ Object
- .exists?(name) ⇒ Boolean
- .uri(name) ⇒ Object
Instance Method Summary collapse
- #add_members(*names) ⇒ Object (also: #add_member)
- #commit ⇒ Object
-
#initialize(name, native_group = nil) ⇒ Group
constructor
A new instance of Group.
- #members ⇒ Object
- #remove_members(*names) ⇒ Object (also: #remove_member)
- #set_members(desired_members) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(name, native_group = nil) ⇒ Group
Returns a new instance of Group.
210 211 212 213 |
# File 'lib/vendor/puppet/util/adsi.rb', line 210 def initialize(name, native_group = nil) @name = name @native_group = native_group end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
209 210 211 |
# File 'lib/vendor/puppet/util/adsi.rb', line 209 def name @name end |
#native_group ⇒ Object
Returns the value of attribute native_group.
208 209 210 |
# File 'lib/vendor/puppet/util/adsi.rb', line 208 def native_group @native_group end |
Class Method Details
.create(name) ⇒ Object
271 272 273 274 275 |
# File 'lib/vendor/puppet/util/adsi.rb', line 271 def self.create(name) # Windows error 2224: The account already exists. raise Puppet::Error.new( "Cannot create group if user '#{name}' exists." ) if Puppet::Util::ADSI::User.exists? name new(name, Puppet::Util::ADSI.create(name, 'group')) end |
.delete(name) ⇒ Object
281 282 283 |
# File 'lib/vendor/puppet/util/adsi.rb', line 281 def self.delete(name) Puppet::Util::ADSI.delete(name, 'group') end |
.each(&block) ⇒ Object
285 286 287 288 289 290 291 292 293 294 |
# File 'lib/vendor/puppet/util/adsi.rb', line 285 def self.each(&block) wql = Puppet::Util::ADSI.execquery( "select * from win32_group" ) groups = [] wql.each do |g| groups << new(g.name, g) end groups.each(&block) end |
Instance Method Details
#add_members(*names) ⇒ Object Also known as: add_member
236 237 238 239 240 |
# File 'lib/vendor/puppet/util/adsi.rb', line 236 def add_members(*names) names.each do |name| native_group.Add(Puppet::Util::ADSI::User.uri(name)) end end |
#commit ⇒ Object
227 228 229 230 231 232 233 234 |
# File 'lib/vendor/puppet/util/adsi.rb', line 227 def commit begin native_group.SetInfo unless native_group.nil? rescue Exception => e raise Puppet::Error.new( "Group update failed: #{e}" ) end self end |
#members ⇒ Object
250 251 252 253 254 255 |
# File 'lib/vendor/puppet/util/adsi.rb', line 250 def members # WIN32OLE objects aren't enumerable, so no map members = [] native_group.Members.each {|m| members << m.Name} members end |
#remove_members(*names) ⇒ Object Also known as: remove_member
243 244 245 246 247 |
# File 'lib/vendor/puppet/util/adsi.rb', line 243 def remove_members(*names) names.each do |name| native_group.Remove(Puppet::Util::ADSI::User.uri(name)) end end |
#set_members(desired_members) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/vendor/puppet/util/adsi.rb', line 257 def set_members(desired_members) return if desired_members.nil? or desired_members.empty? current_members = self.members # First we add all missing members members_to_add = desired_members - current_members add_members(*members_to_add) # Then we remove all extra members members_to_remove = current_members - desired_members remove_members(*members_to_remove) end |
#uri ⇒ Object
215 216 217 |
# File 'lib/vendor/puppet/util/adsi.rb', line 215 def uri self.class.uri(name) end |