persey 1.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/README.md +5 -1
- data/lib/persey/adapters/base.rb +9 -3
- data/lib/persey/adapters/ini.rb +7 -7
- data/lib/persey/adapters/json.rb +8 -8
- data/lib/persey/adapters/ssm.rb +38 -0
- data/lib/persey/adapters/toml.rb +7 -7
- data/lib/persey/adapters/yaml.rb +11 -11
- data/lib/persey/builder.rb +2 -0
- data/lib/persey/configus_patch.rb +2 -0
- data/lib/persey/inspector.rb +10 -5
- data/lib/persey/loader.rb +3 -1
- data/lib/persey/version.rb +3 -1
- data/lib/persey.rb +4 -1
- data/persey.gemspec +1 -0
- data/spec/lib/persey_spec.rb +7 -2
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25b98a5bf970d30e825aaef946b99786d99c565fe6d38a1ff1cf9f8d5dd820d5
|
4
|
+
data.tar.gz: 07c32c8824ec406863b19f534b0ce1254a4d5278fc73d5f9a43fb2dd6043c58f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f82c680006f731c112c87f7a834aa66aea87be293dff1addd23b091e6bd151eac16931af20a1d338ea7c8acf128c34feba0517425424dc6ba524987b42767c8
|
7
|
+
data.tar.gz: edc5d2fdc4591fcbc4f2cb56e8b69ed410b6b435e5b02701abc9555b3e8931b3a9714f7a710ff5ee19f26d3993afe6560f70fbb0e9c00fd35246e7d226d20920
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Persey [![Build Status](https://travis-ci.org/zzet/persey.svg?branch=master)](https://travis-ci.org/zzet/persey) [![Gem Version](https://badge.fury.io/rb/persey.svg)](http://badge.fury.io/rb/persey)
|
1
|
+
# Persey [![Build Status](https://travis-ci.org/zzet/persey.svg?branch=master)](https://travis-ci.org/zzet/persey) [![Gem Version](https://badge.fury.io/rb/persey.svg)](http://badge.fury.io/rb/persey)[![Code Climate](https://codeclimate.com/github/zzet/persey.svg)](https://codeclimate.com/github/zzet/persey) [![Downloads count](https://img.shields.io/gem/dt/persey.svg)](https://img.shields.io/gem/dt/persey.svg)
|
2
2
|
|
3
3
|
|
4
4
|
## Summary
|
@@ -67,6 +67,8 @@ my_node_js_config = '/rest/u/apps/node/config.json'
|
|
67
67
|
my_berkshelf_config = File.join(app_path, 'provisioning', '.berkshelf')
|
68
68
|
# And INI
|
69
69
|
my_ini_config = File.join(app_path, 'provisioning', 'php.ini') # lol
|
70
|
+
# And AWS SSM secure string (we assume you're using JSON inside)
|
71
|
+
my_ssm_config = '/some/ssm/parameter/path.json'
|
70
72
|
|
71
73
|
# Persey.init ENV["environment"] do # set current environment
|
72
74
|
Persey.init Rails.env do # set current environment
|
@@ -78,6 +80,7 @@ Persey.init Rails.env do # set current environment
|
|
78
80
|
source :json, my_node_js_config, :node_js_namespace
|
79
81
|
source :toml, my_berkshelf_config, :berkshelf_namespace
|
80
82
|
source :ini, my_ini_config, :ini_namespace
|
83
|
+
source :ssm, my_ssm_config, :ssm_namespace
|
81
84
|
|
82
85
|
env :production do
|
83
86
|
site_name 'Example'
|
@@ -181,6 +184,7 @@ end
|
|
181
184
|
* JSON
|
182
185
|
* TOML
|
183
186
|
* INI
|
187
|
+
* AWS SSM Secure string (json inside)
|
184
188
|
|
185
189
|
## Similar
|
186
190
|
|
data/lib/persey/adapters/base.rb
CHANGED
@@ -1,18 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Persey
|
2
4
|
module Adapters
|
3
5
|
class Base
|
4
6
|
class << self
|
5
|
-
def load(file, env)
|
7
|
+
def load(file, env, opts)
|
6
8
|
raise NotImplementedError
|
7
9
|
end
|
8
10
|
|
9
11
|
def symbolize_keys(hash)
|
10
|
-
hash.
|
12
|
+
hash.each_with_object({}) do |(k, v), res|
|
11
13
|
n_k = k.is_a?(String) ? k.to_sym : k
|
12
14
|
n_v = v.is_a?(Hash) ? symbolize_keys(v) : v
|
13
15
|
res[n_k] = n_v
|
14
16
|
res
|
15
|
-
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def config_exists?(path, _opts)
|
21
|
+
File.exist?(path)
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
data/lib/persey/adapters/ini.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'inifile'
|
2
4
|
|
3
5
|
module Persey
|
4
6
|
module Adapters
|
5
7
|
class Ini < Persey::Adapters::Base
|
6
8
|
class << self
|
7
|
-
def load(file,
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
puts "FATAL: Error while process config from file '#{file}'"
|
13
|
-
end
|
9
|
+
def load(file, _env, opts: {})
|
10
|
+
raw_hash = IniFile.load(file).to_h
|
11
|
+
symbolize_keys(raw_hash)
|
12
|
+
rescue
|
13
|
+
puts "FATAL: Error while process config from file '#{file}'"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/persey/adapters/json.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json/stream'
|
2
4
|
|
3
5
|
module Persey
|
4
6
|
module Adapters
|
5
7
|
class Json < Persey::Adapters::Base
|
6
8
|
class << self
|
7
|
-
def load(file,
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
puts "FATAL: Error while process config from file '#{file}'"
|
14
|
-
end
|
9
|
+
def load(file, _env, opts: {})
|
10
|
+
json = File.new(file, 'r')
|
11
|
+
raw_hash = JSON::Stream::Parser.parse(json)
|
12
|
+
symbolize_keys(raw_hash)
|
13
|
+
rescue
|
14
|
+
puts "FATAL: Error while process config from file '#{file}'"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'aws-sdk-ssm'
|
5
|
+
|
6
|
+
module Persey
|
7
|
+
class MissingEnvVariable < RuntimeError; end
|
8
|
+
|
9
|
+
module Adapters
|
10
|
+
class Ssm < Persey::Adapters::Base
|
11
|
+
class << self
|
12
|
+
def load(path, _env, opts: {})
|
13
|
+
ssm = ssm_client(opts)
|
14
|
+
param = ssm.get_parameter(name: path, with_decryption: true).parameter
|
15
|
+
|
16
|
+
res = begin
|
17
|
+
JSON.parse(param.value)
|
18
|
+
rescue JSON::ParserError
|
19
|
+
param.to_h
|
20
|
+
end
|
21
|
+
|
22
|
+
symbolize_keys(res)
|
23
|
+
end
|
24
|
+
|
25
|
+
def config_exists?(path, opts: {})
|
26
|
+
ssm = ssm_client(opts)
|
27
|
+
ssm.get_parameter(name: path, with_decryption: true).parameter.nil? == false
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def ssm_client(opts)
|
33
|
+
opts[:client] || Aws::SSM::Client.new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/persey/adapters/toml.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'toml'
|
2
4
|
|
3
5
|
module Persey
|
4
6
|
module Adapters
|
5
7
|
class Toml < Persey::Adapters::Base
|
6
8
|
class << self
|
7
|
-
def load(file,
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
puts "FATAL: Error while process config from file '#{file}'"
|
13
|
-
end
|
9
|
+
def load(file, _env, opts: {})
|
10
|
+
raw_hash = TOML.load_file(file)
|
11
|
+
symbolize_keys(raw_hash)
|
12
|
+
rescue
|
13
|
+
puts "FATAL: Error while process config from file '#{file}'"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/persey/adapters/yaml.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
require 'erb'
|
3
5
|
|
@@ -7,17 +9,15 @@ module Persey
|
|
7
9
|
module Adapters
|
8
10
|
class Yaml < Persey::Adapters::Base
|
9
11
|
class << self
|
10
|
-
def load(file,
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
raise e
|
20
|
-
end
|
12
|
+
def load(file, _env, opts: {})
|
13
|
+
raw_hash = YAML.load(ERB.new(File.read(file)).result)
|
14
|
+
symbolize_keys(raw_hash)
|
15
|
+
rescue KeyError => e
|
16
|
+
_, line, method = /\(erb\):(\d+):in `(.*)'/.match(e.backtrace[0]).to_a
|
17
|
+
if method == 'fetch'
|
18
|
+
raise MissingEnvVariable.new("Check line ##{line} in #{file}")
|
19
|
+
else
|
20
|
+
raise e
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/persey/builder.rb
CHANGED
data/lib/persey/inspector.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/inflector'
|
2
4
|
|
3
5
|
module Persey
|
@@ -11,14 +13,17 @@ module Persey
|
|
11
13
|
@sources
|
12
14
|
end
|
13
15
|
|
14
|
-
def source(source_type, config_file, namespace = nil)
|
15
|
-
raise MissingConfigFile.new("Can't find #{source_type} config: #{config_file}") unless File.exist?(config_file)
|
16
|
-
|
16
|
+
def source(source_type, config_file, namespace = nil, opts = {})
|
17
17
|
klass = "persey/adapters/#{source_type}".camelize.constantize
|
18
|
-
|
18
|
+
|
19
|
+
unless klass.config_exists?(config_file, opts: opts)
|
20
|
+
raise MissingConfigFile, "Can't find #{source_type} config: #{config_file}"
|
21
|
+
end
|
22
|
+
|
23
|
+
@sources << { class: klass, file: config_file, namespace: namespace, opts: opts }
|
19
24
|
|
20
25
|
override_config_file = config_file + '.override'
|
21
|
-
@sources << { class: klass, file: override_config_file, namespace: namespace } if
|
26
|
+
@sources << { class: klass, file: override_config_file, namespace: namespace, opts: opts } if klass.config_exists?(override_config_file, opts: opts)
|
22
27
|
end
|
23
28
|
|
24
29
|
def env(*args)
|
data/lib/persey/loader.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Persey
|
2
4
|
class Loader
|
3
5
|
attr_accessor :configs
|
@@ -18,7 +20,7 @@ module Persey
|
|
18
20
|
|
19
21
|
configs.each do |pdc|
|
20
22
|
klass = pdc[:class]
|
21
|
-
raw_config = klass.load(pdc[:file], env)
|
23
|
+
raw_config = klass.load(pdc[:file], env, opts: pdc[:opts])
|
22
24
|
env_config = raw_config[env].nil? ? raw_config : raw_config[env]
|
23
25
|
|
24
26
|
n = pdc[:namespace]
|
data/lib/persey/version.rb
CHANGED
data/lib/persey.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'persey/version'
|
2
4
|
require 'persey/builder'
|
3
5
|
require 'persey/inspector'
|
@@ -7,6 +9,7 @@ require 'persey/adapters/yaml'
|
|
7
9
|
require 'persey/adapters/json'
|
8
10
|
require 'persey/adapters/toml'
|
9
11
|
require 'persey/adapters/ini'
|
12
|
+
require 'persey/adapters/ssm'
|
10
13
|
require 'persey/configus_patch'
|
11
14
|
|
12
15
|
module Persey
|
@@ -19,7 +22,7 @@ module Persey
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def config
|
22
|
-
raise
|
25
|
+
raise 'Please, init config before usage' if @config.nil?
|
23
26
|
|
24
27
|
@config
|
25
28
|
end
|
data/persey.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency 'json-stream'
|
24
24
|
spec.add_runtime_dependency 'toml', '~> 0.1.0'
|
25
25
|
spec.add_runtime_dependency 'inifile'
|
26
|
+
spec.add_runtime_dependency 'aws-sdk-ssm', '~> 1.120'
|
26
27
|
|
27
28
|
spec.add_development_dependency 'simplecov'
|
28
29
|
end
|
data/spec/lib/persey_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Persey do
|
@@ -8,6 +10,7 @@ describe Persey do
|
|
8
10
|
plain_json_config = File.join(fixtures_path, 'json_config.json')
|
9
11
|
plain_toml_config = File.join(fixtures_path, 'toml_config.toml')
|
10
12
|
plain_ini_config = File.join(fixtures_path, 'ini_config.ini')
|
13
|
+
plain_ssm_config = '/some/ssm/parameter/path.json'
|
11
14
|
|
12
15
|
Persey.init :production do
|
13
16
|
source :yaml, plain_config
|
@@ -15,11 +18,12 @@ describe Persey do
|
|
15
18
|
source :json, plain_json_config, :json_config
|
16
19
|
source :toml, plain_toml_config, :toml_config
|
17
20
|
source :ini, plain_ini_config, :ini_config
|
21
|
+
source :ssm, plain_ssm_config, :ssm_config, { client: Aws::SSM::Client.new(stub_responses: true) }
|
18
22
|
|
19
23
|
env :production do
|
20
24
|
option do
|
21
|
-
first
|
22
|
-
second
|
25
|
+
first 'first value'
|
26
|
+
second 'second value'
|
23
27
|
end
|
24
28
|
|
25
29
|
first do
|
@@ -44,6 +48,7 @@ describe Persey do
|
|
44
48
|
expect(@config.json_config.owner.name).to eq('John Doe')
|
45
49
|
expect(@config.toml_config.owner.name).to eq('Tom Preston-Werner')
|
46
50
|
expect(@config.ini_config.section1.var1).to eq('foo')
|
51
|
+
expect(@config.ssm_config.value).to eq('PSParameterValue')
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: persey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Kumanyaev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aws-sdk-ssm
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.120'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.120'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: simplecov
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +130,7 @@ files:
|
|
116
130
|
- lib/persey/adapters/base.rb
|
117
131
|
- lib/persey/adapters/ini.rb
|
118
132
|
- lib/persey/adapters/json.rb
|
133
|
+
- lib/persey/adapters/ssm.rb
|
119
134
|
- lib/persey/adapters/toml.rb
|
120
135
|
- lib/persey/adapters/yaml.rb
|
121
136
|
- lib/persey/builder.rb
|
@@ -151,8 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
166
|
- !ruby/object:Gem::Version
|
152
167
|
version: '0'
|
153
168
|
requirements: []
|
154
|
-
|
155
|
-
rubygems_version: 2.7.3
|
169
|
+
rubygems_version: 3.1.2
|
156
170
|
signing_key:
|
157
171
|
specification_version: 4
|
158
172
|
summary: Helps you easily manage environment specific settings
|