required_env_fetcher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3c05aaed51a04e734c9cade8ba3c5ce66250a552bad4bbca11c7f34befc57c97
4
+ data.tar.gz: 033a4a04fb363c3146c9780888efb6d1f5f76bde96a4b0ac82c7f97ea3aaea14
5
+ SHA512:
6
+ metadata.gz: d2cf669516608c1cd592f08bd94bd43724da76b8216762f51f5f8522ec3096af87d9192465e9d76970a2348da78e173b7d5734774327991e7d91d29d0f0c7945
7
+ data.tar.gz: 6088b2bf25e937eed0d29f2d0cab30424897cd68ea4d8ad93cc584f132661e6668dd601706e037e415e59f6f0991f889a42500e61c061b8dcd75f976c876a19e
data/.codeclimate.yml ADDED
@@ -0,0 +1,53 @@
1
+ version: "2"
2
+ checks:
3
+ file-lines:
4
+ enabled: false
5
+ method-lines:
6
+ enabled: false
7
+ plugins:
8
+ csslint:
9
+ enabled: true
10
+ duplication:
11
+ enabled: true
12
+ config:
13
+ languages:
14
+ - ruby
15
+ - javascript
16
+ fixme:
17
+ enabled: true
18
+ exclude_patterns:
19
+ - config/
20
+ - db/
21
+ - script/
22
+ - spec/
23
+ - vendor/
24
+ - "**.jpg"
25
+ - "**.png"
26
+ - "**.gif"
27
+ - "**.svg"
28
+ - "**.scss"
29
+ - "**.md"
30
+ - ".rubocop.yml"
31
+ - "Dockerfile"
32
+ - "Capfile"
33
+ - "README.md"
34
+ - "**.erb"
35
+ - "**.jbuilder"
36
+ - "**.rabl"
37
+ - "**.zip"
38
+ - "**.crt"
39
+ - "**.txt"
40
+ - "**.ico"
41
+ - "**.eot"
42
+ - "**.pdf"
43
+ - "**.html"
44
+ - "**.key"
45
+ - "**.docx"
46
+ - "**.fcgi"
47
+ - "**.xml"
48
+ - "**.pem"
49
+ - "**.csr"
50
+ - "**.org"
51
+ - "**.cgi"
52
+ - "**.ru"
53
+ - "**.pptx"
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # required_env_fetcher
2
+
3
+ ## v0.1.0
4
+ - Initial version
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # override the :github shortcut to be secure by using HTTPS
6
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
7
+
8
+ # Specify your gem's dependencies in required_env_fetcher.gemspec
9
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 ezCater, Inc.
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,76 @@
1
+ # required_env_fetcher
2
+
3
+ In certain situations it makes sense to allow default values of environment variables that
4
+ are otherwise required. For example, imagine we're precompiling assets as part of CI when
5
+ we don't have access to some environment variables we require for the app be up and
6
+ accepting requests, but aren't required for asset compilation. Using this library we can
7
+ designate it safe to use default values in those situations.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem "required_env_fetcher"
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install required_env_fetcher
24
+
25
+ ## Usage
26
+
27
+ When you have an environment variable that is required - perhaps with code like:
28
+
29
+ ```ruby
30
+ # in config/application.rb
31
+ module MyApp
32
+ class Application < Rails::Application
33
+ config.x.redis_url = ENV.fetch("REDIS_URL")
34
+ end
35
+ end
36
+ ```
37
+
38
+ When you run `rails assets:precompile` you'll always need to have a `REDIS_URL` set or else loading
39
+ the application environment will fail. You can update your initializer to do something like:
40
+
41
+ ```ruby
42
+ config.x.redis_url = RequiredEnvFetcher.fetch("REDIS_URL")
43
+ ```
44
+
45
+ Now you can run `SKIP_REQUIRED_ENV_VAR_ENFORCEMENT=true rails assets:precompile` and so long as none of
46
+ your assets rely on the redis URL they will be able to compile.
47
+
48
+ If you need a specific default value (for example, if the value needs to be a valid URL) you can do:
49
+
50
+ ```ruby
51
+ config.x.redis_url = RequiredEnvFetcher.fetch("REDIS_URL", "http://example.com")
52
+ ```
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
57
+ run `rake spec` to run the tests. You can also run `bin/console` for an
58
+ interactive prompt that will allow you to experiment.
59
+
60
+ To install this gem onto your local machine, run `bundle exec rake install`.
61
+
62
+ To release a new version, update the version number in `version.rb`, and then
63
+ run `bundle exec rake release`, which will create a git tag for the version,
64
+ push git commits and tags, and push the `.gem` file to
65
+ [rubygems.org](https://rubygems.org)
66
+ .
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at
71
+ https://github.com/ezcater/required_env_fetcher-ruby.
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the
76
+ [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "required_env_fetcher/version"
4
+
5
+ module RequiredEnvFetcher
6
+ def self.fetch(key, default = nil)
7
+ if ENV["SKIP_REQUIRED_ENV_VAR_ENFORCEMENT"] == "true"
8
+ ENV.fetch(key, default || "")
9
+ else
10
+ ENV.fetch(key)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RequiredEnvFetcher
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "required_env_fetcher/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "required_env_fetcher"
9
+ spec.version = RequiredEnvFetcher::VERSION
10
+ spec.authors = ["ezCater, Inc"]
11
+ spec.email = ["engineering@ezcater.com"]
12
+
13
+ spec.summary = "Allow a default value to be used for a required environment variable"
14
+ spec.description = <<~DESC
15
+ In certain situations it makes sense to allow default values of environment variables that
16
+ are otherwise required. For example, imagine we're precompiling assets as part of CI when
17
+ we don't have access to some environment variables we require for the app be up and
18
+ accepting requests, but aren't required for asset compilation. Using this library we can
19
+ designate it safe to use default values in those situations.
20
+ DESC
21
+ spec.homepage = "https://github.com/ezcater/required_env_fetcher-ruby"
22
+
23
+ spec.license = "MIT"
24
+
25
+ # Set "allowed_push_post" to control where this gem can be published.
26
+ if spec.respond_to?(:metadata)
27
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
28
+
29
+ else
30
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
31
+ end
32
+
33
+ excluded_files = %w(.circleci/config.yml
34
+ .github/PULL_REQUEST_TEMPLATE.md
35
+ .gitignore
36
+ .rspec
37
+ .rubocop.yml
38
+ .ruby-gemset
39
+ .ruby-version
40
+ .travis.yml
41
+ bin/console
42
+ bin/setup
43
+ Rakefile)
44
+
45
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
46
+ f.match(/^(test|spec|features)\//)
47
+ end - excluded_files
48
+ spec.bindir = "bin"
49
+ spec.executables = []
50
+ spec.require_paths = ["lib"]
51
+
52
+ spec.add_development_dependency "bundler", "~> 1.12"
53
+
54
+ spec.add_development_dependency "climate_control"
55
+ spec.add_development_dependency "ezcater_rubocop", "0.58.0"
56
+ spec.add_development_dependency "overcommit"
57
+ spec.add_development_dependency "rake", "~> 10.0"
58
+ spec.add_development_dependency "rspec", "~> 3.4"
59
+ spec.add_development_dependency "rspec_junit_formatter", "0.2.2"
60
+ spec.add_development_dependency "simplecov"
61
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: required_env_fetcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ezCater, Inc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: climate_control
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ezcater_rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.58.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.58.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: overcommit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_junit_formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.2.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.2.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: |
126
+ In certain situations it makes sense to allow default values of environment variables that
127
+ are otherwise required. For example, imagine we're precompiling assets as part of CI when
128
+ we don't have access to some environment variables we require for the app be up and
129
+ accepting requests, but aren't required for asset compilation. Using this library we can
130
+ designate it safe to use default values in those situations.
131
+ email:
132
+ - engineering@ezcater.com
133
+ executables: []
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - ".codeclimate.yml"
138
+ - CHANGELOG.md
139
+ - Gemfile
140
+ - LICENSE.txt
141
+ - README.md
142
+ - lib/required_env_fetcher.rb
143
+ - lib/required_env_fetcher/version.rb
144
+ - required_env_fetcher.gemspec
145
+ homepage: https://github.com/ezcater/required_env_fetcher-ruby
146
+ licenses:
147
+ - MIT
148
+ metadata:
149
+ allowed_push_host: https://rubygems.org
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.7.8
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Allow a default value to be used for a required environment variable
170
+ test_files: []