pears 0.0.7 → 0.0.8
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/Gemfile.lock +2 -1
- data/README.md +72 -12
- data/lib/pears/errors.rb +5 -1
- data/lib/pears/provider/base.rb +13 -0
- data/lib/pears/provider/local_file.rb +7 -7
- data/lib/pears/provider/remote_file.rb +9 -2
- data/lib/pears/provider/subscription.rb +3 -3
- data/lib/pears/version.rb +1 -1
- data/pears.gemspec +3 -3
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 314b1898a9c7b3f45eeaf3f2eb34097dba27a23c36c76af9efc18a61f247a56b
|
4
|
+
data.tar.gz: 1a021c4464cd3daafb0a2b222824abbcd6552e3990daf40fde4f17c9cc26aafe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6893c3c466be5d1da5f9d8e3eb05900a2d6292c4be0135dc531a9ec2902ada9958760fc26b345793cb45308f064ef14efaed760667e192791da66ea9def7d00c
|
7
|
+
data.tar.gz: cd69dcc4d02e48a6b0a89aed4e06b3558264d6f142c553ae7efd5641905ee5a4b49bc304661fc617f8294d1e4cc88d8733f0cac89a31420e3100a58d4517cd2a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,31 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Examples:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# You can load a dynamic config file like this
|
29
|
+
dynamic_config = Pears.subject(:settings) do |provider|
|
30
|
+
provider.subscription do
|
31
|
+
provider.remote_file "https://raw.githubusercontent.com/codefresh-io/yaml-examples/master/codefresh-build-1.yml"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# You can "Cascade" data like this
|
36
|
+
cascading_config = Pears.subject(:settings) do |provider|
|
37
|
+
provider.local_file Rails.root.join('config', 'settings.concrete.yml') # defines foo: 'foo'
|
38
|
+
provider.local_file Rails.root.join('config', 'settings.default.yml') # defines foo: 'bar', baz: 'baz'
|
39
|
+
end
|
40
|
+
|
41
|
+
cascading_config[:foo] # => foo
|
42
|
+
cascading_config[:baz] # => baz
|
43
|
+
|
44
|
+
# And you can combine these
|
45
|
+
combined_config = Pears.subject(:settings) do |provider|
|
46
|
+
provider.subscription { provider.remote_file "https://admin/configuration.yml" }
|
47
|
+
provider.local_file Rails.root.join('config', 'default.yml')
|
48
|
+
end
|
49
|
+
```
|
26
50
|
|
27
51
|
|
28
52
|
## Terminology
|
@@ -37,20 +61,40 @@ Configuration is loaded via the provider setting.
|
|
37
61
|
- LocalFile - read a yaml file identified by a path into a "Subject"
|
38
62
|
- RemoteFile - read a yaml file identified by a URI into a "Subject"
|
39
63
|
- Subscription - Read a yaml file identified by a URI as a segment and update it whenever the the provided redis channel gets an update.
|
40
|
-
- ENV - read the ENV and overwrite keys found on lower layers of the segment. **
|
41
|
-
- LOCO - read a loco file into a segment. **
|
42
64
|
|
43
|
-
|
65
|
+
You can create a custom povider like this:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
class GcloudProvider < Pears::Provider::LocalFile
|
69
|
+
def initialize
|
70
|
+
@data = parse_yaml Faraday.get(url, {}, authorization: token )
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def url
|
76
|
+
'https://velogica-portal-admin.ey.r.appspot.com/settings/' \
|
77
|
+
"#{Rails.application.secrets.settings_file}"
|
78
|
+
end
|
79
|
+
|
80
|
+
def token
|
81
|
+
path = 'http://metadata.google.internal/computeMetadata/v1/instance/'
|
82
|
+
|
83
|
+
'Bearer ' + Faraday.get(path, {}, { metadata_flavor: 'Google' }).body
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
And register it like this:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
# config/initializers/pears.rb
|
92
|
+
Pears::Provider::Builder.enable_provider Pears::GcloudProvider
|
93
|
+
```
|
44
94
|
|
45
95
|
|
46
96
|
## Todo
|
47
|
-
|
48
|
-
- Add Loco as a provider.
|
49
|
-
- Add ENV as a provider.
|
50
|
-
- Add Redis as a provider.
|
51
|
-
- Figure out if there is a sensible tie in with kubernetes.
|
52
|
-
- Add support for different file-types.
|
53
|
-
- Add different ways to trigger updates from redis subscriptions. (like hand fired events?)
|
97
|
+
|
54
98
|
|
55
99
|
## Development
|
56
100
|
|
@@ -58,9 +102,25 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
58
102
|
|
59
103
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
60
104
|
|
105
|
+
|
106
|
+
## Future
|
107
|
+
|
108
|
+
- Factor subject as a distinct, non-provider entitity.
|
109
|
+
- Add Loco as a provider.
|
110
|
+
- Add ENV as a provider.
|
111
|
+
- Figure out if there is a sensible tie in with kubernetes.
|
112
|
+
- Add support for different file-types.
|
113
|
+
- Add different ways to trigger updates from redis subscriptions.
|
114
|
+
|
115
|
+
We want to add the following providers:
|
116
|
+
- ENV - read the ENV and overwrite keys found on lower layers of the segment. **
|
117
|
+
- LOCO - read a loco file into a segment.
|
118
|
+
- Redis - consume data drom a redis key.
|
119
|
+
|
120
|
+
|
61
121
|
## Contributing
|
62
122
|
|
63
|
-
|
123
|
+
Hit me up on slack, jira or Bitbucket!
|
64
124
|
|
65
125
|
## License
|
66
126
|
|
data/lib/pears/errors.rb
CHANGED
data/lib/pears/provider/base.rb
CHANGED
@@ -2,6 +2,11 @@ module Pears
|
|
2
2
|
module Provider
|
3
3
|
class Base
|
4
4
|
attr_accessor :data
|
5
|
+
|
6
|
+
def initialize(data, on_failure: :raise)
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
|
5
10
|
def has_key?(key)
|
6
11
|
@data.has_key? key
|
7
12
|
end
|
@@ -13,6 +18,14 @@ module Pears
|
|
13
18
|
def [](key)
|
14
19
|
@data[key]
|
15
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def parse_yaml(yaml_data)
|
25
|
+
yaml_data = YAML.load(yaml_data)
|
26
|
+
raise Pears::InvalidProviderData if yaml_data.is_a? String
|
27
|
+
yaml_data.with_indifferent_access
|
28
|
+
end
|
16
29
|
end
|
17
30
|
end
|
18
31
|
end
|
@@ -5,15 +5,15 @@ module Pears
|
|
5
5
|
module Provider
|
6
6
|
# Used for loading simple YAML file locally.
|
7
7
|
class LocalFile < Base
|
8
|
-
def initialize(file_path)
|
8
|
+
def initialize(file_path, on_failure: :raise)
|
9
9
|
yaml_data = File.read(file_path)
|
10
10
|
@data = parse_yaml(yaml_data)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
rescue Errno::ENOENT => error
|
12
|
+
if on_failure == :null
|
13
|
+
@data = {}
|
14
|
+
else
|
15
|
+
raise error
|
16
|
+
end
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -3,10 +3,17 @@ require 'net/http'
|
|
3
3
|
module Pears
|
4
4
|
module Provider
|
5
5
|
# Fetch a yaml file via HTTP
|
6
|
-
class RemoteFile <
|
7
|
-
def initialize(remote_url)
|
6
|
+
class RemoteFile < Base
|
7
|
+
def initialize(remote_url, on_failure: :raise)
|
8
8
|
yaml_data = Net::HTTP.get(URI(remote_url))
|
9
9
|
@data = parse_yaml(yaml_data)
|
10
|
+
|
11
|
+
rescue SocketError, InvalidProviderData => e
|
12
|
+
if on_failure == :null
|
13
|
+
@data = {}
|
14
|
+
else
|
15
|
+
raise e
|
16
|
+
end
|
10
17
|
end
|
11
18
|
end
|
12
19
|
end
|
@@ -24,7 +24,7 @@ module Pears
|
|
24
24
|
|
25
25
|
# Setup redis subscription
|
26
26
|
establish_connection(redis_host)
|
27
|
-
|
27
|
+
load_config
|
28
28
|
subscribe
|
29
29
|
end
|
30
30
|
|
@@ -32,7 +32,7 @@ module Pears
|
|
32
32
|
@channel ||= @builder.subject_name
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def load_config
|
36
36
|
@builder.freeze_layers do
|
37
37
|
@data = @fetcher.call.data
|
38
38
|
end
|
@@ -50,7 +50,7 @@ module Pears
|
|
50
50
|
@subscription = Thread.new do
|
51
51
|
connection.subscribe(channel) do |on|
|
52
52
|
on.message do |channel, message|
|
53
|
-
|
53
|
+
load_config
|
54
54
|
end
|
55
55
|
end
|
56
56
|
puts "Redis connection died!"
|
data/lib/pears/version.rb
CHANGED
data/pears.gemspec
CHANGED
@@ -8,10 +8,10 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Steven Kemp"]
|
9
9
|
spec.email = ["steven@remarkgroup.com"]
|
10
10
|
|
11
|
-
spec.summary = "
|
12
|
-
spec.homepage = "https://
|
11
|
+
spec.summary = "An overly complicated library for juggling configuration data."
|
12
|
+
spec.homepage = "https://bitbucket.org/ivaldi/rubygems-pears/src/master/"
|
13
13
|
spec.license = "MIT"
|
14
|
-
spec.required_ruby_version = ">=
|
14
|
+
spec.required_ruby_version = ">= 2.7.4"
|
15
15
|
|
16
16
|
spec.metadata["homepage_uri"] = spec.homepage
|
17
17
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pears
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Kemp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -97,11 +97,11 @@ files:
|
|
97
97
|
- lib/pears/subject.rb
|
98
98
|
- lib/pears/version.rb
|
99
99
|
- pears.gemspec
|
100
|
-
homepage: https://
|
100
|
+
homepage: https://bitbucket.org/ivaldi/rubygems-pears/src/master/
|
101
101
|
licenses:
|
102
102
|
- MIT
|
103
103
|
metadata:
|
104
|
-
homepage_uri: https://
|
104
|
+
homepage_uri: https://bitbucket.org/ivaldi/rubygems-pears/src/master/
|
105
105
|
post_install_message:
|
106
106
|
rdoc_options: []
|
107
107
|
require_paths:
|
@@ -110,15 +110,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
113
|
+
version: 2.7.4
|
114
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
120
|
+
rubygems_version: 3.1.6
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
|
-
summary:
|
123
|
+
summary: An overly complicated library for juggling configuration data.
|
124
124
|
test_files: []
|