Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
Azure Storage Core: Added ?Sized on impl (#308)
Browse files Browse the repository at this point in the history
* Added ?Sized on impl

* bumped deps
  • Loading branch information
Francesco Cogno authored Jun 30, 2020
1 parent 1036adc commit d13d5f6
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 67 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[![Build Status](https://travis-ci.org/MindFlavor/AzureSDKForRust.svg?branch=master)](https://travis-ci.org/MindFlavor/AzureSDKForRust) [![Coverage Status](https://coveralls.io/repos/MindFlavor/AzureSDKForRust/badge.svg?branch=master&service=github)](https://coveralls.io/github/MindFlavor/AzureSDKForRust?branch=master) ![stability-unstable](https://img.shields.io/badge/stability-unstable-yellow.svg)

[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/storage_blob_0.44.3) [![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/storage_blob_0.44.3) [![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/storage_blob_0.44.3)](https://github.com/MindFlavor/AzureSDKForRust/commits/master)
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/storage_core_0.44.3) [![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/storage_core_0.44.3) [![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/storage_core_0.44.3)](https://github.com/MindFlavor/AzureSDKForRust/commits/master)

[![GitHub contributors](https://img.shields.io/github/contributors/MindFlavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/graphs/contributors)

Expand Down
4 changes: 2 additions & 2 deletions azure_sdk_storage_account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "azure_sdk_storage_account"
version = "0.41.2"
version = "0.41.3"
description = "Rust wrappers around Microsoft Azure REST APIs - Blob storage account crate"
readme = "README.md"
authors = ["Francesco Cogno <[email protected]>", "Max Gortman <[email protected]>"]
Expand All @@ -16,7 +16,7 @@ edition = "2018"

[dependencies]
azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" }
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.2" }
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.3" }
chrono = "0.4"
http = "0.2"
hyper = "0.13"
Expand Down
4 changes: 2 additions & 2 deletions azure_sdk_storage_blob/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "azure_sdk_storage_blob"
version = "0.44.3"
version = "0.44.4"
description = "Rust wrappers around Microsoft Azure REST APIs - Blob storage crate"
readme = "README.md"
authors = ["Francesco Cogno <[email protected]>", "Max Gortman <[email protected]>", "Dong Liu <[email protected]>"]
Expand All @@ -16,7 +16,7 @@ edition = "2018"

[dependencies]
azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" }
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.2" }
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.3" }
md5 = "0.7"
RustyXML = "0.3"
base64 = "0.12"
Expand Down
39 changes: 35 additions & 4 deletions azure_sdk_storage_blob/examples/blob_03_boxed_client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#[macro_use]
extern crate log;

use azure_sdk_core::errors::AzureError;
use azure_sdk_core::prelude::*;
use azure_sdk_storage_blob::prelude::*;
use azure_sdk_storage_core::prelude::*;
use std::error::Error;
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -22,7 +24,23 @@ async fn main() -> Result<(), Box<dyn Error>> {
.expect("please specify blob name as command line parameter");

let client: Box<dyn Client> = Box::new(client::with_access_key(&account, &master_key));
let s_content = get_blob_box(&client, &container, &blob).await?;
println!("blob == {:?}", blob);
println!("s_content == {}", s_content);

let client: Arc<dyn Client> = Arc::new(client::with_access_key(&account, &master_key));
let s_content = get_blob_arc(client, &container, &blob).await?;
println!("blob == {:?}", blob);
println!("s_content == {}", s_content);

Ok(())
}

async fn get_blob_box<'a>(
client: &'a Box<dyn Client>,
container: &'a str,
blob: &'a str,
) -> Result<String, AzureError> {
trace!("Requesting blob");

let response = client
Expand All @@ -32,9 +50,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
.finalize()
.await?;

let s_content = String::from_utf8(response.data)?;
println!("blob == {:?}", blob);
println!("s_content == {}", s_content);
Ok(String::from_utf8(response.data)?)
}

Ok(())
async fn get_blob_arc<'a>(
client: Arc<dyn Client>,
container: &'a str,
blob: &'a str,
) -> Result<String, AzureError> {
trace!("Requesting blob");

let response = client
.get_blob()
.with_container_name(&container)
.with_blob_name(&blob)
.finalize()
.await?;

Ok(String::from_utf8(response.data)?)
}
1 change: 0 additions & 1 deletion azure_sdk_storage_blob/src/blob/block_list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::blob::{BlobBlockType, BlockWithSizeList};
use base64;
use std::borrow::Borrow;

#[derive(Default, Debug, Clone, PartialEq)]
Expand Down
1 change: 0 additions & 1 deletion azure_sdk_storage_blob/src/blob/block_with_size_list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::blob::BlobBlockType;
use crate::blob::BlobBlockWithSize;
use azure_sdk_core::errors::AzureError;
use base64;
use std::borrow::Borrow;

#[derive(Debug, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion azure_sdk_storage_blob/src/blob/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ pub(crate) fn incomplete_vector_from_response(
}

#[inline]
pub(crate) fn generate_blob_uri<'a, C>(
pub(crate) fn generate_blob_uri<C>(
t: &C,
container_name: &str,
blob_name: &str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"azure_sdk_core::lease::LeaseId",
"azure_sdk_core::prelude::*",
"hyper::{Method, StatusCode}",
"md5",
"azure_sdk_storage_core::prelude::*",
"azure_sdk_core::add_content_md5_header",
"azure_sdk_core::{Yes, No, ToAssign}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use azure_sdk_core::prelude::*;
use azure_sdk_core::{No, ToAssign, Yes};
use azure_sdk_storage_core::prelude::*;
use hyper::{Method, StatusCode};
use md5;
use std::borrow::Borrow;
use std::collections::HashMap;
use std::marker::PhantomData;
Expand Down
6 changes: 1 addition & 5 deletions azure_sdk_storage_blob/src/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,7 @@ pub(crate) fn incomplete_vector_from_container_response(
}

#[inline]
pub(crate) fn generate_container_uri<'a, C>(
c: &C,
container_name: &str,
params: Option<&str>,
) -> String
pub(crate) fn generate_container_uri<C>(c: &C, container_name: &str, params: Option<&str>) -> String
where
C: Client,
{
Expand Down
2 changes: 1 addition & 1 deletion azure_sdk_storage_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "azure_sdk_storage_core"
version = "0.44.2"
version = "0.44.3"
description = "Rust wrappers around Microsoft Azure REST APIs - Core storage crate"
readme = "README.md"
authors = ["Francesco Cogno <[email protected]>", "Max Gortman <[email protected]>", "Dong Liu <[email protected]>"]
Expand Down
12 changes: 10 additions & 2 deletions azure_sdk_storage_core/examples/box.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use azure_sdk_storage_core::prelude::*;
use std::sync::Arc;
use std::thread;

fn get_box() -> Box<dyn Client> {
Box::new(client::with_access_key("fake", "fake"))
}

fn get_box_send() -> Box<dyn Client + Send + Sync> {
Box::new(client::with_access_key("fake", "fake"))
fn get_box_send() -> Box<dyn Client> {
Box::new(client::with_access_key("send", "fake"))
}

fn get_arc() -> Arc<dyn Client> {
Arc::new(client::with_access_key("arc", "fake"))
}

pub fn main() {
Expand All @@ -19,4 +24,7 @@ pub fn main() {
println!("client_send.blob_uri() == {}", client_send.blob_uri());
});
handler.join().unwrap();

let client_arc = get_arc();
println!("client_arc.blob_uri() == {}", client_arc.blob_uri());
}
9 changes: 6 additions & 3 deletions azure_sdk_storage_core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub trait Client: Send + Sync {

impl<C> Client for Box<C>
where
C: Client,
C: Client + ?Sized,
{
fn blob_uri(&self) -> &str {
self.as_ref().blob_uri()
Expand Down Expand Up @@ -77,7 +77,10 @@ where
}
}

impl Client for Box<dyn Client> {
impl<C> Client for std::sync::Arc<C>
where
C: Client + ?Sized,
{
fn blob_uri(&self) -> &str {
self.as_ref().blob_uri()
}
Expand Down Expand Up @@ -191,7 +194,7 @@ pub fn from_connection_string(connection_string: &str) -> Result<KeyClient, Azur
format!("https://{}.table.core.windows.net", account),
)),
_ => {
return Err(AzureError::GenericErrorWithText(
Err(AzureError::GenericErrorWithText(
"Could not create a storage client from the provided connection string. Please validate that you have specified the account name and means of authentication (key, SAS, etc.)."
.to_owned(),
))
Expand Down
4 changes: 2 additions & 2 deletions azure_sdk_storage_core/src/connection_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ impl<'a> ConnectionString<'a> {
let mut file_secondary_endpoint = None;

let kv_str_pairs = connection_string
.split(";")
.split(';')
.filter(|s| !s.chars().all(char::is_whitespace));

for kv_pair_str in kv_str_pairs {
let mut kv = kv_pair_str.trim().split("=");
let mut kv = kv_pair_str.trim().split('=');
let k = match kv.next() {
Some(k) if k.chars().all(char::is_whitespace) => {
return Err(ConnectionStringError::ParsingError {
Expand Down
51 changes: 16 additions & 35 deletions azure_sdk_storage_core/src/connection_string_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ use crate::connection_string::*;

pub struct ConnectionStringBuilder<'a>(ConnectionString<'a>);

impl<'a> Default for ConnectionStringBuilder<'a> {
fn default() -> Self {
Self(ConnectionString::default())
}
}

impl<'a> ConnectionStringBuilder<'a> {
pub fn new() -> Self {
Self(ConnectionString::default())
Expand Down Expand Up @@ -32,73 +38,48 @@ impl<'a> ConnectionStringBuilder<'a> {
));
}
if let Some(endpoint_suffix) = self.0.endpoint_suffix {
kv_pairs.push(format!(
"{}={}",
ENDPOINT_SUFFIX_KEY_NAME,
endpoint_suffix
));
kv_pairs.push(format!("{}={}", ENDPOINT_SUFFIX_KEY_NAME, endpoint_suffix));
}
if let Some(default_endpoints_protocol) = self.0.default_endpoints_protocol.as_ref() {
kv_pairs.push(format!(
"{}={}",
DEFAULT_ENDPOINTS_PROTOCOL_KEY_NAME,
default_endpoints_protocol
DEFAULT_ENDPOINTS_PROTOCOL_KEY_NAME, default_endpoints_protocol
));
}
if let Some(blob_endpoint) = self.0.blob_endpoint {
kv_pairs.push(format!(
"{}={}",
BLOB_ENDPOINT_KEY_NAME,
blob_endpoint
));
kv_pairs.push(format!("{}={}", BLOB_ENDPOINT_KEY_NAME, blob_endpoint));
}
if let Some(blob_secondary_endpoint) = self.0.blob_secondary_endpoint {
kv_pairs.push(format!(
"{}={}",
BLOB_SECONDARY_ENDPOINT_KEY_NAME,
blob_secondary_endpoint
BLOB_SECONDARY_ENDPOINT_KEY_NAME, blob_secondary_endpoint
));
}
if let Some(table_endpoint) = self.0.table_endpoint {
kv_pairs.push(format!(
"{}={}",
TABLE_ENDPOINT_KEY_NAME,
table_endpoint
));
kv_pairs.push(format!("{}={}", TABLE_ENDPOINT_KEY_NAME, table_endpoint));
}
if let Some(table_secondary_endpoint) = self.0.table_secondary_endpoint {
kv_pairs.push(format!(
"{}={}",
TABLE_SECONDARY_ENDPOINT_KEY_NAME,
table_secondary_endpoint
TABLE_SECONDARY_ENDPOINT_KEY_NAME, table_secondary_endpoint
));
}
if let Some(queue_endpoint) = self.0.queue_endpoint {
kv_pairs.push(format!(
"{}={}",
QUEUE_ENDPOINT_KEY_NAME,
queue_endpoint
));
kv_pairs.push(format!("{}={}", QUEUE_ENDPOINT_KEY_NAME, queue_endpoint));
}
if let Some(queue_secondary_endpoint) = self.0.queue_secondary_endpoint {
kv_pairs.push(format!(
"{}={}",
QUEUE_SECONDARY_ENDPOINT_KEY_NAME,
queue_secondary_endpoint
QUEUE_SECONDARY_ENDPOINT_KEY_NAME, queue_secondary_endpoint
));
}
if let Some(file_endpoint) = self.0.file_endpoint {
kv_pairs.push(format!(
"{}={}",
FILE_ENDPOINT_KEY_NAME,
file_endpoint
));
kv_pairs.push(format!("{}={}", FILE_ENDPOINT_KEY_NAME, file_endpoint));
}
if let Some(file_secondary_endpoint) = self.0.file_secondary_endpoint {
kv_pairs.push(format!(
"{}={}",
FILE_SECONDARY_ENDPOINT_KEY_NAME,
file_secondary_endpoint
FILE_SECONDARY_ENDPOINT_KEY_NAME, file_secondary_endpoint
));
}

Expand Down
4 changes: 1 addition & 3 deletions azure_sdk_storage_core/src/rest_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ use crate::{ClientEndpoint, HyperClientEndpoint};
use azure_sdk_core::errors::AzureError;
use azure_sdk_core::headers;
use azure_sdk_core::util::{format_header_value, HeaderMapExt, RequestBuilderExt};
use base64;
use chrono;
use chrono::{DateTime, Utc};
use http::request::Builder;
use hyper::{self, header, HeaderMap, Method};
use ring::hmac;
use std::fmt::Write;
use url;
use url::form_urlencoded;

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -74,6 +71,7 @@ pub(crate) enum SASType {
Table,
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn generate_storage_sas<CE: ClientEndpoint>(
client_endpoint: &CE,
start: Option<&DateTime<Utc>>,
Expand Down
1 change: 1 addition & 0 deletions azure_sdk_storage_core/src/shared_access_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ pub struct SharedAccessSignature {
}

impl SharedAccessSignature {
#[allow(clippy::new_ret_no_self)]
pub fn new(key_client: &KeyClient) -> SharedAccessSignatureBuilder<No, No, No, No> {
SharedAccessSignatureBuilder::new(key_client)
}
Expand Down
4 changes: 2 additions & 2 deletions azure_sdk_storage_table/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "azure_sdk_storage_table"
version = "0.41.2"
version = "0.41.3"
description = "Rust wrappers around Microsoft Azure REST APIs - Table storage crate"
readme = "README.md"
authors = ["Francesco Cogno <[email protected]>", "gzp-crey", "Max Gortman <[email protected]>", "Dong Liu <[email protected]>"]
Expand All @@ -16,7 +16,7 @@ edition = "2018"

[dependencies]
azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" }
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.2" }
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.3" }
chrono = "0.4"
http = "0.2"
hyper = "0.13"
Expand Down

0 comments on commit d13d5f6

Please sign in to comment.