secrets_parser 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +16 -0
- data/lib/secrets_parser/parser.rb +20 -6
- data/lib/secrets_parser/version.rb +1 -1
- data/secrets_parser.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 482b595adb191ed6b889340e239cdcc376e84a3ee3e0e0e15a4df745ee28009f
|
4
|
+
data.tar.gz: 3e077fcda36d288afaebac53430bc567aae58b50e936e66cad5464e3dd4c1e9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48775396ba15fa9ff16ec517d13ee4e53a8349072ed9704c455c24cb42c53f5c627b1f00cbfc7e6b070ce5db96ed6044aa1822299fc46656c9b6e092bb8bb851
|
7
|
+
data.tar.gz: eb1f9e854bb59043f2f9bc50f190b03e4177fbe76d7f110302bdd470cf769a9f449e25b64c5b1cae909a897f737aa89ade8e8420365f24e67bc7af0f65410949
|
data/README.md
CHANGED
@@ -91,3 +91,19 @@ puts JSON.pretty_generate(parsed_file)
|
|
91
91
|
}
|
92
92
|
}
|
93
93
|
```
|
94
|
+
|
95
|
+
### Logging
|
96
|
+
|
97
|
+
To enable logging feature just configure `:logger` key injecting a logger that implements [Logger interface](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html).
|
98
|
+
|
99
|
+
Sample using ruby's Logger stdlib:
|
100
|
+
|
101
|
+
```
|
102
|
+
require 'secrets_parser'
|
103
|
+
require 'logger'
|
104
|
+
|
105
|
+
parser = Secrets::Parser.new
|
106
|
+
parser.set_config do |config|
|
107
|
+
config[:logger] = Logger.new(STDOUT)
|
108
|
+
end
|
109
|
+
```
|
@@ -9,7 +9,8 @@ module Secrets
|
|
9
9
|
def initialize
|
10
10
|
@config = {
|
11
11
|
s3_client: nil,
|
12
|
-
kms_client: nil
|
12
|
+
kms_client: nil,
|
13
|
+
logger: nil
|
13
14
|
}
|
14
15
|
end
|
15
16
|
|
@@ -25,6 +26,8 @@ module Secrets
|
|
25
26
|
app_json = JSON.parse(IO.read(file_to_parse))
|
26
27
|
app_variables = app_json[field_to_parse]
|
27
28
|
|
29
|
+
logger.info "Parsing #{field_to_parse} section of #{file_to_parse}" if logger?
|
30
|
+
|
28
31
|
app_json[field_to_parse] = parse_secrets_from app_variables
|
29
32
|
|
30
33
|
app_json
|
@@ -54,6 +57,8 @@ module Secrets
|
|
54
57
|
file = file[file.index('/') + 1..file.length] + SECRETS_FILE_SUFFIX
|
55
58
|
tmp_file = "/tmp/secrets#{SECRETS_FILE_SUFFIX}"
|
56
59
|
|
60
|
+
logger.info "Downloading #{file} from #{bucket_name}" if logger?
|
61
|
+
|
57
62
|
File.open(tmp_file, 'wb') do |secret_file|
|
58
63
|
@config[:s3_client].get_object({ bucket: bucket_name, key: file }, target: secret_file)
|
59
64
|
end
|
@@ -79,23 +84,32 @@ module Secrets
|
|
79
84
|
def parse_secrets_from(variables)
|
80
85
|
secret_variables = {}
|
81
86
|
|
82
|
-
variables.each_pair do |
|
83
|
-
next unless secret?
|
87
|
+
variables.each_pair do |key, value|
|
88
|
+
next unless secret?(value)
|
84
89
|
|
85
|
-
secret =
|
90
|
+
secret = value
|
86
91
|
|
87
92
|
secret_file = secret_file_path_from(secret)
|
88
93
|
secret_key = secret_key_from(secret)
|
89
94
|
|
90
|
-
unless secret_variables.key?
|
95
|
+
unless secret_variables.key?(secret_file)
|
91
96
|
secret_variables[secret_file] = extract_secrets_from secret_file
|
92
97
|
end
|
93
98
|
|
94
|
-
|
99
|
+
logger.info "Updating #{key} value" if logger?
|
100
|
+
|
101
|
+
variables[key] = secret_variables[secret_file][secret_key]
|
95
102
|
end
|
96
103
|
|
97
104
|
variables
|
98
105
|
end
|
99
106
|
|
107
|
+
def logger?
|
108
|
+
!logger.nil?
|
109
|
+
end
|
110
|
+
|
111
|
+
def logger
|
112
|
+
@config[:logger]
|
113
|
+
end
|
100
114
|
end
|
101
115
|
end
|
data/secrets_parser.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = 'https://github.com/peertransfer/secrets_parser'
|
15
15
|
|
16
16
|
if spec.respond_to?(:metadata)
|
17
|
-
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://travis-ci.org/'
|
18
18
|
else
|
19
19
|
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
20
20
|
'public gem pushes.'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secrets_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paco Sanchez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,7 +71,8 @@ files:
|
|
71
71
|
homepage: https://github.com/peertransfer/secrets_parser
|
72
72
|
licenses:
|
73
73
|
- MIT
|
74
|
-
metadata:
|
74
|
+
metadata:
|
75
|
+
allowed_push_host: https://travis-ci.org/
|
75
76
|
post_install_message:
|
76
77
|
rdoc_options: []
|
77
78
|
require_paths:
|
@@ -88,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
89
|
version: '0'
|
89
90
|
requirements: []
|
90
91
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.7.7
|
92
93
|
signing_key:
|
93
94
|
specification_version: 4
|
94
95
|
summary: Write a short summary, because RubyGems requires one.
|