Skip to content

Commit d774aa9

Browse files
authored
Fix multiple assignments and parsing of raw (#190)
* fix: Add explicit type coercions Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com> * fix: Don't merge default config Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com> * fix: Explicitly pass key and salt Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com> * fix: Use #dup instead of initializing the same config Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com> * fix: Mixing raw_key/salt ans salt options fix Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com>
1 parent 4b40eb0 commit d774aa9

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

lib/imgproxy/config.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class Config < Anyway::Config
4343
services: {},
4444
)
4545

46+
coerce_types use_short_options: :boolean,
47+
base64_encode_urls: :boolean,
48+
always_escape_plain_urls: :boolean,
49+
use_s3_urls: :boolean,
50+
use_gcs_urls: :boolean,
51+
gcs_bucket: :string,
52+
shrine_host: :string
53+
4654
def endpoint
4755
service(:default).endpoint
4856
end
@@ -92,23 +100,29 @@ def signature_size=(value)
92100
end
93101

94102
def service(name)
95-
services[name.to_sym] ||= ServiceConfig.new(services[:default].to_h)
103+
services[name.to_sym] ||= services[:default].dup
104+
96105
yield services[name.to_sym] if block_given?
97106

98107
services[name.to_sym]
99108
end
100109

110+
# rubocop: disable Metrics/AbcSize
101111
def services
102112
@services ||= {}.tap do |s|
103113
s[:default] = ServiceConfig.new
104114

105115
super.each do |name, data|
106-
s[name.to_sym] = ServiceConfig.new(
107-
s[:default].to_h.merge(data.symbolize_keys),
108-
)
116+
config = s[name.to_sym] = s[:default].dup
117+
118+
data.symbolize_keys.slice(*config.class.config_attributes).each do |key, value|
119+
value = config.class.type_caster.coerce(key, value)
120+
config.public_send("#{key}=", value)
121+
end
109122
end
110123
end
111124
end
125+
# rubocop: enable Metrics/AbcSize
112126

113127
# @deprecated Please use {#key} instead
114128
def hex_key=(value)

lib/imgproxy/service_config.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class ServiceConfig < Anyway::Config
3636
signature_size: 32,
3737
)
3838

39+
coerce_types endpoint: :string,
40+
key: :string,
41+
salt: :string,
42+
raw_key: :string,
43+
raw_salt: :string,
44+
signature_size: :integer
45+
3946
alias_method :set_key, :key=
4047
alias_method :set_raw_key, :raw_key=
4148
alias_method :set_salt, :salt=

0 commit comments

Comments
 (0)