Skip to content

Commit c1c666a

Browse files
committed
Merge branch 'configuration'
2 parents 19f4f58 + 141c07b commit c1c666a

File tree

14 files changed

+132
-140
lines changed

14 files changed

+132
-140
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
## [Unreleased]
22

3+
## [0.11.2] - 2024-09-06
4+
5+
- Simplify the getters to not use memoization
6+
7+
## [0.11.1] - 2024-09-06
8+
9+
- Ensure the litestream initializer handles `nil`s
10+
311
## [0.11.0] - 2024-06-21
412

513
- Add a default username for the Litestream engine ([@fractaledmind](https://github.com/fractaledmind/litestream-ruby/commit/91c4de8b85be01f8cfd0cc2bf0027a6c0d9f3aaf))

Gemfile.lock

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
PATH
22
remote: .
33
specs:
4-
litestream (0.11.0)
5-
activejob
4+
litestream (0.11.2)
5+
actionpack (>= 7.0)
6+
actionview (>= 7.0)
7+
activejob (>= 7.0)
8+
activesupport (>= 7.0)
69
logfmt (>= 0.0.10)
10+
railties (>= 7.0)
711
sqlite3
812

913
GEM

app/controllers/litestream/application_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ class ApplicationController < ActionController::Base
33
protect_from_forgery with: :exception
44
around_action :force_english_locale!
55

6-
http_basic_authenticate_with name: Litestream.username, password: Litestream.password if Litestream.password
6+
if Litestream.password
7+
http_basic_authenticate_with(
8+
name: Litestream.username,
9+
password: Litestream.password
10+
)
11+
end
712

813
private
914

bin/console

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# frozen_string_literal: true
33

44
require "bundler/setup"
5+
require "rails"
56
require "litestream"
67

78
# You can add fixtures and/or initialization code here to make experimenting

lib/litestream.rb

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,25 @@
33
require "sqlite3"
44

55
module Litestream
6+
VerificationFailure = Class.new(StandardError)
7+
68
class << self
7-
attr_accessor :configuration
9+
attr_writer :configuration
10+
11+
def configuration
12+
@configuration ||= Configuration.new
13+
end
14+
15+
def deprecator
16+
@deprecator ||= ActiveSupport::Deprecation.new("0.12.0", "Litestream")
17+
end
818
end
919

1020
def self.configure
21+
deprecator.warn(
22+
"Configuring Litestream via Litestream.configure is deprecated. Use Rails.application.configure { config.litestream.* = ... } instead.",
23+
caller
24+
)
1125
self.configuration ||= Configuration.new
1226
yield(configuration)
1327
end
@@ -19,11 +33,7 @@ def initialize
1933
end
2034
end
2135

22-
VerificationFailure = Class.new(StandardError)
23-
24-
mattr_writer :username
25-
mattr_writer :password
26-
mattr_writer :queue
36+
mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key
2737

2838
class << self
2939
def verify!(database_path)
@@ -52,17 +62,27 @@ def verify!(database_path)
5262
# use method instead of attr_accessor to ensure
5363
# this works if variable set after Litestream is loaded
5464
def username
55-
@username ||= ENV["LITESTREAM_USERNAME"] || @@username || "litestream"
65+
ENV["LITESTREAM_USERNAME"] || @@username || "litestream"
5666
end
5767

58-
# use method instead of attr_accessor to ensure
59-
# this works if variable set after Litestream is loaded
6068
def password
61-
@password ||= ENV["LITESTREAM_PASSWORD"] || @@password
69+
ENV["LITESTREAM_PASSWORD"] || @@password
6270
end
6371

6472
def queue
65-
@queue ||= ENV["LITESTREAM_QUEUE"] || @@queue || "default"
73+
ENV["LITESTREAM_QUEUE"] || @@queue || "default"
74+
end
75+
76+
def replica_bucket
77+
@@replica_bucket || configuration.replica_bucket
78+
end
79+
80+
def replica_key_id
81+
@@replica_key_id || configuration.replica_key_id
82+
end
83+
84+
def replica_access_key
85+
@@replica_access_key || configuration.replica_access_key
6686
end
6787

6888
def replicate_process

lib/litestream/commands.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,9 @@ def execute(command, argv = {}, database = nil, async: false, tabled_output: fal
118118
end
119119

120120
def prepare(command, argv = {}, database = nil)
121-
if Litestream.configuration
122-
ENV["LITESTREAM_REPLICA_BUCKET"] ||= Litestream.configuration.replica_bucket
123-
ENV["LITESTREAM_ACCESS_KEY_ID"] ||= Litestream.configuration.replica_key_id
124-
ENV["LITESTREAM_SECRET_ACCESS_KEY"] ||= Litestream.configuration.replica_access_key
125-
end
121+
ENV["LITESTREAM_REPLICA_BUCKET"] ||= Litestream.replica_bucket
122+
ENV["LITESTREAM_ACCESS_KEY_ID"] ||= Litestream.replica_key_id
123+
ENV["LITESTREAM_SECRET_ACCESS_KEY"] ||= Litestream.replica_access_key
126124

127125
args = {
128126
"--config" => Rails.root.join("config", "litestream.yml").to_s

lib/litestream/engine.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ class Engine < ::Rails::Engine
1818
Litestream.public_send(:"#{name}=", value)
1919
end
2020
end
21+
22+
initializer "deprecator" do |app|
23+
app.deprecators[:litestream] = Litestream.deprecator
24+
end
2125
end
2226
end

lib/litestream/generators/litestream/templates/initializer.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This allows you to configure Litestream using Rails encrypted credentials,
55
# or some other mechanism where the values are only avaialble at runtime.
66

7-
Litestream.configure do |config|
7+
Rails.application.configure do
88
# An example of using Rails encrypted credentials to configure Litestream.
99
# litestream_credentials = Rails.application.credentials.litestream
1010

@@ -19,15 +19,15 @@
1919
# any SFTP server.
2020
# In this example, we are using Rails encrypted credentials to store the URL to
2121
# our storage provider bucket.
22-
# config.replica_bucket = litestream_credentials.replica_bucket
22+
# config.litestream.replica_bucket = litestream_credentials&.replica_bucket
2323

2424
# Replica-specific authentication key.
2525
# Litestream needs authentication credentials to access your storage provider bucket.
2626
# In this example, we are using Rails encrypted credentials to store the access key ID.
27-
# config.replica_key_id = litestream_credentials.replica_key_id
27+
# config.litestream.replica_key_id = litestream_credentials&.replica_key_id
2828

2929
# Replica-specific secret key.
3030
# Litestream needs authentication credentials to access your storage provider bucket.
3131
# In this example, we are using Rails encrypted credentials to store the secret access key.
32-
# config.replica_access_key = litestream_credentials.replica_access_key
32+
# config.litestream.replica_access_key = litestream_credentials&.replica_access_key
3333
end

lib/litestream/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Litestream
2-
VERSION = "0.11.0"
2+
VERSION = "0.11.2"
33
end

lib/tasks/litestream_tasks.rake

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
namespace :litestream do
22
desc "Print the ENV variables needed for the Litestream config file"
33
task env: :environment do
4-
if Litestream.configuration.nil?
5-
warn "You have not configured the Litestream gem with any values to generate ENV variables"
6-
next
7-
end
8-
9-
puts "LITESTREAM_REPLICA_BUCKET=#{Litestream.configuration.replica_bucket}"
10-
puts "LITESTREAM_ACCESS_KEY_ID=#{Litestream.configuration.replica_key_id}"
11-
puts "LITESTREAM_SECRET_ACCESS_KEY=#{Litestream.configuration.replica_access_key}"
4+
puts "LITESTREAM_REPLICA_BUCKET=#{Litestream.replica_bucket}"
5+
puts "LITESTREAM_ACCESS_KEY_ID=#{Litestream.replica_key_id}"
6+
puts "LITESTREAM_SECRET_ACCESS_KEY=#{Litestream.replica_access_key}"
127

138
true
149
end

0 commit comments

Comments
 (0)