google_cloud_env_secrets 0.1.0
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +38 -0
- data/Rakefile +27 -0
- data/lib/google_cloud_env_secrets.rb +5 -0
- data/lib/google_cloud_env_secrets/config.rb +21 -0
- data/lib/google_cloud_env_secrets/railtie.rb +14 -0
- data/lib/google_cloud_env_secrets/secrets.rb +54 -0
- data/lib/google_cloud_env_secrets/version.rb +3 -0
- data/lib/tasks/google_cloud_env_secrets_tasks.rake +5 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7fab903e59b088a60cb9d49094486fe45b02548810173815d3402dce4691dad2
|
4
|
+
data.tar.gz: f3282975fd0322ccce97d160c66deceddecabae685923d16d686bfc1eec471ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e0edffc6c1e70e59960d9f05a03a4a452aa0701f77c81d7a682fe746e721aad2f4a41d8f583019a2906e20cd8841e294e5f146ed3c592f9417149562be8d6af
|
7
|
+
data.tar.gz: 11f1759d55177b5c7f3eb99b749f589b7d59eb4eedfacebf6d435f98208a3e1f6574824f782239032e689352c8aed3f605e2746601b4bb3b39f480b637d83d66
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Matthias Kadenbach
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Google Cloud ENV Secrets
|
2
|
+
|
3
|
+
Load Google Cloud Secrets into ENV.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'google_cloud_env_secrets'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
```bash
|
14
|
+
$ bundle
|
15
|
+
```
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
```bash
|
19
|
+
$ gem install google_cloud_env_secrets
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Configure this gem with environment vars:
|
25
|
+
|
26
|
+
| Variable | Description |
|
27
|
+
|----------------------------------|--------------------------------------------------------------------|
|
28
|
+
| `GOOGLE_APPLICATION_CREDENTIALS` | Manually set path to Google Application Credentials. |
|
29
|
+
| `GOOGLE_PROJECT` | Manually set the Google project. Automatically detected otherwise. |
|
30
|
+
| `GOOGLE_SECRETS_PREFIX` | Only load secrets that start with prefix. |
|
31
|
+
|
32
|
+
|
33
|
+
## Required IAM Roles
|
34
|
+
|
35
|
+
```
|
36
|
+
Secret Manager Secret Accessor
|
37
|
+
Secret Manager Viewer
|
38
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'GoogleCloudEnvSecrets'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GoogleCloudEnvSecrets
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :project
|
4
|
+
attr_accessor :credentials
|
5
|
+
attr_accessor :cache_secrets
|
6
|
+
attr_accessor :prefix
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@cache_secrets = true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
self.configuration ||= Configuration.new
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module GoogleCloudEnvSecrets
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
initializer "google_cloud_env_secrets.initialize", after: :bootstrap_hook do |app|
|
4
|
+
GoogleCloudEnvSecrets.configure do |config|
|
5
|
+
config.credentials = ENV["GOOGLE_APPLICATION_CREDENTIALS"] || nil
|
6
|
+
config.project = ENV["GOOGLE_PROJECT"] || Google::Cloud.env.project_id
|
7
|
+
config.prefix = ENV["GOOGLE_SECRETS_PREFIX"] || nil
|
8
|
+
end
|
9
|
+
|
10
|
+
secrets = GoogleCloudEnvSecrets.all
|
11
|
+
GoogleCloudEnvSecrets.inject_env!(secrets)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module GoogleCloudEnvSecrets
|
2
|
+
def self.all
|
3
|
+
@secrets = nil unless self.configuration.cache_secrets
|
4
|
+
@secrets ||= begin
|
5
|
+
# Configure and initialize
|
6
|
+
# https://googleapis.dev/ruby/google-cloud-secret_manager/latest/Google/Cloud/SecretManager.html
|
7
|
+
Google::Cloud::SecretManager.configure do |config|
|
8
|
+
config.credentials = self.configuration.credentials
|
9
|
+
end
|
10
|
+
|
11
|
+
client = Google::Cloud::SecretManager.secret_manager_service
|
12
|
+
|
13
|
+
# create worker pool to read secrets in parallel
|
14
|
+
pool = Concurrent::FixedThreadPool.new(Concurrent.processor_count * 4)
|
15
|
+
secrets = Concurrent::Hash.new
|
16
|
+
|
17
|
+
# read all secrets ...
|
18
|
+
client.list_secrets(parent: "projects/" + self.configuration.project).each do |secret|
|
19
|
+
pool.post(secret) do |secret|
|
20
|
+
name = secret.name.split("/").last
|
21
|
+
|
22
|
+
# only consider prefixed secrets?
|
23
|
+
if self.configuration.prefix
|
24
|
+
next unless name.start_with? self.configuration.prefix
|
25
|
+
|
26
|
+
# clean up name
|
27
|
+
name.delete_prefix! self.configuration.prefix
|
28
|
+
name.sub! /^[^a-z0-9]+/i, ""
|
29
|
+
end
|
30
|
+
|
31
|
+
secrets[name] = client.access_secret_version(name: secret.name + "/versions/latest").payload.data
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# shutdown worker pool
|
36
|
+
pool.shutdown
|
37
|
+
pool.wait_for_termination
|
38
|
+
|
39
|
+
secrets
|
40
|
+
end
|
41
|
+
@secrets
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.find(name)
|
45
|
+
self.all # make sure we have the secrets loaded
|
46
|
+
@secrets[name.to_s]
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.inject_env!(secrets = {})
|
50
|
+
secrets.each do |name, value|
|
51
|
+
ENV[name.to_s] = value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_cloud_env_secrets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthias Kadenbach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.3
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.0.3.4
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 6.0.3
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.0.3.4
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: google-cloud-secret_manager
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.0.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: google-cloud-env
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.3.3
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.3.3
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: concurrent-ruby
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.1.7
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.1.7
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: sqlite3
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description:
|
90
|
+
email:
|
91
|
+
executables: []
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files: []
|
94
|
+
files:
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/google_cloud_env_secrets.rb
|
99
|
+
- lib/google_cloud_env_secrets/config.rb
|
100
|
+
- lib/google_cloud_env_secrets/railtie.rb
|
101
|
+
- lib/google_cloud_env_secrets/secrets.rb
|
102
|
+
- lib/google_cloud_env_secrets/version.rb
|
103
|
+
- lib/tasks/google_cloud_env_secrets_tasks.rake
|
104
|
+
homepage: https://github.com/mattes/rails_google_cloud_env_secrets
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata:
|
108
|
+
allowed_push_host: https://rubygems.org
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubygems_version: 3.0.3
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Load Google Cloud Secrets into ENV
|
128
|
+
test_files: []
|