Class: Bosh::Director::PermissionAuthorizer
- Defined in:
- lib/bosh/director/permission_authorizer.rb
Instance Method Summary collapse
- #granted_or_raise(subject, permission, user_scopes) ⇒ Object
-
#initialize(uuid_provider) ⇒ PermissionAuthorizer
constructor
A new instance of PermissionAuthorizer.
- #is_granted?(subject, permission, user_scopes) ⇒ Boolean
- #list_expected_scope(subject, permission, user_scopes) ⇒ Object
Constructor Details
#initialize(uuid_provider) ⇒ PermissionAuthorizer
Returns a new instance of PermissionAuthorizer.
3 4 5 |
# File 'lib/bosh/director/permission_authorizer.rb', line 3 def initialize(uuid_provider) @uuid_provider = uuid_provider end |
Instance Method Details
#granted_or_raise(subject, permission, user_scopes) ⇒ Object
7 8 9 10 11 |
# File 'lib/bosh/director/permission_authorizer.rb', line 7 def granted_or_raise(subject, , user_scopes) if !is_granted?(subject, , user_scopes) raise UnauthorizedToAccessDeployment, "Require one of the scopes: #{list_expected_scope(subject, , user_scopes).join(', ')}" end end |
#is_granted?(subject, permission, user_scopes) ⇒ Boolean
13 14 15 |
# File 'lib/bosh/director/permission_authorizer.rb', line 13 def is_granted?(subject, , user_scopes) !intersect(user_scopes, list_expected_scope(subject, , user_scopes)).empty? end |
#list_expected_scope(subject, permission, user_scopes) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bosh/director/permission_authorizer.rb', line 17 def list_expected_scope(subject, , user_scopes) expected_scope = [:admin] if subject.instance_of? Models::Deployment expected_scope << subject_team_scopes(subject, 'admin') if :admin == # already allowed with initial expected_scope elsif :read == expected_scope << [:read] else raise ArgumentError, "Unexpected permission for deployment: #{}" end elsif :director == subject if :admin == # already allowed with initial expected_scope elsif :create_deployment == expected_scope << add_bosh_admin_scopes(user_scopes) elsif [:read_releases, :list_deployments, :read_stemcells, :list_tasks].include?() expected_scope << [:read] expected_scope << add_bosh_admin_scopes(user_scopes) elsif :read == expected_scope << [:read] else raise ArgumentError, "Unexpected permission for director: #{}" end elsif subject.instance_of?(Models::Task) expected_scope << subject_team_scopes(subject, 'admin') if :admin == # already allowed with initial expected_scope elsif :read == expected_scope << [:read] else raise ArgumentError, "Unexpected permission for task: #{}" end else raise ArgumentError, "Unexpected subject: #{subject}" end expected_scope.flatten.uniq end |