-
Notifications
You must be signed in to change notification settings - Fork 0
/
mix_setting.rake
54 lines (50 loc) · 1.56 KB
/
mix_setting.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# TODO rotate :secret_key_base
namespace :setting do
task :context => :environment do
puts "{ env: #{Setting.env}, app: #{Setting.app} }"
end
task :dump, [:env, :app, :file] do |t, args|
raise 'argument [:file] must be specified' unless (file = args[:file]).present?
with_stage! args do
Pathname.new(file).expand_path.write(Setting.to_yaml)
puts "[#{Setting.stage}] settings written to file [#{file}]"
end
end
desc "encrypt file or ENV['DATA'] --> wrap with double quotes for escaped newlines"
task :encrypt, [:env, :file] do |t, args|
with_stage(args) do
if ENV['DATA'].present?
puts Setting.encrypt(ENV['DATA'])
else
puts Setting.encrypt(Pathname.new(args[:file]).expand_path.read)
end
end
end
desc "decrypt key and optionally output to file"
task :decrypt, [:env, :key, :file] do |t, args|
with_stage(args) do
if args[:file].present?
Pathname.new(args[:file]).expand_path.write(Setting[args[:key]])
puts "[#{args[:key]}] key written to file [#{args[:file]}]"
else
value =
if ENV['DATA'].present?
Setting.decrypt(ENV['DATA'])
else
Setting[args[:key]]
end
if ENV['ESCAPE'].to_b
value = value.escape_newlines
end
if ENV['UNESCAPE'].to_b
value = value.unescape_newlines
end
puts value
end
end
end
desc 'escape file newlines'
task :escape, [:file] do |t, args|
puts Pathname.new(args[:file]).expand_path.read.escape_newlines
end
end