Module: Aws::Session::Credentials::FileProvider::YamlFileProvider

Included in:
Cache, Config
Defined in:
lib/aws/session/credentials/file_provider/yaml_file_provider.rb

Overview

Mixin to store configuration in a YAML file

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



7
8
9
# File 'lib/aws/session/credentials/file_provider/yaml_file_provider.rb', line 7

def [](key)
  read[key]
end

#[]=(key, value) ⇒ Object



11
12
13
14
15
# File 'lib/aws/session/credentials/file_provider/yaml_file_provider.rb', line 11

def []=(key, value)
  hash = read.dup
  hash[key] = value
  write(hash)
end

#readHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


19
20
21
22
# File 'lib/aws/session/credentials/file_provider/yaml_file_provider.rb', line 19

def read
  return {} unless File.exist?(path)
  YAML.load(File.read(path)).deep_symbolize_keys
end

#write(hash) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • hash (Hash)


26
27
28
29
# File 'lib/aws/session/credentials/file_provider/yaml_file_provider.rb', line 26

def write(hash)
  hsh = hash.deep_stringify_keys
  File.open(path, 'w', 0600) { |file| file.write(YAML.dump(hsh)) }
end