Class: Duse::CLIConfig
Instance Attribute Summary
#settings
Class Method Summary
collapse
Instance Method Summary
collapse
#initialize, #to_h, #token, #token=, #uri, #uri=
Class Method Details
.config_dir ⇒ Object
38
39
40
|
# File 'lib/duse/cli/cli_config.rb', line 38
def self.config_dir
File.join Dir.home, '.config', 'duse'
end
|
.config_file ⇒ Object
34
35
36
|
# File 'lib/duse/cli/cli_config.rb', line 34
def self.config_file
File.join config_dir, 'config.yml'
end
|
.load ⇒ Object
20
21
22
23
24
|
# File 'lib/duse/cli/cli_config.rb', line 20
def self.load
config = YAML.load load_config_file
return {} unless config.is_a? Hash
config
end
|
.save(config) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/duse/cli/cli_config.rb', line 26
def self.save(config)
FileUtils.mkdir_p config_dir
File.open(config_file, 'w') do |file|
file.write config.to_h.to_yaml
file.chmod 0600
end
end
|
Instance Method Details
#private_key_file_for(user) ⇒ Object
42
43
44
|
# File 'lib/duse/cli/cli_config.rb', line 42
def private_key_file_for(user)
File.join self.class.config_dir, user.username
end
|
#private_key_for(user) ⇒ Object
8
9
10
11
12
|
# File 'lib/duse/cli/cli_config.rb', line 8
def private_key_for(user)
private_key_filename = private_key_file_for user
fail PrivateKeyMissing unless File.exists? private_key_filename
OpenSSL::PKey::RSA.new File.read private_key_filename
end
|
#save_private_key_for(user, private_key) ⇒ Object
14
15
16
17
18
|
# File 'lib/duse/cli/cli_config.rb', line 14
def save_private_key_for(user, private_key)
File.open(private_key_file_for(user), 'w') do |file|
file.write private_key
end
end
|