pears 0.0.6 → 0.0.10
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 +12 -2
- data/lib/pears/provider/subscription.rb +5 -4
- data/lib/pears/version.rb +1 -1
- data/pears.gemspec +3 -3
- metadata +6 -7
- data/pears-0.0.5.gem +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 40970c145a4cb29cc549b0534c7ced74e799fab7745f153562b579c966c4bb19
|
|
4
|
+
data.tar.gz: a91ba1e130712c40d9d97f3c6fb21ebe562982bc370284988f8033e999a1d111
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 30515f3509a1c6832247fcf5c444881c28a87f442cacee341d84a75dc20117722fe2029561d8685b09592c2a84f38351cbfcce24a50d5a91a9dbe62d1b69a107
|
|
7
|
+
data.tar.gz: 367c680e08109add0b2f7c13dc1bb3c24cb6aaa1d817873cfa863eead5b5d5f6ff10e887c6ddb861ae85135a0ef08829cfcbea1695c799097431205ab2c62b90
|
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,20 @@ 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,
|
|
12
|
+
InvalidProviderData,
|
|
13
|
+
Errno::ECONNREFUSED,
|
|
14
|
+
Errno::EHOSTUNREACH => e
|
|
15
|
+
if on_failure == :null
|
|
16
|
+
@data = {}
|
|
17
|
+
else
|
|
18
|
+
raise e
|
|
19
|
+
end
|
|
10
20
|
end
|
|
11
21
|
end
|
|
12
22
|
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
|
|
@@ -48,11 +48,12 @@ module Pears
|
|
|
48
48
|
|
|
49
49
|
def subscribe
|
|
50
50
|
@subscription = Thread.new do
|
|
51
|
-
connection.subscribe(
|
|
51
|
+
connection.subscribe(channel) do |on|
|
|
52
52
|
on.message do |channel, message|
|
|
53
|
-
|
|
53
|
+
load_config
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
|
+
puts "Redis connection died!"
|
|
56
57
|
end
|
|
57
58
|
end
|
|
58
59
|
|
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.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steven Kemp
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-01-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: dry-configurable
|
|
@@ -96,13 +96,12 @@ files:
|
|
|
96
96
|
- lib/pears/provider/subscription.rb
|
|
97
97
|
- lib/pears/subject.rb
|
|
98
98
|
- lib/pears/version.rb
|
|
99
|
-
- pears-0.0.5.gem
|
|
100
99
|
- pears.gemspec
|
|
101
|
-
homepage: https://
|
|
100
|
+
homepage: https://bitbucket.org/ivaldi/rubygems-pears/src/master/
|
|
102
101
|
licenses:
|
|
103
102
|
- MIT
|
|
104
103
|
metadata:
|
|
105
|
-
homepage_uri: https://
|
|
104
|
+
homepage_uri: https://bitbucket.org/ivaldi/rubygems-pears/src/master/
|
|
106
105
|
post_install_message:
|
|
107
106
|
rdoc_options: []
|
|
108
107
|
require_paths:
|
|
@@ -111,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
111
110
|
requirements:
|
|
112
111
|
- - ">="
|
|
113
112
|
- !ruby/object:Gem::Version
|
|
114
|
-
version:
|
|
113
|
+
version: 2.7.4
|
|
115
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
115
|
requirements:
|
|
117
116
|
- - ">="
|
|
@@ -121,5 +120,5 @@ requirements: []
|
|
|
121
120
|
rubygems_version: 3.2.22
|
|
122
121
|
signing_key:
|
|
123
122
|
specification_version: 4
|
|
124
|
-
summary:
|
|
123
|
+
summary: An overly complicated library for juggling configuration data.
|
|
125
124
|
test_files: []
|
data/pears-0.0.5.gem
DELETED
|
Binary file
|