Secrets Manager C++ SDK
The C++ language wrapper for interacting with Bitwarden Secrets Manager. The SDK, like the Secrets Manager CLI built on-top of it, can be used to execute the following operations:
Authenticate using an access token.
Perform commands for secrets and project including:
list,create,updateanddelete.
note
This SDK is a beta release. Therefore, some functionality may be missing.
Setting up a Secrets Manager account prior to using the C++ SDK is recommended. This includes:
Enabling the Secrets Manager CLI.
Setting up machine accounts.
Setting up access tokens.
Locate the C++ GitHub repository here.
Client settings
Initialize BitwardenSettings by passing in api_url and identity_url. If these values are not defined in /.env, Bitwarden will use defaults https://api.bitwarden.com and https://identity.bitwarden.com for api_url and identity_url respectively.
Plain Text// Optional - if not stressed, then default values are used BitwardenSettings bitwardenSettings; bitwardenSettings.set_api_url("<bitwarden-url>"); bitwardenSettings.set_identity_url("<bitwarden-identity>");
Create new Bitwarden client
Before using the client you must pass the accessToken:
Plain Textstd::string accessToken = "<access-token>"; // Optional - argument in BitwardenClient BitwardenClient bitwardenClient = BitwardenClient(bitwardenSettings); bitwardenClient.accessTokenLogin(accessToken);
Once the Bitwarden client has been created and authorized, Secrets Manager CLI commands can be passed into the client.
The project command is used to access, manipulate, and create projects. The scope of access assigned to your machine account will determine what actions can be completed with the project command.
create project
Plain Textboost::uuids::uuid organizationUuid = boost::uuids::string_generator()("<organization-id>"); ProjectResponse projectResponseCreate = bitwardenClient.createProject(organizationUuid, "TestProject");
list projects
Plain TextProjectsResponse projectResponseList = bitwardenClient.listProjects(organizationUuid);
get project
Plain Textboost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id()); ProjectResponse projectResponseGet = bitwardenClient.getProject(projectId);
update project
Plain Textboost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id()); ProjectResponse projectResponseUpdate = bitwardenClient.updateProject(projectId, organizationUuid, "TestProjectUpdated");
delete projects
Plain TextProjectDeleteResponse projectDeleteResponse = bitwardenClient.deleteProjects({projectId});
The secret command is used to access, manipulate and create secrets. As with all commands, secrets and projects outside your access token's scope of access cannot be read or written-to.
create secret
Plain Textstd::string key = "key"; std::string value = "value"; std::string note = "note"; SecretResponse secretResponseCreate = bitwardenClient.createSecret(key, value, note, organizationUuid, {projectId});
list secrets
Plain TextSecretIdentifiersResponse secretIdentifiersResponse = bitwardenClient.listSecrets(organizationUuid);
get secret
Plain Textboost::uuids::uuid secretId = boost::uuids::string_generator()(secretResponseCreate.get_id()); SecretResponse secretResponseGet = bitwardenClient.getSecret(secretId);
update secret
Plain TextSecretResponse secretResponseUpdate = bitwardenClient.updateSecret(secretId, "key2", "value2", "note2", organizationUuid, {projectId});
delete secrets
Plain TextSecretsDeleteResponse secretsDeleteResponse = bitwardenClient.deleteSecrets({secretId});