CynaraClientBootstrap :: ~CynaraClientBootstrap() {
}
-cynara_api_result CynaraClientBootstrap :: check(const std::string& client,
- const std::string& session UNUSED, const std::string& user UNUSED, const std::string& privilege)
+cynara_api_result CynaraClientBootstrap :: check(const std::string &client,
+ const std::string &session UNUSED, const std::string &user UNUSED, const std::string &privilege)
{
int is_enabled = 0;
public:
CynaraClientBootstrap();
virtual ~CynaraClientBootstrap();
- virtual cynara_api_result check(const std::string& client, const std::string& session,
- const std::string& user, const std::string& privilege);
+ virtual cynara_api_result check(const std::string &client, const std::string &session,
+ const std::string &user, const std::string &privilege);
};
#endif /* CYNARA_CLIENT_BOOTSTRAP_H */
#include <bootstrap/cynara-client-bootstrap.h>
struct cynara {
- CynaraClientInterface* impl;
+ CynaraClientInterface *impl;
cynara(CynaraClientInterface *_impl) : impl(_impl) {
}
try {
*pp_cynara = new cynara(new CynaraClientBootstrap);
- } catch (std::bad_alloc& ex) {
+ } catch (std::bad_alloc &ex) {
return cynara_api_result::CYNARA_API_OUT_OF_MEMORY;
}
public:
virtual ~CynaraClientInterface() {
}
- virtual cynara_api_result check(const std::string& client, const std::string& session,
- const std::string& user, const std::string& privilege) = 0;
+ virtual cynara_api_result check(const std::string &client, const std::string &session,
+ const std::string &user, const std::string &privilege) = 0;
};
#endif /* CYNARA_CLIENT_INTERFACE_H */
#include "result/Result.h"
#include "types/ClientId.h"
-#include "types/ExtendedPolicyType.h"
#include "types/Policy.h"
#include "types/PolicyBucket.h"
#include "types/PolicyKey.h"
#include "types/PolicyType.h"
#include "types/PolicyTypeExtension.h"
-#include "types/PolicyVector.h"
+#include "types/PolicyCollection.h"
#include "types/PrivilegeId.h"
#include "types/UserId.h"
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file BucketAlreadyExistsException.h
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Implementation of BucketAlreadyExistsException
+ */
+
+#ifndef BUCKETALREADYEXISTS_H
+#define BUCKETALREADYEXISTS_H
+
+#include "types/PolicyBucketId.h"
+
+#include <exception>
+
+namespace Cynara {
+
+class BucketAlreadyExistsException : public std::exception {
+public:
+ BucketAlreadyExistsException(const PolicyBucketId &bucketId) : m_bucketId(bucketId) {
+ }
+
+private:
+ PolicyBucketId m_bucketId;
+};
+
+} /* namespace Cynara */
+
+#endif // BUCKETALREADYEXISTS_H
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file BucketNotExistsException.h
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Implementation of BucketNotExistsException
+ */
+
+#ifndef BUCKETNOTEXISTSEXCEPTION_H_
+#define BUCKETNOTEXISTSEXCEPTION_H_
+
+#include "types/PolicyBucketId.h"
+
+#include <exception>
+
+namespace Cynara {
+
+class BucketNotExistsException : public std::exception {
+public:
+ BucketNotExistsException(const PolicyBucketId &bucketId) : m_bucketId(bucketId) {
+
+ }
+
+private:
+ PolicyBucketId m_bucketId;
+};
+
+} /* namespace Cynara */
+
+
+#endif /* BUCKETNOTEXISTSEXCEPTION_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file DefaultBucketDeletionException.h
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Implementation of DefaultBucketDeletionException
+ */
+
+#ifndef DEFAULTBUCKETDELETIONEXCEPTION_H
+#define DEFAULTBUCKETDELETIONEXCEPTION_H
+
+#include <exception>
+
+namespace Cynara {
+
+class DefaultBucketDeletionException : public std::exception {
+
+};
+
+} /* namespace Cynara */
+
+#endif // DEFAULTBUCKETDELETIONEXCEPTION_H
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file NotImplementedException.h
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Implementation of NotImplementedException
+ */
+
+#ifndef NOTIMPLEMENTEDEXCEPTION_H_
+#define NOTIMPLEMENTEDEXCEPTION_H_
+
+#include <exception>
+
+namespace Cynara {
+
+class NotImplementedException : public std::exception {
+
+};
+
+
+}
+
+#endif /* NOTIMPLEMENTEDEXCEPTION_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * @file ExtendedPolicyType.h
- * @author Lukasz Wojciechowski <l.wojciechowski@partner.samsung.com>
- * @version 1.0
- * @brief This file defines ExtendedPolicyType - used to describe policy
- type with extended data (that may be used by plugins)
- */
-
-#ifndef CYNARA_COMMON_TYPES_EXTENDEDPOLICYTYPE_H
-#define CYNARA_COMMON_TYPES_EXTENDEDPOLICYTYPE_H
-
-#include "PolicyType.h"
-#include "PolicyTypeExtension.h"
-
-struct ExtendedPolicyType
-{
- PolicyType m_type;
- PolicyTypeExtension m_ext;
-};
-
-#endif /* CYNARA_COMMON_TYPES_EXTENDEDPOLICYTYPE_H */
/*
* @file Policy.h
* @author Lukasz Wojciechowski <l.wojciechowski@partner.samsung.com>
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
* @version 1.0
* @brief This file defines Policy type - used to describe single policy
rule identified by policy key
#define CYNARA_COMMON_TYPES_POLICY_H
#include "PolicyKey.h"
-#include "ExtendedPolicyType.h"
+#include "PolicyResult.h"
+#include "types/pointers.h"
+#include "types/PolicyType.h"
+#include "types/PolicyBucketId.h"
-struct Policy
+#include <memory>
+
+namespace Cynara {
+
+class Policy
{
- PolicyKey m_key;
- ExtendedPolicyType m_extType;
+public:
+ Policy(const PolicyKey &key, const PolicyResult &result) :
+ m_key(key), m_result(result) {}
+
+ static PolicyPtr simpleWithKey(const PolicyKey &key, const PolicyType &type) {
+ return std::make_shared<Policy>(key, PolicyResult(type));
+ }
+
+ static PolicyPtr bucketWithKey(const PolicyKey &key, const PolicyBucketId &bucketId) {
+ auto result = PolicyResult(PolicyType::BUCKET, bucketId);
+ return std::make_shared<Policy>(key, result);
+ }
+
+private:
+ PolicyKey m_key;
+ PolicyResult m_result;
+
+public:
+ const PolicyKey &key() const {
+ return m_key;
+ }
+
+ const PolicyResult &result() const {
+ return m_result;
+ }
};
+} // namespace Cynara
+
#endif /* CYNARA_COMMON_TYPES_POLICY_H */
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file PolicyBucket.cpp
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Implementation of Cynara::PolicyBucket methods
+ */
+
+
+#include "PolicyBucket.h"
+
+namespace Cynara {
+
+PolicyBucket PolicyBucket::filtered(const PolicyKey &key) const {
+ PolicyBucket result;
+
+ const auto &policies = policyCollection();
+ std::copy_if(policies.begin(), policies.end(), std::back_inserter(result.policyCollection()),
+ [=] (PolicyCollection::value_type policy) {
+ return policy->key() == key;
+ });
+
+ // Inherit original policy
+ result.setDefaultPolicy(defaultPolicy());
+ return result;
+}
+
+} // namespace Cynara
/*
* @file PolicyBucket.h
* @author Lukasz Wojciechowski <l.wojciechowski@partner.samsung.com>
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
* @version 1.0
* @brief This file defines PolicyBucket type - a policy aggregation
entity name
#ifndef CYNARA_COMMON_TYPES_POLICYBUCKET_H
#define CYNARA_COMMON_TYPES_POLICYBUCKET_H
+#include "PolicyCollection.h"
+#include "PolicyKey.h"
+#include "Policy.h"
+#include "exceptions/NotImplementedException.h"
+#include "types/pointers.h"
+#include "types/PolicyType.h"
+#include "PolicyBucketId.h"
+
#include <string>
-typedef std::string PolicyBucket;
+#include <memory>
+#include <algorithm>
+
+namespace Cynara {
+
+// TODO: Move this const somewhere else
+const PolicyBucketId defaultPolicyBucketId("");
+
+class PolicyBucket {
+public:
+
+ PolicyBucket() : m_defaultPolicy(PolicyResult(PolicyType::DENY)) {}
+
+ PolicyBucket filtered(const PolicyKey &key) const;
+
+private:
+ PolicyCollection m_policyCollection;
+ PolicyResult m_defaultPolicy;
+ PolicyBucketId m_id;
+
+public:
+ const PolicyResult &defaultPolicy() const {
+ return m_defaultPolicy;
+ }
+
+ const PolicyBucketId &id() const {
+ return m_id;
+ }
+
+ PolicyCollection &policyCollection() {
+ return m_policyCollection;
+ }
+
+ const PolicyCollection &policyCollection() const {
+ return m_policyCollection;
+ }
-const PolicyBucket defaultPolicyBucket("");
+ void setDefaultPolicy(const PolicyResult &defaultPolicy) {
+ m_defaultPolicy = defaultPolicy;
+ }
+};
+} /* namespace Cynara */
#endif /* CYNARA_COMMON_TYPES_POLICYBUCKET_H */
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file PolicBucketId.h
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Definition of Cynara::PolicyBucketId type
+ */
+#ifndef POLICBUCKETID_H_
+#define POLICBUCKETID_H_
+
+
+namespace Cynara {
+
+typedef std::string PolicyBucketId;
+
+} // namespace Cynara
+
+
+#endif /* POLICBUCKETID_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file PolicyCollection.h
+ * @author Lukasz Wojciechowski <l.wojciechowski@partner.samsung.com>
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief This file defines a collection of policies
+ */
+
+#ifndef CYNARA_COMMON_TYPES_POLICYCOLLECTION_H
+#define CYNARA_COMMON_TYPES_POLICYCOLLECTION_H
+
+#include "types/pointers.h"
+
+#include <vector>
+
+namespace Cynara {
+
+typedef std::vector<PolicyPtr> PolicyCollection;
+
+} // namespace Cynara
+
+#endif /* CYNARA_COMMON_TYPES_POLICYCOLLECTION_H */
/*
* @file PolicyKey.h
* @author Lukasz Wojciechowski <l.wojciechowski@partner.samsung.com>
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
* @version 1.0
- * @brief This file defines PolicyKey - tripple that defines a single
+ * @brief This file defines PolicyKey - triple, which defines a single
policy rule
*/
#include "UserId.h"
#include "PrivilegeId.h"
+#include <tuple>
+
+namespace Cynara {
+
struct PolicyKey
{
- ClientId m_client;
- UserId m_user;
- PrivilegeId m_privilege;
+public:
+ PolicyKey() {};
+ PolicyKey(const ClientId &clientId, const UserId &userId, const PrivilegeId &privilegeId)
+ : m_client(clientId), m_user(userId), m_privilege(privilegeId) {};
+
+ bool operator==(const PolicyKey &other) const {
+ return std::tie(m_client, m_user, m_privilege)
+ == std::tie(other.m_client, other.m_user, other.m_privilege);
+ }
+
+private:
+ ClientId m_client;
+ UserId m_user;
+ PrivilegeId m_privilege;
};
+}
#endif /* CYNARA_COMMON_TYPES_POLICYKEY_H */
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file PolicyResult.h
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Definitions of PolicyResult and friends
+ */
+
+#ifndef POLICYRESULT_H_
+#define POLICYRESULT_H_
+
+#include "types/PolicyType.h"
+
+namespace Cynara {
+
+class PolicyResult {
+public:
+ typedef std::string PolicyMetadata;
+
+public:
+ PolicyResult(const PolicyType &policyType) : m_type(policyType) {}
+ PolicyResult(const PolicyType &policyType, const PolicyMetadata &metadata)
+ : m_type(policyType), m_metaData(metadata) {}
+
+private:
+ PolicyType m_type;
+ PolicyMetadata m_metaData;
+
+public:
+ PolicyType policyType() const { return m_type; }
+ const PolicyMetadata& metaData() const { return m_metaData; }
+
+ bool operator <(const PolicyResult& other) const {
+ return this->m_type < other.m_type;
+ }
+};
+
+} // namespace Cynara
+
+
+#endif /* POLICYRESULT_H_ */
/*
* @file PolicyType.h
* @author Lukasz Wojciechowski <l.wojciechowski@partner.samsung.com>
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
* @version 1.0
* @brief This file defines PolicyType e.g. ALLOW or DENY
*/
#ifndef CYNARA_COMMON_TYPES_POLICYTYPE_H
#define CYNARA_COMMON_TYPES_POLICYTYPE_H
-typedef int PolicyType;
+namespace Cynara {
-const int PolicyType_DENY = 0;
+enum class PolicyType : std::uint16_t {
+ DENY = 0,
+ BUCKET = 0xFFFE,
+ ALLOW = 0xFFFF
+};
-const int PolicyType_ALLOW = 0xFFFF;
+} // namespace Cynara
#endif /* CYNARA_COMMON_TYPES_POLICYTYPE_H */
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file pointers.h
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Typedefs for smart pointers of common types
+ */
+
+#ifndef POINTERS_H_
+#define POINTERS_H_
+
+#include <memory>
+
+namespace Cynara {
+
+class Policy;
+
+typedef std::shared_ptr<Policy> PolicyPtr;
+
+
+} /* namespace Cynara */
+
+#endif /* POINTERS_H_ */
/*
* @file Storage.cpp
* @author Lukasz Wojciechowski <l.wojciechowski@partner.samsung.com>
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
* @version 1.0
* @brief This file implements policy rules storage procedures
*/
#include "Storage.h"
+#include "StorageBackend.h"
+#include "types/pointers.h"
+#include "types/PolicyType.h"
+#include "exceptions/NotImplementedException.h"
+#include "exceptions/BucketAlreadyExistsException.h"
+#include "exceptions/DefaultBucketDeletionException.h"
-Result Storage::checkPolicy(const PolicyKey& key, ExtendedPolicyType& result)
-{
- //todo
- TODO_USE_ME(key);
- TODO_USE_ME(result);
- return RESULT_OK;
-}
+#include <iostream>
+#include <memory>
+
+
+namespace Cynara {
+
+PolicyResult Storage::checkPolicy(const PolicyKey &key) {
+ auto policies = m_backend.searchDefaultBucket(key);
+ return minimalPolicy(policies);
+};
+
+PolicyResult Storage::minimalPolicy(const PolicyBucket &bucket) {
+ bool hasMinimal = false;
+ PolicyResult minimal = bucket.defaultPolicy();
+
+ const auto &policies = bucket.policyCollection();
+
+ auto proposeMinimal = [&minimal, &hasMinimal](const PolicyResult &candidate) {
+ if(hasMinimal == false) {
+ minimal = candidate;
+ } else if(candidate < minimal) {
+ minimal = candidate;
+ }
+ hasMinimal = true;
+ };
+
+ for(const auto &policyRecord : policies) {
+ const auto &policyResult = policyRecord->result();
-Result Storage::insertOrUpdatePolicy(const PolicyVector& policyVector, const PolicyBucket& bucket)
-{
- //todo
- TODO_USE_ME(policyVector);
- TODO_USE_ME(bucket);
- return RESULT_OK;
+ switch(policyResult.policyType()) {
+ case PolicyType::DENY:
+ return policyResult; // Do not expect lower value than DENY
+ break;
+ case PolicyType::BUCKET: {
+ auto bucketResults = m_backend.searchBucket(policyResult.metaData(),
+ policyRecord->key());
+ auto minimumOfBucket = minimalPolicy(bucketResults);
+ proposeMinimal(minimumOfBucket);
+ continue;
+ }
+ break;
+ case PolicyType::ALLOW:
+ default:
+ break;
+ }
+
+ proposeMinimal(policyResult);
+ }
+
+ return minimal;
}
-Result Storage::insertOrUpdateBucket(const PolicyBucket& newBucket, const PolicyKey& key, const ExtendedPolicyType& defaultBucketPolicy, const PolicyBucket& bucket)
-{
- //todo
- TODO_USE_ME(newBucket);
- TODO_USE_ME(key);
- TODO_USE_ME(defaultBucketPolicy);
- TODO_USE_ME(bucket);
- return RESULT_OK;
+void Storage::insertPolicies(const std::vector<PolicyPolicyBucket> &policies) {
+ for(const auto &policyTuple : policies) {
+ PolicyBucketId bucketId;
+ PolicyPtr policyPtr;
+ std::tie(policyPtr, bucketId) = policyTuple;
+ auto existingPolicies = m_backend.searchBucket(bucketId, policyPtr->key());
+ for(auto existingPolicy : existingPolicies.policyCollection()) {
+ m_backend.deletePolicy(bucketId, existingPolicy->key());
+ }
+ m_backend.insertPolicy(bucketId, policyPtr);
+ }
}
-Result Storage::deletePolicy(const PolicyKey& policyKey, const PolicyBucket& bucket)
-{
- //todo
- TODO_USE_ME(policyKey);
- TODO_USE_ME(bucket);
- return RESULT_OK;
+void Storage::createBucket(const PolicyBucketId &newBucketId, const PolicyResult &defaultBucketPolicy) {
+ // TODO: Check if bucket already exists
+
+ if (newBucketId == defaultPolicyBucketId) {
+ throw BucketAlreadyExistsException(newBucketId);
+ }
+
+ m_backend.createBucket(newBucketId, defaultBucketPolicy);
}
-Result Storage::deleteBucket(const PolicyBucket& bucket)
-{
- //todo
- TODO_USE_ME(bucket);
- return RESULT_OK;
+void Storage::deleteBucket(const PolicyBucketId &bucketId) {
+ // TODO: Check if bucket exists
+
+ if (bucketId == defaultPolicyBucketId) {
+ throw DefaultBucketDeletionException();
+ }
+
+ m_backend.deleteLinking(bucketId);
+ m_backend.deleteBucket(bucketId);
}
-/*
-Result Storage::listPolicy(const PolicyKey& policyKey, PolicyVector& result)
-{
- //todo
- TODO_USE_ME(policyKey);
- TODO_USE_ME(result);;
- return RESULT_OK;
+void Storage::deletePolicies(const std::vector<PolicyKeyBucket> &policies) {
+ for(const auto &policy : policies) {
+ m_backend.deletePolicy(std::get<1>(policy), std::get<0>(policy));
+ }
}
-*/
+
+} // namespace Cynara
/*
* @file Storage.h
* @author Lukasz Wojciechowski <l.wojciechowski@partner.samsung.com>
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
* @version 1.0
* @brief This file is the implementation file of log system
*/
#ifndef CYNARA_SERVICE_STORAGE_STORAGE_H
#define CYNARA_SERVICE_STORAGE_STORAGE_H
-#include <common.h>
+#include "types/pointers.h"
+#include "types/PolicyBucketId.h"
+#include "types/PolicyResult.h"
+#include "types/PolicyKey.h"
+
+#include <memory>
+#include <vector>
+#include <tuple>
+
+namespace Cynara {
+
+class StorageBackend;
+class PolicyBucket;
class Storage
{
public:
-//CHECKING policies
-//checks policies matching key and returns minimal policy type as result
- Result checkPolicy(const PolicyKey& key, ExtendedPolicyType& result);
-
-//ADMINISTRATION of polices
-//insert (or update) new policies defined in policyVector into bucket
- Result insertOrUpdatePolicy(const PolicyVector& policyVector, const PolicyBucket& bucket = defaultPolicyBucket);
-//insert (or update) new bucket (newBucket) in bucket for key with defaultPolicyKey
- Result insertOrUpdateBucket(const PolicyBucket& newBucket, const PolicyKey& key, const ExtendedPolicyType& defaultBucketPolicy, const PolicyBucket& bucket = defaultPolicyBucket);
-//remove single policy rule
- Result deletePolicy(const PolicyKey& policyKey, const PolicyBucket& bucket = defaultPolicyBucket);
-//remove bucket and all policy rules related (inside or pointing to) bucket
- Result deleteBucket(const PolicyBucket& bucket);
-
-//listing will be defined later
-// Result listPolicy(const PolicyKey& policyKey, PolicyVector& result);
+ // TODO: These tuples are ugly -- refactorize
+ typedef std::tuple<PolicyPtr, PolicyBucketId> PolicyPolicyBucket;
+ typedef std::tuple<PolicyKey, PolicyBucketId> PolicyKeyBucket;
+
+ Storage(StorageBackend &backend) : m_backend(backend) {}
+
+ PolicyResult checkPolicy(const PolicyKey &key);
+
+ void insertPolicies(const std::vector<PolicyPolicyBucket> &policies);
+ void createBucket(const PolicyBucketId &newBucketId, const PolicyResult &defaultBucketPolicy);
+ void deletePolicies(const std::vector<PolicyKeyBucket> &policies);
+ void deleteBucket(const PolicyBucketId &bucketId);
+
+protected:
+ PolicyResult minimalPolicy(const PolicyBucket &bucket);
+
+private:
+ StorageBackend &m_backend; // backend strategy
};
+} // namespace Cynara
+
#endif /* CYNARA_SERVICE_STORAGE_STORAGE_H */
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file StorageBackend.h
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Headers for StorageBackend base class
+ */
+
+#ifndef STORAGEBACKEND_H_
+#define STORAGEBACKEND_H_
+
+
+#include "types/pointers.h"
+#include "types/PolicyBucket.h"
+#include "types/PolicyBucketId.h"
+
+#include <memory>
+
+namespace Cynara {
+
+class PolicyKey;
+
+class StorageBackend {
+public:
+ virtual ~StorageBackend() {}
+
+ virtual PolicyBucket searchDefaultBucket(const PolicyKey &key) = 0;
+ virtual PolicyBucket searchBucket(const PolicyBucketId &bucket, const PolicyKey &key) = 0;
+
+ virtual void insertPolicy(const PolicyBucketId &bucket, PolicyPtr policy) = 0;
+
+ virtual void createBucket(const PolicyBucketId &bucketId, const PolicyResult &defaultPolicy) = 0;
+ virtual void deleteBucket(const PolicyBucketId &bucketId) = 0;
+
+ virtual void deletePolicy(const PolicyBucketId &bucketId, const PolicyKey &key) = 0;
+ virtual void deleteLinking(const PolicyBucketId &bucket) = 0;
+};
+
+} /* namespace Cynara */
+#endif /* STORAGEBACKEND_H_ */