https://github.com/hidakatsuya/gsm_env
A gem to set parameters obtained from GCP Secret Manager as environment variables.
https://github.com/hidakatsuya/gsm_env
gcp ruby secret-manager
Last synced: 9 months ago
JSON representation
A gem to set parameters obtained from GCP Secret Manager as environment variables.
- Host: GitHub
- URL: https://github.com/hidakatsuya/gsm_env
- Owner: hidakatsuya
- License: mit
- Archived: true
- Created: 2023-02-19T12:11:18.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-28T14:39:38.000Z (almost 2 years ago)
- Last Synced: 2025-10-09T12:42:45.705Z (9 months ago)
- Topics: gcp, ruby, secret-manager
- Language: Ruby
- Homepage: https://rubygems.org/gems/gsm_env
- Size: 51.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# GsmEnv
[](https://badge.fury.io/rb/gsm_env)
[](https://github.com/hidakatsuya/gsm_env/actions/workflows/test.yml)
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).
## Prerequisites
### Supported Ruby Versions
2.7, 3.0, 3.1, 3.2
### Google Cloud
- [Authentication Settings](https://cloud.google.com/ruby/docs/reference/google-cloud-secret_manager/latest/AUTHENTICATION)
- Required Permissions: `secretmanager.secrets.list` and `secretmanager.versions.access`
#### FYI
- [Access a secret version](https://cloud.google.com/secret-manager/docs/access-secret-version)
- [List a secret's versions](https://cloud.google.com/secret-manager/docs/view-secret-version#list)
- [Cloud Build network](https://cloud.google.com/build/docs/build-config-file-schema#network)
## Installation
Install the gem and add to the application's Gemfile by executing:
bundle add gsm_env
If bundler is not being used to manage dependencies, install the gem by executing:
gem install gsm_env
## Usage
```ruby
GsmEnv.load(project_id: "your-project-id")
```
Alternatively, you can omit the `project_id` by setting it to `GCP_PROJECT_ID` environment variable.
```ruby
ENV["GCP_PROJECT_ID"] = "your-project-id"
GsmEnv.load
```
### Filtering Secrets
```ruby
GsmEnv.load(filter: "labels.environment=production")
```
See https://cloud.google.com/secret-manager/docs/filtering for more details.
### Customizing Environment Assignment
```ruby
GsmEnv.load do |secret|
ENV["DEVELOPMENT_#{secret.name}"] = secret.value
end
```
See [test/gsm_env_test.rb](https://github.com/hidakatsuya/gsm_env/blob/main/test/gsm_env_test.rb) for more details.
### Using with Rails
```ruby
# config/application.rb
if defined?(GsmEnv)
GsmEnv.load(project_id: "your-project-id")
end
```
See also [hidakatsuya/shopping_list](https://github.com/hidakatsuya/shopping_list) for a reference of actual usage.
## Contributing
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).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
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).