Class: SdrClient::Credentials
- Inherits:
-
Object
- Object
- SdrClient::Credentials
show all
- Defined in:
- lib/sdr_client/credentials.rb
Overview
Defined Under Namespace
Classes: NoCredentialsError
Class Method Summary
collapse
Class Method Details
.credentials_file ⇒ Object
31
32
33
|
# File 'lib/sdr_client/credentials.rb', line 31
def self.credentials_file
File.join(credentials_path, 'credentials')
end
|
.credentials_path ⇒ Object
27
28
29
|
# File 'lib/sdr_client/credentials.rb', line 27
def self.credentials_path
@credentials_path ||= File.join(Dir.home, '.sdr')
end
|
.read ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/sdr_client/credentials.rb', line 18
def self.read
raise NoCredentialsError unless ::File.exist?(credentials_file)
creds = IO.readlines(credentials_file, chomp: true).first if ::File.exist?(credentials_file)
raise NoCredentialsError if creds.nil?
creds
end
|
.write(body) ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/sdr_client/credentials.rb', line 9
def self.write(body)
json = JSON.parse(body)
Dir.mkdir(credentials_path, 0o700) unless Dir.exist?(credentials_path)
File.atomic_write(credentials_file) do |file|
file.write(json.fetch('token'))
end
File.chmod(0o600, credentials_file)
end
|