Class: Insights::API::Common::RBAC::Access
- Inherits:
-
Object
- Object
- Insights::API::Common::RBAC::Access
- Defined in:
- lib/insights/api/common/rbac/access.rb
Constant Summary collapse
- DEFAULT_LIMIT =
500- ADMIN_SCOPE =
"admin"- GROUP_SCOPE =
"group"- USER_SCOPE =
"user"
Instance Attribute Summary collapse
-
#acl ⇒ Object
readonly
Returns the value of attribute acl.
Class Method Summary collapse
Instance Method Summary collapse
- #accessible?(resource, verb, app_name = ) ⇒ Boolean
- #admin_scope?(resource, verb, app_name = ) ⇒ Boolean
- #group_scope?(resource, verb, app_name = ) ⇒ Boolean
-
#initialize(app_name_filter = ENV["APP_NAME"]) ⇒ Access
constructor
A new instance of Access.
- #process ⇒ Object
- #scopes(resource, verb, app_name = ENV['APP_NAME']) ⇒ Object
- #user_scope?(resource, verb, app_name = ) ⇒ Boolean
Constructor Details
#initialize(app_name_filter = ENV["APP_NAME"]) ⇒ Access
12 13 14 |
# File 'lib/insights/api/common/rbac/access.rb', line 12 def initialize(app_name_filter = ENV["APP_NAME"]) @app_name_filter = app_name_filter end |
Instance Attribute Details
#acl ⇒ Object (readonly)
Returns the value of attribute acl.
6 7 8 |
# File 'lib/insights/api/common/rbac/access.rb', line 6 def acl @acl end |
Class Method Details
.enabled? ⇒ Boolean
49 50 51 |
# File 'lib/insights/api/common/rbac/access.rb', line 49 def self.enabled? ENV['BYPASS_RBAC'] != "true" end |
Instance Method Details
#accessible?(resource, verb, app_name = ) ⇒ Boolean
32 33 34 35 |
# File 'lib/insights/api/common/rbac/access.rb', line 32 def accessible?(resource, verb, app_name = ENV['APP_NAME']) regexp = create_regexp(app_name, resource, verb) @acls.any? { |item| regexp.match?(item.) } end |
#admin_scope?(resource, verb, app_name = ) ⇒ Boolean
37 38 39 |
# File 'lib/insights/api/common/rbac/access.rb', line 37 def admin_scope?(resource, verb, app_name = ENV['APP_NAME']) scope?(app_name, resource, verb, ADMIN_SCOPE) end |
#group_scope?(resource, verb, app_name = ) ⇒ Boolean
41 42 43 |
# File 'lib/insights/api/common/rbac/access.rb', line 41 def group_scope?(resource, verb, app_name = ENV['APP_NAME']) scope?(app_name, resource, verb, GROUP_SCOPE) end |
#process ⇒ Object
16 17 18 19 20 21 |
# File 'lib/insights/api/common/rbac/access.rb', line 16 def process Service.call(RBACApiClient::AccessApi) do |api| @acls ||= Service.paginate(api, :get_principal_access, {:limit => DEFAULT_LIMIT}, @app_name_filter).to_a end self end |
#scopes(resource, verb, app_name = ENV['APP_NAME']) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/insights/api/common/rbac/access.rb', line 23 def scopes(resource, verb, app_name = ENV['APP_NAME']) regexp = create_regexp(app_name, resource, verb) @acls.each_with_object([]) do |item, memo| if regexp.match?(item.) memo << all_scopes(item) end end.flatten.uniq.sort end |
#user_scope?(resource, verb, app_name = ) ⇒ Boolean
45 46 47 |
# File 'lib/insights/api/common/rbac/access.rb', line 45 def user_scope?(resource, verb, app_name = ENV['APP_NAME']) scope?(app_name, resource, verb, USER_SCOPE) end |