Class: CommandTower::Configuration::Registry::AdminWorkspace::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/command_tower/configuration/registry/admin_workspace/config.rb

Constant Summary collapse

PLATFORM_TOOLS =
{
  users: {
    label: "Users",
    description: "Find and inspect platform user accounts.",
    route: "/admin/users",
    group: "operations",
    sort_order: 50,
    required_entity: "admin_users",
    icon: "users"
  },
  audit: {
    label: "Audit",
    description: "Browse account and administrative audit history.",
    route: "/admin/audit",
    group: "operations",
    sort_order: 100,
    required_entity: "admin_audit_events",
    icon: "history"
  },
  messaging: {
    label: "Messaging",
    description: "Manage platform announcements and administrative messaging.",
    route: "/admin/messaging",
    group: "messaging",
    sort_order: 200,
    required_entity: "admin_messaging_announcements",
    icon: "megaphone"
  }
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



41
42
43
44
45
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 41

def initialize
  @definitions = {}
  @finalized = false
  seed_platform_tools!
end

Instance Method Details

#configure_tool(name) {|definition| ... } ⇒ Object

Yields:

  • (definition)

Raises:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 71

def configure_tool(name)
  raise CommandTower::AdminWorkspace::FrozenRegistryError, "admin workspace registry is frozen" if @finalized

  normalized = normalize_name!(name)
  definition = fetch(normalized)
  if definition.owner != :command_tower
    raise CommandTower::AdminWorkspace::HostOverrideError,
      "configure_tool is only for CommandTower-owned admin workspace tools"
  end

  yield definition
  definition.validate_definition!(name: normalized)
  definition
end

#definitionsObject



103
104
105
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 103

def definitions
  @definitions.dup.freeze
end

#fetch(name) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 86

def fetch(name)
  normalized = normalize_name!(name)
  definition = @definitions[normalized]
  if definition.nil?
    raise CommandTower::AdminWorkspace::UnregisteredToolError,
      "admin workspace tool #{normalized} is not registered"
  end

  definition
end

#finalize!Object



107
108
109
110
111
112
113
114
115
116
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 107

def finalize!
  @definitions.each_value do |definition|
    next unless definition.respond_to?(:class_composer_freeze_objects!)

    definition.class_composer_freeze_objects!(behavior: :raise, children: true)
  end
  @definitions.freeze
  @finalized = true
  self
end

#finalized?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 118

def finalized?
  @finalized
end

#registered?(name) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
100
101
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 97

def registered?(name)
  @definitions.key?(normalize_name!(name))
rescue CommandTower::AdminWorkspace::InvalidToolNameError
  false
end

#reset_host_definitions!Object



134
135
136
137
138
139
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 134

def reset_host_definitions!
  thaw_for_test!
  @definitions.delete_if { |_name, definition| definition.owner == :host }
  restore_platform_tools!
  self
end

#reset_platform_tool_scope_config!Object

Spec cleanup: re-seed unfrozen platform tools (scope_required defaults false). finalize! freezes ToolDefinition composers; thaw alone does not unfreeze them.



143
144
145
146
147
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 143

def reset_platform_tool_scope_config!
  thaw_for_test!
  restore_platform_tools!
  self
end

#tool(name, owner: :host) {|definition| ... } ⇒ Object

Yields:

  • (definition)

Raises:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 47

def tool(name, owner: :host)
  raise CommandTower::AdminWorkspace::FrozenRegistryError, "admin workspace registry is frozen" if @finalized

  normalized = normalize_name!(name)
  existing = @definitions[normalized]
  if existing
    if existing.owner == :command_tower && owner == :host
      raise CommandTower::AdminWorkspace::HostOverrideError,
        "host cannot redefine CommandTower-owned admin workspace tool #{normalized}"
    end

    raise CommandTower::AdminWorkspace::DuplicateToolError,
      "admin workspace tool #{normalized} is already registered"
  end

  definition = ToolDefinition.new
  yield definition if block_given?
  definition.owner = owner
  definition.validate_definition!(name: normalized)
  assert_unique_route!(definition)
  @definitions[normalized] = definition
  definition
end

#validate_required_entities!(entities) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/command_tower/configuration/registry/admin_workspace/config.rb', line 122

def validate_required_entities!(entities)
  missing = @definitions.filter_map do |name, definition|
    next if entities.key?(definition.required_entity)

    "#{name} requires #{definition.required_entity}"
  end
  return self if missing.empty?

  raise CommandTower::AdminWorkspace::MissingRequiredEntityError,
    "admin workspace tools reference unknown RBAC entities: #{missing.join(", ")}"
end