Skip to content

Commit

Permalink
Changed types - removed ResponseFor*
Browse files Browse the repository at this point in the history
  • Loading branch information
Todosijevic-Slobodan authored and Todosijevic-Slobodan committed Nov 24, 2023
1 parent 268e75c commit 39070b7
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 85 deletions.
28 changes: 14 additions & 14 deletions languages/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,40 @@ clientSettings.set_user_agent(user_agent);
```c++
std::string accessToken = "<access-token>";
BitwardenClient bitwardenClient = BitwardenClient(clientSettings);
ResponseForApiKeyLoginResponse responseForApiKeyLoginResponse = bitwardenClient.accessTokenLogin(accessToken);
bitwardenClient.accessTokenLogin(accessToken);
```

### Create new project

```c++
boost::uuids::uuid organizationUuid = boost::uuids::string_generator()("<organization-id>");
ResponseForProjectResponse responseForProjectResponseCreate = bitwardenClient.createProject(organizationUuid, "TestProject");
ProjectResponse projectResponseCreate = bitwardenClient.createProject(organizationUuid, "TestProject");
```

### List all projects

```c++
ResponseForProjectsResponse responseForProjectResponseList = bitwardenClient.listProjects(organizationUuid);
ProjectsResponse projectResponseList = bitwardenClient.listProjects(organizationUuid);
```

### Get project details

```c++
boost::uuids::uuid projectId = boost::uuids::string_generator()(responseForProjectResponseCreate.get_data()->get_id());
ResponseForProjectResponse responseForProjectResponseGet = bitwardenClient.getProject(projectId);
boost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id());
ProjectResponse projectResponseGet = bitwardenClient.getProject(projectId);
```

### Update project

```c++
boost::uuids::uuid projectId = boost::uuids::string_generator()(responseForProjectResponseCreate.get_data()->get_id());
ResponseForProjectResponse responseForProjectResponseUpdate = bitwardenClient.updateProject(projectId, organizationUuid, "TestProjectUpdated");
boost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id());
ProjectResponse projectResponseUpdate = bitwardenClient.updateProject(projectId, organizationUuid, "TestProjectUpdated");
```

### Delete projects

```c++
ResponseForSecretsDeleteResponse responseForSecretsDeleteResponse = bitwardenClient.deleteSecrets({secretId});
SecretsDeleteResponse secretsDeleteResponse = bitwardenClient.deleteSecrets({secretId});
```
### Add new secret
Expand All @@ -67,31 +67,31 @@ ResponseForSecretsDeleteResponse responseForSecretsDeleteResponse = bitwardenCli
std::string key = "key";
std::string value = "value";
std::string note = "note";
ResponseForSecretResponse responseForSecretResponseCreate = bitwardenClient.createSecret(key, value, note, organizationUuid, {projectId});
SecretResponse secretResponseCreate = bitwardenClient.createSecret(key, value, note, organizationUuid, {projectId});
```

### List secrets

```c++
ResponseForSecretIdentifiersResponse responseForSecretIdentifiersResponse = bitwardenClient.listSecrets(organizationUuid);
SecretIdentifiersResponse secretIdentifiersResponse = bitwardenClient.listSecrets(organizationUuid);
```

### Get secret details

```
boost::uuids::uuid secretId = boost::uuids::string_generator()(responseForSecretResponseCreate.get_data()->get_id());
ResponseForSecretResponse responseForSecretResponseGet = bitwardenClient.getSecret(secretId);
boost::uuids::uuid secretId = boost::uuids::string_generator()(secretResponseCreate.get_id());
SecretResponse secretResponseGet = bitwardenClient.getSecret(secretId);
```

### Update secret
```c++
ResponseForSecretResponse responseForSecretResponseUpdate = bitwardenClient.updateSecret(secretId, "key2", "value2", "note2", organizationUuid, {projectId});
SecretResponse secretResponseUpdate = bitwardenClient.updateSecret(secretId, "key2", "value2", "note2", organizationUuid, {projectId});
```
# Delete secrets
```c++
ResponseForSecretsDeleteResponse responseForSecretsDeleteResponse = bitwardenClient.deleteSecrets({secretId});
SecretsDeleteResponse secretsDeleteResponse = bitwardenClient.deleteSecrets({secretId});
```

[Access Tokens]: https://bitwarden.com/help/access-tokens/
Expand Down
26 changes: 13 additions & 13 deletions languages/cpp/examples/Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,49 @@ int main() {
// Create a Bitwarden client instance
BitwardenClient bitwardenClient = BitwardenClient(clientSettings);
// // Access token login
ResponseForApiKeyLoginResponse responseForApiKeyLoginResponse = bitwardenClient.accessTokenLogin(accessToken);
bitwardenClient.accessTokenLogin(accessToken);
// Organization ID
boost::uuids::uuid organizationUuid = boost::uuids::string_generator()(organizationId);

// // Create a new project
ResponseForProjectResponse responseForProjectResponseCreate = bitwardenClient.createProject(organizationUuid, "NewTestProject");
boost::uuids::uuid projectId = boost::uuids::string_generator()(responseForProjectResponseCreate.get_data()->get_id());
ProjectResponse projectResponseCreate = bitwardenClient.createProject(organizationUuid, "NewTestProject");
boost::uuids::uuid projectId = boost::uuids::string_generator()(projectResponseCreate.get_id());

// List projects
ResponseForProjectsResponse responseForProjectResponseList = bitwardenClient.listProjects(organizationUuid);
ProjectsResponse projectResponseList = bitwardenClient.listProjects(organizationUuid);

// Get project details
ResponseForProjectResponse responseForProjectResponseGet = bitwardenClient.getProject(projectId);
ProjectResponse projectResponseGet = bitwardenClient.getProject(projectId);

// Update project
ResponseForProjectResponse responseForProjectResponseUpdate = bitwardenClient.updateProject(projectId, organizationUuid, "NewTestProject2");
ProjectResponse ProjectResponseUpdate = bitwardenClient.updateProject(projectId, organizationUuid, "NewTestProject2");

// Secrets
std::string key = "key";
std::string value = "value";
std::string note = "note";

// Create a new secret
ResponseForSecretResponse responseForSecretResponseCreate = bitwardenClient.createSecret(key, value, note, organizationUuid, {projectId});
boost::uuids::uuid secretId = boost::uuids::string_generator()(responseForSecretResponseCreate.get_data()->get_id());
SecretResponse secretResponseCreate = bitwardenClient.createSecret(key, value, note, organizationUuid, {projectId});
boost::uuids::uuid secretId = boost::uuids::string_generator()(secretResponseCreate.get_id());

// List secrets
ResponseForSecretIdentifiersResponse responseForSecretIdentifiersResponse = bitwardenClient.listSecrets(organizationUuid);
SecretIdentifiersResponse secretIdentifiersResponse = bitwardenClient.listSecrets(organizationUuid);

// Get secret details
ResponseForSecretResponse responseForSecretResponseGet = bitwardenClient.getSecret(secretId);
SecretResponse secretResponseGet = bitwardenClient.getSecret(secretId);

// Update secret
key = "key2";
value = "value2";
note = "note2";
ResponseForSecretResponse responseForSecretResponseUpdate = bitwardenClient.updateSecret(secretId, key, value, note, organizationUuid, {projectId});
SecretResponse responseForSecretResponseUpdate = bitwardenClient.updateSecret(secretId, key, value, note, organizationUuid, {projectId});

// Delete secrets
ResponseForSecretsDeleteResponse responseForSecretsDeleteResponse = bitwardenClient.deleteSecrets({secretId});
SecretsDeleteResponse secretsDeleteResponse = bitwardenClient.deleteSecrets({secretId});

// Delete projects
ResponseForProjectsDeleteResponse responseForProjectsDeleteResponse = bitwardenClient.deleteProjects({projectId});
ProjectsDeleteResponse projectsDeleteResponse = bitwardenClient.deleteProjects({projectId});

return 0;
}
22 changes: 11 additions & 11 deletions languages/cpp/include/BitwardenClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ class BitwardenClient {
BitwardenClient(ClientSettings clientSettings);
~BitwardenClient();

ResponseForApiKeyLoginResponse accessTokenLogin(const std::string& accessToken);
ResponseForProjectResponse getProject(const boost::uuids::uuid& id);
ResponseForProjectResponse createProject(const boost::uuids::uuid& organizationId, const std::string& name);
ResponseForProjectResponse updateProject(const boost::uuids::uuid& id, const boost::uuids::uuid& organizationId, const std::string& name);
ResponseForProjectsDeleteResponse deleteProjects(const std::vector<boost::uuids::uuid>& ids);
ResponseForProjectsResponse listProjects(const boost::uuids::uuid &organizationId);
ResponseForSecretResponse getSecret(const boost::uuids::uuid& id);
ResponseForSecretResponse createSecret(const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds);
ResponseForSecretResponse updateSecret(const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds);
ResponseForSecretsDeleteResponse deleteSecrets(const std::vector<boost::uuids::uuid>& ids);
ResponseForSecretIdentifiersResponse listSecrets(const boost::uuids::uuid& organizationId);
void accessTokenLogin(const std::string& accessToken);
ProjectResponse getProject(const boost::uuids::uuid& id);
ProjectResponse createProject(const boost::uuids::uuid& organizationId, const std::string& name);
ProjectResponse updateProject(const boost::uuids::uuid& id, const boost::uuids::uuid& organizationId, const std::string& name);
ProjectsDeleteResponse deleteProjects(const std::vector<boost::uuids::uuid>& ids);
ProjectsResponse listProjects(const boost::uuids::uuid &organizationId);
SecretResponse getSecret(const boost::uuids::uuid& id);
SecretResponse createSecret(const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds);
SecretResponse updateSecret(const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds);
SecretsDeleteResponse deleteSecrets(const std::vector<boost::uuids::uuid>& ids);
SecretIdentifiersResponse listSecrets(const boost::uuids::uuid& organizationId);

private:
BitwardenLibrary* library;
Expand Down
10 changes: 5 additions & 5 deletions languages/cpp/include/CommandRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class CommandRunner {
public:
CommandRunner(BitwardenLibrary* library, void* client);

template <typename T, typename Func>
T runCommand(const Command& command, Func deserializer);
template <typename T, typename R, typename Func>
R runCommand(const Command& command, Func deserializer);



Expand All @@ -25,8 +25,8 @@ class CommandRunner {
nlohmann::json filterNullObjects(const nlohmann::json& input);
};

template <typename T, typename Func>
T CommandRunner::runCommand(const Command& command, Func deserializer) {
template <typename T, typename R, typename Func>
R CommandRunner::runCommand(const Command& command, Func deserializer) {
// Serialize the Command object to a JSON string
std::string jsonString = commandToString(command);
const char* jsonCStr = jsonString.c_str();
Expand All @@ -40,6 +40,6 @@ T CommandRunner::runCommand(const Command& command, Func deserializer) {
throw std::runtime_error(*deserialized.get_error_message());
}

return deserialized;
return deserialized.get_data().get();
}

10 changes: 5 additions & 5 deletions languages/cpp/include/Projects.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class Projects {
public:
Projects(CommandRunner* commandRunner);

ResponseForProjectResponse get(const boost::uuids::uuid& id);
ResponseForProjectResponse create(const boost::uuids::uuid& organizationId, const std::string& name);
ResponseForProjectResponse update(const boost::uuids::uuid& id, const boost::uuids::uuid& organizationId, const std::string& name);
ResponseForProjectsDeleteResponse deleteProjects(const std::vector<boost::uuids::uuid>& ids);
ResponseForProjectsResponse list(const boost::uuids::uuid& organizationId);
ProjectResponse get(const boost::uuids::uuid& id);
ProjectResponse create(const boost::uuids::uuid& organizationId, const std::string& name);
ProjectResponse update(const boost::uuids::uuid& id, const boost::uuids::uuid& organizationId, const std::string& name);
ProjectsDeleteResponse deleteProjects(const std::vector<boost::uuids::uuid>& ids);
ProjectsResponse list(const boost::uuids::uuid& organizationId);

private:
CommandRunner* commandRunner;
Expand Down
10 changes: 5 additions & 5 deletions languages/cpp/include/Secrets.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class Secrets {
public:
Secrets(CommandRunner* commandRunner);

ResponseForSecretResponse get(const boost::uuids::uuid& id);
ResponseForSecretResponse create(const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds);
ResponseForSecretResponse update(const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds);
ResponseForSecretsDeleteResponse deleteSecrets(const std::vector<boost::uuids::uuid>& ids);
ResponseForSecretIdentifiersResponse list(const boost::uuids::uuid& organizationId);
SecretResponse get(const boost::uuids::uuid& id);
SecretResponse create(const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds);
SecretResponse update(const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds);
SecretsDeleteResponse deleteSecrets(const std::vector<boost::uuids::uuid>& ids);
SecretIdentifiersResponse list(const boost::uuids::uuid& organizationId);

private:
CommandRunner* commandRunner;
Expand Down
24 changes: 12 additions & 12 deletions languages/cpp/src/BitwardenClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ BitwardenClient::~BitwardenClient() {
}
}

ResponseForApiKeyLoginResponse BitwardenClient::accessTokenLogin(const std::string& accessToken) {
void BitwardenClient::accessTokenLogin(const std::string& accessToken) {
Command command;
AccessTokenLoginRequest accessTokenLoginRequest;
accessTokenLoginRequest.set_access_token(accessToken);
Expand All @@ -45,80 +45,80 @@ ResponseForApiKeyLoginResponse BitwardenClient::accessTokenLogin(const std::stri
return loginResponse;
};
try {
return commandRunner->runCommand<ResponseForApiKeyLoginResponse>(command, deserializer);
commandRunner->runCommand<ResponseForApiKeyLoginResponse, ApiKeyLoginResponse>(command, deserializer);
} catch (const std::exception& ex) {
std::cerr << "Error in accessTokenLogin: " << ex.what() << std::endl;
throw ex;
}
}

ResponseForProjectResponse BitwardenClient::getProject(const boost::uuids::uuid& id){
ProjectResponse BitwardenClient::getProject(const boost::uuids::uuid& id){
if (!isClientOpen) {
throw std::runtime_error("Client is not open.");
}
return projects.get(id);
}

ResponseForProjectResponse BitwardenClient::createProject(const boost::uuids::uuid& organizationId, const std::string& name){
ProjectResponse BitwardenClient::createProject(const boost::uuids::uuid& organizationId, const std::string& name){
if (!isClientOpen) {
throw std::runtime_error("Client is not open.");
}
return projects.create(organizationId, name);
}

ResponseForProjectResponse BitwardenClient::updateProject(const boost::uuids::uuid& id, const boost::uuids::uuid& organizationId, const std::string& name){
ProjectResponse BitwardenClient::updateProject(const boost::uuids::uuid& id, const boost::uuids::uuid& organizationId, const std::string& name){
if (!isClientOpen) {
throw std::runtime_error("Client is not open.");
}
return projects.update(id, organizationId, name);
}

ResponseForProjectsDeleteResponse BitwardenClient::deleteProjects(const std::vector<boost::uuids::uuid>& ids) {
ProjectsDeleteResponse BitwardenClient::deleteProjects(const std::vector<boost::uuids::uuid>& ids) {
if (!isClientOpen) {
throw std::runtime_error("Client is not open.");
}
return projects.deleteProjects(ids);

}

ResponseForProjectsResponse BitwardenClient::listProjects(const boost::uuids::uuid &organizationId) {
ProjectsResponse BitwardenClient::listProjects(const boost::uuids::uuid &organizationId) {
if (!isClientOpen) {
throw std::runtime_error("Client is not open.");
}
return projects.list(organizationId);

}

ResponseForSecretResponse BitwardenClient::getSecret(const boost::uuids::uuid& id){
SecretResponse BitwardenClient::getSecret(const boost::uuids::uuid& id){
if (!isClientOpen) {
throw std::runtime_error("Client is not open.");
}
return secrets.get(id);
}

ResponseForSecretResponse BitwardenClient::createSecret(const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds){
SecretResponse BitwardenClient::createSecret(const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds){
if (!isClientOpen) {
throw std::runtime_error("Client is not open.");
}
return secrets.create(key, value, note, organizationId, projectIds);
}

ResponseForSecretResponse BitwardenClient::updateSecret(const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds){
SecretResponse BitwardenClient::updateSecret(const boost::uuids::uuid& id, const std::string& key, const std::string& value, const std::string& note, const boost::uuids::uuid& organizationId, const std::vector<boost::uuids::uuid>& projectIds){
if (!isClientOpen) {
throw std::runtime_error("Client is not open.");
}
return secrets.update(id, key, value, note, organizationId, projectIds);
}

ResponseForSecretsDeleteResponse BitwardenClient::deleteSecrets(const std::vector<boost::uuids::uuid>& ids) {
SecretsDeleteResponse BitwardenClient::deleteSecrets(const std::vector<boost::uuids::uuid>& ids) {
if (!isClientOpen) {
throw std::runtime_error("Client is not open.");
}
return secrets.deleteSecrets(ids);

}

ResponseForSecretIdentifiersResponse BitwardenClient::listSecrets(const boost::uuids::uuid &organizationId) {
SecretIdentifiersResponse BitwardenClient::listSecrets(const boost::uuids::uuid &organizationId) {
if (!isClientOpen) {
throw std::runtime_error("Client is not open.");
}
Expand Down
Loading

0 comments on commit 39070b7

Please sign in to comment.