KSConnect

KSConnect provides a Ruby connection interface for Kloudsec plugins by exposing a simple to use API for managing and synchronizing plugin data.

Usage

Initialize the api:

api = KSConnect.new(:ssl).api

Use it:

api.domains['domain-1.com'].data['some_flag'] = true

Options

Initialize with additional (untested) helpers:

api = KSConnect.new(:ssl, use_helpers: true).api
api.ip_address_for('example.com') => # 127.0.0.1

Getting the full domain list

All domain objects:

api.all_domains # => { 'domain-1.com' => <Domain>, ... }

Domain names only:

api.all_domains.keys # => ['domain-1.com',..]

Getting data

api.domains['domain-1.com'].data['key'] # => 'value'

api.domains['domain-1.com'].data.getall # => { 'key' => 'value', ... }

Setting data

api.domains['domain-1.com'].data['key'] = new_value

api.domains['domain-1.com'].data.setall = { 'key': new_value, ... }

Event callbacks

Available callbacks for <plugin>:push:

  • When plugin is enabled: on_initialize
  • When plugin's IP is updated: on_update
  • When plugin is removed: on_teardown
  • Any other incoming message: on_push
api = KSConnect.new(:ssl).api
api.configure do |config|
    config.on_initialize = lambda { |msg| do_some_initialization(msg) }
end

NOTE: there is no need to re-message proxy / core plugins to re-read configuration. This is done automatically.

Channels

Safely acquire a redis channel in a separate thread by doing:

new_channel = KSConnect.channel('channel_name') { |msg| puts msg }

Development

Ensure tests are ran using:

$ rspec