smuggle-env 0.3.0

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/smuggle-env.rb +48 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aa8d2492a205376346d7d15496c484fb0b9cfbfb38fa5e1985a856320dbbc98a
4
+ data.tar.gz: 3f717903b8061802056df7bd429060311a8d1bc7b3ab7c82470285b6e8bceb40
5
+ SHA512:
6
+ metadata.gz: cd460a01c552055b1c30ac7b97bf2de39b51afd306197e9d63b57c517bffef4fafbb10bd01118440efe966b4248a477be798635fd97183e9a8b58168fe4180b8
7
+ data.tar.gz: 1d6008225afa70bbf6715715114fef889094a0c867119022e49e453d483728c898d2703751b5bad63f8b46d37efce5c1ecb2e0b9c1f2018c9d76c84dc587fff9
@@ -0,0 +1,48 @@
1
+ ENV.instance_eval do
2
+ OLD_ASSIGN = ENV.method(:[]=)
3
+ OLD_HASH = ENV.method(:[])
4
+ OLD_TO_H = ENV.method(:to_h)
5
+ SMUGGLED = {}
6
+ @smuggling = false
7
+
8
+ def start_smuggling(keys: [])
9
+ keys.each { |key|
10
+ hide(key)
11
+ }
12
+
13
+ @smuggling = true
14
+ end
15
+
16
+ def [](key)
17
+ value = OLD_HASH.call key
18
+ return value unless value.nil?
19
+ return SMUGGLED[key]
20
+ end
21
+
22
+ def []=(key, value)
23
+ if @smuggling
24
+ SMUGGLED[key] = value
25
+ else
26
+ OLD_ASSIGN.call(key, value)
27
+ end
28
+ end
29
+
30
+ def smuggle(key, value)
31
+ SMUGGLED[key] = value
32
+ end
33
+
34
+ def hide(key)
35
+ SMUGGLED[key] = OLD_HASH.call key
36
+ ENV.delete key
37
+ end
38
+
39
+ def to_h
40
+ OLD_TO_H.call.merge(SMUGGLED.map { |k,v|
41
+ [k, "**REDACTED**"]
42
+ }.to_h)
43
+ end
44
+
45
+ def inspect
46
+ to_h.inspect
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smuggle-env
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - OMAR
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-11-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: smuggle-env
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/smuggle-env.rb
20
+ homepage: https://github.com/ancat/smuggle-env
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.5'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.3.19
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Expose sensitive values to your environment without leaking them
43
+ test_files: []