-
Notifications
You must be signed in to change notification settings - Fork 53
/
dynamodb.rb
92 lines (90 loc) · 5.47 KB
/
dynamodb.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require "ldclient-rb/impl/integrations/dynamodb_impl"
require "ldclient-rb/integrations/util/store_wrapper"
module LaunchDarkly
module Integrations
#
# Integration with [DynamoDB](https://aws.amazon.com/dynamodb/).
#
# Note that in order to use this integration, you must first install one of the AWS SDK gems: either
# `aws-sdk-dynamodb`, or the full `aws-sdk`.
#
# @since 5.5.0
#
module DynamoDB
#
# Creates a DynamoDB-backed persistent feature store. For more details about how and why you can
# use a persistent feature store, see the
# [SDK reference guide](https://docs.launchdarkly.com/sdk/features/storing-data#ruby).
#
# To use this method, you must first install one of the AWS SDK gems: either `aws-sdk-dynamodb`, or
# the full `aws-sdk`. Then, put the object returned by this method into the `feature_store` property
# of your client configuration ({LaunchDarkly::Config}).
#
# @example Configuring the feature store
# store = LaunchDarkly::Integrations::DynamoDB::new_feature_store("my-table-name")
# config = LaunchDarkly::Config.new(feature_store: store)
# client = LaunchDarkly::LDClient.new(my_sdk_key, config)
#
# Note that the specified table must already exist in DynamoDB. It must have a partition key called
# "namespace", and a sort key called "key" (both strings). The SDK does not create the table
# automatically because it has no way of knowing what additional properties (such as permissions
# and throughput) you would want it to have.
#
# By default, the DynamoDB client will try to get your AWS credentials and region name from
# environment variables and/or local configuration files, as described in the AWS SDK documentation.
# You can also specify any supported AWS SDK options in `dynamodb_opts`-- or, provide an
# already-configured DynamoDB client in `existing_client`.
#
# @param table_name [String] name of an existing DynamoDB table
# @param opts [Hash] the configuration options
# @option opts [Hash] :dynamodb_opts options to pass to the DynamoDB client constructor (ignored if you specify `:existing_client`)
# @option opts [Object] :existing_client an already-constructed DynamoDB client for the feature store to use
# @option opts [String] :prefix namespace prefix to add to all keys used by LaunchDarkly
# @option opts [Logger] :logger a `Logger` instance; defaults to `Config.default_logger`
# @option opts [Integer] :expiration (15) expiration time for the in-memory cache, in seconds; 0 for no local caching
# @option opts [Integer] :capacity (1000) maximum number of items in the cache
# @return [LaunchDarkly::Interfaces::FeatureStore] a feature store object
#
def self.new_feature_store(table_name, opts)
core = LaunchDarkly::Impl::Integrations::DynamoDB::DynamoDBFeatureStoreCore.new(table_name, opts)
LaunchDarkly::Integrations::Util::CachingStoreWrapper.new(core, opts)
end
#
# Creates a DynamoDB-backed Big Segment store.
#
# Big Segments are a specific type of user segments. For more information, read the LaunchDarkly
# documentation: https://docs.launchdarkly.com/home/users/big-segments
#
# To use this method, you must first install one of the AWS SDK gems: either `aws-sdk-dynamodb`, or
# the full `aws-sdk`. Then, put the object returned by this method into the `store` property of your
# Big Segments configuration (see `Config`).
#
# @example Configuring Big Segments
# store = LaunchDarkly::Integrations::DynamoDB::new_big_segment_store("my-table-name")
# config = LaunchDarkly::Config.new(big_segments: LaunchDarkly::BigSegmentsConfig.new(store: store)
# client = LaunchDarkly::LDClient.new(my_sdk_key, config)
#
# Note that the specified table must already exist in DynamoDB. It must have a partition key called
# "namespace", and a sort key called "key" (both strings). The SDK does not create the table
# automatically because it has no way of knowing what additional properties (such as permissions
# and throughput) you would want it to have.
#
# By default, the DynamoDB client will try to get your AWS credentials and region name from
# environment variables and/or local configuration files, as described in the AWS SDK documentation.
# You can also specify any supported AWS SDK options in `dynamodb_opts`-- or, provide an
# already-configured DynamoDB client in `existing_client`.
#
# @param opts [Hash] the configuration options (these are all the same as for `new_feature_store`,
# except that there are no caching parameters)
# @option opts [Hash] :dynamodb_opts options to pass to the DynamoDB client constructor (ignored if you specify `:existing_client`)
# @option opts [Object] :existing_client an already-constructed DynamoDB client for the feature store to use
# @option opts [String] :prefix namespace prefix to add to all keys used by LaunchDarkly
# @option opts [Logger] :logger a `Logger` instance; defaults to `Config.default_logger`
# @return [LaunchDarkly::Interfaces::BigSegmentStore] a Big Segment store object
#
def self.new_big_segment_store(table_name, opts)
LaunchDarkly::Impl::Integrations::DynamoDB::DynamoDBBigSegmentStore.new(table_name, opts)
end
end
end
end