Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
name: CI

on: [ push ]
on: [push]

jobs:
build:
name: Run tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.3
bundler-cache: true
bundler: '2.4.22'
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.8
bundler-cache: true
bundler: "2.6.9"

- name: Bundle Install
run: bundle install --jobs=4 --retry=3 --path=vendor/bundle
- name: Bundle Install
run: bundle install --jobs=4 --retry=3 --path=vendor/bundle

- name: Run RSpec
env:
RAILS_ENV: test
RACK_ENV: test
run: bundle exec rspec --format progress spec
- name: Run RSpec
env:
RAILS_ENV: test
RACK_ENV: test
run: bundle exec rspec --format progress spec
71 changes: 0 additions & 71 deletions .rubocop.yml

This file was deleted.

10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM ruby:2.5.1-slim
FROM ruby:3.3.0-slim

ENV RAILS_ENV=test
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LC_CTYPE en_US.UTF-8
ENV XDG_CACHE_HOME /nonexistent/.cache

ENV RUNTIME_PACKAGES pkg-config git

Expand All @@ -13,7 +14,8 @@ WORKDIR /tmp/tmpapp
ADD . /tmp/tmpapp

RUN echo 'gem: --no-document' >> ~/.gemrc && \
apt-get clean && apt-get update -qq && apt-get install -y build-essential $RUNTIME_PACKAGES && \
apt-get clean && apt-get update -qq && \
apt-get install -y build-essential $RUNTIME_PACKAGES && \
gem install bundler --version 2.2.10 && \
gem install gem-release && \
bundle update && bundle install --jobs 20 --retry 5 && \
Expand All @@ -26,7 +28,9 @@ WORKDIR /app

RUN bundle install -j1

RUN chown -R nobody:nogroup /app
RUN mkdir -p /nonexistent && \
mkdir -p /nonexistent/.cache && \
chown -R nobody:nogroup /app /nonexistent
RUN whoami
USER nobody
RUN whoami
9 changes: 8 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in blinkist-config.gemspec
gemspec

group :development do
gem "bundler", "~> 2.6.9"
gem "rake", "~> 13.0"
gem "standard", ">= 1.50.0"
end

group :test do
gem "codeclimate-test-reporter", "~> 1.0.0"
gem "rspec"
gem "simplecov"
end
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ my_config_value = Blinkist::Config.get! "some/folder/config"
### Error handling

When configured with `Blinkist::Config.error_handler = :strict` (as recommended)
reading a configuration entry for which the value is missing
reading a configuration entry for which the value is missing
(for example missing enviroment variables) will cause
`Blinkist::Config::ValueMissingError` to be raised.

Expand All @@ -48,12 +48,24 @@ my_config_value = Blinkist::Config.get! "some/folder/config", "default value"
# If ENV["SOME_FOLDER_CONFIG"] is nil, "default value" will be returned
```

### Refetching a value

If you want to refetch a value from the config store, you can set the `refetch` parameter to `true`.
**WARNING**: This will cut into our SSM quota on AWS - please use this with caution and behind another way of caching.
See [AWS SSM Quota](https://docs.aws.amazon.com/general/latest/gr/ssm.html#parameter-store) for more information.

```ruby
my_config_value = Blinkist::Config.get! "some/folder/config", refetch: true

# This will reload the value from the config store, even if it's cached. The re-fetched value will then be cached.
```

### Using Diplomat & Consul

If you want to use Consul's key value store, simply use our diplomat adapter.

* [https://www.consul.io/](https://www.consul.io/)
* [https://github.com/WeAreFarmGeek/diplomat](https://github.com/WeAreFarmGeek/diplomat)
- [https://www.consul.io/](https://www.consul.io/)
- [https://github.com/WeAreFarmGeek/diplomat](https://github.com/WeAreFarmGeek/diplomat)

The GEM expects consul to listen to `http://172.17.0.1:8500`

Expand All @@ -69,6 +81,7 @@ my_config_value = Blinkist::Config.get! "some/folder/config"
```

### Using Diplomat with a folder scope

```ruby
# Here we setting a scope outside of the app

Expand Down Expand Up @@ -99,6 +112,7 @@ Blinkist::Config.preload scope: "global" # in case you need also another scope b
```

### Using SSM with a folder scope

```ruby
# Here we setting a scope outside of the app

Expand All @@ -107,7 +121,6 @@ my_config_value = Blinkist::Config.get! "another/config", scope: "global"
# This will replace `my_nice_app` with `global` and try to resolve "/application/global/another/config"
```


## Installation

Add this line to your application's Gemfile:
Expand Down Expand Up @@ -141,21 +154,21 @@ require "rails"
You can build this project easily with [docker compose](https://docs.docker.com/compose/).

```
docker-compose run rake
docker compose run rake
```

This will execute rake and run all specs by auto correcting the code with rubocop.
This will execute rake and run all specs by auto correcting the code with StandardRB.

If you're ready to tag a new version, do this

```
docker-compose run gem bump -t -v major|minor|patch
docker compose run gem bump -t -v major|minor|patch
```

To deploy to rubygems.org do this then

```
docker-compose run gem release
docker compose run gem release
```

You'll have to have proper rights to access rubygems.org
Expand All @@ -164,7 +177,6 @@ You'll have to have proper rights to access rubygems.org

Bug reports and pull requests are welcome on GitHub at https://github.com/blinkist/blinkist-config.


## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
11 changes: 5 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rubocop/rake_task"

RuboCop::RakeTask.new do |task|
task.options = %w(-a)
end

RSpec::Core::RakeTask.new(:spec)

task :standardrb do
sh "bundle exec standardrb --fix"
end

task(:default).clear
task default: %i(rubocop spec)
task default: %i[standardrb spec]
33 changes: 16 additions & 17 deletions blinkist-config.gemspec
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@

lib = File.expand_path("../lib", __FILE__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require_relative "lib/blinkist/config/version"

Gem::Specification.new do |spec|
spec.name = "blinkist-config"
spec.version = Blinkist::Config::VERSION
spec.authors = ["Sebastian Schleicher, Blinks Labs GmbH"]
spec.email = ["sj@blinkist.com"]
spec.name = "blinkist-config"
spec.version = Blinkist::Config::VERSION
spec.authors = ["Sebastian Schleicher, Blinks Labs GmbH"]
spec.email = ["sj@blinkist.com"]

spec.required_ruby_version = ">= 3.2.8"

spec.summary = "Simple adapter based configuration handler (supports ENV and Consul/Diplomat)."
spec.description = "This GEM allows you to keep your configuration class-based by calling Blinkist::Config.get!(...) instead of accessing the ENV directly. You can set up different types of adapters to connect to various configuration systems like your ENV or Consul's key-value-store."
spec.homepage = "https://github.com/blinkist/blinkist-config"
spec.license = "MIT"
spec.summary = "Simple adapter based configuration handler (supports ENV and Consul/Diplomat)."
spec.description = "This GEM allows you to keep your configuration class-based by calling Blinkist::Config.get!(...) instead of accessing the ENV directly. You can set up different types of adapters to connect to various configuration systems like your ENV or Consul's key-value-store."
spec.homepage = "https://github.com/blinkist/blinkist-config"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.require_paths = %w(lib)
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.require_paths = %w[lib]

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_dependency "aws-sdk-ssm", "~> 1"
spec.add_dependency "diplomat", "~> 2"

spec.add_runtime_dependency "diplomat", "~> 2"
spec.add_runtime_dependency "aws-sdk-ssm", "~> 1"
spec.metadata["rubygems_mfa_required"] = "true"
end
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2"
services:
rake:
entrypoint: bundle exec rake
Expand All @@ -9,7 +8,7 @@ services:
- RACK_ENV=test
volumes:
- .:/app

gem:
build:
context: .
Expand All @@ -18,4 +17,4 @@ services:
- .:/app
- ~/.gitconfig:/nonexistent/.gitconfig
- ~/.ssh:/nonexistent/.ssh
- ~/.gem:/nonexistent/.gem
- ~/.gem:/nonexistent/.gem
15 changes: 7 additions & 8 deletions lib/blinkist/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Config
class << self
attr_accessor :adapter_type, :logger, :env, :app_name, :error_handler

def get(key, default = nil, scope: nil)
get!(key, default, scope: scope)
def get(key, default = nil, scope: nil, refetch: false)
get!(key, default, scope: scope, refetch: refetch)
end

def preload(scope: nil)
Expand All @@ -28,26 +28,26 @@ def preload(scope: nil)
extend Gem::Deprecate
deprecate :get, "get!", 2017, 12

def get!(key, *args, scope: nil)
def get!(key, *args, scope: nil, refetch: false)
# NOTE: we need to do this this way
# to handle 'nil' default correctly
case args.length
when 0
default = nil
bang = true
bang = true
when 1
default = args.first
bang = false
bang = false
else
raise ArgumentError, "wrong number of arguments (given #{args.length + 1}, expected 1..2)"
end

from_adapter = adapter.get(key, scope: scope)
from_adapter = adapter.get(key, scope: scope, refetch: refetch)

if from_adapter.nil? && bang
handle_error(key, scope)
else
return from_adapter || default
from_adapter || default
end
end

Expand All @@ -59,7 +59,6 @@ def handle_error(key, scope)
handler = Factory.new("Blinkist::Config.error_handler", ErrorHandlers::BUILT_IN).call(error_handler)
handler.call(key, scope)
end

end

# NOTE: default configuration goes here
Expand Down
Loading