gsm_env 1.1.0 → 1.1.1

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: 68da355638f4baa880b299e71a347fea533fb81c82519f429651618d322b370f
4
- data.tar.gz: ae1fb6abda27ad0dc0a74a5f4947e331770ad9b9954a2b17ebc2817d918ae4bf
3
+ metadata.gz: 2230abfd45f19f912efe1bfd7b6eebd77910f9425a08fe3465c0d15ee7347b04
4
+ data.tar.gz: a4a3242a7489bfb018895ad5ce5382b455a8c7f8637591a82013fdbaf8c63d65
5
5
  SHA512:
6
- metadata.gz: 7c8a295eb9cf62c89b9fcb5e701a2de48be13acb8aef1b4e8174a826035392d3a659da8ef1b2504896dfbcb5e90b11a9723d09beb633b8c6ad6d6310c3d05e9f
7
- data.tar.gz: fd6b8f0ffd0c3eac23e0e23fef769de92214750fbcc62004c0c5151fa75d388b53305e7a85db6d4de0136a155d5f42068c9947dea49b0d4fe6ae2172ac8b3394
6
+ metadata.gz: 413aa45859751f1bbae846a4a16b7cc1fa55da961bd1c99ad674299693ad3b1d9564e1e1efa494e1db8ffcfd8308296d3619b1ad04b19a2aaceec4b411f318fc
7
+ data.tar.gz: f7c757dc9e904e5cf334709196c08a5749661efed3dbe409ec7696b987fc75a97ffb555a69efb2343bd7c11e0e4c3cca8c35b660f9624d090af62bc212b729a9
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hidakatsuya@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'rake'
8
+ gem 'test-unit'
9
+ gem 'test-unit-rr'
10
+ gem 'hashie'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Katsuya Hidaka
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,87 @@
1
+ # GsmEnv
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/gsm_env.svg)](https://badge.fury.io/rb/gsm_env)
4
+ [![Test](https://github.com/hidakatsuya/gsm_env/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/hidakatsuya/gsm_env/actions/workflows/test.yml)
5
+
6
+ GsmEnv is a gem to set parameters obtained from GCP Secret Manager as environment variables, inspired by [aws-ssm-env gem](https://github.com/sonodar/aws-ssm-env-ruby).
7
+
8
+ ## Prerequisites
9
+
10
+ ### Supported Ruby Versions
11
+
12
+ 2.7, 3.0, 3.1, 3.2
13
+
14
+ ### Google Cloud
15
+
16
+ - [Authentication Settings](https://cloud.google.com/ruby/docs/reference/google-cloud-secret_manager/latest/AUTHENTICATION)
17
+ - Required Permissions: `secretmanager.secrets.list` and `secretmanager.versions.access`
18
+
19
+ #### FYI
20
+ - [Access a secret version](https://cloud.google.com/secret-manager/docs/access-secret-version)
21
+ - [List a secret's versions](https://cloud.google.com/secret-manager/docs/view-secret-version#list)
22
+ - [Cloud Build network](https://cloud.google.com/build/docs/build-config-file-schema#network)
23
+
24
+ ## Installation
25
+
26
+ Install the gem and add to the application's Gemfile by executing:
27
+
28
+ bundle add gsm_env
29
+
30
+ If bundler is not being used to manage dependencies, install the gem by executing:
31
+
32
+ gem install gsm_env
33
+
34
+ ## Usage
35
+
36
+ ```ruby
37
+ GsmEnv.load(project_id: 'your-project-id')
38
+ ```
39
+
40
+ Alternatively, you can omit the `project_id` by setting it to `GCP_PROJECT_ID` environment variable.
41
+
42
+ ```ruby
43
+ ENV['GCP_PROJECT_ID'] = 'your-project-id'
44
+
45
+ GsmEnv.load
46
+ ```
47
+
48
+ ### Filtering Secrets
49
+
50
+ ```ruby
51
+ GsmEnv.load(filter: 'labels.environment=production')
52
+ ```
53
+
54
+ See https://cloud.google.com/secret-manager/docs/filtering for more details.
55
+
56
+ ### Customizing Environment Assignment
57
+
58
+ ```ruby
59
+ GsmEnv.load do |secret|
60
+ ENV["DEVELOPMENT_#{secret.name}"] = secret.value
61
+ end
62
+ ```
63
+
64
+ See [test/gsm_env_test.rb](https://github.com/hidakatsuya/gsm_env/blob/main/test/gsm_env_test.rb) for more details.
65
+
66
+ ### Using with Rails
67
+
68
+ ```ruby
69
+ # config/application.rb
70
+ if defined?(GsmEnv)
71
+ GsmEnv.load(project_id: 'your-project-id')
72
+ end
73
+ ```
74
+
75
+ See also [hidakatsuya/shopping_list](https://github.com/hidakatsuya/shopping_list) for a reference of actual usage.
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hidakatsuya/gsm_env. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hidakatsuya/gsm_env/blob/main/CODE_OF_CONDUCT.md).
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
84
+
85
+ ## Code of Conduct
86
+
87
+ Everyone interacting in the GsmEnv project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hidakatsuya/gsm_env/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/gsm_env.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/gsm_env/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'gsm_env'
7
+ spec.version = GsmEnv::VERSION
8
+ spec.authors = ['Katsuya Hidaka']
9
+ spec.email = ['hidakatsuya@gmail.com']
10
+
11
+ spec.summary = 'A gem to set parameters obtained from GCP Secret Manager as environment variables.'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/hidakatsuya/gsm_env'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.7.0'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/hidakatsuya/gsm_env'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/hidakatsuya/gsm_env/releases'
20
+
21
+ spec.require_paths = ['lib']
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+
28
+ spec.add_dependency 'google-cloud-secret_manager', '>= 1.2.0', '< 2.0.0'
29
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'google/cloud/secret_manager'
4
+
5
+ require_relative 'secret'
6
+
7
+ module GsmEnv
8
+ class Loader
9
+ def initialize(project_id:, filter: nil)
10
+ @project_id = project_id
11
+ @filter = filter
12
+ @client = Google::Cloud::SecretManager.secret_manager_service
13
+ end
14
+
15
+ def load
16
+ secrets.map do |secret|
17
+ version = client.access_secret_version(name: "#{secret.name}/versions/latest")
18
+ Secret.new(secret, version)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :project_id, :client, :filter
25
+
26
+ def secrets
27
+ client.list_secrets(parent: project_path, filter: filter)
28
+ end
29
+
30
+ def project_path
31
+ client.project_path(project: project_id)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GsmEnv
4
+ class Secret
5
+ class InvalidName < StandardError; end
6
+
7
+ attr_reader :secret, :version
8
+
9
+ def initialize(secret, version)
10
+ @secret = secret
11
+ @version = version
12
+ end
13
+
14
+ def name
15
+ @name ||= extract_secret_name_from(secret.name)
16
+ end
17
+
18
+ def value
19
+ version.payload.data&.chomp
20
+ end
21
+
22
+ private
23
+
24
+ SECRET_RESOURCE_NAME_REGEXP = %r{^projects/.+/secrets/(?<secret>[^/]+)$}
25
+
26
+ def extract_secret_name_from(secret_resource_name)
27
+ match = SECRET_RESOURCE_NAME_REGEXP.match(secret_resource_name)
28
+
29
+ raise InvalidName unless match && match['secret']
30
+
31
+ match['secret']
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GsmEnv
4
+ VERSION = '1.1.1'
5
+ end
data/lib/gsm_env.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'gsm_env/version'
4
+ require_relative 'gsm_env/loader'
5
+
6
+ module GsmEnv
7
+ def self.load(project_id: nil, filter: nil, &assigner)
8
+ loader = Loader.new(
9
+ project_id: project_id || ENV['GCP_PROJECT_ID'],
10
+ filter: filter
11
+ )
12
+ secrets = loader.load
13
+
14
+ assigner ||= lambda { |secret|
15
+ ENV[secret.name] = secret.value
16
+ }
17
+ secrets.each(&assigner)
18
+ end
19
+ end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gsm_env
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuya Hidaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-25 00:00:00.000000000 Z
11
+ date: 2023-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-secret_manager
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: 1.2.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.0
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '1.2'
32
+ version: 2.0.0
27
33
  description: A gem to set parameters obtained from GCP Secret Manager as environment
28
34
  variables.
29
35
  email:
@@ -31,7 +37,17 @@ email:
31
37
  executables: []
32
38
  extensions: []
33
39
  extra_rdoc_files: []
34
- files: []
40
+ files:
41
+ - CODE_OF_CONDUCT.md
42
+ - Gemfile
43
+ - LICENSE.txt
44
+ - README.md
45
+ - Rakefile
46
+ - gsm_env.gemspec
47
+ - lib/gsm_env.rb
48
+ - lib/gsm_env/loader.rb
49
+ - lib/gsm_env/secret.rb
50
+ - lib/gsm_env/version.rb
35
51
  homepage: https://github.com/hidakatsuya/gsm_env
36
52
  licenses:
37
53
  - MIT