Skip to content

[datalake] add missing file and directory methods #853

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

Merged
merged 3 commits into from
Jul 5, 2022
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
30 changes: 28 additions & 2 deletions sdk/storage_datalake/src/clients/directory_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,33 @@ impl DirectoryClient {
HeadPathBuilder::new(self.clone(), self.file_system_client.context.clone())
}

pub fn set_properties(&self, _properties: Properties) -> SetFileSystemPropertiesBuilder {
todo!()
pub fn get_status(&self) -> HeadPathBuilder<Self> {
HeadPathBuilder::new(self.clone(), self.file_system_client.context.clone())
.action(PathGetPropertiesAction::GetStatus)
}

pub fn get_access_control_list(&self) -> HeadPathBuilder<Self> {
HeadPathBuilder::new(self.clone(), self.file_system_client.context.clone())
.action(PathGetPropertiesAction::GetAccessControl)
}

pub fn set_properties(&self, properties: impl Into<Properties>) -> PatchPathBuilder<Self> {
PatchPathBuilder::new(self.clone(), self.file_system_client.context.clone())
.properties(properties)
.action(PathUpdateAction::SetProperties)
}

pub fn set_access_control_list(
&self,
acl: impl Into<AccessControlList>,
recursive: bool,
) -> PatchPathBuilder<Self> {
let builder =
PatchPathBuilder::new(self.clone(), self.file_system_client.context.clone()).acl(acl);
if recursive {
builder.action(PathUpdateAction::SetAccessControlRecursive)
} else {
builder.action(PathUpdateAction::SetAccessControl)
}
}
}
11 changes: 10 additions & 1 deletion sdk/storage_datalake/src/clients/file_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,18 @@ impl FileClient {
.action(PathGetPropertiesAction::GetAccessControl)
}

pub fn set_properties(&self, properties: Properties) -> PatchPathBuilder<Self> {
pub fn set_properties(&self, properties: impl Into<Properties>) -> PatchPathBuilder<Self> {
PatchPathBuilder::new(self.clone(), self.file_system_client.context.clone())
.properties(properties)
.action(PathUpdateAction::SetProperties)
}

pub fn set_access_control_list(
&self,
acl: impl Into<AccessControlList>,
) -> PatchPathBuilder<Self> {
PatchPathBuilder::new(self.clone(), self.file_system_client.context.clone())
.acl(acl)
.action(PathUpdateAction::SetAccessControl)
}
}
4 changes: 4 additions & 0 deletions sdk/storage_datalake/src/operations/path_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ where
C: PathClient,
{
client: C,
acl: Option<AccessControlList>,
action: Option<PathUpdateAction>,
close: Option<Close>,
continuation: Option<NextMarker>,
Expand All @@ -38,6 +39,7 @@ impl<C: PathClient + 'static> PatchPathBuilder<C> {
pub(crate) fn new(client: C, context: Context) -> Self {
Self {
client,
acl: None,
action: None,
close: None,
continuation: None,
Expand All @@ -54,6 +56,7 @@ impl<C: PathClient + 'static> PatchPathBuilder<C> {
}

setters! {
acl: AccessControlList => Some(acl),
action: PathUpdateAction => Some(action),
close: Close => Some(close),
continuation: NextMarker => Some(continuation),
Expand Down Expand Up @@ -86,6 +89,7 @@ impl<C: PathClient + 'static> PatchPathBuilder<C> {

let mut request = Request::new(url, http::Method::PATCH);

request.insert_headers(&this.acl);
request.insert_headers(&this.client_request_id);
request.insert_headers(&this.properties);
request.insert_headers(&this.if_match_condition);
Expand Down
6 changes: 6 additions & 0 deletions sdk/storage_datalake/src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ impl Default for Properties {
}
}

impl From<BTreeMap<Cow<'static, str>, Cow<'static, str>>> for Properties {
fn from(value: BTreeMap<Cow<'static, str>, Cow<'static, str>>) -> Self {
Self(value)
}
}
Comment on lines +17 to +21
Copy link
Contributor Author

@roeap roeap Jun 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about providing a more flexible implementation, like

impl<T> From<T> for Properties
where
    T: Into<BTreeMap<Cow<'static, str>, Cow<'static, str>>>,
{
    fn from(value: T) -> Self {
        Self(value.into())
    }
}

however that conflicts with the TryFrom<&Headers> implementation, which needs to look into a specific header key. Not sure if this is that important here, but maybe we can remove the conflicting trait implementations since they are used to convert responses - i.e. no added convenience for the user - vs. adding convenience in the user facing methods...


impl Properties {
pub fn new() -> Self {
Self(BTreeMap::new())
Expand Down
22 changes: 22 additions & 0 deletions sdk/storage_datalake/src/request_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,25 @@ impl AppendToUrlQuery for Directory {
url.query_pairs_mut().append_pair("directory", &self.0);
}
}

#[derive(Debug, Clone)]
pub struct AccessControlList(String);

impl<S> From<S> for AccessControlList
where
S: Into<String>,
{
fn from(s: S) -> Self {
Self(s.into())
}
}

impl Header for AccessControlList {
fn name(&self) -> azure_core::headers::HeaderName {
azure_core::headers::ACL
}

fn value(&self) -> azure_core::headers::HeaderValue {
self.0.to_owned().into()
}
}