creds 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/creds.gemspec +29 -0
- data/lib/creds.rb +33 -0
- data/lib/creds/plain_configuration.rb +26 -0
- data/lib/creds/railtie.rb +12 -0
- data/lib/creds/version.rb +3 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 586a8999485b4530fe262e7779b739821f68949d815ae68e0f2021651b636f29
|
4
|
+
data.tar.gz: cd2181a15b91c0e6a79ebbdd8acf2d52a79a97773638b3c8a42d5395c4b5a327
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad21fecefc0484a84113c27394f761c3c0bceceaf718fb3f2069f575015e07e72c4ef4146d2b7e3c55a2e9e923615fe377ba24a4dd09b095260d16cb1bb25127
|
7
|
+
data.tar.gz: 4f059e592baca5be3fcb5ea7edc5ffbd9f850ee3a1fd2fd0619e7a28b1119a548c85a0812ae866168482c4869589d4ffaff30255196bcc894609e670ec311f84
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
creds (0.2.0)
|
5
|
+
activesupport (>= 5.2.0.rc2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (5.2.0.rc2)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 0.7, < 2)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
concurrent-ruby (1.0.5)
|
16
|
+
i18n (1.0.0)
|
17
|
+
concurrent-ruby (~> 1.0)
|
18
|
+
minitest (5.11.3)
|
19
|
+
rake (12.3.1)
|
20
|
+
thread_safe (0.3.6)
|
21
|
+
tzinfo (1.2.5)
|
22
|
+
thread_safe (~> 0.1)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bundler (>= 1.16)
|
29
|
+
creds!
|
30
|
+
minitest (>= 5.0)
|
31
|
+
rake (>= 10.0)
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Wojciech Wnętrzak
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Creds
|
2
|
+
|
3
|
+
Manage encrypted credentials (added in Rails 5.2.0) with multiple environments.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Available as a gem [`creds`](https://rubygems.org/gems/creds)
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Using Rails command, generate new encrypted file by
|
12
|
+
```
|
13
|
+
bin/rails encrypted:edit config/credentials-production.yml.enc --key config/master-production.key
|
14
|
+
```
|
15
|
+
If `config/master-production.key` doesn't exist yet, run `bin/rails generate master_key` and adjust naming to match desired one.
|
16
|
+
Content of file can be displayed by
|
17
|
+
```
|
18
|
+
bin/rails encrypted:show config/credentials-production.yml.enc --key config/master-production.key
|
19
|
+
```
|
20
|
+
|
21
|
+
Add to `config/environments/production.rb` (or any other env)
|
22
|
+
```ruby
|
23
|
+
config.creds = Creds.new("config/credentials-production.yml.enc")
|
24
|
+
```
|
25
|
+
|
26
|
+
In the code:
|
27
|
+
```ruby
|
28
|
+
Rails.configuration.creds.aws_access_key_id
|
29
|
+
```
|
30
|
+
|
31
|
+
To ease working in development/test environments with the same API, add `config/credentials-plain.yml` with key/value pairs
|
32
|
+
nested under environment name, like:
|
33
|
+
```yml
|
34
|
+
development:
|
35
|
+
aws_access_key_id: "aws-key-id"
|
36
|
+
```
|
37
|
+
|
38
|
+
Then add to `config/environments/development.rb`
|
39
|
+
```ruby
|
40
|
+
config.creds = Creds.new("config/credentials-plain.yml", env: "development")
|
41
|
+
```
|
42
|
+
|
43
|
+
### Additions
|
44
|
+
|
45
|
+
* To raise error in case of missing key you can add bang to the name, like `Rails.configuration.creds.database_url!`
|
46
|
+
* To list all defined key/value pairs call `config`, like `Rails.configuration.creds.config`
|
47
|
+
* If `secret_key_base` is specified in credentials file, it will be assigned to `Rails.configuration.secret_key_base`, as it is required by Rails
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
[![Build Status](https://travis-ci.org/freeletics/creds.svg?branch=master)](https://travis-ci.org/freeletics/creds)
|
52
|
+
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
54
|
+
|
55
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/freeletics/creds
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "creds"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/creds.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "creds/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "creds"
|
8
|
+
spec.version = Creds::VERSION
|
9
|
+
spec.authors = ["Wojciech Wnętrzak"]
|
10
|
+
spec.email = ["w.wnetrzak@gmail.com", "eng@freeletics.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Encrypted Credentials for multiple environments}
|
13
|
+
spec.description = %q{Unified interface for encrypted credentials and plain text file based}
|
14
|
+
spec.homepage = "https://github.com/freeletics/creds"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "activesupport", ">= 5.2.0.rc2"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", ">= 1.16"
|
27
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
28
|
+
spec.add_development_dependency "minitest", ">= 5.0"
|
29
|
+
end
|
data/lib/creds.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "creds/version"
|
2
|
+
require "creds/plain_configuration"
|
3
|
+
|
4
|
+
require "active_support/core_ext/module/attribute_accessors" # https://github.com/rails/rails/pull/32383
|
5
|
+
require "active_support/core_ext/module/delegation"
|
6
|
+
require "active_support/encrypted_configuration"
|
7
|
+
|
8
|
+
require "creds/railtie" if defined?(Rails)
|
9
|
+
|
10
|
+
class Creds
|
11
|
+
delegate_missing_to :configuration
|
12
|
+
|
13
|
+
def initialize(file_path, key_path: "config/master.key", env_key: "RAILS_MASTER_KEY", raise_if_missing_key: true, env: nil)
|
14
|
+
@file_path = file_path
|
15
|
+
@key_path = key_path
|
16
|
+
@env_key = env_key
|
17
|
+
@raise_if_missing_key = raise_if_missing_key
|
18
|
+
@env = env
|
19
|
+
end
|
20
|
+
|
21
|
+
def configuration
|
22
|
+
@configuration ||= if @file_path.end_with?(".enc")
|
23
|
+
ActiveSupport::EncryptedConfiguration.new(
|
24
|
+
config_path: @file_path,
|
25
|
+
key_path: @key_path,
|
26
|
+
env_key: @env_key,
|
27
|
+
raise_if_missing_key: @raise_if_missing_key
|
28
|
+
)
|
29
|
+
else
|
30
|
+
Creds::PlainConfiguration.new(@file_path, env: @env)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Based on http://api.rubyonrails.org/classes/Rails/Application.html#method-i-config_for
|
2
|
+
require "yaml"
|
3
|
+
require "erb"
|
4
|
+
require "pathname"
|
5
|
+
require "active_support/core_ext/hash/keys"
|
6
|
+
require "active_support/ordered_options"
|
7
|
+
require "active_support/core_ext/module/delegation"
|
8
|
+
|
9
|
+
class Creds::PlainConfiguration
|
10
|
+
delegate_missing_to :options
|
11
|
+
|
12
|
+
def initialize(file_path, env:)
|
13
|
+
@file = Pathname.new(file_path)
|
14
|
+
@env = env
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
@config ||= (YAML.load(ERB.new(@file.read).result) || {}).fetch(@env, {}).deep_symbolize_keys
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def options
|
24
|
+
@options ||= ActiveSupport::InheritableOptions.new(config)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "rails/railtie"
|
2
|
+
|
3
|
+
class Creds::Railtie < Rails::Railtie
|
4
|
+
# Secret key base is required in Rails.
|
5
|
+
# By default it is taken from one of: env variable, credentials or secrets with fallback
|
6
|
+
# to config which is set here if present.
|
7
|
+
initializer "creds.set_secret_key_base", before: :load_config_initializers do
|
8
|
+
if config.respond_to?(:creds) && config.creds.secret_key_base
|
9
|
+
Rails.configuration.secret_key_base ||= config.creds.secret_key_base
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: creds
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wojciech Wnętrzak
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.0.rc2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.0.rc2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
description: Unified interface for encrypted credentials and plain text file based
|
70
|
+
email:
|
71
|
+
- w.wnetrzak@gmail.com
|
72
|
+
- eng@freeletics.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- creds.gemspec
|
87
|
+
- lib/creds.rb
|
88
|
+
- lib/creds/plain_configuration.rb
|
89
|
+
- lib/creds/railtie.rb
|
90
|
+
- lib/creds/version.rb
|
91
|
+
homepage: https://github.com/freeletics/creds
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.7.6
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Encrypted Credentials for multiple environments
|
115
|
+
test_files: []
|