r_creds 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -15
- data/lib/r_creds.rb +2 -2
- data/lib/r_creds/fetcher.rb +9 -2
- data/lib/r_creds/version.rb +1 -1
- data/r_creds.gemspec +3 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6edc8f797ac6ff69cfefcb20f7c264ad2e343e31e81587ff22801283d3ef0000
|
4
|
+
data.tar.gz: 1231fafcb7427607baf4bc9a2b3d450db155fba687f2fb1263afa0143962d786
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bd20b25108f689437f4401e0d3d19bdb6614e88714858cfd43bbcb280410cdd573830f2ad39479e5de67249b1afe31411f4b63c13f401f846343b915ffa50fe
|
7
|
+
data.tar.gz: 3f998b19a77ac0bb665ebd0b28a60c33fe47a07002daa76790de6d4bd5491f30256f3b47e579ff3d03587910f9d0b96231f54cdf65736fd0932213c13cec647a
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RCreds
|
2
2
|
|
3
|
-
|
3
|
+
RCreds makes working with Rails 5.2 credentials easier
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -19,24 +19,33 @@ Or install it yourself as:
|
|
19
19
|
$ gem install r_creds
|
20
20
|
|
21
21
|
## Usage
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
There are no need to do this:
|
23
|
+
```ruby
|
24
|
+
Rails.application.credentials[Rails.env.to_sym][:aws][:access_key_id]
|
25
|
+
```
|
26
|
+
Use RCreds instead:
|
25
27
|
```ruby
|
26
|
-
|
27
|
-
RCreds.fetch(:payment_system, :secret_key)
|
28
|
+
RCreds.fetch(:aws, :access_key_id)
|
28
29
|
```
|
30
|
+
|
31
|
+
RCreds give an ability to read credentials in credentials.yml, ENV or use default value!
|
29
32
|
```ruby
|
30
|
-
#
|
31
|
-
RCreds.fetch(:
|
33
|
+
# value set in credentials.yml
|
34
|
+
RCreds.fetch(:aws, :access_key_id) # output: secret_key_from_credentials_yaml
|
35
|
+
|
36
|
+
# no value in credentials.yml but,
|
37
|
+
ENV['AWS_ACCESS_KEY_ID'] = 'aws_key_from_env_variable'
|
38
|
+
RCreds.fetch(:aws, :access_key_id) # output: aws_key_from_env_variable
|
39
|
+
|
40
|
+
# no value in credentials.yml and ENV - use default
|
41
|
+
RCreds.fetch(:aws, :access_key_id, default: 'some_default_test_key') # output: some_default_test_key
|
32
42
|
```
|
43
|
+
RCreds searches for values in following order: credentials.yml > ENV > default and returns nil if nothing match
|
44
|
+
|
45
|
+
RCreds uses `Rails.env` to determinate environment. But you can set any environement.
|
33
46
|
```ruby
|
34
|
-
|
35
|
-
# keys concatenates as in following example
|
36
|
-
ENV['REDIS_URL'] = 'redis://real_redis_url'
|
37
|
-
RCreds.fetch(:redis, :url, default: 'redis://localhost:6379/0') # output: redis://real_redis_url
|
47
|
+
RCreds.fetch(:aws, :access_key_id, environment: 'production')
|
38
48
|
```
|
39
|
-
RCreds search for values in following order: credentials.yml > ENV > default:
|
40
49
|
|
41
50
|
## Development
|
42
51
|
|
@@ -46,7 +55,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
46
55
|
|
47
56
|
## Contributing
|
48
57
|
|
49
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/OrestF/r_creds. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
50
59
|
|
51
60
|
## License
|
52
61
|
|
@@ -54,4 +63,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
54
63
|
|
55
64
|
## Code of Conduct
|
56
65
|
|
57
|
-
Everyone interacting in the RCreds project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
66
|
+
Everyone interacting in the RCreds project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/OrestF/r_creds/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/r_creds.rb
CHANGED
@@ -2,7 +2,7 @@ require "r_creds/version"
|
|
2
2
|
require_relative "r_creds/fetcher"
|
3
3
|
|
4
4
|
module RCreds
|
5
|
-
def self.fetch(*keys, default: nil)
|
6
|
-
Fetcher.new(keys, default).call
|
5
|
+
def self.fetch(*keys, default: nil, environment: nil)
|
6
|
+
Fetcher.new(keys, default, environment).call
|
7
7
|
end
|
8
8
|
end
|
data/lib/r_creds/fetcher.rb
CHANGED
@@ -2,9 +2,10 @@ module RCreds
|
|
2
2
|
class Fetcher
|
3
3
|
class NoRailsError < StandardError; end
|
4
4
|
|
5
|
-
def initialize(keys, default)
|
5
|
+
def initialize(keys, default, environment)
|
6
6
|
@keys = keys
|
7
7
|
@default = default
|
8
|
+
@environment = environment
|
8
9
|
end
|
9
10
|
|
10
11
|
attr_reader :keys, :default
|
@@ -14,8 +15,14 @@ module RCreds
|
|
14
15
|
fetch
|
15
16
|
end
|
16
17
|
|
18
|
+
private
|
19
|
+
|
20
|
+
def environment
|
21
|
+
(presence?(@environment) || Rails.env).to_sym
|
22
|
+
end
|
23
|
+
|
17
24
|
def fetch
|
18
|
-
cred = Rails.application.credentials.dig(
|
25
|
+
cred = Rails.application.credentials.dig(environment, *keys)
|
19
26
|
|
20
27
|
presence?(cred) || presence?(ENV[keys.join('_').upcase]) || default
|
21
28
|
end
|
data/lib/r_creds/version.rb
CHANGED
data/r_creds.gemspec
CHANGED
@@ -9,10 +9,11 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["OrestF"]
|
10
10
|
spec.email = ["falchuko@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = 'RCreds
|
13
|
-
spec.description = 'RCreds
|
12
|
+
spec.summary = 'RCreds makes working with Rails 5.2 credentials easier'
|
13
|
+
spec.description = 'RCreds makes working with Rails 5.2 credentials easier'
|
14
14
|
spec.homepage = 'https://github.com/OrestF/r_creds'
|
15
15
|
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = '>= 2.0.0'
|
16
17
|
|
17
18
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
19
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r_creds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OrestF
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description: RCreds
|
55
|
+
description: RCreds makes working with Rails 5.2 credentials easier
|
56
56
|
email:
|
57
57
|
- falchuko@gmail.com
|
58
58
|
executables: []
|
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
76
|
requirements:
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
79
|
+
version: 2.0.0
|
80
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - ">="
|
@@ -84,8 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.7.
|
87
|
+
rubygems_version: 2.7.7
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
|
-
summary: RCreds
|
90
|
+
summary: RCreds makes working with Rails 5.2 credentials easier
|
91
91
|
test_files: []
|