Add EmptyBucket convenience method to CynaraAdmin class. 97/31297/25
authorKrzysztof Sasiak <k.sasiak@samsung.com>
Fri, 19 Dec 2014 14:37:33 +0000 (15:37 +0100)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 29 Jan 2015 13:33:54 +0000 (05:33 -0800)
Change-Id: Ia050336fb69d669488601a18211775b9136d8070
Signed-off-by: Krzysztof Sasiak <k.sasiak@samsung.com>
src/common/cynara.cpp
src/common/include/cynara.h

index c29f426..4d4ec75 100644 (file)
@@ -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<int>(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(
index 7713f42..98ce805 100644 (file)
@@ -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;
 };