Class: SmartCloud::Credentials
- Inherits:
-
Base
- Object
- Base
- SmartCloud::Credentials
show all
- Defined in:
- lib/smart_cloud/credentials.rb
Constant Summary
collapse
- CIPHER =
"aes-256-gcm"
Instance Method Summary
collapse
Methods included from Logger
configure_logger_for, included, #logger, logger_for
Constructor Details
Returns a new instance of Credentials.
12
13
|
# File 'lib/smart_cloud/credentials.rb', line 12
def initialize
end
|
Instance Method Details
#config ⇒ Object
45
46
47
|
# File 'lib/smart_cloud/credentials.rb', line 45
def config
@config ||= deserialize(read).deep_symbolize_keys
end
|
#create ⇒ Object
15
16
17
18
|
# File 'lib/smart_cloud/credentials.rb', line 15
def create
write_key
write credentials_template
end
|
#edit ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/smart_cloud/credentials.rb', line 20
def edit
content_path = Pathname.new "config/credentials.yml.enc"
tmp_file = "#{Process.pid}.#{content_path.basename.to_s.chomp('.enc')}"
tmp_path = Pathname.new File.join(Dir.tmpdir, tmp_file)
contents = read
tmp_path.binwrite contents
system("#{ENV['EDITOR']} #{tmp_path}")
updated_contents = tmp_path.binread
if updated_contents != contents
write(updated_contents)
puts "File encrypted and saved."
else
puts "File contents were not changed."
end
ensure
FileUtils.rm(tmp_path) if tmp_path&.exist?
end
|
#read_key ⇒ Object
41
42
43
|
# File 'lib/smart_cloud/credentials.rb', line 41
def read_key
read_env_key || read_key_file || handle_missing_key
end
|