Skip to content
Snippets Groups Projects
Verified Commit c22c28ca authored by Timm Fitschen's avatar Timm Fitschen
Browse files

ENH: add Connection::ListUsers method

parent a1058f7a
No related branches found
No related tags found
2 merge requests!61Release 0.3.0,!47F null pointer list users
Pipeline #47071 failed
Pipeline: caosdb-cppinttest

#47073

    This commit is part of merge request !47. Comments created here will be created in the context of that merge request.
    ...@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
    ### Added ### Added
    - Connection::ListUsers method
    ### Changed ### Changed
    - Updated dependency versions. - Updated dependency versions.
    ......
    ...@@ -43,6 +43,9 @@ ...@@ -43,6 +43,9 @@
    #include <map> // for map #include <map> // for map
    #include <memory> // for shared_ptr, unique_ptr #include <memory> // for shared_ptr, unique_ptr
    #include <string> // for string, basic_string #include <string> // for string, basic_string
    #ifdef BUILD_ACM
    #include <vector> // for vector
    #endif
    namespace caosdb::connection { namespace caosdb::connection {
    #ifdef BUILD_ACM #ifdef BUILD_ACM
    ...@@ -122,6 +125,11 @@ public: ...@@ -122,6 +125,11 @@ public:
    // TODO(tf) find a way to deal with this: // TODO(tf) find a way to deal with this:
    // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
    auto DeleteSingleUser(const std::string &realm, const std::string &name) const -> void; auto DeleteSingleUser(const std::string &realm, const std::string &name) const -> void;
    /**
    * List known users.
    */
    auto ListUsers() const -> std::vector<User>;
    #endif #endif
    private: private:
    ......
    ...@@ -15,7 +15,7 @@ pluginbase==1.0.1 ...@@ -15,7 +15,7 @@ pluginbase==1.0.1
    Pygments==2.13.0 Pygments==2.13.0
    PyJWT==2.6.0 PyJWT==2.6.0
    python-dateutil==2.8.2 python-dateutil==2.8.2
    PyYAML==6.0 PyYAML==6.0.1
    requests==2.28.1 requests==2.28.1
    six==1.16.0 six==1.16.0
    tqdm==4.64.1 tqdm==4.64.1
    ......
    ...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
    #include <grpcpp/create_channel.h> // for CreateChannel #include <grpcpp/create_channel.h> // for CreateChannel
    #include <grpcpp/support/status.h> // for Status #include <grpcpp/support/status.h> // for Status
    #include <string> // for string, operator+ #include <string> // for string, operator+
    #ifdef BUILD_ACM
    #include <vector> // for vector
    #endif
    // IWYU pragma: no_include "net/proto2/public/repeated_field.h" // IWYU pragma: no_include "net/proto2/public/repeated_field.h"
    namespace caosdb::connection { namespace caosdb::connection {
    ...@@ -46,6 +49,8 @@ using caosdb::acm::v1alpha1::CreateSingleUserRequest; ...@@ -46,6 +49,8 @@ using caosdb::acm::v1alpha1::CreateSingleUserRequest;
    using caosdb::acm::v1alpha1::CreateSingleUserResponse; using caosdb::acm::v1alpha1::CreateSingleUserResponse;
    using caosdb::acm::v1alpha1::DeleteSingleUserRequest; using caosdb::acm::v1alpha1::DeleteSingleUserRequest;
    using caosdb::acm::v1alpha1::DeleteSingleUserResponse; using caosdb::acm::v1alpha1::DeleteSingleUserResponse;
    using caosdb::acm::v1alpha1::ListUsersRequest;
    using caosdb::acm::v1alpha1::ListUsersResponse;
    using caosdb::acm::v1alpha1::RetrieveSingleUserRequest; using caosdb::acm::v1alpha1::RetrieveSingleUserRequest;
    using caosdb::acm::v1alpha1::RetrieveSingleUserResponse; using caosdb::acm::v1alpha1::RetrieveSingleUserResponse;
    #endif #endif
    ...@@ -204,6 +209,37 @@ auto Connection::CreateSingleUser(const User &user) const -> void { ...@@ -204,6 +209,37 @@ auto Connection::CreateSingleUser(const User &user) const -> void {
    } }
    status.ThrowExceptionIfError(); status.ThrowExceptionIfError();
    } }
    auto Connection::ListUsers() const -> std::vector<User> {
    ListUsersRequest request;
    ListUsersResponse response;
    grpc::ClientContext context;
    const grpc::Status grpc_status =
    this->access_controll_management_service->ListUsers(&context, request, &response);
    auto status = TransactionStatus::SUCCESS();
    if (!grpc_status.ok()) {
    switch (grpc_status.error_code()) {
    case grpc::StatusCode::UNAUTHENTICATED:
    status = TransactionStatus::AUTHENTICATION_ERROR(grpc_status.error_message());
    break;
    case grpc::StatusCode::UNAVAILABLE:
    status = TransactionStatus::CONNECTION_ERROR();
    break;
    default:
    auto error_message = grpc_status.error_message();
    status = TransactionStatus::RPC_ERROR(std::to_string(grpc_status.error_code()) + " - " +
    error_message);
    }
    }
    status.ThrowExceptionIfError();
    std::vector<User> results;
    for (auto &user : *(response.mutable_users())) {
    results.push_back(User(std::make_unique<UserImpl>(&user)));
    }
    return results;
    }
    #endif #endif
    auto ConnectionManager::mHasConnection(const std::string &name) const -> bool { auto ConnectionManager::mHasConnection(const std::string &name) const -> bool {
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment