Class: OpenC3::ToolConfigModel

Inherits:
Object
  • Object
show all
Defined in:
lib/openc3/models/tool_config_model.rb

Defined Under Namespace

Classes: InvalidNameError

Constant Summary collapse

VALID_NAME_PATTERN =

Allowlist: letters, digits, hyphens, underscores, spaces, and periods

/\A[A-Za-z0-9_\-. ]+\z/

Class Method Summary collapse

Class Method Details

.config_tool_names(scope: $openc3_scope) ⇒ Object



27
28
29
30
31
# File 'lib/openc3/models/tool_config_model.rb', line 27

def self.config_tool_names(scope: $openc3_scope)
  _, keys = Store.scan(0, match: "#{scope}__config__*", type: 'hash', count: 100)
  # Just return the tool name that is used in the other APIs
  return keys.map! { |key| key.split('__')[2] }.sort
end

.delete_config(tool, name, local_mode: true, scope: $openc3_scope) ⇒ Object

Raises:



51
52
53
54
55
56
# File 'lib/openc3/models/tool_config_model.rb', line 51

def self.delete_config(tool, name, local_mode: true, scope: $openc3_scope)
  raise InvalidNameError, "Invalid tool name: #{tool}" unless tool.match?(VALID_NAME_PATTERN)
  raise InvalidNameError, "Invalid config name: #{name}" unless name.match?(VALID_NAME_PATTERN)
  Store.hdel("#{scope}__config__#{tool}", name)
  LocalMode.delete_tool_config(scope, tool, name) if local_mode
end

.list_configs(tool, scope: $openc3_scope) ⇒ Object

Raises:



33
34
35
36
# File 'lib/openc3/models/tool_config_model.rb', line 33

def self.list_configs(tool, scope: $openc3_scope)
  raise InvalidNameError, "Invalid tool name: #{tool}" unless tool.match?(VALID_NAME_PATTERN)
  Store.hkeys("#{scope}__config__#{tool}")
end

.load_config(tool, name, scope: $openc3_scope) ⇒ Object

Raises:



38
39
40
41
42
# File 'lib/openc3/models/tool_config_model.rb', line 38

def self.load_config(tool, name, scope: $openc3_scope)
  raise InvalidNameError, "Invalid tool name: #{tool}" unless tool.match?(VALID_NAME_PATTERN)
  raise InvalidNameError, "Invalid config name: #{name}" unless name.match?(VALID_NAME_PATTERN)
  Store.hget("#{scope}__config__#{tool}", name)
end

.save_config(tool, name, data, local_mode: true, scope: $openc3_scope) ⇒ Object

Raises:



44
45
46
47
48
49
# File 'lib/openc3/models/tool_config_model.rb', line 44

def self.save_config(tool, name, data, local_mode: true, scope: $openc3_scope)
  raise InvalidNameError, "Invalid tool name: #{tool}" unless tool.match?(VALID_NAME_PATTERN)
  raise InvalidNameError, "Invalid config name: #{name}" unless name.match?(VALID_NAME_PATTERN)
  Store.hset("#{scope}__config__#{tool}", name, data)
  LocalMode.save_tool_config(scope, tool, name, data) if local_mode
end