Sha256: 14df286f0d709779ff2b7e0f85548b3db628f53a85062232657ec66e6c3c3f33

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

# encoding: ascii-8bit

# Copyright 2022 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# This program may also be used under the terms of a commercial or
# enterprise edition license of COSMOS if purchased from the
# copyright holder

module Cosmos
  module Api
    SETTINGS_KEY = "cosmos__settings"

    WHITELIST ||= []
    WHITELIST.concat([
                       'list_settings',
                       'get_all_settings',
                       'get_setting',
                       'get_settings',
                       'save_setting'
                     ])

    def list_settings(scope: $cosmos_scope, token: $cosmos_token)
      Store.instance.hkeys(SETTINGS_KEY)
    end

    def get_all_settings(scope: $cosmos_scope, token: $cosmos_token)
      Store.instance.hgetall(SETTINGS_KEY)
    end

    def get_setting(name, scope: $cosmos_scope, token: $cosmos_token)
      Store.instance.hget(SETTINGS_KEY, name)
    end

    def get_settings(*args, scope: $cosmos_scope, token: $cosmos_token)
      ret = []
      args.each do |name|
        ret << Store.instance.hget(SETTINGS_KEY, name)
      end
      return ret
    end

    def save_setting(name, data, scope: $cosmos_scope, token: $cosmos_token)
      authorize(permission: 'admin', scope: scope, token: token)
      Store.instance.hset(SETTINGS_KEY, name, data)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cosmos-5.0.3 lib/cosmos/api/settings_api.rb
cosmos-5.0.2 lib/cosmos/api/settings_api.rb
cosmos-5.0.2.pre.beta2 lib/cosmos/api/settings_api.rb