-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
45 lines (37 loc) · 1.34 KB
/
Rakefile
File metadata and controls
45 lines (37 loc) · 1.34 KB
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
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.test_files = FileList["test/**/*_test.rb"]
end
task default: :test
namespace :credentials do
desc "Generate a new encryption key (save this securely, share via BXFTOOLS_KEY env var)"
task :generate_key do
require "securerandom"
key = SecureRandom.hex(32)
puts "Generated key (64 hex chars):"
puts key
puts
puts "Set this as BXFTOOLS_KEY in the host app's environment."
puts "Keep it secret. The encrypted credentials file is useless without it."
end
desc "Encrypt credentials from credentials.json using BXFTOOLS_KEY"
task :encrypt do
require_relative "lib/bxftools"
json_path = File.expand_path("credentials.json", __dir__)
unless File.exist?(json_path)
abort "Create credentials.json first with {\"binary_url\": \"...\", \"binary_name\": \"...\"}"
end
key = ENV["BXFTOOLS_KEY"]
abort "Set BXFTOOLS_KEY env var" unless key
Bxftools::Credentials.write(File.read(json_path), key)
puts "Encrypted credentials.json -> credentials.enc"
puts "You can now safely commit credentials.enc and delete credentials.json"
end
desc "Decrypt and display credentials (requires BXFTOOLS_KEY)"
task :decrypt do
require_relative "lib/bxftools"
puts Bxftools::Credentials.read
end
end