Class: Aptible::Auth::Role

Inherits:
Resource
  • Object
show all
Defined in:
lib/aptible/auth/role.rb

Instance Method Summary collapse

Methods inherited from Resource

#namespace, #root_url

Instance Method Details

#account_permissions(account) ⇒ Object



28
29
30
31
32
# File 'lib/aptible/auth/role.rb', line 28

def ()
  .permissions.select do |permission|
    (link = permission.links[:role]) && link.href == href
  end
end

#add_account_scope(account, scope) ⇒ Object



38
39
40
# File 'lib/aptible/auth/role.rb', line 38

def (, scope)
  .create_permission!(scope: scope, role: href)
end

#add_account_scopes(account, scopes) ⇒ Object



34
35
36
# File 'lib/aptible/auth/role.rb', line 34

def (, scopes)
  scopes.each { |scope| (, scope) }
end

#permissionsObject



42
43
44
45
46
47
48
49
50
# File 'lib/aptible/auth/role.rb', line 42

def permissions
  require 'aptible/api'

  permissions = Aptible::Api::Permission.all(token: token,
                                             headers: headers)
  permissions.select do |permission|
    (link = permission.links[:role]) && link.href == href
  end
end

#set_account_permissions(account, scopes) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/aptible/auth/role.rb', line 18

def (, scopes)
  permissions = ()

  permissions.each { |p| p.destroy unless scopes.include? p.scope }
  existing = permissions.keep_if { |p| scopes.include? p.scope }

  new_scopes = scopes - existing.map(&:scope)
  (, new_scopes)
end

#usersObject



14
15
16
# File 'lib/aptible/auth/role.rb', line 14

def users
  @users ||= memberships.map(&:user).uniq
end