Class: Tasker::Authorization::ResourceRegistry

Inherits:
Object
  • Object
show all
Includes:
ResourceConstants
Defined in:
lib/tasker/authorization/resource_registry.rb

Overview

Resource registry defining available resources and their permitted actions for authorization purposes.

This registry serves as a central catalog of all resources that can be authorized within the Tasker system. Each resource defines a set of actions that can be performed on it.

Examples:

Checking if a resource exists

ResourceRegistry.resource_exists?(RESOURCES::TASK) # => true

Checking if an action is valid for a resource

ResourceRegistry.action_exists?(RESOURCES::TASK, ACTIONS::SHOW) # => true

Getting all available permissions

ResourceRegistry.all_permissions
# => ["tasker.task:index", "tasker.task:show", ...]

Constant Summary collapse

RESOURCES =

Registry of all available resources and their permitted actions

{
  ResourceConstants::RESOURCES::TASK => {
    actions: [
      ResourceConstants::ACTIONS::INDEX,
      ResourceConstants::ACTIONS::SHOW,
      ResourceConstants::ACTIONS::CREATE,
      ResourceConstants::ACTIONS::UPDATE,
      ResourceConstants::ACTIONS::DESTROY,
      ResourceConstants::ACTIONS::RETRY,
      ResourceConstants::ACTIONS::CANCEL
    ],
    description: 'Tasker workflow tasks'
  },
  ResourceConstants::RESOURCES::WORKFLOW_STEP => {
    actions: [
      ResourceConstants::ACTIONS::INDEX,
      ResourceConstants::ACTIONS::SHOW,
      ResourceConstants::ACTIONS::UPDATE,
      ResourceConstants::ACTIONS::DESTROY,
      ResourceConstants::ACTIONS::RETRY,
      ResourceConstants::ACTIONS::CANCEL
    ],
    description: 'Individual workflow steps'
  },
  ResourceConstants::RESOURCES::HEALTH_STATUS => {
    actions: [
      ResourceConstants::ACTIONS::INDEX
    ],
    description: 'Health status endpoint information'
  },
  ResourceConstants::RESOURCES::HANDLER => {
    actions: [
      ResourceConstants::ACTIONS::INDEX,
      ResourceConstants::ACTIONS::SHOW
    ],
    description: 'Handler discovery and metadata'
  },
  ResourceConstants::RESOURCES::METRICS => {
    actions: [
      ResourceConstants::ACTIONS::INDEX
    ],
    description: 'Prometheus metrics endpoint'
  },
  ResourceConstants::RESOURCES::ANALYTICS => {
    actions: [
      ResourceConstants::ACTIONS::INDEX
    ],
    description: 'Analytics and performance monitoring endpoints'
  }
}.freeze

Class Method Summary collapse

Class Method Details

.action_exists?(resource, action) ⇒ Boolean

Check if an action is valid for a given resource



99
100
101
102
103
# File 'lib/tasker/authorization/resource_registry.rb', line 99

def action_exists?(resource, action)
  return false unless resource_exists?(resource)

  RESOURCES[resource][:actions].include?(action.to_sym)
end

.actions_for_resource(resource) ⇒ Array<Symbol>

Get all actions for a specific resource



118
119
120
121
122
# File 'lib/tasker/authorization/resource_registry.rb', line 118

def actions_for_resource(resource)
  return [] unless resource_exists?(resource)

  RESOURCES[resource][:actions]
end

.all_permissionsArray<String>

Get all available permissions in "resource:action" format



108
109
110
111
112
# File 'lib/tasker/authorization/resource_registry.rb', line 108

def all_permissions
  RESOURCES.flat_map do |resource, config|
    config[:actions].map { |action| "#{resource}:#{action}" }
  end
end

.resource_description(resource) ⇒ String?

Get description for a resource



128
129
130
131
132
# File 'lib/tasker/authorization/resource_registry.rb', line 128

def resource_description(resource)
  return nil unless resource_exists?(resource)

  RESOURCES[resource][:description]
end

.resource_exists?(resource) ⇒ Boolean

Check if a resource exists in the registry



90
91
92
# File 'lib/tasker/authorization/resource_registry.rb', line 90

def resource_exists?(resource)
  RESOURCES.key?(resource)
end

.resourcesHash

Get all registered resources



82
83
84
# File 'lib/tasker/authorization/resource_registry.rb', line 82

def resources
  RESOURCES
end