neon_secrets 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: df260eeb955f5de70d0527f19139de2a63f1719531cbd7108fca78759a145e79
4
+ data.tar.gz: 1161dd945b93c5a58aef3acf26bd39a51b5ad58b378773bbfcb55a8b787ac56d
5
+ SHA512:
6
+ metadata.gz: c0cfef9dc53275dd8445030905c2eea8d802517a8523486d8c1ffd43ced4107c23c0ad64e690ce2cfc8e7a2c4b174600f2f73d19281c015f984844ec037c509d
7
+ data.tar.gz: 180cd5558f3c3ce0652bbf2fbef4adb601e332dfd81ccd6e9bbe661bf72e838e6ab15304ad85363259fb36e95dfe97a4da40a91d41eb35222f9cc9082f5b9266
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in neon_postgres.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "standard"
9
+
10
+ gem "pry", "~> 0.14.1"
11
+
12
+ gem "faker", "~> 2.17"
data/Gemfile.lock ADDED
@@ -0,0 +1,147 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ neon_secrets (0.0.1)
5
+ google-cloud-secret_manager (~> 1.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.2)
13
+ coderay (1.1.3)
14
+ concurrent-ruby (1.1.8)
15
+ diff-lcs (1.4.4)
16
+ faker (2.17.0)
17
+ i18n (>= 1.6, < 2)
18
+ faraday (1.4.2)
19
+ faraday-em_http (~> 1.0)
20
+ faraday-em_synchrony (~> 1.0)
21
+ faraday-excon (~> 1.1)
22
+ faraday-net_http (~> 1.0)
23
+ faraday-net_http_persistent (~> 1.1)
24
+ multipart-post (>= 1.2, < 3)
25
+ ruby2_keywords (>= 0.0.4)
26
+ faraday-em_http (1.0.0)
27
+ faraday-em_synchrony (1.0.0)
28
+ faraday-excon (1.1.0)
29
+ faraday-net_http (1.0.1)
30
+ faraday-net_http_persistent (1.1.0)
31
+ gapic-common (0.5.0)
32
+ faraday (~> 1.3)
33
+ google-protobuf (~> 3.14)
34
+ googleapis-common-protos (>= 1.3.11, < 2.a)
35
+ googleapis-common-protos-types (>= 1.0.6, < 2.a)
36
+ googleauth (>= 0.16.2, < 2.a)
37
+ grpc (~> 1.36)
38
+ google-cloud-core (1.6.0)
39
+ google-cloud-env (~> 1.0)
40
+ google-cloud-errors (~> 1.0)
41
+ google-cloud-env (1.5.0)
42
+ faraday (>= 0.17.3, < 2.0)
43
+ google-cloud-errors (1.1.0)
44
+ google-cloud-secret_manager (1.1.0)
45
+ google-cloud-core (~> 1.5)
46
+ google-cloud-secret_manager-v1 (~> 0.1)
47
+ google-cloud-secret_manager-v1beta1 (~> 0.3)
48
+ google-cloud-secret_manager-v1 (0.10.0)
49
+ gapic-common (~> 0.4)
50
+ google-cloud-errors (~> 1.0)
51
+ grpc-google-iam-v1 (>= 0.6.10, < 2.0)
52
+ google-cloud-secret_manager-v1beta1 (0.8.0)
53
+ gapic-common (~> 0.3)
54
+ google-cloud-errors (~> 1.0)
55
+ grpc-google-iam-v1 (>= 0.6.10, < 2.0)
56
+ google-protobuf (3.17.3)
57
+ googleapis-common-protos (1.3.11)
58
+ google-protobuf (~> 3.14)
59
+ googleapis-common-protos-types (>= 1.0.6, < 2.0)
60
+ grpc (~> 1.27)
61
+ googleapis-common-protos-types (1.0.6)
62
+ google-protobuf (~> 3.14)
63
+ googleauth (0.16.2)
64
+ faraday (>= 0.17.3, < 2.0)
65
+ jwt (>= 1.4, < 3.0)
66
+ memoist (~> 0.16)
67
+ multi_json (~> 1.11)
68
+ os (>= 0.9, < 2.0)
69
+ signet (~> 0.14)
70
+ grpc (1.38.0)
71
+ google-protobuf (~> 3.15)
72
+ googleapis-common-protos-types (~> 1.0)
73
+ grpc-google-iam-v1 (0.6.11)
74
+ google-protobuf (~> 3.14)
75
+ googleapis-common-protos (>= 1.3.11, < 2.0)
76
+ grpc (~> 1.27)
77
+ i18n (1.8.10)
78
+ concurrent-ruby (~> 1.0)
79
+ jwt (2.2.3)
80
+ memoist (0.16.2)
81
+ method_source (1.0.0)
82
+ multi_json (1.15.0)
83
+ multipart-post (2.1.1)
84
+ os (1.1.1)
85
+ parallel (1.20.1)
86
+ parser (3.0.1.0)
87
+ ast (~> 2.4.1)
88
+ pry (0.14.1)
89
+ coderay (~> 1.1)
90
+ method_source (~> 1.0)
91
+ public_suffix (4.0.6)
92
+ rainbow (3.0.0)
93
+ rake (12.3.3)
94
+ regexp_parser (2.1.1)
95
+ rexml (3.2.5)
96
+ rspec (3.10.0)
97
+ rspec-core (~> 3.10.0)
98
+ rspec-expectations (~> 3.10.0)
99
+ rspec-mocks (~> 3.10.0)
100
+ rspec-core (3.10.1)
101
+ rspec-support (~> 3.10.0)
102
+ rspec-expectations (3.10.1)
103
+ diff-lcs (>= 1.2.0, < 2.0)
104
+ rspec-support (~> 3.10.0)
105
+ rspec-mocks (3.10.2)
106
+ diff-lcs (>= 1.2.0, < 2.0)
107
+ rspec-support (~> 3.10.0)
108
+ rspec-support (3.10.2)
109
+ rubocop (1.12.1)
110
+ parallel (~> 1.10)
111
+ parser (>= 3.0.0.0)
112
+ rainbow (>= 2.2.2, < 4.0)
113
+ regexp_parser (>= 1.8, < 3.0)
114
+ rexml
115
+ rubocop-ast (>= 1.2.0, < 2.0)
116
+ ruby-progressbar (~> 1.7)
117
+ unicode-display_width (>= 1.4.0, < 3.0)
118
+ rubocop-ast (1.4.1)
119
+ parser (>= 2.7.1.5)
120
+ rubocop-performance (1.10.1)
121
+ rubocop (>= 0.90.0, < 2.0)
122
+ rubocop-ast (>= 0.4.0)
123
+ ruby-progressbar (1.11.0)
124
+ ruby2_keywords (0.0.4)
125
+ signet (0.15.0)
126
+ addressable (~> 2.3)
127
+ faraday (>= 0.17.3, < 2.0)
128
+ jwt (>= 1.5, < 3.0)
129
+ multi_json (~> 1.10)
130
+ standard (1.0.5)
131
+ rubocop (= 1.12.1)
132
+ rubocop-performance (= 1.10.1)
133
+ unicode-display_width (2.0.0)
134
+
135
+ PLATFORMS
136
+ ruby
137
+
138
+ DEPENDENCIES
139
+ faker (~> 2.17)
140
+ neon_secrets!
141
+ pry (~> 0.14.1)
142
+ rake (~> 12.0)
143
+ rspec (~> 3.0)
144
+ standard
145
+
146
+ BUNDLED WITH
147
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Neon Secrets
2
+
3
+ This gem is used by other gems to manage environment variables, either locally
4
+ with Doppler, or in our GCP environments with GCP Secrets Manager.
5
+
6
+ ## Interface
7
+
8
+ This gem exposes one class, `NeonSecrets::Getter`, with one method, `.get`. In
9
+ your code you can call it like:
10
+
11
+ ```ruby
12
+ import 'neon_secrets'
13
+
14
+ NeonSecrets::Getter.get(secret_name: "postgres_url")
15
+ NeonSecrets::Getter.get(secret_name: "stripe_api_key")
16
+ ```
17
+
18
+ Secrets are set in Doppler by Neon Law administrators.
19
+
20
+ ## The NEON_ENV environment variable
21
+
22
+ This gem works based on the value of `NEON_ENV`, which should either be
23
+ `development`, `staging`, or `production`. If this is not set,
24
+ `NeonSecrets::Getter.get` will throw an error.
25
+
26
+ If the `NEON_ENV` is `staging` or `production`, you will also need the
27
+ `NEON_PROJECT` set so that this library can find the proper GCP Secret
28
+ containing the environment variables.
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at
33
+ https://github.com/neonlaw/codebase.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,41 @@
1
+ require "neon_secrets/version"
2
+ require "google/cloud/secret_manager"
3
+
4
+ module NeonSecrets
5
+ class Error < StandardError; end
6
+
7
+ class Getter
8
+ def self.get(secret_name:, gcp_secret_name: nil)
9
+ new(
10
+ secret_name: secret_name,
11
+ gcp_secret_name: gcp_secret_name
12
+ ).secret_value
13
+ end
14
+
15
+ def initialize(secret_name:, gcp_secret_name:)
16
+ @secret_name = secret_name.upcase
17
+ @gcp_secret_name = gcp_secret_name
18
+ end
19
+
20
+ def secret_value
21
+ if neon_env == "development"
22
+ ENV.fetch(secret_name)
23
+ else
24
+ client = Google::Cloud::SecretManager.secret_manager_service
25
+ secret_name = "#{gcp_secret_name}.latest"
26
+
27
+ secrets = client.access_secret_version name: secret_name
28
+
29
+ JSON.parse(secrets).fetch(secret_name)
30
+ end
31
+ end
32
+
33
+ attr_reader :secret_name, :gcp_secret_name
34
+
35
+ private
36
+
37
+ def neon_env
38
+ @_neon_env ||= ENV.fetch("NEON_ENV") { "development" }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module NeonSecrets
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ require_relative "lib/neon_secrets/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "neon_secrets"
5
+ spec.version = NeonSecrets::VERSION
6
+ spec.authors = ["Neon Law"]
7
+ spec.email = ["support@neonlaw.com"]
8
+
9
+ spec.summary = "A gem to handle secrets in the Neon Law software space."
10
+ spec.description = spec.summary
11
+ spec.homepage = "https://github.com/neonlaw/codebase"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ spec.metadata["changelog_uri"] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_runtime_dependency "google-cloud-secret_manager", "~> 1.1"
26
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neon_secrets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Neon Law
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google-cloud-secret_manager
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ description: A gem to handle secrets in the Neon Law software space.
28
+ email:
29
+ - support@neonlaw.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".ruby-version"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - README.md
40
+ - Rakefile
41
+ - lib/neon_secrets.rb
42
+ - lib/neon_secrets/version.rb
43
+ - neon_secrets.gemspec
44
+ homepage: https://github.com/neonlaw/codebase
45
+ licenses: []
46
+ metadata:
47
+ homepage_uri: https://github.com/neonlaw/codebase
48
+ source_code_uri: https://github.com/neonlaw/codebase
49
+ changelog_uri: https://github.com/neonlaw/codebase
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 2.3.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.2.15
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: A gem to handle secrets in the Neon Law software space.
69
+ test_files: []