pears 0.0.6 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 645ae89efe6ddeadbdad1d0e7a7e5688c58b62a747048b541b94ef10e9f2026a
4
- data.tar.gz: 3baa65f99f31f0229de5c500c5dcc373532fe793453c29f4ab5ae978de43f4a6
3
+ metadata.gz: 40970c145a4cb29cc549b0534c7ced74e799fab7745f153562b579c966c4bb19
4
+ data.tar.gz: a91ba1e130712c40d9d97f3c6fb21ebe562982bc370284988f8033e999a1d111
5
5
  SHA512:
6
- metadata.gz: 57dc635116560ce42ad9c71e9f23134f61ae25040f59d0edc1ebfbef9654dd18305f4c49e86b5026a312c7a79237e49b48233fb564063d82d2bdef44e1d73c7e
7
- data.tar.gz: 3897e7f03640897df2aa77709fc2fb494ec9eab1c4bf1642f89d25adf99d86605c9793314c9c94ace252293bc9fa484b2d65297a1662eefbd31cfc95b5b1e184
6
+ metadata.gz: 30515f3509a1c6832247fcf5c444881c28a87f442cacee341d84a75dc20117722fe2029561d8685b09592c2a84f38351cbfcce24a50d5a91a9dbe62d1b69a107
7
+ data.tar.gz: 367c680e08109add0b2f7c13dc1bb3c24cb6aaa1d817873cfa863eead5b5d5f6ff10e887c6ddb861ae85135a0ef08829cfcbea1695c799097431205ab2c62b90
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pears (0.0.6)
4
+ pears (0.0.8)
5
5
  activesupport
6
6
  dry-configurable (>= 0.13.0)
7
7
  redis
@@ -47,6 +47,7 @@ GEM
47
47
 
48
48
  PLATFORMS
49
49
  arm64-darwin-20
50
+ ruby
50
51
 
51
52
  DEPENDENCIES
52
53
  byebug
data/README.md CHANGED
@@ -22,7 +22,31 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- Configuration is loaded via the provider setting.
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
- ** Nice to have
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
- - Figure out if subscription should be a providerof maybe something else.
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
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pears.
123
+ Hit me up on slack, jira or Bitbucket!
64
124
 
65
125
  ## License
66
126
 
data/lib/pears/errors.rb CHANGED
@@ -1 +1,5 @@
1
- class Error < StandardError; end
1
+ module Pears
2
+ class Error < StandardError; end
3
+ class RedisHasLeftTheBuilding < Error; end
4
+ class Pears::InvalidProviderData < Error; end
5
+ end
@@ -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
- end
12
-
13
- private
14
-
15
- def parse_yaml(yaml_data)
16
- YAML.load(yaml_data).with_indifferent_access
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 < LocalFile
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
- reload
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 reload
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(@channel) do |on|
51
+ connection.subscribe(channel) do |on|
52
52
  on.message do |channel, message|
53
- reload
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pears
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.10"
5
5
  end
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 = "Ingest hot-swappable configuration data"
12
- spec.homepage = "https://www.rubygems.com"
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 = ">= 3.0.1"
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.6
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: 2021-12-15 00:00:00.000000000 Z
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://www.rubygems.com
100
+ homepage: https://bitbucket.org/ivaldi/rubygems-pears/src/master/
102
101
  licenses:
103
102
  - MIT
104
103
  metadata:
105
- homepage_uri: https://www.rubygems.com
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: 3.0.1
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: Ingest hot-swappable configuration data
123
+ summary: An overly complicated library for juggling configuration data.
125
124
  test_files: []
data/pears-0.0.5.gem DELETED
Binary file