diff --git a/sdk/core/src/auth.rs b/sdk/core/src/auth.rs index 42266b7d76..bf5252d6e2 100644 --- a/sdk/core/src/auth.rs +++ b/sdk/core/src/auth.rs @@ -2,17 +2,21 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; -use std::fmt::Debug; +use std::{borrow::Cow, fmt::Debug}; #[derive(Debug, Clone, Deserialize, Serialize)] -pub struct AccessToken(String); +pub struct AccessToken(Cow<'static, str>); impl AccessToken { - pub fn new(access_token: String) -> Self { - Self(access_token) + pub fn new(access_token: T) -> Self + where + T: Into>, + { + Self(access_token.into()) } + pub fn secret(&self) -> &str { - self.0.as_str() + &self.0 } } diff --git a/sdk/core/src/headers/mod.rs b/sdk/core/src/headers/mod.rs index e8be2d8432..6fba959a2b 100644 --- a/sdk/core/src/headers/mod.rs +++ b/sdk/core/src/headers/mod.rs @@ -214,7 +214,7 @@ impl HeaderValue { Self(std::borrow::Cow::Borrowed(s)) } - fn from_cow(c: C) -> Self + pub fn from_cow(c: C) -> Self where C: Into>, { @@ -299,6 +299,7 @@ pub const IF_UNMODIFIED_SINCE: HeaderName = HeaderName::from_static("if-unmodifi pub const IF_SEQUENCE_NUMBER_EQ: HeaderName = HeaderName::from_static("x-ms-if-sequence-number-eq"); pub const IF_SEQUENCE_NUMBER_LE: HeaderName = HeaderName::from_static("x-ms-if-sequence-number-le"); pub const IF_SEQUENCE_NUMBER_LT: HeaderName = HeaderName::from_static("x-ms-if-sequence-number-lt"); +pub const IF_TAGS: HeaderName = HeaderName::from_static("x-ms-if-tags"); pub const ITEM_COUNT: HeaderName = HeaderName::from_static("x-ms-item-count"); pub const ITEM_TYPE: HeaderName = HeaderName::from_static("x-ms-item-type"); pub const KEEP_ALIVE: HeaderName = HeaderName::from_static("keep-alive"); diff --git a/sdk/core/src/macros.rs b/sdk/core/src/macros.rs index 708d60924d..7cbe0d27a7 100644 --- a/sdk/core/src/macros.rs +++ b/sdk/core/src/macros.rs @@ -290,6 +290,103 @@ macro_rules! future { }; } +/// The following macro invocation: +/// ``` +/// # #[macro_use] extern crate azure_core; +/// request_header!( +/// #[doc="builds a client request id header"] +/// ClientRequestId, CLIENT_REQUEST_ID, +/// ); +/// ``` +/// Turns into a Header value used to construct requests. +#[macro_export] +macro_rules! request_header { + ($(#[$outer:meta])* $name:ident, $header:ident, $(($variant:ident, $value:expr)), *) => { + #[derive(Debug, Clone)] + $(#[$outer])* + pub struct $name(std::borrow::Cow<'static, str>); + + impl $name { + $( + pub const $variant: $name = $name::from_static($value); + )* + + pub fn new(s: S) -> Self + where + S: Into>, + { + Self(s.into()) + } + + pub const fn from_static(s: &'static str) -> Self { + Self(std::borrow::Cow::Borrowed(s)) + } + } + + impl From for $name + where + S: Into>, + { + fn from(s: S) -> Self { + Self::new(s) + } + } + + impl $crate::headers::Header for $name { + fn name(&self) -> $crate::headers::HeaderName { + $crate::headers::$header + } + + fn value(&self) -> $crate::headers::HeaderValue { + $crate::headers::HeaderValue::from_cow(self.0.clone()) + } + } + }; +} + +/// The following macro invocation: +/// ``` +/// # #[macro_use] extern crate azure_core; +/// request_query_option!(Prefix, "prefix"); +/// ``` +/// Turns into a request query option used to construct requests +#[macro_export] +macro_rules! request_query_option { + ($(#[$outer:meta])* $name:ident, $option:expr) => { + #[derive(Debug, Clone)] + $(#[$outer])* + pub struct $name(std::borrow::Cow<'static, str>); + + impl $name { + pub fn new(s: S) -> Self + where + S: Into>, + { + Self(s.into()) + } + + pub const fn from_static(s: &'static str) -> Self { + Self(std::borrow::Cow::Borrowed(s)) + } + } + + impl From for $name + where + S: Into>, + { + fn from(s: S) -> Self { + Self::new(s) + } + } + + impl $crate::AppendToUrlQuery for $name { + fn append_to_url_query(&self, url: &mut url::Url) { + url.query_pairs_mut().append_pair($option, &self.0); + } + } + }; +} + /// The following macro invocation: /// ``` /// # #[macro_use] extern crate azure_core; diff --git a/sdk/core/src/request_options/accept.rs b/sdk/core/src/request_options/accept.rs deleted file mode 100644 index 5fb2e5818c..0000000000 --- a/sdk/core/src/request_options/accept.rs +++ /dev/null @@ -1,39 +0,0 @@ -use crate::headers::{self, Header}; - -/// Advertises which content types the client is able to understand. -/// -/// The Accept request HTTP header advertises which content types, expressed -/// as MIME types, the client is able to understand. Using content -/// negotiation, the server then selects one of the proposals, uses it and -/// informs the client of its choice with the Content-Type response header. -/// Browsers set adequate values for this header depending of the context -/// where the request is done: when fetching a CSS stylesheet a different -/// value is set for the request than when fetching an image, video or a -/// script. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct Accept(String); - -impl Accept { - pub fn new(s: String) -> Self { - Self(s) - } -} - -impl From for Accept -where - S: Into, -{ - fn from(s: S) -> Self { - Self(s.into()) - } -} - -impl Header for Accept { - fn name(&self) -> headers::HeaderName { - headers::ACCEPT - } - - fn value(&self) -> headers::HeaderValue { - self.0.clone().into() - } -} diff --git a/sdk/core/src/request_options/accept_encoding.rs b/sdk/core/src/request_options/accept_encoding.rs deleted file mode 100644 index 19c2d8dc00..0000000000 --- a/sdk/core/src/request_options/accept_encoding.rs +++ /dev/null @@ -1,40 +0,0 @@ -use crate::headers::{self, Header}; - -/// Advertises which content encoding the client is able to understand. -/// -/// The Accept-Encoding request HTTP header advertises which content -/// encoding, usually a compression algorithm, the client is able to -/// understand. Using content negotiation, the server selects one of the -/// proposals, uses it and informs the client of its choice with the -/// Content-Encoding response header. -/// -/// Even if both the client and the server supports the same compression -/// algorithms, the server may choose not to compress the body of a -/// response, if the identity value is also acceptable. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct AcceptEncoding(String); - -impl AcceptEncoding { - pub fn new(s: String) -> Self { - Self(s) - } -} - -impl From for AcceptEncoding -where - S: Into, -{ - fn from(s: S) -> Self { - Self(s.into()) - } -} - -impl Header for AcceptEncoding { - fn name(&self) -> headers::HeaderName { - headers::ACCEPT_ENCODING - } - - fn value(&self) -> headers::HeaderValue { - self.0.clone().into() - } -} diff --git a/sdk/core/src/request_options/activity_id.rs b/sdk/core/src/request_options/activity_id.rs deleted file mode 100644 index e5e1a44379..0000000000 --- a/sdk/core/src/request_options/activity_id.rs +++ /dev/null @@ -1,29 +0,0 @@ -use crate::headers::{self, Header}; - -#[derive(Debug, Clone)] -pub struct ActivityId(String); - -impl ActivityId { - pub fn new(id: String) -> Self { - Self(id) - } -} - -impl From for ActivityId -where - S: Into, -{ - fn from(s: S) -> Self { - Self(s.into()) - } -} - -impl Header for ActivityId { - fn name(&self) -> headers::HeaderName { - headers::ACTIVITY_ID - } - - fn value(&self) -> headers::HeaderValue { - self.0.clone().into() - } -} diff --git a/sdk/core/src/request_options/app.rs b/sdk/core/src/request_options/app.rs deleted file mode 100644 index e2f3bc20f7..0000000000 --- a/sdk/core/src/request_options/app.rs +++ /dev/null @@ -1,30 +0,0 @@ -use crate::headers::{self, Header}; - -/// The (friendly) name of the application making the request -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct App(String); - -impl App { - pub fn new(s: String) -> Self { - Self(s) - } -} - -impl From for App -where - S: Into, -{ - fn from(s: S) -> Self { - Self(s.into()) - } -} - -impl Header for App { - fn name(&self) -> headers::HeaderName { - headers::APP - } - - fn value(&self) -> headers::HeaderValue { - self.0.clone().into() - } -} diff --git a/sdk/core/src/request_options/client_request_id.rs b/sdk/core/src/request_options/client_request_id.rs deleted file mode 100644 index 646cd8eadb..0000000000 --- a/sdk/core/src/request_options/client_request_id.rs +++ /dev/null @@ -1,31 +0,0 @@ -use crate::headers; -use crate::Header; - -/// A unique identifier for the request -#[derive(Debug, Clone)] -pub struct ClientRequestId(String); - -impl ClientRequestId { - pub fn new(client_request_id: String) -> Self { - Self(client_request_id) - } -} - -impl From for ClientRequestId -where - S: Into, -{ - fn from(s: S) -> Self { - Self(s.into()) - } -} - -impl Header for ClientRequestId { - fn name(&self) -> headers::HeaderName { - headers::CLIENT_REQUEST_ID - } - - fn value(&self) -> headers::HeaderValue { - self.0.clone().into() - } -} diff --git a/sdk/core/src/request_options/client_version.rs b/sdk/core/src/request_options/client_version.rs deleted file mode 100644 index 9cb0ac0205..0000000000 --- a/sdk/core/src/request_options/client_version.rs +++ /dev/null @@ -1,31 +0,0 @@ -use crate::headers; -use crate::Header; - -/// The (friendly) version identifier for the client making the request -#[derive(Debug, Clone)] -pub struct ClientVersion(String); - -impl ClientVersion { - pub fn new(client_request_id: String) -> Self { - Self(client_request_id) - } -} - -impl From for ClientVersion -where - S: Into, -{ - fn from(s: S) -> Self { - Self(s.into()) - } -} - -impl Header for ClientVersion { - fn name(&self) -> headers::HeaderName { - headers::CLIENT_VERSION - } - - fn value(&self) -> headers::HeaderValue { - self.0.clone().into() - } -} diff --git a/sdk/core/src/request_options/content_disposition.rs b/sdk/core/src/request_options/content_disposition.rs deleted file mode 100644 index 40bca05dbb..0000000000 --- a/sdk/core/src/request_options/content_disposition.rs +++ /dev/null @@ -1,42 +0,0 @@ -use crate::headers::{self, Header}; - -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct ContentDisposition(std::borrow::Cow<'static, str>); - -impl ContentDisposition { - pub fn as_str(&self) -> &str { - self.0.as_ref() - } - - pub const fn from_static(s: &'static str) -> Self { - Self(std::borrow::Cow::Borrowed(s)) - } -} - -impl From<&'static str> for ContentDisposition { - fn from(s: &'static str) -> Self { - Self::from_static(s) - } -} - -impl From for ContentDisposition { - fn from(s: String) -> Self { - Self(std::borrow::Cow::Owned(s)) - } -} - -impl From<&String> for ContentDisposition { - fn from(s: &String) -> Self { - Self(std::borrow::Cow::Owned(s.clone())) - } -} - -impl Header for ContentDisposition { - fn name(&self) -> headers::HeaderName { - headers::CONTENT_DISPOSITION - } - - fn value(&self) -> headers::HeaderValue { - self.0.to_string().into() - } -} diff --git a/sdk/core/src/request_options/content_encoding.rs b/sdk/core/src/request_options/content_encoding.rs deleted file mode 100644 index 22e2a5bf02..0000000000 --- a/sdk/core/src/request_options/content_encoding.rs +++ /dev/null @@ -1,42 +0,0 @@ -use crate::headers::{self, Header}; - -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct ContentEncoding(std::borrow::Cow<'static, str>); - -impl ContentEncoding { - pub fn as_str(&self) -> &str { - self.0.as_ref() - } - - pub const fn from_static(s: &'static str) -> Self { - Self(std::borrow::Cow::Borrowed(s)) - } -} - -impl From<&'static str> for ContentEncoding { - fn from(s: &'static str) -> Self { - Self::from_static(s) - } -} - -impl From for ContentEncoding { - fn from(s: String) -> Self { - Self(std::borrow::Cow::Owned(s)) - } -} - -impl From<&String> for ContentEncoding { - fn from(s: &String) -> Self { - Self(std::borrow::Cow::Owned(s.clone())) - } -} - -impl Header for ContentEncoding { - fn name(&self) -> headers::HeaderName { - headers::CONTENT_ENCODING - } - - fn value(&self) -> headers::HeaderValue { - self.0.to_string().into() - } -} diff --git a/sdk/core/src/request_options/content_language.rs b/sdk/core/src/request_options/content_language.rs deleted file mode 100644 index c4138fa50b..0000000000 --- a/sdk/core/src/request_options/content_language.rs +++ /dev/null @@ -1,42 +0,0 @@ -use crate::headers::{self, Header}; - -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct ContentLanguage(std::borrow::Cow<'static, str>); - -impl ContentLanguage { - pub fn as_str(&self) -> &str { - self.0.as_ref() - } - - pub const fn from_static(s: &'static str) -> Self { - Self(std::borrow::Cow::Borrowed(s)) - } -} - -impl From<&'static str> for ContentLanguage { - fn from(s: &'static str) -> Self { - Self::from_static(s) - } -} - -impl From for ContentLanguage { - fn from(s: String) -> Self { - Self(std::borrow::Cow::Owned(s)) - } -} - -impl From<&String> for ContentLanguage { - fn from(s: &String) -> Self { - Self(std::borrow::Cow::Owned(s.clone())) - } -} - -impl Header for ContentLanguage { - fn name(&self) -> headers::HeaderName { - headers::CONTENT_LANGUAGE - } - - fn value(&self) -> headers::HeaderValue { - self.0.to_string().into() - } -} diff --git a/sdk/core/src/request_options/content_type.rs b/sdk/core/src/request_options/content_type.rs deleted file mode 100644 index c876cf10e8..0000000000 --- a/sdk/core/src/request_options/content_type.rs +++ /dev/null @@ -1,47 +0,0 @@ -use crate::headers::{self, Header, HeaderValue}; - -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct ContentType(HeaderValue); - -impl ContentType { - pub const APPLICATION_JSON: ContentType = - ContentType(HeaderValue::from_static("application/json")); - - pub fn as_str(&self) -> &str { - self.0.as_str() - } -} - -impl From<&'static str> for ContentType { - fn from(s: &'static str) -> Self { - Self(s.into()) - } -} - -impl From for ContentType { - fn from(s: String) -> Self { - Self(s.into()) - } -} - -impl From<&String> for ContentType { - fn from(s: &String) -> Self { - Self(s.into()) - } -} - -impl ContentType { - pub fn new(s: impl Into) -> Self { - s.into() - } -} - -impl Header for ContentType { - fn name(&self) -> headers::HeaderName { - headers::CONTENT_TYPE - } - - fn value(&self) -> headers::HeaderValue { - self.0.clone() - } -} diff --git a/sdk/core/src/request_options/continuation.rs b/sdk/core/src/request_options/continuation.rs deleted file mode 100644 index 81af06395b..0000000000 --- a/sdk/core/src/request_options/continuation.rs +++ /dev/null @@ -1,26 +0,0 @@ -use crate::{headers, Header}; - -#[derive(Clone, Debug)] -pub struct Continuation(std::borrow::Cow<'static, str>); - -impl From for Continuation { - fn from(s: String) -> Self { - Self(s.into()) - } -} - -impl From<&'static str> for Continuation { - fn from(s: &'static str) -> Self { - Self(s.into()) - } -} - -impl Header for Continuation { - fn name(&self) -> headers::HeaderName { - headers::CONTINUATION - } - - fn value(&self) -> headers::HeaderValue { - self.0.clone().into_owned().into() - } -} diff --git a/sdk/core/src/request_options/delimiter.rs b/sdk/core/src/request_options/delimiter.rs deleted file mode 100644 index 689538aefe..0000000000 --- a/sdk/core/src/request_options/delimiter.rs +++ /dev/null @@ -1,23 +0,0 @@ -use crate::AppendToUrlQuery; - -#[derive(Debug, Clone)] -pub struct Delimiter(String); - -impl AppendToUrlQuery for Delimiter { - fn append_to_url_query(&self, url: &mut url::Url) { - url.query_pairs_mut() - .append_pair("delimiter", self.0.as_ref()); - } -} - -impl From<&str> for Delimiter { - fn from(delimiter: &str) -> Self { - Self(delimiter.into()) - } -} - -impl From for Delimiter { - fn from(delimiter: String) -> Self { - Self(delimiter) - } -} diff --git a/sdk/core/src/request_options/mod.rs b/sdk/core/src/request_options/mod.rs index 19ccfb6355..e9cc6463d8 100644 --- a/sdk/core/src/request_options/mod.rs +++ b/sdk/core/src/request_options/mod.rs @@ -1,17 +1,5 @@ -mod accept; -mod accept_encoding; -mod activity_id; -mod app; -mod client_request_id; -mod client_version; -mod content_disposition; -mod content_encoding; -mod content_language; mod content_length; mod content_range; -mod content_type; -mod continuation; -mod delimiter; mod if_match_condition; mod if_modified_since; mod if_modified_since_condition; @@ -24,31 +12,15 @@ mod max_item_count; mod max_results; mod metadata; mod next_marker; -mod prefix; mod proposed_lease_id; mod range; mod sequence_number; mod sequence_number_condition; mod source_lease_id; mod timeout; -mod user; -mod user_agent; -mod version; -pub use accept::Accept; -pub use accept_encoding::AcceptEncoding; -pub use activity_id::ActivityId; -pub use app::App; -pub use client_request_id::ClientRequestId; -pub use client_version::ClientVersion; -pub use content_disposition::ContentDisposition; -pub use content_encoding::ContentEncoding; -pub use content_language::ContentLanguage; pub use content_length::ContentLength; pub use content_range::ContentRange; -pub use content_type::*; -pub use continuation::Continuation; -pub use delimiter::Delimiter; pub use if_match_condition::IfMatchCondition; pub use if_modified_since::IfModifiedSince; pub use if_modified_since_condition::IfModifiedSinceCondition; @@ -61,13 +33,74 @@ pub use max_item_count::MaxItemCount; pub use max_results::MaxResults; pub use metadata::Metadata; pub use next_marker::NextMarker; -pub use prefix::Prefix; pub use proposed_lease_id::ProposedLeaseId; pub use range::Range; pub use sequence_number::SequenceNumber; pub use sequence_number_condition::SequenceNumberCondition; pub use source_lease_id::SourceLeaseId; pub use timeout::Timeout; -pub use user::User; -pub use user_agent::UserAgent; -pub use version::Version; + +request_header!( + #[doc = "Advertises which content encoding the client is able to understand. + +The Accept-Encoding request HTTP header advertises which content +encoding, usually a compression algorithm, the client is able to +understand. Using content negotiation, the server selects one of the +proposals, uses it and informs the client of its choice with the +Content-Encoding response header. + +Even if both the client and the server supports the same compression +algorithms, the server may choose not to compress the body of a +response, if the identity value is also acceptable. +"] + AcceptEncoding, + ACCEPT_ENCODING, +); +request_header!( + #[doc = "The (friendly) version identifier for the client making the request"] + ClientVersion, + CLIENT_VERSION, +); +request_header!( + #[doc = "The Content Type indicates the media type of the request body"] + ContentType, + CONTENT_TYPE, + (APPLICATION_JSON, "application/json") +); +request_header!( + #[doc = "Advertises which content types the client is able to understand. + +The Accept request HTTP header advertises which content types, expressed +as MIME types, the client is able to understand. Using content +negotiation, the server then selects one of the proposals, uses it and +informs the client of its choice with the Content-Type response header. +Browsers set adequate values for this header depending of the context +where the request is done: when fetching a CSS stylesheet a different +value is set for the request than when fetching an image, video or a +script. +"] + Accept, + ACCEPT, +); +request_header!(ActivityId, ACTIVITY_ID,); +request_header!(App, APP,); +request_header!(ClientRequestId, CLIENT_REQUEST_ID,); +request_header!(ContentDisposition, CONTENT_DISPOSITION,); +request_header!(ContentEncoding, CONTENT_ENCODING,); +request_header!(ContentLanguage, CONTENT_LANGUAGE,); +request_header!(Continuation, CONTINUATION,); +request_header!(IfTags, IF_TAGS,); +request_header!(UserAgent, USER_AGENT,); +request_header!( + #[doc = "The (friendly) name of the user making the request"] + User, + USER, +); +request_header!(Version, VERSION,); + +request_query_option!(Prefix, "prefix"); +request_query_option!( + #[doc = "Set delimiter for the request"] + Delimiter, + "delimiter" +); diff --git a/sdk/core/src/request_options/prefix.rs b/sdk/core/src/request_options/prefix.rs deleted file mode 100644 index df88b4b25d..0000000000 --- a/sdk/core/src/request_options/prefix.rs +++ /dev/null @@ -1,28 +0,0 @@ -use crate::AppendToUrlQuery; - -#[derive(Debug, Clone)] -pub struct Prefix(String); - -impl Prefix { - pub fn new(prefix: String) -> Self { - Self(prefix) - } -} - -impl AppendToUrlQuery for Prefix { - fn append_to_url_query(&self, url: &mut url::Url) { - url.query_pairs_mut().append_pair("prefix", &self.0); - } -} - -impl From for Prefix { - fn from(s: String) -> Self { - Self(s) - } -} - -impl From<&str> for Prefix { - fn from(s: &str) -> Self { - Self(s.into()) - } -} diff --git a/sdk/core/src/request_options/user.rs b/sdk/core/src/request_options/user.rs deleted file mode 100644 index 6980c4bb43..0000000000 --- a/sdk/core/src/request_options/user.rs +++ /dev/null @@ -1,30 +0,0 @@ -use crate::headers::{self, Header}; - -/// The (friendly) name of the user making the request -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct User(String); - -impl User { - pub fn new(s: String) -> Self { - Self(s) - } -} - -impl From for User -where - S: Into, -{ - fn from(s: S) -> Self { - Self(s.into()) - } -} - -impl Header for User { - fn name(&self) -> headers::HeaderName { - headers::USER - } - - fn value(&self) -> headers::HeaderValue { - self.0.clone().into() - } -} diff --git a/sdk/core/src/request_options/user_agent.rs b/sdk/core/src/request_options/user_agent.rs deleted file mode 100644 index 55fcb28ddd..0000000000 --- a/sdk/core/src/request_options/user_agent.rs +++ /dev/null @@ -1,20 +0,0 @@ -use crate::headers::{self, Header}; - -#[derive(Debug, Clone, Copy)] -pub struct UserAgent<'a>(&'a str); - -impl<'a> UserAgent<'a> { - pub fn new(agent: &'a str) -> Self { - Self(agent) - } -} - -impl<'a> Header for UserAgent<'a> { - fn name(&self) -> headers::HeaderName { - headers::USER_AGENT - } - - fn value(&self) -> headers::HeaderValue { - self.0.to_owned().into() - } -} diff --git a/sdk/core/src/request_options/version.rs b/sdk/core/src/request_options/version.rs deleted file mode 100644 index f08fb4de1b..0000000000 --- a/sdk/core/src/request_options/version.rs +++ /dev/null @@ -1,29 +0,0 @@ -use crate::headers::{self, Header}; - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct Version(String); - -impl Version { - pub fn new(s: String) -> Self { - Self(s) - } -} - -impl From for Version -where - S: Into, -{ - fn from(s: S) -> Self { - Self(s.into()) - } -} - -impl Header for Version { - fn name(&self) -> headers::HeaderName { - headers::VERSION - } - - fn value(&self) -> headers::HeaderValue { - self.0.clone().into() - } -} diff --git a/sdk/storage_blobs/src/blob/operations/append_block.rs b/sdk/storage_blobs/src/blob/operations/append_block.rs index 15ebe4ed28..730b1420b3 100644 --- a/sdk/storage_blobs/src/blob/operations/append_block.rs +++ b/sdk/storage_blobs/src/blob/operations/append_block.rs @@ -10,7 +10,7 @@ operation! { ?condition_append_position: ConditionAppendPosition, ?if_modified_since: IfModifiedSinceCondition, ?if_match: IfMatchCondition, - ?if_tag: IfTagsCondition, + ?if_tag: IfTags, ?lease_id: LeaseId } diff --git a/sdk/storage_blobs/src/blob/operations/copy_blob.rs b/sdk/storage_blobs/src/blob/operations/copy_blob.rs index 6ef87606f6..ea4627caa0 100644 --- a/sdk/storage_blobs/src/blob/operations/copy_blob.rs +++ b/sdk/storage_blobs/src/blob/operations/copy_blob.rs @@ -16,7 +16,7 @@ operation! { ?if_sequence_number: SequenceNumberCondition, ?if_modified_since: IfModifiedSinceCondition, ?if_match: IfMatchCondition, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?access_tier: AccessTier, ?lease_id: LeaseId, ?if_source_since: IfSourceModifiedSinceCondition, diff --git a/sdk/storage_blobs/src/blob/operations/delete_blob.rs b/sdk/storage_blobs/src/blob/operations/delete_blob.rs index df0894b47a..a07a7f8483 100644 --- a/sdk/storage_blobs/src/blob/operations/delete_blob.rs +++ b/sdk/storage_blobs/src/blob/operations/delete_blob.rs @@ -7,7 +7,7 @@ operation! { client: BlobClient, ?if_modified_since: IfModifiedSinceCondition, ?if_match: IfMatchCondition, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?delete_snapshots_method: DeleteSnapshotsMethod, ?lease_id: LeaseId } diff --git a/sdk/storage_blobs/src/blob/operations/get_blob.rs b/sdk/storage_blobs/src/blob/operations/get_blob.rs index 709d1f3f58..7a59875ee7 100644 --- a/sdk/storage_blobs/src/blob/operations/get_blob.rs +++ b/sdk/storage_blobs/src/blob/operations/get_blob.rs @@ -18,7 +18,7 @@ operation! { ?chunk_size: u64, ?if_modified_since: IfModifiedSinceCondition, ?if_match: IfMatchCondition, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, } impl GetBlobBuilder { diff --git a/sdk/storage_blobs/src/blob/operations/get_block_list.rs b/sdk/storage_blobs/src/blob/operations/get_block_list.rs index a13a090fba..184e26f35c 100644 --- a/sdk/storage_blobs/src/blob/operations/get_block_list.rs +++ b/sdk/storage_blobs/src/blob/operations/get_block_list.rs @@ -9,7 +9,7 @@ use std::str::from_utf8; operation! { GetBlockList, client: BlobClient, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?block_list_type: BlockListType, ?blob_versioning: BlobVersioning, ?lease_id: LeaseId diff --git a/sdk/storage_blobs/src/blob/operations/get_metadata.rs b/sdk/storage_blobs/src/blob/operations/get_metadata.rs index 507381ce9c..eb292b3be8 100644 --- a/sdk/storage_blobs/src/blob/operations/get_metadata.rs +++ b/sdk/storage_blobs/src/blob/operations/get_metadata.rs @@ -8,7 +8,7 @@ operation! { client: BlobClient, ?if_modified_since: IfModifiedSinceCondition, ?if_match: IfMatchCondition, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?blob_versioning: BlobVersioning, ?lease_id: LeaseId } diff --git a/sdk/storage_blobs/src/blob/operations/get_page_ranges.rs b/sdk/storage_blobs/src/blob/operations/get_page_ranges.rs index 448dbc4d60..f4a87354c9 100644 --- a/sdk/storage_blobs/src/blob/operations/get_page_ranges.rs +++ b/sdk/storage_blobs/src/blob/operations/get_page_ranges.rs @@ -8,7 +8,7 @@ operation! { client: BlobClient, ?if_modified_since: IfModifiedSinceCondition, ?if_match: IfMatchCondition, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?blob_versioning: BlobVersioning, ?lease_id: LeaseId } diff --git a/sdk/storage_blobs/src/blob/operations/get_properties.rs b/sdk/storage_blobs/src/blob/operations/get_properties.rs index af7a2218f9..6da22abd61 100644 --- a/sdk/storage_blobs/src/blob/operations/get_properties.rs +++ b/sdk/storage_blobs/src/blob/operations/get_properties.rs @@ -7,7 +7,7 @@ operation! { client: BlobClient, ?if_modified_since: IfModifiedSinceCondition, ?if_match: IfMatchCondition, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?blob_versioning: BlobVersioning, ?lease_id: LeaseId } diff --git a/sdk/storage_blobs/src/blob/operations/get_tags.rs b/sdk/storage_blobs/src/blob/operations/get_tags.rs index cba733d9c9..06c75071ce 100644 --- a/sdk/storage_blobs/src/blob/operations/get_tags.rs +++ b/sdk/storage_blobs/src/blob/operations/get_tags.rs @@ -6,7 +6,7 @@ use chrono::{DateTime, Utc}; operation! { GetTags, client: BlobClient, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?blob_versioning: BlobVersioning, ?lease_id: LeaseId } diff --git a/sdk/storage_blobs/src/blob/operations/put_page.rs b/sdk/storage_blobs/src/blob/operations/put_page.rs index ae039f9ed2..b572716d71 100644 --- a/sdk/storage_blobs/src/blob/operations/put_page.rs +++ b/sdk/storage_blobs/src/blob/operations/put_page.rs @@ -12,7 +12,7 @@ operation! { ?if_sequence_number: SequenceNumberCondition, ?if_modified_since: IfModifiedSinceCondition, ?if_match: IfMatchCondition, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?lease_id: LeaseId } diff --git a/sdk/storage_blobs/src/blob/operations/set_metadata.rs b/sdk/storage_blobs/src/blob/operations/set_metadata.rs index 4fdd0454c0..c19bb01c35 100644 --- a/sdk/storage_blobs/src/blob/operations/set_metadata.rs +++ b/sdk/storage_blobs/src/blob/operations/set_metadata.rs @@ -8,7 +8,7 @@ operation! { client: BlobClient, ?if_modified_since: IfModifiedSinceCondition, ?if_match: IfMatchCondition, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?lease_id: LeaseId, ?metadata: Metadata } diff --git a/sdk/storage_blobs/src/blob/operations/set_properties.rs b/sdk/storage_blobs/src/blob/operations/set_properties.rs index 1d107b8e28..606fd3b786 100644 --- a/sdk/storage_blobs/src/blob/operations/set_properties.rs +++ b/sdk/storage_blobs/src/blob/operations/set_properties.rs @@ -14,7 +14,7 @@ operation! { client: BlobClient, ?if_modified_since: IfModifiedSinceCondition, ?if_match: IfMatchCondition, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?lease_id: LeaseId, ?cache_control: BlobCacheControl, ?content_type: BlobContentType, diff --git a/sdk/storage_blobs/src/blob/operations/set_tags.rs b/sdk/storage_blobs/src/blob/operations/set_tags.rs index 6349013afd..e6fa4ff69e 100644 --- a/sdk/storage_blobs/src/blob/operations/set_tags.rs +++ b/sdk/storage_blobs/src/blob/operations/set_tags.rs @@ -11,7 +11,7 @@ operation! { SetTags, client: BlobClient, tags: Tags, - ?if_tags: IfTagsCondition, + ?if_tags: IfTags, ?lease_id: LeaseId } diff --git a/sdk/storage_blobs/src/options/condition_tags.rs b/sdk/storage_blobs/src/options/condition_tags.rs deleted file mode 100644 index 4f62ae75ff..0000000000 --- a/sdk/storage_blobs/src/options/condition_tags.rs +++ /dev/null @@ -1,26 +0,0 @@ -use azure_core::headers::{Header, HeaderName, HeaderValue}; - -#[derive(Debug, Clone)] -pub struct IfTagsCondition(String); - -impl IfTagsCondition { - pub fn new(value: String) -> Self { - Self(value) - } -} - -impl From for IfTagsCondition { - fn from(n: String) -> Self { - Self(n) - } -} - -impl Header for IfTagsCondition { - fn name(&self) -> HeaderName { - "x-ms-if-tags".into() - } - - fn value(&self) -> HeaderValue { - self.0.clone().into() - } -} diff --git a/sdk/storage_blobs/src/options/mod.rs b/sdk/storage_blobs/src/options/mod.rs index 577fcba25d..ae35befc48 100644 --- a/sdk/storage_blobs/src/options/mod.rs +++ b/sdk/storage_blobs/src/options/mod.rs @@ -13,13 +13,10 @@ mod blob_versioning; mod block_id; mod condition_append_position; mod condition_max_size; -mod condition_tags; mod delete_snapshot_method; mod hash; mod rehydrate_policy; -mod snapshot; mod tags; -mod version_id; pub use access_tier::AccessTier; pub use ba512_range::BA512Range; @@ -34,10 +31,23 @@ pub use blob_versioning::BlobVersioning; pub use block_id::BlockId; pub use condition_append_position::ConditionAppendPosition; pub use condition_max_size::ConditionMaxSize; -pub use condition_tags::IfTagsCondition; pub use delete_snapshot_method::DeleteSnapshotsMethod; pub use hash::Hash; pub use rehydrate_policy::RehydratePriority; -pub use snapshot::Snapshot; pub use tags::Tags; -pub use version_id::VersionId; + +request_query_option!( + #[doc = "This type could also be a DateTime but the docs clearly states to treat is as opaque so we do not convert it in any way. + +See: "] + VersionId, + "version_id" +); + +request_query_option!( + #[doc = "This type could also be a DateTime but the docs clearly states to treat is as opaque so we do not convert it in any way. + +See: "] + Snapshot, + "snapshot" +); diff --git a/sdk/storage_blobs/src/options/snapshot.rs b/sdk/storage_blobs/src/options/snapshot.rs deleted file mode 100644 index d36aa17a4e..0000000000 --- a/sdk/storage_blobs/src/options/snapshot.rs +++ /dev/null @@ -1,30 +0,0 @@ -use azure_core::AppendToUrlQuery; - -// This type could also be a DateTime -// but the docs clearly states to treat is -// as opaque so we do not convert it in -// any way. -// see: https://docs.microsoft.com/rest/api/storageservices/get-blob -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct Snapshot(String); - -impl Snapshot { - pub fn new(snapshot: String) -> Self { - Self(snapshot) - } -} - -impl AppendToUrlQuery for &Snapshot { - fn append_to_url_query(&self, url: &mut url::Url) { - url.query_pairs_mut().append_pair("snapshot", &self.0); - } -} - -impl From for Snapshot -where - S: Into, -{ - fn from(snapshot: S) -> Self { - Self::new(snapshot.into()) - } -} diff --git a/sdk/storage_blobs/src/options/version_id.rs b/sdk/storage_blobs/src/options/version_id.rs deleted file mode 100644 index 13015d0726..0000000000 --- a/sdk/storage_blobs/src/options/version_id.rs +++ /dev/null @@ -1,30 +0,0 @@ -use azure_core::AppendToUrlQuery; - -// This type could also be a DateTime -// but the docs clearly states to treat is -// as opaque so we do not convert it in -// any way. -// see: https://docs.microsoft.com/rest/api/storageservices/get-blob -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct VersionId(String); - -impl VersionId { - pub fn new(version_id: String) -> Self { - Self(version_id) - } -} - -impl AppendToUrlQuery for VersionId { - fn append_to_url_query(&self, url: &mut url::Url) { - url.query_pairs_mut().append_pair("version_id", &self.0); - } -} - -impl From for VersionId -where - S: Into, -{ - fn from(version_id: S) -> Self { - Self::new(version_id.into()) - } -} diff --git a/sdk/storage_datalake/src/request_options.rs b/sdk/storage_datalake/src/request_options.rs index c4e10be1d6..69fbbfd396 100644 --- a/sdk/storage_datalake/src/request_options.rs +++ b/sdk/storage_datalake/src/request_options.rs @@ -200,42 +200,5 @@ impl Header for RenameSource { } } -#[derive(Debug, Clone)] -pub struct Directory(String); - -impl From for Directory -where - S: Into, -{ - fn from(s: S) -> Self { - Self(s.into()) - } -} - -impl AppendToUrlQuery for Directory { - fn append_to_url_query(&self, url: &mut url::Url) { - url.query_pairs_mut().append_pair("directory", &self.0); - } -} - -#[derive(Debug, Clone)] -pub struct AccessControlList(String); - -impl From for AccessControlList -where - S: Into, -{ - 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() - } -} +request_query_option!(Directory, "directory"); +request_header!(AccessControlList, ACL,);