Class: RightAws::Sqs::Grantee

Inherits:
Object
  • Object
show all
Defined in:
lib/sqs/right_sqs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue, email = nil, id = nil, name = nil, perms = []) ⇒ Grantee

Creates new Grantee instance. To create new grantee for queue use:

grantee = Grantee.new(queue, [email protected])
grantee.grant('FULLCONTROL')


316
317
318
319
320
321
322
323
# File 'lib/sqs/right_sqs.rb', line 316

def initialize(queue, email=nil, id=nil, name=nil, perms=[])
  @queue = queue
  @id    = id
  @name  = name
  @perms = perms
  @email = email
  retrieve unless id
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



308
309
310
# File 'lib/sqs/right_sqs.rb', line 308

def email
  @email
end

#idObject

Returns the value of attribute id.



308
309
310
# File 'lib/sqs/right_sqs.rb', line 308

def id
  @id
end

#nameObject

Returns the value of attribute name.



308
309
310
# File 'lib/sqs/right_sqs.rb', line 308

def name
  @name
end

#permsObject

Returns the value of attribute perms.



308
309
310
# File 'lib/sqs/right_sqs.rb', line 308

def perms
  @perms
end

#queueObject

Returns the value of attribute queue.



308
309
310
# File 'lib/sqs/right_sqs.rb', line 308

def queue
  @queue
end

Instance Method Details

#dropObject

Revokes all permissions for this grantee. Returns true



369
370
371
372
373
374
375
# File 'lib/sqs/right_sqs.rb', line 369

def drop
  @perms.each do |permission|
    @queue.sqs.interface.remove_grant(@queue.url, @email || @id, permission)
  end
  retrieve
  true
end

#grant(permission = nil) ⇒ Object

Adds permissions for grantee. Permission: ‘FULLCONTROL’ | ‘RECEIVEMESSAGE’ | ‘SENDMESSAGE’. The caller must have set the email instance variable.



346
347
348
349
350
# File 'lib/sqs/right_sqs.rb', line 346

def grant(permission=nil)
  raise "You can't grant permission without defining a grantee email address!" unless @email
  @queue.sqs.interface.add_grant(@queue.url, @email, permission)
  retrieve
end

#retrieveObject

Retrieves security information for grantee identified by email. Returns nil if the named user has no privileges on this queue, or true if perms updated successfully.



328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/sqs/right_sqs.rb', line 328

def retrieve # :nodoc:
  @id    = nil
  @name  = nil
  @perms = []
  
  hash = @queue.sqs.interface.list_grants(@queue.url, @email)
  return nil if hash.empty?
  
  grantee = hash.shift
  @id     = grantee[0]
  @name   = grantee[1][:name]
  @perms  = grantee[1][:perms]
  true
end

#revoke(permission = 'FULLCONTROL') ⇒ Object

Revokes permissions for grantee. Permission: ‘FULLCONTROL’ | ‘RECEIVEMESSAGE’ | ‘SENDMESSAGE’. Default value is ‘FULLCONTROL’. User must have @email or @id set. Returns true.



357
358
359
360
361
362
363
364
365
# File 'lib/sqs/right_sqs.rb', line 357

def revoke(permission='FULLCONTROL')
  @queue.sqs.interface.remove_grant(@queue.url, @email || @id, permission)
  unless @email   # if email is unknown - just remove permission from local perms list...
    @perms.delete(permission)
  else            # ... else retrieve updated information from Amazon
    retrieve
  end
  true
end