-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
51 lines (42 loc) · 1.46 KB
/
Rakefile
File metadata and controls
51 lines (42 loc) · 1.46 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
46
47
48
49
50
51
# frozen_string_literal: true
require_relative 'config/environment'
env = ENV.fetch('RACK_ENV', 'development')
# development and production use an unmodifiable db
if env == 'test'
require 'sinatra/activerecord'
require 'sinatra/activerecord/rake'
end
desc 'Check that we can connect to the database'
task :check do
require 'sinatra/activerecord'
require 'application_record'
ApplicationRecord.establish_connection(env.to_sym)
ApplicationRecord.connection.execute('SELECT 1')
puts 'Database connection successful'
end
namespace :credentials do
desc 'Outputs the credentials stored in `ARGV[1]` (used by diff helper)'
task :diff do
credentials = ActiveSupport::EncryptedConfiguration.new(
config_path: File.expand_path(ARGV[1], __dir__),
key_path: CREDENTIALS.key_path,
env_key: CREDENTIALS.env_key,
raise_if_missing_key: false
)
begin
puts credentials.read.presence || credentials.content_path.read
rescue ActiveSupport::MessageEncryptor::InvalidMessage
puts credentials.content_path.read
end
end
desc 'Edit the credentials file using the system editor'
task :edit do
require 'rails/command/helpers/editor'
include Rails::Command::Helpers::Editor
using_system_editor { CREDENTIALS.change { |tempfile| system_editor(tempfile) } }
end
desc 'Show the credentials stored in the credentials file'
task :show do
puts CREDENTIALS.read.presence || 'No decryptable credentials found'
end
end