pears 0.0.7 → 0.0.8

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: 19c55e7f744c1a5403452f6c6d3a88246e185ce2e1abad292b66146347fac14a
4
- data.tar.gz: 2bf8070b221f5bb58b843c83ff3d9a19e355f4134fbca2920622b1898a93a433
3
+ metadata.gz: 314b1898a9c7b3f45eeaf3f2eb34097dba27a23c36c76af9efc18a61f247a56b
4
+ data.tar.gz: 1a021c4464cd3daafb0a2b222824abbcd6552e3990daf40fde4f17c9cc26aafe
5
5
  SHA512:
6
- metadata.gz: b0b5d6f09fe5f6c1aca571afed5f5c3576441f370ef27d67083ae7e9f98ddd270c0e55404dad2afa9c6ae0ca8f92af275504261dc3e87c6ddaa26c644d544e01
7
- data.tar.gz: 940068ae86b7ba75f7290fea87d0f36b5c38d02bf39946c2bb253d469c017175307abd58e3c3ee7f10a31764e644bcd69cb0d25afdaeb51976d9c57b32ebb529
6
+ metadata.gz: 6893c3c466be5d1da5f9d8e3eb05900a2d6292c4be0135dc531a9ec2902ada9958760fc26b345793cb45308f064ef14efaed760667e192791da66ea9def7d00c
7
+ data.tar.gz: cd69dcc4d02e48a6b0a89aed4e06b3558264d6f142c553ae7efd5641905ee5a4b49bc304661fc617f8294d1e4cc88d8733f0cac89a31420e3100a58d4517cd2a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pears (0.0.7)
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,17 @@ 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, 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
- 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
@@ -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
- reload
53
+ load_config
54
54
  end
55
55
  end
56
56
  puts "Redis connection died!"
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.7"
4
+ VERSION = "0.0.8"
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.7
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-15 00:00:00.000000000 Z
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://www.rubygems.com
100
+ homepage: https://bitbucket.org/ivaldi/rubygems-pears/src/master/
101
101
  licenses:
102
102
  - MIT
103
103
  metadata:
104
- homepage_uri: https://www.rubygems.com
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: 3.0.1
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.2.22
120
+ rubygems_version: 3.1.6
121
121
  signing_key:
122
122
  specification_version: 4
123
- summary: Ingest hot-swappable configuration data
123
+ summary: An overly complicated library for juggling configuration data.
124
124
  test_files: []