Add --set-bucket and --delete-bucket to Cyad
[platform/core/security/cynara.git] / src / cyad / CommandsDispatcher.cpp
index dee8ce3..b8e256c 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include <cynara-error.h>
+#include <cynara-policy-types.h>
 
 #include <cyad/AdminLibraryInitializationFailedException.h>
 
@@ -58,4 +59,18 @@ int CommandsDispatcher::execute(ErrorCyadCommand &result) {
     return CYNARA_API_INVALID_COMMANDLINE_PARAM;
 }
 
+int CommandsDispatcher::execute(DeleteBucketCyadCommand &result) {
+    return m_adminApiWrapper.cynara_admin_set_bucket(m_cynaraAdmin, result.bucketId().c_str(),
+                                                     CYNARA_ADMIN_DELETE, nullptr);
+}
+
+int CommandsDispatcher::execute(SetBucketCyadCommand &result) {
+    const auto &policyResult = result.policyResult();
+    const char *metadata = policyResult.metadata().empty() ? nullptr
+                                                           : policyResult.metadata().c_str();
+    return m_adminApiWrapper.cynara_admin_set_bucket(m_cynaraAdmin,
+                                                     result.bucketId().c_str(),
+                                                     policyResult.policyType(), metadata);
+}
+
 } /* namespace Cynara */