From f427df45b7516b659248f7148867f6ec842f641d Mon Sep 17 00:00:00 2001 From: Krzysztof Sasiak Date: Fri, 19 Dec 2014 15:37:33 +0100 Subject: [PATCH] Add EmptyBucket convenience method to CynaraAdmin class. Change-Id: Ia050336fb69d669488601a18211775b9136d8070 Signed-off-by: Krzysztof Sasiak --- src/common/cynara.cpp | 12 ++++++++++++ src/common/include/cynara.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/common/cynara.cpp b/src/common/cynara.cpp index c29f426..4d4ec75 100644 --- a/src/common/cynara.cpp +++ b/src/common/cynara.cpp @@ -198,6 +198,8 @@ static bool checkCynaraError(int result, const std::string &msg) ThrowMsg(CynaraException::InvalidParam, msg); case CYNARA_API_SERVICE_NOT_AVAILABLE: ThrowMsg(CynaraException::ServiceNotAvailable, msg); + case CYNARA_API_BUCKET_NOT_FOUND: + ThrowMsg(CynaraException::BucketNotFound, msg); default: ThrowMsg(CynaraException::UnknownError, msg); } @@ -359,6 +361,16 @@ void CynaraAdmin::ListPolicies( } +void CynaraAdmin::EmptyBucket(const std::string &bucketName, bool recursive, const std::string &client, + const std::string &user, const std::string &privilege) +{ + checkCynaraError( + cynara_admin_erase(m_CynaraAdmin, bucketName.c_str(), static_cast(recursive), + client.c_str(), user.c_str(), privilege.c_str()), + "Error while emptying bucket: " + bucketName + ", filter (C, U, P): " + + client + ", " + user + ", " + privilege); +} + Cynara::Cynara() { checkCynaraError( diff --git a/src/common/include/cynara.h b/src/common/include/cynara.h index 7713f42..98ce805 100644 --- a/src/common/include/cynara.h +++ b/src/common/include/cynara.h @@ -55,6 +55,7 @@ public: DECLARE_EXCEPTION_TYPE(Base, InvalidParam) DECLARE_EXCEPTION_TYPE(Base, ServiceNotAvailable) DECLARE_EXCEPTION_TYPE(Base, UnknownError) + DECLARE_EXCEPTION_TYPE(Base, BucketNotFound) }; struct CynaraAdminPolicy : cynara_admin_policy @@ -153,6 +154,19 @@ public: private: CynaraAdmin(); + + /** + * Empty bucket using filter - matching rules will be removed + * + * @param bucketName name of the bucket to be emptied + * @param recursive flag to remove privileges recursively + * @param client client name + * @param user user name + * @param privilege privilege name + */ + void EmptyBucket(const std::string &bucketName, bool recursive, + const std::string &client, const std::string &user, const std::string &privilege); + struct cynara_admin *m_CynaraAdmin; }; -- 2.7.4