Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: implement container policies #8

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions Sources/PrivMXEndpointSwift/Inboxes/InboxApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class InboxApi{
}

/// Creates a new Inbox in the specified context.
///
/// If `policies` argument is set to `nil`, the default policies will be applied.
///
/// - Parameters:
/// - contextId: The ID of the context where the Inbox should be created.
Expand All @@ -65,6 +67,7 @@ public class InboxApi{
/// - publicMeta: Public metadata that is not encrypted.
/// - privateMeta: Private metadata that is encrypted.
/// - filesConfig: An optional configuration for file storage.
/// - policies: A set of policies for the Container.
///
/// - Throws: `PrivMXEndpointError.failedCreatingInbox` if Inbox creation fails.
///
Expand All @@ -75,7 +78,8 @@ public class InboxApi{
managers: privmx.UserWithPubKeyVector,
publicMeta: privmx.endpoint.core.Buffer,
privateMeta: privmx.endpoint.core.Buffer,
filesConfig: privmx.endpoint.inbox.FilesConfig?
filesConfig: privmx.endpoint.inbox.FilesConfig?,
policies: privmx.endpoint.core.ContainerPolicyWithoutItem? = nil
) throws -> std.string {

var optFilesConfig = privmx.OptionalInboxFilesConfig()
Expand All @@ -84,12 +88,18 @@ public class InboxApi{
optFilesConfig = privmx.makeOptional(filesConfig)
}

var optPolicies = privmx.OptionalContainerPolicyWithoutItem()
if let policies{
optPolicies = privmx.makeOptional(policies)
}

let res = api.createInbox(contextId,
users,
managers,
publicMeta,
privateMeta,
optFilesConfig)
optFilesConfig,
optPolicies)

guard res.error.value == nil else {
throw PrivMXEndpointError.failedCreatingInbox(res.error.value!)
Expand All @@ -104,6 +114,8 @@ public class InboxApi{
}

/// Updates an existing Inbox with new metadata and configuration.
///
/// If `policies` argument is set to `nil`, the default policies will be applied.
///
/// - Parameters:
/// - inboxId: The ID of the Inbox to be updated.
Expand All @@ -115,6 +127,7 @@ public class InboxApi{
/// - version: The current version of the Inbox for version control.
/// - force: Whether to force the update, ignoring version control.
/// - forceGenerateNewKey: Whether to force regeneration of a new key for the Inbox.
/// - policies: New set of policies for the Container.
///
/// - Throws: `PrivMXEndpointError.failedUpdatingInbox` if the update process fails.
public func updateInbox(
Expand All @@ -126,16 +139,21 @@ public class InboxApi{
filesConfig: privmx.endpoint.inbox.FilesConfig?,
version: Int64,
force: Bool,
forceGenerateNewKey: Bool
forceGenerateNewKey: Bool,
policies: privmx.endpoint.core.ContainerPolicyWithoutItem? = nil
) throws -> Void {


var optFilesConfig = privmx.OptionalInboxFilesConfig()

if let filesConfig{
optFilesConfig = privmx.makeOptional(filesConfig)
}

var optPolicies = privmx.OptionalContainerPolicyWithoutItem()
if let policies{
optPolicies = privmx.makeOptional(policies)
}

let res = api.updateInbox(inboxId,
users,
managers,
Expand All @@ -144,7 +162,8 @@ public class InboxApi{
optFilesConfig,
version,
force,
forceGenerateNewKey)
forceGenerateNewKey,
optPolicies)

guard res.error.value == nil else {
throw PrivMXEndpointError.failedUpdatingInbox(res.error.value!)
Expand Down
32 changes: 27 additions & 5 deletions Sources/PrivMXEndpointSwift/Stores/StoreApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ public class StoreApi{
/// Creates a new Store within a specified Context.
///
/// This method creates a new Store with specified users and managers. Note that managers must be added as users to gain access to the Store.
///
/// If `policies` argument is set to `nil`, the default policies will be applied.
///
/// - Parameters:
/// - contextId: The Context in which the Store should be created.
/// - users: A vector of users who will have access to the Store.
/// - managers: A vector of managers responsible for the Store.
/// - publicMeta: Public metadata for the Store, which will not be encrypted.
/// - privateMeta: Private metadata for the Store, which will be encrypted.
/// - policies: A set of policies for the Container.
///
/// - Throws: `PrivMXEndpointError.failedCreatingStore` if Store creation fails.
///
Expand All @@ -122,13 +125,21 @@ public class StoreApi{
users: privmx.UserWithPubKeyVector,
managers: privmx.UserWithPubKeyVector,
publicMeta: privmx.endpoint.core.Buffer,
privateMeta: privmx.endpoint.core.Buffer
privateMeta: privmx.endpoint.core.Buffer,
policies: privmx.endpoint.core.ContainerPolicy? = nil
) throws -> std.string{
let res = api.createStore(contextId,

var optPolicies = privmx.OptionalContainerPolicy()
if let policies{
optPolicies = privmx.makeOptional(policies)
}

let res = api.createStore(contextId,
users,
managers,
publicMeta,
privateMeta)
privateMeta,
optPolicies)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedCreatingStore(res.error.value!)
}
Expand All @@ -144,6 +155,8 @@ public class StoreApi{
/// Updates an existing Store.
///
/// The provided values will override the existing ones. You can also force regeneration of the Store's key if needed.
///
/// If `policies` argument is set to `nil`, the default policies will be applied.
///
/// - Parameters:
/// - storeId: The unique identifier of the Store to be updated.
Expand All @@ -154,6 +167,7 @@ public class StoreApi{
/// - privateMeta: New private metadata for the Store, which will be encrypted.
/// - force: Whether to force the update, bypassing version control.
/// - forceGenerateNewKey: Whether to generate a new key for the Store.
/// - policies: New set of policies for the Container.
///
/// - Throws: `PrivMXEndpointError.failedUpdatingStore` if updating the Store fails.
public func updateStore(
Expand All @@ -164,16 +178,24 @@ public class StoreApi{
publicMeta: privmx.endpoint.core.Buffer,
privateMeta: privmx.endpoint.core.Buffer,
force: Bool,
forceGenerateNewKey: Bool
forceGenerateNewKey: Bool,
policies: privmx.endpoint.core.ContainerPolicy? = nil
) throws -> Void {

var optPolicies = privmx.OptionalContainerPolicy()
if let policies{
optPolicies = privmx.makeOptional(policies)
}

let res = api.updateStore(storeId,
users,
managers,
publicMeta,
privateMeta,
version,
force,
forceGenerateNewKey)
forceGenerateNewKey,
optPolicies)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedUpdatingStore(res.error.value!)
}
Expand Down
30 changes: 26 additions & 4 deletions Sources/PrivMXEndpointSwift/Threads/ThreadApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ public class ThreadApi{
///
/// This method creates a new Thread in the specified context, assigning users and managers to it. Note that managers must be added explicitly as users to access the Thread.
///
/// If `policies` argument is set to `nil`, the default policies will be applied.
///
/// - Parameters:
/// - contextId: The context in which the Thread should be created.
/// - users: A vector of users who will have access to the Thread.
/// - managers: A vector of managers responsible for the Thread.
/// - publicMeta: Public metadata for the Thread, which will not be encrypted.
/// - privateMeta: Private metadata for the Thread, which will be encrypted.
/// - policies: A set of policies for the Container.
///
/// - Throws: `PrivMXEndpointError.failedCreatingThread` if the Thread creation fails.
///
Expand All @@ -68,13 +71,21 @@ public class ThreadApi{
users: privmx.UserWithPubKeyVector,
managers: privmx.UserWithPubKeyVector,
publicMeta: privmx.endpoint.core.Buffer,
privateMeta: privmx.endpoint.core.Buffer
privateMeta: privmx.endpoint.core.Buffer,
policies: privmx.endpoint.core.ContainerPolicy? = nil
)throws -> std.string {

var optPolicies = privmx.OptionalContainerPolicy()
if let policies{
optPolicies = privmx.makeOptional(policies)
}

let res = api.createThread(contextId,
users,
managers,
publicMeta,
privateMeta)
privateMeta,
optPolicies)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedCreatingThread(res.error.value!)
}
Expand Down Expand Up @@ -115,6 +126,8 @@ public class ThreadApi{
///
/// This method updates the metadata, users, and managers of a Thread. The update can be forced, and a new key can be generated if needed.
///
/// If `policies` argument is set to `nil`, the default policies will be applied.
///
/// - Parameters:
/// - threadId: The unique identifier of the Thread to be updated.
/// - version: The current version of the Thread to ensure version consistency.
Expand All @@ -124,6 +137,7 @@ public class ThreadApi{
/// - privateMeta: New private metadata for the Thread, which will be encrypted.
/// - force: Whether to force the update, bypassing version control.
/// - forceGenerateNewKey: Whether to generate a new key for the Thread.
/// - policies: A new set of policies for the Container.
///
/// - Throws: `PrivMXEndpointError.failedUpdatingThread` if the update process fails.
public func updateThread(
Expand All @@ -134,16 +148,24 @@ public class ThreadApi{
publicMeta: privmx.endpoint.core.Buffer,
privateMeta: privmx.endpoint.core.Buffer,
force: Bool,
forceGenerateNewKey: Bool
forceGenerateNewKey: Bool,
policies: privmx.endpoint.core.ContainerPolicy? = nil
) throws -> Void {

var optPolicies = privmx.OptionalContainerPolicy()
if let policies{
optPolicies = privmx.makeOptional(policies)
}

let res = api.updateThread(threadId,
users,
managers,
publicMeta,
privateMeta,
version,
force,
forceGenerateNewKey)
forceGenerateNewKey,
optPolicies)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedUpdatingThread(res.error.value!)
}
Expand Down
9 changes: 6 additions & 3 deletions Sources/PrivMXEndpointSwiftNative/NativeInboxApiWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ ResultWithError<std::string> NativeInboxApiWrapper::createInbox(const std::strin
const UserWithPubKeyVector& managers,
const endpoint::core::Buffer& publicMeta,
const endpoint::core::Buffer& privateMeta,
const OptionalInboxFilesConfig& filesConfig) {
const OptionalInboxFilesConfig& filesConfig,
const OptionalContainerPolicyWithoutItem& policies) {
ResultWithError<std::string> res;
try {
res.result = getapi()->createInbox(contextId,
Expand Down Expand Up @@ -90,7 +91,8 @@ ResultWithError<nullptr_t> NativeInboxApiWrapper::updateInbox(const std::string&
const OptionalInboxFilesConfig& filesConfig,
const int64_t version,
const bool force,
const bool forceGenerateNewKey){
const bool forceGenerateNewKey,
const OptionalContainerPolicyWithoutItem& policies){
ResultWithError<nullptr_t> res;
try {
getapi()->updateInbox(inboxId,
Expand All @@ -101,7 +103,8 @@ ResultWithError<nullptr_t> NativeInboxApiWrapper::updateInbox(const std::string&
filesConfig,
version,
force,
forceGenerateNewKey);
forceGenerateNewKey,
policies);
}catch(core::Exception& err){
res.error = {
.name = err.getName(),
Expand Down
16 changes: 12 additions & 4 deletions Sources/PrivMXEndpointSwiftNative/NativeStoreApiWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ ResultWithError<std::string> NativeStoreApiWrapper::createStore(const std::strin
const UserWithPubKeyVector& users,
const UserWithPubKeyVector& managers,
const core::Buffer& publicMeta,
const core::Buffer& privateMeta){
const core::Buffer& privateMeta,
const OptionalContainerPolicy& policies){
ResultWithError<std::string> res;
try{
res.result = getapi()->createStore(contextId, users, managers, publicMeta,privateMeta);
res.result = getapi()->createStore(contextId,
users,
managers,
publicMeta,
privateMeta,
policies);
}catch(core::Exception& err){
res.error = {
.name = err.getName(),
Expand Down Expand Up @@ -131,7 +137,8 @@ ResultWithError<std::nullptr_t> NativeStoreApiWrapper::updateStore(const std::st
const core::Buffer& privateMeta,
const int64_t version,
const bool force,
const bool forceGenerateNewKey){
const bool forceGenerateNewKey,
const OptionalContainerPolicy& policies){
ResultWithError<std::nullptr_t> res;
try{
getapi()->updateStore(storeId,
Expand All @@ -141,7 +148,8 @@ ResultWithError<std::nullptr_t> NativeStoreApiWrapper::updateStore(const std::st
privateMeta,
version,
force,
forceGenerateNewKey);
forceGenerateNewKey,
policies);
}catch(core::Exception& err){
res.error = {
.name = err.getName(),
Expand Down
12 changes: 8 additions & 4 deletions Sources/PrivMXEndpointSwiftNative/NativeThreadApiWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ ResultWithError<std::string> NativeThreadApiWrapper::createThread(const std::str
const UserWithPubKeyVector& users,
const UserWithPubKeyVector& managers,
const core::Buffer& publicMeta,
const core::Buffer& privateMeta){
const core::Buffer& privateMeta,
const OptionalContainerPolicy& policies){
ResultWithError<std::string> res;
try {
res.result = getapi()->createThread(contextId,
users,
managers,
publicMeta,
privateMeta);
privateMeta,
policies);
}catch(core::Exception& err){
res.error = {
.name = err.getName(),
Expand Down Expand Up @@ -266,7 +268,8 @@ ResultWithError<std::nullptr_t> NativeThreadApiWrapper::updateThread(const std::
const core::Buffer& privateMeta,
const int64_t version,
const bool force,
const bool generateNewKeyId){
const bool generateNewKeyId,
const OptionalContainerPolicy& policies){
ResultWithError<std::nullptr_t> res;
try {
getapi()->updateThread(threadId,
Expand All @@ -276,7 +279,8 @@ ResultWithError<std::nullptr_t> NativeThreadApiWrapper::updateThread(const std::
privateMeta,
version,
force,
generateNewKeyId);
generateNewKeyId,
policies);
}catch(core::Exception& err){
res.error = {
.name = err.getName(),
Expand Down
Loading