Skip to content

Commit

Permalink
try again
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Aug 22, 2024
1 parent 4ec13d8 commit 4ed043a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/ffi/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ pub extern "C" fn askar_store_copy(
key_method: FfiStr<'_>,
pass_key: FfiStr<'_>,
recreate: i8,
tenant_profile: FfiStr<'_>,
cb: Option<extern "C" fn(cb_id: CallbackId, err: ErrorCode, handle: StoreHandle)>,
cb_id: CallbackId,
) -> ErrorCode {
Expand All @@ -482,6 +483,7 @@ pub extern "C" fn askar_store_copy(
None => StoreKeyMethod::default()
};
let pass_key = PassKey::from(pass_key.as_opt_str()).into_owned();
let tenant_profile_str = tenant_profile.into_opt_string();
let cb = EnsureCallback::new(move |result|
match result {
Ok(handle) => cb(cb_id, ErrorCode::Success, handle),
Expand All @@ -491,7 +493,7 @@ pub extern "C" fn askar_store_copy(
spawn_ok(async move {
let result = async move {
let store = handle.load().await?;
let copied = store.copy_to(target_uri.as_str(), key_method, pass_key.as_ref(), recreate != 0).await?;
let copied = store.copy_to(target_uri.as_str(), key_method, pass_key.as_ref(), recreate != 0, tenant_profile_str).await?;
debug!("Copied store {}", handle);
Ok(StoreHandle::create(copied).await)
}.await;
Expand Down
25 changes: 18 additions & 7 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,27 @@ impl Store {
key_method: StoreKeyMethod,
pass_key: PassKey<'_>,
recreate: bool,
tenant_profile: Option<String>,
) -> Result<Self, Error> {
let default_profile = self.get_default_profile().await?;
let profile_ids = self.list_profiles().await?;
let target = target_url
.provision_backend(key_method, pass_key, Some(default_profile), recreate)
if tenant_profile.as_ref().map_or(false, |s| s.is_empty()) {
let tenant = tenant_profile.unwrap_or_else(|| String::from("default value"));
let tenant_copy = tenant.clone();
let target = target_url
.provision_backend(key_method, pass_key, Some(tenant), recreate)
.await?;
for profile in profile_ids {
copy_profile(&self.0, &target, &profile, &profile).await?;
copy_profile(&self.0, &target, &tenant_copy, &tenant_copy).await?;
Ok(Self::new(target))
} else {
let default_profile = self.get_default_profile().await?;
let profile_ids = self.list_profiles().await?;
let target = target_url
.provision_backend(key_method, pass_key, Some(default_profile), recreate)
.await?;
for profile in profile_ids {
copy_profile(&self.0, &target, &profile, &profile).await?;
}
Ok(Self::new(target))
}
Ok(Self::new(target))
}

/// Create a new profile with the given profile name
Expand Down
1 change: 1 addition & 0 deletions tests/store_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn store_copy() {
StoreKeyMethod::RawKey,
pass_key_copy,
true,
None
)
.await
.expect("Error copying store");
Expand Down
25 changes: 12 additions & 13 deletions wrappers/python/aries_askar/bindings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
import asyncio
import json
import logging

from ctypes import POINTER, byref, c_int8, c_int32, c_int64
from typing import Optional, Sequence, Union

from ..types import EntryOperation, KeyAlg, KeyBackend, SeedMethod

from .handle import (
EntryListHandle,
KeyEntryListHandle,
LocalKeyHandle,
ScanHandle,
SessionHandle,
StoreHandle,
StringListHandle,
)
from .lib import (
AeadParams,
ByteBuffer,
Expand All @@ -20,16 +27,6 @@
Lib,
StrBuffer,
)
from .handle import (
EntryListHandle,
KeyEntryListHandle,
LocalKeyHandle,
ScanHandle,
SessionHandle,
StoreHandle,
StringListHandle,
)


LIB = Lib()
LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -228,16 +225,18 @@ async def store_copy(
key_method: Optional[str] = None,
pass_key: Optional[str] = None,
recreate: bool = False,
tenant_profile: Optional[str] = None,
) -> StoreHandle:
"""Copy the Store contents to a new location."""
return await invoke_async(
"askar_store_copy",
(StoreHandle, FfiStr, FfiStr, FfiStr, c_int8),
(StoreHandle, FfiStr, FfiStr, FfiStr, c_int8, FfiStr),
handle,
target_uri,
key_method and key_method.lower(),
pass_key,
recreate,
tenant_profile,
return_type=StoreHandle,
)

Expand Down
4 changes: 2 additions & 2 deletions wrappers/python/aries_askar/store.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Handling of Store instances."""

import json

from typing import Optional, Sequence, Union

from cached_property import cached_property
Expand Down Expand Up @@ -439,11 +438,12 @@ async def copy_to(
pass_key: str = None,
*,
recreate: bool = False,
tenant_profile: str = None,
) -> "Store":
"""Copy the store contents to a new location."""
return Store(
await bindings.store_copy(
self._handle, target_uri, key_method, pass_key, recreate
self._handle, target_uri, key_method, pass_key, recreate, tenant_profile
),
target_uri,
)
Expand Down
2 changes: 1 addition & 1 deletion wrappers/python/aries_askar/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""aries_askar library wrapper version."""

__version__ = "0.3.3b10"
__version__ = "0.3.3b11"
2 changes: 1 addition & 1 deletion wrappers/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools import find_packages, setup

PACKAGE_NAME = "aries_askar_jamshale"
VERSION = "0.3.3b10"
VERSION = "0.3.3b11"

with open(os.path.abspath("./README.md"), "r") as fh:
long_description = fh.read()
Expand Down

0 comments on commit 4ed043a

Please sign in to comment.