dotenvx 4.0.3-x86_64-linux → 4.0.5-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/lib/dotenvx/dotenvx_native.so +0 -0
- data/lib/dotenvx/rails.rb +3 -0
- data/lib/dotenvx/version.rb +1 -1
- data/lib/dotenvx.rb +95 -31
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eed8288974a56e99bb64dc3c42e68a8e29b6fe7dfc28ac2509a6c34ec6c9cdfe
|
|
4
|
+
data.tar.gz: 248c383166ac9a268f2ea1724cf733eaf7bb71587e297662bf7fe518b558f8a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d378737dbc885ce124e8072a846234a2c08f15be242b84aace2deabdd70c2818d47c31fb3eae4f2e8ba843fc86fba6628a5d6fac79d5ac423f458c2ee392b815
|
|
7
|
+
data.tar.gz: 0060ab3dc3fdc4c6ae2a61d8eaecd9bbdb355a76a0bff013634a667989bfd2652fb08437ab229b15a1a5dad16b71fb39c12acef00ee9fc34dc9fa9a39ca35803
|
data/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
## [Unreleased](https://github.com/dotenvx/dotenvx-ruby/compare/v4.0.
|
|
5
|
+
## [Unreleased](https://github.com/dotenvx/dotenvx-ruby/compare/v4.0.5...main)
|
|
6
|
+
|
|
7
|
+
## [4.0.5](https://github.com/dotenvx/dotenvx-ruby/compare/v4.0.4...v4.0.5)
|
|
8
|
+
|
|
9
|
+
- Continue after parse and decryption errors by default, with strict and
|
|
10
|
+
error-code ignore options for callers that need them.
|
|
11
|
+
|
|
12
|
+
## [4.0.4](https://github.com/dotenvx/dotenvx-ruby/compare/v4.0.3...v4.0.4)
|
|
13
|
+
|
|
14
|
+
- Report the unique variables injected from readable dotenv files.
|
|
6
15
|
|
|
7
16
|
## [4.0.0](https://github.com/dotenvx/dotenvx-ruby/compare/v0.0.2...v4.0.0)
|
|
8
17
|
|
|
Binary file
|
data/lib/dotenvx/rails.rb
CHANGED
data/lib/dotenvx/version.rb
CHANGED
data/lib/dotenvx.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require "dotenvx/version"
|
|
2
2
|
require "dotenvx/dotenvx_native"
|
|
3
3
|
require "json"
|
|
4
|
+
require "pathname"
|
|
4
5
|
|
|
5
6
|
module Dotenvx
|
|
6
7
|
class MissingKeys < RuntimeError
|
|
@@ -12,16 +13,32 @@ module Dotenvx
|
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
|
|
16
|
+
class ParseError < RuntimeError
|
|
17
|
+
attr_reader :code
|
|
18
|
+
|
|
19
|
+
def initialize(code, message)
|
|
20
|
+
@code = code
|
|
21
|
+
super(message)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
15
25
|
class << self
|
|
16
26
|
attr_accessor :instrumenter
|
|
17
27
|
|
|
18
|
-
def load(*filenames, overwrite: false, ignore: true)
|
|
19
|
-
env
|
|
20
|
-
|
|
28
|
+
def load(*filenames, overwrite: false, ignore: true, strict: false)
|
|
29
|
+
env, injected_keys, loaded_paths = parse_files(
|
|
30
|
+
*filenames,
|
|
31
|
+
overwrite: overwrite,
|
|
32
|
+
ignore: ignore,
|
|
33
|
+
strict: strict
|
|
34
|
+
)
|
|
35
|
+
changed = update(env, overwrite: overwrite)
|
|
36
|
+
log_injected(injected_keys, loaded_paths)
|
|
37
|
+
changed
|
|
21
38
|
end
|
|
22
39
|
|
|
23
40
|
def load!(*filenames)
|
|
24
|
-
load(*filenames, ignore: false)
|
|
41
|
+
load(*filenames, ignore: false, strict: true)
|
|
25
42
|
end
|
|
26
43
|
|
|
27
44
|
def overwrite(*filenames)
|
|
@@ -30,36 +47,17 @@ module Dotenvx
|
|
|
30
47
|
alias overload overwrite
|
|
31
48
|
|
|
32
49
|
def overwrite!(*filenames)
|
|
33
|
-
load(*filenames, overwrite: true, ignore: false)
|
|
50
|
+
load(*filenames, overwrite: true, ignore: false, strict: true)
|
|
34
51
|
end
|
|
35
52
|
alias overload! overwrite!
|
|
36
53
|
|
|
37
|
-
def parse(*filenames, overwrite: false, ignore: true)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
begin
|
|
45
|
-
source = File.binread(path).sub(/\A\xEF\xBB\xBF/, "").force_encoding(Encoding::UTF_8)
|
|
46
|
-
rescue Errno::ENOENT, Errno::EISDIR
|
|
47
|
-
raise unless ignore
|
|
48
|
-
next values
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
parsed, = Native.parse_dotenv(JSON.generate(
|
|
52
|
-
source: source,
|
|
53
|
-
process_env: process_env,
|
|
54
|
-
overwrite: overwrite == true,
|
|
55
|
-
key_files: key_files(path)
|
|
56
|
-
))
|
|
57
|
-
parsed = parsed.to_h
|
|
58
|
-
process_env.merge!(parsed)
|
|
59
|
-
values.merge!(parsed)
|
|
60
|
-
yield Environment.new(path, parsed) if block_given?
|
|
61
|
-
values
|
|
62
|
-
end
|
|
54
|
+
def parse(*filenames, overwrite: false, ignore: true, strict: false)
|
|
55
|
+
parse_files(
|
|
56
|
+
*filenames,
|
|
57
|
+
overwrite: overwrite,
|
|
58
|
+
ignore: ignore,
|
|
59
|
+
strict: strict
|
|
60
|
+
).first
|
|
63
61
|
end
|
|
64
62
|
|
|
65
63
|
def update(env = {}, overwrite: false)
|
|
@@ -89,6 +87,72 @@ module Dotenvx
|
|
|
89
87
|
|
|
90
88
|
private
|
|
91
89
|
|
|
90
|
+
def parse_files(*filenames, overwrite: false, ignore: true, strict: false)
|
|
91
|
+
filenames = [".env"] if filenames.empty?
|
|
92
|
+
filenames = filenames.flatten.reverse if overwrite
|
|
93
|
+
|
|
94
|
+
process_env = ENV.to_h
|
|
95
|
+
injected_keys = {}
|
|
96
|
+
loaded_paths = []
|
|
97
|
+
values = filenames.reduce({}) do |accumulator, filename|
|
|
98
|
+
path = File.expand_path(filename)
|
|
99
|
+
begin
|
|
100
|
+
source = File.binread(path).sub(/\A\xEF\xBB\xBF/, "").force_encoding(Encoding::UTF_8)
|
|
101
|
+
rescue Errno::ENOENT, Errno::EISDIR
|
|
102
|
+
raise unless ignore_missing?(ignore)
|
|
103
|
+
next accumulator
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
parsed, injected, errors = Native.parse_dotenv(JSON.generate(
|
|
107
|
+
source: source,
|
|
108
|
+
process_env: process_env,
|
|
109
|
+
overwrite: overwrite == true,
|
|
110
|
+
key_files: key_files(path)
|
|
111
|
+
))
|
|
112
|
+
handle_errors(errors, ignore: ignore, strict: strict)
|
|
113
|
+
parsed = parsed.to_h
|
|
114
|
+
injected.each { |key, _value| injected_keys[key] = true }
|
|
115
|
+
loaded_paths << path
|
|
116
|
+
process_env.merge!(parsed)
|
|
117
|
+
accumulator.merge!(parsed)
|
|
118
|
+
yield Environment.new(path, parsed) if block_given?
|
|
119
|
+
accumulator
|
|
120
|
+
end
|
|
121
|
+
[values, injected_keys.keys, loaded_paths]
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def handle_errors(errors, ignore:, strict:)
|
|
125
|
+
ignored_codes = Array(ignore).grep(String)
|
|
126
|
+
errors.each do |code, message|
|
|
127
|
+
next if ignored_codes.include?(code)
|
|
128
|
+
|
|
129
|
+
raise ParseError.new(code, message) if strict
|
|
130
|
+
|
|
131
|
+
warn "☠ #{message}"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def ignore_missing?(ignore)
|
|
136
|
+
ignore == true || Array(ignore).map(&:to_s).include?("MISSING_ENV_FILE")
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def log_injected(injected_keys, loaded_paths)
|
|
140
|
+
message = "⟐ injected env (#{injected_keys.length})"
|
|
141
|
+
unless loaded_paths.empty?
|
|
142
|
+
paths = loaded_paths.map { |path| readable_path(path) }
|
|
143
|
+
message = "#{message} from #{paths.join(", ")}"
|
|
144
|
+
end
|
|
145
|
+
warn message
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def readable_path(path)
|
|
149
|
+
pathname = Pathname.new(path)
|
|
150
|
+
relative = pathname.relative_path_from(Pathname.pwd).to_s
|
|
151
|
+
relative.start_with?("../") ? pathname.to_s : relative
|
|
152
|
+
rescue ArgumentError
|
|
153
|
+
pathname.to_s
|
|
154
|
+
end
|
|
155
|
+
|
|
92
156
|
def key_files(path)
|
|
93
157
|
candidates = ["#{path}.keys", File.join(File.dirname(path), ".env.keys")]
|
|
94
158
|
candidates.select { |candidate| File.file?(candidate) }
|