-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(DOCSP-33831): C++: Add docs for encryption and metadata encryption (#…
…3073) ## Pull Request Info ### Jira - https://jira.mongodb.org/browse/DOCSP-33831 ### Staged Changes - [Encrypt a Realm](https://preview-mongodbdacharyc.gatsbyjs.io/realm/DOCSP-33831/sdk/cpp/realm-files/encrypt-a-realm/): New page based on similar pages in other SDKs - [Connect to App Services](https://preview-mongodbdacharyc.gatsbyjs.io/realm/DOCSP-33831/sdk/cpp/app-services/connect-to-app/#encrypt-app-metadata): Add a section about encrypting metadata. Update custom HTTP section for deprecated `realm::App(...)` ### Reminder Checklist If your PR modifies the docs, you might need to also update some corresponding pages. Check if completed or N/A. - [x] Create Jira ticket for corresponding docs-app-services update(s), if any - [x] Checked/updated Admin API - [x] Checked/updated CLI reference ### Review Guidelines [REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md) --------- Co-authored-by: cbullinger <[email protected]>
- Loading branch information
1 parent
30e51bd
commit a308b56
Showing
12 changed files
with
327 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <cpprealm/sdk.hpp> | ||
#include <cpprealm/experimental/sdk.hpp> | ||
|
||
using namespace realm::experimental; | ||
|
||
struct Dog { | ||
std::string name; | ||
int64_t age; | ||
}; | ||
REALM_SCHEMA(Dog, name, age) | ||
|
||
TEST_CASE("Encrypt a realm example", "[write]") { | ||
auto relative_realm_path_directory = "beta_encrypt-realm/"; | ||
std::filesystem::create_directories(relative_realm_path_directory); | ||
std::filesystem::path path = std::filesystem::current_path().append(relative_realm_path_directory); | ||
path = path.append("encrypted"); | ||
path = path.replace_extension("realm"); | ||
// :snippet-start: beta-open-encrypted-realm | ||
// Check if we already have a key stored in the platform's secure storage. | ||
// If we don't, generate a new one. | ||
// Use your preferred method to generate a key. This example key is | ||
// NOT representative of a secure encryption key. It only exists to | ||
// illustrate the form your key might take. | ||
std::array<char, 64> exampleKey = { | ||
0,0,0,0,0,0,0,0, | ||
1,1,0,0,0,0,0,0, | ||
2,2,0,0,0,0,0,0, | ||
3,3,0,0,0,0,0,0, | ||
4,4,0,0,0,0,0,0, | ||
5,5,0,0,0,0,0,0, | ||
6,6,0,0,0,0,0,0, | ||
7,7,0,0,0,0,0,0 | ||
}; | ||
|
||
// Store the key securely to be used next time we want to open the database. | ||
// We don't illustrate this here because it varies depending on the platform. | ||
|
||
// Create a database configuration. | ||
auto config = realm::db_config(); | ||
config.set_path(path); // :remove: | ||
// Set the encryption key in your config. | ||
config.set_encryption_key(exampleKey); | ||
|
||
// Open or create a realm with the config containing the encryption key. | ||
auto realm = db(config); | ||
// :snippet-end: | ||
|
||
auto dog = Dog { | ||
.name = "Maui", | ||
.age = 3 | ||
}; | ||
|
||
realm.write([&] { | ||
realm.add(std::move(dog)); | ||
}); | ||
|
||
auto managedDogs = realm.objects<Dog>(); | ||
auto specificDog = managedDogs[0]; | ||
REQUIRE(specificDog.name == "Maui"); | ||
REQUIRE(specificDog.age == static_cast<long long>(3)); | ||
REQUIRE(managedDogs.size() == 1); | ||
|
||
realm.write([&] { | ||
realm.remove(specificDog); | ||
}); | ||
|
||
auto managedDogsAfterDelete = realm.objects<Dog>(); | ||
REQUIRE(managedDogsAfterDelete.size() == 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
source/examples/generated/cpp/app.snippet.encrypt-metadata.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Check if we already have a key stored in the platform's secure storage. | ||
// If we don't, generate a new one. | ||
// Use your preferred method to generate a key. This example key is | ||
// NOT representative of a secure encryption key. It only exists to | ||
// illustrate the form your key might take. | ||
std::array<char, 64> exampleKey = { | ||
0,0,0,0,0,0,0,0, | ||
1,1,0,0,0,0,0,0, | ||
2,2,0,0,0,0,0,0, | ||
3,3,0,0,0,0,0,0, | ||
4,4,0,0,0,0,0,0, | ||
5,5,0,0,0,0,0,0, | ||
6,6,0,0,0,0,0,0, | ||
7,7,0,0,0,0,0,0 | ||
}; | ||
|
||
// Create and populate an App configuration. | ||
auto appConfig = realm::App::configuration(); | ||
appConfig.app_id = APP_ID; | ||
// Specify the metadata key. | ||
appConfig.metadata_encryption_key = exampleKey; | ||
|
||
// Use the configuration when you open the app. | ||
auto app = realm::App(appConfig); |
2 changes: 1 addition & 1 deletion
2
source/examples/generated/cpp/app.snippet.set-custom-headers-for-app.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
std::map<std::string, std::string> customHttpHeaders; | ||
customHttpHeaders.emplace("CUSTOM_HEADER_NAME", "CUSTOM_HEADER_VALUE"); | ||
|
||
auto app = realm::App(APP_ID, std::nullopt, std::nullopt, customHttpHeaders); | ||
auto app = realm::App(realm::App::configuration({APP_ID, std::nullopt, std::nullopt, customHttpHeaders})); |
26 changes: 26 additions & 0 deletions
26
source/examples/generated/cpp/realm-files.snippet.beta-open-encrypted-realm.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Check if we already have a key stored in the platform's secure storage. | ||
// If we don't, generate a new one. | ||
// Use your preferred method to generate a key. This example key is | ||
// NOT representative of a secure encryption key. It only exists to | ||
// illustrate the form your key might take. | ||
std::array<char, 64> exampleKey = { | ||
0,0,0,0,0,0,0,0, | ||
1,1,0,0,0,0,0,0, | ||
2,2,0,0,0,0,0,0, | ||
3,3,0,0,0,0,0,0, | ||
4,4,0,0,0,0,0,0, | ||
5,5,0,0,0,0,0,0, | ||
6,6,0,0,0,0,0,0, | ||
7,7,0,0,0,0,0,0 | ||
}; | ||
|
||
// Store the key securely to be used next time we want to open the database. | ||
// We don't illustrate this here because it varies depending on the platform. | ||
|
||
// Create a database configuration. | ||
auto config = realm::db_config(); | ||
// Set the encryption key in your config. | ||
config.set_encryption_key(exampleKey); | ||
|
||
// Open or create a realm with the config containing the encryption key. | ||
auto realm = db(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.. _cpp-realms: | ||
|
||
======================================= | ||
Work with Realm Files - C++ SDK Preview | ||
======================================= | ||
|
||
.. toctree:: | ||
:titlesonly: | ||
|
||
Configure & Open a Realm </sdk/cpp/realm-files/configure-and-open-a-realm> | ||
Encrypt a Realm </sdk/cpp/realm-files/encrypt-a-realm> |
Oops, something went wrong.