-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cpp Wrapper for sdk #259
Cpp Wrapper for sdk #259
Conversation
Some comments about the current PR, plus solutions for some of the issues brought up on the last email: We should update the schema generation, to something like this: const cpp = await quicktype({
inputData,
lang: "cpp",
rendererOptions: {
namespace: "Bitwarden::Sdk",
"include-location": "global-include",
},
});
cpp.lines.forEach((line, idx) => {
// Replace DOMAIN for URI_DOMAIN, because DOMAIN is an already defined macro
cpp.lines[idx] = line.replace(/DOMAIN/g, "URI_DOMAIN");
});
writeToFile("./languages/cpp/include/schemas.hpp", cpp.lines); With this change we generate a I've also added two parameters to the schema generation:
About the errors when compiling in release mode vs debug mode, make sure that the schemas and the libraries are generated with the same version of the SDK. The object field was removed from the ProjectResponse in the SDK about a month ago: https://github.com/bitwarden/sdk/pull/242/files#diff-3d8ec8aaa44ddda5d8b6751bcd05fa6ed203dcea8a4ef67693ca99aeaf2d0634L37. On another topic, I had some compile errors when trying to test the example. Don't know if this is because whatever clang version I use, but I had to wrap the strings in clientSettings.set_api_url(std::string("https://bitwarden.test:8080/api"));
clientSettings.set_identity_url(std::string("https://bitwarden.test:8080/identity"));
clientSettings.set_user_agent(std::string("Bitwarden CPP-SDK")); The commands I've used to compile this on my Mac, for reference: brew install cmake
brew install boost
brew install nlohmann-json
# Run this from the cpp directory
## Compile the library
mkdir -p build
cd build
cmake .. -DNLOHMANN=/opt/homebrew/include -DBOOST=/opt/homebrew/include -DTARGET=../../target/release/libbitwarden_c.dylib
cmake --build .
## Compile the example
cd ../examples
clang++ -std=c++20 -I../include -I/opt/homebrew/include -I/opt/homebrew/include -L../build/ -o MyBitwardenApp Wrapper.cpp -lBitwardenClient -ldl
# Using DYLD_LIBRARY_PATH to avoid having to copy the library
ACCESS_TOKEN=... ORGANIZATION_ID=... DYLD_LIBRARY_PATH=../build ./MyBitwardenApp
|
Hi Daniel,
Regarding the wrapping in std:string, yes that is correct for all
compilers, I forgot to change that in the Readme file. Other than that
everything works on your side?
I will try to adapt to the changes and come back to you.
Kindly,
Slobodan
…On Mon, Oct 16, 2023 at 2:35 PM Daniel García ***@***.***> wrote:
Some comments about the current PR, plus solutions for some of the issues
brought up on the last email:
We should update the schema generation, to something like this:
const cpp = await quicktype({
inputData,
lang: "cpp",
rendererOptions: {
namespace: "Bitwarden::Sdk",
"include-location": "global-include",
},
});
cpp.lines.forEach((line, idx) => {
// Replace DOMAIN for URI_DOMAIN, because DOMAIN is an already defined macro
cpp.lines[idx] = line.replace(/DOMAIN/g, "URI_DOMAIN");
});
writeToFile("./languages/cpp/include/schemas.hpp", cpp.lines);
With this change we generate a hpp file instead of cpp, which should
solve that warning when including a cpp file. At the same time we're
doing the DOMAIN rename to avoid conflicts with the predefined macro.
Ultimately we might decide to rename this from our side on all the clients,
but for now this should work.
I've also added two parameters to the schema generation:
- Changed the namespace from the default quicktype to Bitwarden::Sdk.
This will require updating the code and changing a few using namespace
quicktype; to using namespace Bitwarden::Sdk; and quicktype::to_json
to Bitwarden::Sdk::to_json
- Changed the include location of the JSON to be global (#include
<nlohmann/json.hpp>) instead of local (#include "json.hpp"), which I
think makes more sense.
------------------------------
About the errors when compiling in release mode vs debug mode, make sure
that the schemas and the libraries are generated with the same version of
the SDK. The object field was removed from the ProjectResponse in the SDK
about a month ago:
https://github.com/bitwarden/sdk/pull/242/files#diff-3d8ec8aaa44ddda5d8b6751bcd05fa6ed203dcea8a4ef67693ca99aeaf2d0634L37
.
So if the schemas were generated before then it can cause issues.
------------------------------
On another topic, I had some compile errors when trying to test the
example. Don't know if this is because whatever clang version I use, but I
had to wrap the strings in std::string() in Wrapper.cpp:
clientSettings.set_api_url(std::string("https://bitwarden.test:8080/api"));
clientSettings.set_identity_url(std::string("https://bitwarden.test:8080/identity"));
clientSettings.set_user_agent(std::string("Bitwarden CPP-SDK"));
------------------------------
The commands I've used to compile this on my Mac, for reference:
brew install cmake
brew install boost
brew install nlohmann-json
# Run this from the cpp directory
## Compile the library
mkdir -p buildcd build
cmake .. -DNLOHMANN=/opt/homebrew/include -DBOOST=/opt/homebrew/include -DTARGET=../../target/release/libbitwarden_c.dylib
cmake --build .
## Compile the examplecd ../examples
clang++ -std=c++20 -I../include -I/opt/homebrew/include -I/opt/homebrew/include -L../build/ -o MyBitwardenApp Wrapper.cpp -lBitwardenClient -ldl
# Using DYLD_LIBRARY_PATH to avoid having to copy the library
ACCESS_TOKEN=... ORGANIZATION_ID=... DYLD_LIBRARY_PATH=../build ./MyBitwardenApp
—
Reply to this email directly, view it on GitHub
<#259 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQLJDPGDFYS2X7MLS574GULX7US2ZAVCNFSM6AAAAAA5MR6VVSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRUGM4DAOBXGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
*Slobodan Todosijević*
***@***.***>
|
Hi Daniel,
Please let me know if anything else should be changed. Kindly, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please solve the merge conflict, otherwise this is good to go for me
No New Or Fixed Issues Found |
It is resolved, I retrieved the previous |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small changes to match the rest of the implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
Type of change
Objective
Implemented C++ library that wraps native C library and exposed its commands through BitwardenClient class.
Code changes
bitwarden_c
library and its three functions:init
,run_command
, andfree_mem
Cmake
examples
directory