|
| 1 | +/** @file dynamodb_source.hpp |
| 2 | + * @brief Server-Side DynamoDB Source |
| 3 | + */ |
| 4 | + |
1 | 5 | #pragma once |
2 | 6 |
|
| 7 | +#include <launchdarkly/server_side/integrations/data_reader/iserialized_data_reader.hpp> |
| 8 | +#include <launchdarkly/server_side/integrations/dynamodb/options.hpp> |
| 9 | + |
| 10 | +#include <tl/expected.hpp> |
| 11 | + |
| 12 | +#include <memory> |
| 13 | +#include <string> |
| 14 | + |
| 15 | +namespace Aws::DynamoDB { |
| 16 | +class DynamoDBClient; |
| 17 | +} |
| 18 | + |
3 | 19 | namespace launchdarkly::server_side::integrations { |
4 | 20 |
|
5 | | -// Scaffold-only entry point. The real DynamoDBDataSource class will replace |
6 | | -// this in a subsequent PR; this declaration exists so the smoke .cpp has |
7 | | -// something to define and the library produces a non-empty archive. |
8 | | -void DynamoDBSourceLinkSmoke(); |
| 21 | +/** |
| 22 | + * @brief DynamoDBDataSource represents a data source for the Server-Side SDK |
| 23 | + * backed by Amazon DynamoDB. It is meant to be used in place of the standard |
| 24 | + * LaunchDarkly Streaming or Polling data sources. |
| 25 | + * |
| 26 | + * Call DynamoDBDataSource::Create to obtain a new instance. This instance can |
| 27 | + * be passed into the SDK's DataSystem configuration via the LazyLoad builder. |
| 28 | + * |
| 29 | + * The DynamoDB table must already exist and follow the LaunchDarkly schema: |
| 30 | + * a String partition key named `namespace` and a String sort key named `key`. |
| 31 | + * The LaunchDarkly Relay Proxy populates the table with this schema; this |
| 32 | + * class only reads from it. |
| 33 | + * |
| 34 | + * This implementation is backed by the AWS SDK for C++. |
| 35 | + */ |
| 36 | +class DynamoDBDataSource final : public ISerializedDataReader { |
| 37 | + public: |
| 38 | + /** |
| 39 | + * @brief Creates a new DynamoDBDataSource, or returns an error if |
| 40 | + * construction failed. |
| 41 | + * |
| 42 | + * @param table_name Name of the DynamoDB table to read from. The table |
| 43 | + * must already exist; this class does not create it. |
| 44 | + * |
| 45 | + * @param prefix Optional namespace prefix. When non-empty, the source |
| 46 | + * reads rows whose partition key is `<prefix>:features`, |
| 47 | + * `<prefix>:segments`, etc. This allows multiple LaunchDarkly |
| 48 | + * environments to share a single table. |
| 49 | + * |
| 50 | + * @param options Optional AWS DynamoDB client configuration. See |
| 51 | + * @ref DynamoDBClientOptions. When defaulted, the AWS SDK resolves |
| 52 | + * region, endpoint, and credentials from the standard provider chain |
| 53 | + * (environment variables, shared config files, instance metadata). |
| 54 | + * |
| 55 | + * @return A DynamoDBDataSource, or an error if construction failed. |
| 56 | + */ |
| 57 | + static tl::expected<std::unique_ptr<DynamoDBDataSource>, std::string> |
| 58 | + Create(std::string table_name, |
| 59 | + std::string prefix, |
| 60 | + DynamoDBClientOptions options = {}); |
| 61 | + |
| 62 | + [[nodiscard]] GetResult Get(ISerializedItemKind const& kind, |
| 63 | + std::string const& itemKey) const override; |
| 64 | + [[nodiscard]] AllResult All(ISerializedItemKind const& kind) const override; |
| 65 | + [[nodiscard]] std::string const& Identity() const override; |
| 66 | + [[nodiscard]] bool Initialized() const override; |
| 67 | + |
| 68 | + ~DynamoDBDataSource() override; |
| 69 | + |
| 70 | + private: |
| 71 | + DynamoDBDataSource(std::shared_ptr<Aws::DynamoDB::DynamoDBClient> client, |
| 72 | + std::string table_name, |
| 73 | + std::string prefix); |
| 74 | + |
| 75 | + std::shared_ptr<Aws::DynamoDB::DynamoDBClient> client_; |
| 76 | + std::string const table_name_; |
| 77 | + std::string const prefix_; |
| 78 | + std::string const inited_namespace_; |
| 79 | +}; |
9 | 80 |
|
10 | 81 | } // namespace launchdarkly::server_side::integrations |
0 commit comments