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

data_lake/create_path improvements #451

Merged
merged 7 commits into from
Oct 27, 2021
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
6 changes: 6 additions & 0 deletions sdk/storage/src/data_lake/authorization_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ impl Policy<DataLakeContext> for AuthorizationPolicy {
request: &mut Request,
next: &[Arc<dyn Policy<DataLakeContext>>],
) -> PolicyResult<Response> {
if next.is_empty() {
return Err(Box::new(azure_core::PipelineError::InvalidTailPolicy(
"Authorization policies cannot be the last policy of a pipeline".to_owned(),
)));
}

let auth_header_value = format!("Bearer {}", &self.bearer_token);

request
Expand Down
3 changes: 1 addition & 2 deletions sdk/storage/src/data_lake/clients/data_lake_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ impl DataLakeClient {
let auth_policy: Arc<dyn azure_core::Policy<DataLakeContext>> =
Arc::new(AuthorizationPolicy::new(bearer_token.clone()));

let mut per_retry_policies = Vec::new();
// take care of adding the AuthorizationPolicy as **last** retry policy.
// Policies can change the url and/or the headers and the AuthorizationPolicy
// must be able to inspect them or the resulting token will be invalid.
per_retry_policies.push(auth_policy);
let per_retry_policies = vec![auth_policy];

let pipeline = Pipeline::new(
option_env!("CARGO_PKG_NAME"),
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/src/data_lake/clients/file_system_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl FileSystemClient {
options: CreatePathOptions<'_>,
) -> Result<CreatePathResponse, crate::Error> {
let mut request = self.prepare_request_pipeline(&path_name, http::Method::PUT);
let contents: DataLakeContext = DataLakeContext {};
let contents = DataLakeContext {};
let mut pipeline_context = PipelineContext::new(ctx, contents);

options.decorate_request(&mut request)?;
Expand Down
46 changes: 5 additions & 41 deletions sdk/storage/tests/data_lake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ async fn test_data_lake_file_system_functions() -> Result<(), Box<dyn Error + Se
StorageAccountClient::new_access_key(http_client.clone(), &account, &master_key);

let resource_id = "https://storage.azure.com/";
println!("getting bearer token for '{}'...", resource_id);
let bearer_token = DefaultCredential::default().get_token(resource_id).await?;
println!("token expires on {}", bearer_token.expires_on);
println!();

let data_lake_client = storage_account_client
.as_storage_client()
Expand All @@ -43,21 +40,16 @@ async fn test_data_lake_file_system_functions() -> Result<(), Box<dyn Error + Se
let mut fs_properties = Properties::new();
fs_properties.insert("AddedVia", "Azure SDK for Rust");

println!("creating file system '{}'...", &file_system_name);
let create_fs_response = file_system_client
.create()
.properties(&fs_properties)
.execute()
.await?;
println!("create file system response == {:?}", create_fs_response);
assert!(
create_fs_response.namespace_enabled,
"namespace should be enabled"
);
println!("namespace is enabled");
println!();

println!("listing file systems...");
let mut stream = Box::pin(
data_lake_client
.list()
Expand All @@ -69,14 +61,12 @@ async fn test_data_lake_file_system_functions() -> Result<(), Box<dyn Error + Se
for fs in list_fs_response.unwrap().file_systems {
if fs.name == file_system_name {
found = true;
break;
}
}
}
assert!(found, "did not find created file system");
println!("found created file system");
println!();

println!("getting file system properties...");
let get_fs_props_response = file_system_client.get_properties().execute().await?;
let properties_hashmap = get_fs_props_response.properties.hash_map();
let added_via_option = properties_hashmap.get("AddedVia");
Expand All @@ -89,51 +79,30 @@ async fn test_data_lake_file_system_functions() -> Result<(), Box<dyn Error + Se
"Azure SDK for Rust",
"did not find expected property value for: AddedVia"
);
println!("found expected file system property: AddedVia");
println!();

let file_name = "e2etest-file.txt";

println!("creating path '{}'...", file_name);
let create_path_response = file_system_client
file_system_client
.create_path(Context::default(), file_name, CreatePathOptions::default())
.await?;
println!("create path response == {:?}", create_path_response);
println!();

println!("creating path '{}' (overwrite)...", file_name);
let create_path_response = file_system_client
file_system_client
.create_path(Context::default(), file_name, CreatePathOptions::default())
.await?;
println!("create path response == {:?}", create_path_response);
println!();

println!("creating path '{}' (do not overwrite)...", file_name);
let do_not_overwrite =
CreatePathOptions::new().if_match_condition(IfMatchCondition::NotMatch("*"));
let create_path_result = file_system_client
.create_path(Context::default(), file_name, do_not_overwrite)
.await;
assert!(create_path_result.is_err());
println!(
"create path result (should fail) == {:?}",
create_path_result
);
println!();

println!("setting file system properties...");
fs_properties.insert("ModifiedBy", "Iota");
let set_fs_props_response = file_system_client
file_system_client
.set_properties(Some(&fs_properties))
.execute()
.await?;
println!(
"set file system properties response == {:?}",
set_fs_props_response
);
println!();

println!("getting file system properties...");
let get_fs_props_response = file_system_client.get_properties().execute().await?;
let properties_hashmap = get_fs_props_response.properties.hash_map();
let modified_by_option = properties_hashmap.get("ModifiedBy");
Expand All @@ -146,13 +115,8 @@ async fn test_data_lake_file_system_functions() -> Result<(), Box<dyn Error + Se
"Iota",
"did not find expected property value for: ModifiedBy"
);
println!("found expected file system property: ModifiedBy");
println!();

println!("deleting file system...");
let delete_fs_response = file_system_client.delete().execute().await?;
println!("delete file system response == {:?}", delete_fs_response);
println!();
file_system_client.delete().execute().await?;

Ok(())
}