Keystok

Build status

Installation

$ gem install keystok

Usage

require 'keystok'
require 'yaml' # Config is then easier
config = YAML.load_file('keystok.yml')
# or config can be just hash:
# config = { connection_string: 'das21312312_connection_string',
#            api_host: 'https://api_custom_domain.keystok.com'
#          }
keystok = Keystok::Client.new(config)
# get hash with all keys
keystok.keys
# get one key
keystok.get(key_id)

Rails integration

Add keystok to Gemfile:

gem 'keystok'

Keystok have generator that can create config, initializer and .gitignore entry for you

rails g keystok:install connection_string_value

In Rails env Keystok will use Rails.logger. Without Rails it will default to logging to STDOUT. If you would like to define your own logger you can do it like:

Keystok.logger = your_logger

Config options description

api_host, auth_host

Those values are not needed by default. It can be required if you are using separated Keystok servers

connection_string

This value is visible in app page in Keystok service

eager_fetching

When true client will fetch all keys from API even when one was requested. This will save time when another key will be requested, because client will not have to fetch it from API. However in some cases like huge amount of keys or when volatile is set, this option should be set to false. Default value is true

no_cache

If you don't want to use cache functionality, you can disable cache writing by setting no_cache to true in config

tmp_dir

This dir will be used to store encrypted cache which can be used when API can't be contacted

volatile

Normally when asking about key that is in local store, SDK will not perform API request to provide quicker response. Request can be forced on per method call basis by second parameter set to true (default is false)

keystok.get('this_can_change_often', true)

However if you want SDK to make request on every request without adding true to every get or keys, you can set volatile to true in config. This will force SDK to ask API on every request. Please note that this will may decrese performance of you app since it will require API request and cache writing on every get and keys call