Class: StormMQ::SecretKeys

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/stormmq/secret_keys.rb

Instance Method Summary collapse

Instance Method Details

#forget_keysObject



56
57
58
# File 'lib/stormmq/secret_keys.rb', line 56

def forget_keys
  @secret_keys_cache = nil
end

#key_for(user) ⇒ Object

Returns the secret key for the given user name from the secret keys file.



29
30
31
32
# File 'lib/stormmq/secret_keys.rb', line 29

def key_for(user)
  raise Error::UserNotProvidedError, "user cannot be blank." if user.blank?
  keys[user] || (raise Error::SecretKeyNotFoundError, "a secret key for user '#{user}' could not be found in the secret key file.", caller)
end

#load_secret_keys(search_path = SECRET_KEYS_SEARCH_PATH, keyfile = SECRET_KEYS_FILENAME) ⇒ Object

Load the keys from the secret keys file keyfile. Walks the locations specified in search_path in order of preference.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/stormmq/secret_keys.rb', line 41

def load_secret_keys(search_path=SECRET_KEYS_SEARCH_PATH, keyfile=SECRET_KEYS_FILENAME)
  full_paths = search_path.map{|p| File.expand_path(File.join(p,keyfile))}
  full_paths.each do |full_path|
    begin
      return @secret_keys_cache = SecretKeys.secret_keys_hash_from_json(IO.read(full_path))
    rescue
      # A dummy statement so that this branch is picked up by rcov
      dummy = true
    end
  end
  raise Error::LoadSecretKeysError,
      "Could not read the secret keys file from any of [#{full_paths.join ', '}]. Please ensure that a valid keyfile exists in one of these locations and that it is readable.",
      caller
end

#usersObject

Returns an Array of user names of users who have keys in the secret keys file.



35
36
37
# File 'lib/stormmq/secret_keys.rb', line 35

def users
  keys.keys
end