From d8fd761cd44602c4759438e491b76db94401fdce Mon Sep 17 00:00:00 2001 From: Sam Wlody Date: Tue, 27 Oct 2020 14:55:39 -0400 Subject: [PATCH 1/4] Initial go at ADLS Gen2 Filesystem API support (it compiles, at least) --- sdk/core/src/headers/mod.rs | 2 + sdk/core/src/lib.rs | 18 ++ sdk/core/src/prelude.rs | 29 +- sdk/cosmos/src/headers.rs | 1 - sdk/cosmos/src/lib.rs | 18 -- sdk/cosmos/src/prelude.rs | 44 +-- sdk/storage/Cargo.toml | 1 + sdk/storage/src/adls_gen2/filesystem/mod.rs | 52 ++++ .../requests/create_filesystem_builder.json | 60 ++++ .../requests/create_filesystem_builder.rs | 212 ++++++++++++++ .../requests/delete_filesystem_builder.json | 61 ++++ .../requests/delete_filesystem_builder.rs | 214 ++++++++++++++ .../get_filesystem_properties_builder.json | 54 ++++ .../get_filesystem_properties_builder.rs | 173 ++++++++++++ .../requests/list_filesystems_builder.json | 65 +++++ .../requests/list_filesystems_builder.rs | 266 ++++++++++++++++++ .../src/adls_gen2/filesystem/requests/mod.rs | 10 + .../set_filesystem_properties_builder.json | 68 +++++ .../set_filesystem_properties_builder.rs | 255 +++++++++++++++++ .../responses/create_filesystem_response.rs | 12 + .../responses/delete_filesystem_response.rs | 8 + .../get_filesystem_properties_response.rs | 13 + .../responses/list_filesystems_response.rs | 11 + .../src/adls_gen2/filesystem/responses/mod.rs | 10 + .../set_filesystem_properties_response.rs | 10 + sdk/storage/src/adls_gen2/mod.rs | 49 ++++ sdk/storage/src/adls_gen2/prelude.rs | 4 + sdk/storage/src/core/bearer_token_client.rs | 8 + sdk/storage/src/core/client.rs | 21 +- sdk/storage/src/core/key_client.rs | 8 + sdk/storage/src/lib.rs | 4 + 31 files changed, 1703 insertions(+), 58 deletions(-) create mode 100644 sdk/storage/src/adls_gen2/filesystem/mod.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.json create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.json create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.json create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.json create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/mod.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.json create mode 100644 sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/responses/create_filesystem_response.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/responses/delete_filesystem_response.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/responses/get_filesystem_properties_response.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/responses/list_filesystems_response.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/responses/mod.rs create mode 100644 sdk/storage/src/adls_gen2/filesystem/responses/set_filesystem_properties_response.rs create mode 100644 sdk/storage/src/adls_gen2/mod.rs create mode 100644 sdk/storage/src/adls_gen2/prelude.rs diff --git a/sdk/core/src/headers/mod.rs b/sdk/core/src/headers/mod.rs index 2fbd491f30..f4a3af1a79 100644 --- a/sdk/core/src/headers/mod.rs +++ b/sdk/core/src/headers/mod.rs @@ -50,3 +50,5 @@ pub const HEADER_CONTINUATION: &str = "x-ms-continuation"; pub const SESSION_TOKEN: &str = "x-ms-session-token"; pub const REQUIRES_SYNC: &str = "x-ms-requires-sync"; pub const VERSION: &str = "x-ms-version"; +pub const PROPERTIES: &str = "x-ms-properties"; //=> [String] } +pub const NAMESPACE_ENABLED: &str = "x-ms-namespace_enabled"; //=> [String] } diff --git a/sdk/core/src/lib.rs b/sdk/core/src/lib.rs index 39c7b4338b..87b0b6c671 100644 --- a/sdk/core/src/lib.rs +++ b/sdk/core/src/lib.rs @@ -933,6 +933,24 @@ pub trait LeaseBreakPeriodOption { } } +pub trait ContinuationSupport<'a> { + type O; + fn with_continuation(self, continuation: &'a str) -> Self::O; +} + +pub trait ContinuationOption<'a> { + fn continuation(&self) -> Option<&'a str>; + + #[must_use] + fn add_header(&self, builder: Builder) -> Builder { + if let Some(continuation) = self.continuation() { + builder.header(HEADER_CONTINUATION, continuation) + } else { + builder + } + } +} + pub trait ContainerNameSupport<'a> { type O; fn with_container_name(self, container_name: &'a str) -> Self::O; diff --git a/sdk/core/src/prelude.rs b/sdk/core/src/prelude.rs index 2295733eba..9c8843e9b5 100644 --- a/sdk/core/src/prelude.rs +++ b/sdk/core/src/prelude.rs @@ -10,20 +10,21 @@ pub use crate::{ ContentDispositionOption, ContentDispositionSupport, ContentEncodingOption, ContentEncodingSupport, ContentLanguageOption, ContentLanguageSupport, ContentLengthOption, ContentLengthRequired, ContentLengthSupport, ContentMD5Option, ContentMD5Support, - ContentTypeOption, ContentTypeRequired, ContentTypeSupport, DeleteSnapshotsMethod, - DeleteSnapshotsMethodSupport, DelimiterOption, DelimiterSupport, IfMatchConditionOption, - IfMatchConditionSupport, IfModifiedSinceOption, IfModifiedSinceSupport, IfSinceConditionOption, - IfSinceConditionSupport, IncludeCopyOption, IncludeCopySupport, IncludeDeletedOption, - IncludeDeletedSupport, IncludeListOptions, IncludeMetadataOption, IncludeMetadataSupport, - IncludeSnapshotsOption, IncludeSnapshotsSupport, IncludeUncommittedBlobsOption, - IncludeUncommittedBlobsSupport, IsSynchronousOption, IsSynchronousSupport, - LeaseBreakPeriodOption, LeaseBreakPeriodRequired, LeaseBreakPeriodSupport, - LeaseDurationRequired, LeaseDurationSupport, LeaseIdOption, LeaseIdRequired, LeaseIdSupport, - MaxResultsOption, MaxResultsSupport, MetadataOption, MetadataSupport, NextMarkerOption, - NextMarkerSupport, PageBlobLengthRequired, PageBlobLengthSupport, PrefixOption, PrefixSupport, - ProposedLeaseIdOption, ProposedLeaseIdRequired, ProposedLeaseIdSupport, RangeOption, - RangeRequired, RangeSupport, SequenceNumberConditionOption, SequenceNumberConditionSupport, - SequenceNumberOption, SequenceNumberSupport, SnapshotOption, SnapshotRequired, SnapshotSupport, + ContentTypeOption, ContentTypeRequired, ContentTypeSupport, ContinuationOption, + ContinuationSupport, DeleteSnapshotsMethod, DeleteSnapshotsMethodSupport, DelimiterOption, + DelimiterSupport, IfMatchConditionOption, IfMatchConditionSupport, IfModifiedSinceOption, + IfModifiedSinceSupport, IfSinceConditionOption, IfSinceConditionSupport, IncludeCopyOption, + IncludeCopySupport, IncludeDeletedOption, IncludeDeletedSupport, IncludeListOptions, + IncludeMetadataOption, IncludeMetadataSupport, IncludeSnapshotsOption, IncludeSnapshotsSupport, + IncludeUncommittedBlobsOption, IncludeUncommittedBlobsSupport, IsSynchronousOption, + IsSynchronousSupport, LeaseBreakPeriodOption, LeaseBreakPeriodRequired, + LeaseBreakPeriodSupport, LeaseDurationRequired, LeaseDurationSupport, LeaseIdOption, + LeaseIdRequired, LeaseIdSupport, MaxResultsOption, MaxResultsSupport, MetadataOption, + MetadataSupport, NextMarkerOption, NextMarkerSupport, PageBlobLengthRequired, + PageBlobLengthSupport, PrefixOption, PrefixSupport, ProposedLeaseIdOption, + ProposedLeaseIdRequired, ProposedLeaseIdSupport, RangeOption, RangeRequired, RangeSupport, + SequenceNumberConditionOption, SequenceNumberConditionSupport, SequenceNumberOption, + SequenceNumberSupport, SnapshotOption, SnapshotRequired, SnapshotSupport, SourceContentMD5Option, SourceContentMD5Support, SourceUrlRequired, SourceUrlSupport, StoredAccessPolicy, StoredAccessPolicyList, TimeoutOption, TimeoutSupport, UserAgentOption, UserAgentSupport, diff --git a/sdk/cosmos/src/headers.rs b/sdk/cosmos/src/headers.rs index 65ea951813..425e0f1650 100644 --- a/sdk/cosmos/src/headers.rs +++ b/sdk/cosmos/src/headers.rs @@ -4,7 +4,6 @@ pub(crate) const HEADER_DOCUMENTDB_IS_UPSERT: &str = "x-ms-documentdb-is-upsert" pub(crate) const HEADER_INDEXING_DIRECTIVE: &str = "x-ms-indexing-directive"; // [IndexingDirective] pub(crate) const HEADER_MAX_ITEM_COUNT: &str = "x-ms-max-item-count"; // [u64] pub(crate) const HEADER_ITEM_COUNT: &str = "x-ms-item-count"; // [u64] -pub(crate) const HEADER_CONTINUATION: &str = "x-ms-continuation"; // [ContinuationToken] pub(crate) const HEADER_CONSISTENCY_LEVEL: &str = "x-ms-consistency-level"; // [ConsistencyLevel] pub(crate) const HEADER_SESSION_TOKEN: &str = "x-ms-session-token"; // [ContinuationToken] pub(crate) const HEADER_ALLOW_MULTIPLE_WRITES: &str = "x-ms-cosmos-allow-tentative-writes"; // [bool] diff --git a/sdk/cosmos/src/lib.rs b/sdk/cosmos/src/lib.rs index 1b2bdf5bdc..6808373804 100644 --- a/sdk/cosmos/src/lib.rs +++ b/sdk/cosmos/src/lib.rs @@ -242,24 +242,6 @@ pub trait PartitionRangeIdOption<'a> { } } -pub trait ContinuationSupport<'a> { - type O; - fn with_continuation(self, continuation: &'a str) -> Self::O; -} - -pub trait ContinuationOption<'a> { - fn continuation(&self) -> Option<&'a str>; - - #[must_use] - fn add_header(&self, builder: Builder) -> Builder { - if let Some(continuation) = self.continuation() { - builder.header(HEADER_CONTINUATION, continuation) - } else { - builder - } - } -} - pub trait IndexingDirectiveSupport { type O; fn with_indexing_directive(self, indexing_directive: IndexingDirective) -> Self::O; diff --git a/sdk/cosmos/src/prelude.rs b/sdk/cosmos/src/prelude.rs index fb3d162b97..c10973a234 100644 --- a/sdk/cosmos/src/prelude.rs +++ b/sdk/cosmos/src/prelude.rs @@ -11,26 +11,26 @@ pub use crate::{ AttachmentClient, AttachmentClientRequired, AuthorizationToken, CollectionClient, CollectionClientRequired, CollectionNameRequired, CollectionNameSupport, CollectionRequired, CollectionSupport, ConsistencyLevel, ConsistencyLevelOption, ConsistencyLevelSupport, - ContinuationOption, ContinuationSupport, CosmosClient, CosmosClientRequired, DatabaseClient, - DatabaseClientRequired, DatabaseNameRequired, DatabaseNameSupport, DocumentClient, - DocumentIdRequired, DocumentIdSupport, ExpirySecondsOption, ExpirySecondsSupport, - HasStoredProcedureClient, IndexingDirective, IndexingDirectiveOption, IndexingDirectiveSupport, - IndexingPolicyRequired, IndexingPolicySupport, IntoAttachmentClient, IntoCollectionClient, - IntoDatabaseClient, IntoDocumentClient, IntoPermissionClient, IntoStoredProcedureClient, - IntoUserClient, IsUpsertOption, IsUpsertSupport, MaxItemCountOption, MaxItemCountSupport, - MediaRequired, MediaSupport, Offer, OfferRequired, OfferSupport, - ParallelizeCrossPartitionQueryOption, ParallelizeCrossPartitionQuerySupport, ParametersOption, - ParametersSupport, PartitionKeyOption, PartitionKeyRequired, PartitionKeySupport, - PartitionKeys, PartitionKeysOption, PartitionKeysRequired, PartitionKeysSupport, - PartitionRangeIdOption, PartitionRangeIdSupport, PermissionClient, PermissionClientRequired, - QueryCrossPartitionOption, QueryCrossPartitionSupport, QueryRequired, QuerySupport, - StoredProcedureBodyRequired, StoredProcedureBodySupport, StoredProcedureClient, - StoredProcedureClientRequired, StoredProcedureNameRequired, StoredProcedureNameSupport, - TriggerBodyRequired, TriggerBodySupport, TriggerClient, TriggerClientRequired, - TriggerOperationRequired, TriggerOperationSupport, TriggerTypeRequired, TriggerTypeSupport, - UserClient, UserClientRequired, UserDefinedFunctionBodyRequired, - UserDefinedFunctionBodySupport, UserDefinedFunctionClient, UserDefinedFunctionClientRequired, - UserName, UserNameRequired, UserNameSupport, WithAttachmentClient, WithCollectionClient, - WithDatabaseClient, WithDocumentClient, WithPermissionClient, WithStoredProcedureClient, - WithTriggerClient, WithUserClient, WithUserDefinedFunctionClient, + CosmosClient, CosmosClientRequired, DatabaseClient, DatabaseClientRequired, + DatabaseNameRequired, DatabaseNameSupport, DocumentClient, DocumentIdRequired, + DocumentIdSupport, ExpirySecondsOption, ExpirySecondsSupport, HasStoredProcedureClient, + IndexingDirective, IndexingDirectiveOption, IndexingDirectiveSupport, IndexingPolicyRequired, + IndexingPolicySupport, IntoAttachmentClient, IntoCollectionClient, IntoDatabaseClient, + IntoDocumentClient, IntoPermissionClient, IntoStoredProcedureClient, IntoUserClient, + IsUpsertOption, IsUpsertSupport, MaxItemCountOption, MaxItemCountSupport, MediaRequired, + MediaSupport, Offer, OfferRequired, OfferSupport, ParallelizeCrossPartitionQueryOption, + ParallelizeCrossPartitionQuerySupport, ParametersOption, ParametersSupport, PartitionKeyOption, + PartitionKeyRequired, PartitionKeySupport, PartitionKeys, PartitionKeysOption, + PartitionKeysRequired, PartitionKeysSupport, PartitionRangeIdOption, PartitionRangeIdSupport, + PermissionClient, PermissionClientRequired, QueryCrossPartitionOption, + QueryCrossPartitionSupport, QueryRequired, QuerySupport, StoredProcedureBodyRequired, + StoredProcedureBodySupport, StoredProcedureClient, StoredProcedureClientRequired, + StoredProcedureNameRequired, StoredProcedureNameSupport, TriggerBodyRequired, + TriggerBodySupport, TriggerClient, TriggerClientRequired, TriggerOperationRequired, + TriggerOperationSupport, TriggerTypeRequired, TriggerTypeSupport, UserClient, + UserClientRequired, UserDefinedFunctionBodyRequired, UserDefinedFunctionBodySupport, + UserDefinedFunctionClient, UserDefinedFunctionClientRequired, UserName, UserNameRequired, + UserNameSupport, WithAttachmentClient, WithCollectionClient, WithDatabaseClient, + WithDocumentClient, WithPermissionClient, WithStoredProcedureClient, WithTriggerClient, + WithUserClient, WithUserDefinedFunctionClient, }; diff --git a/sdk/storage/Cargo.toml b/sdk/storage/Cargo.toml index 60e78d4d24..612e20381b 100644 --- a/sdk/storage/Cargo.toml +++ b/sdk/storage/Cargo.toml @@ -51,3 +51,4 @@ account = [] blob = [] queue = [] table = [] +adls_gen2 = [] diff --git a/sdk/storage/src/adls_gen2/filesystem/mod.rs b/sdk/storage/src/adls_gen2/filesystem/mod.rs new file mode 100644 index 0000000000..36b0a3b308 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/mod.rs @@ -0,0 +1,52 @@ +pub mod requests; +pub mod responses; + +use azure_core::errors::AzureError; +use azure_core::headers::PROPERTIES; +use azure_core::util::HeaderMapExt; +use http::{request::Builder, HeaderMap}; + +pub trait FilesystemRequired<'a> { + fn filesystem(&self) -> &'a str; +} + +pub trait FilesystemSupport<'a> { + type O; + fn with_filesystem(self, filesystem: &'a str) -> Self::O; +} + +pub trait PropertiesOption<'a> { + fn properties(&self) -> Option<&'a str>; + + #[must_use] + fn add_header(&self, mut builder: Builder) -> Builder { + if let Some(properties) = self.properties() { + builder = builder.header(PROPERTIES, properties); + } + builder + } +} + +pub trait PropertiesSupport<'a> { + type O; + fn with_properties(self, properties: &'a str) -> Self::O; +} + +pub(crate) fn properties_from_headers(headers: &HeaderMap) -> Result { + let properties = headers + .get_as_str(azure_core::headers::PROPERTIES) + .ok_or_else(|| AzureError::HeaderNotFound(azure_core::headers::PROPERTIES.to_owned()))?; + Ok(properties.to_owned()) +} + +pub(crate) fn namespace_enabled_from_headers(headers: &HeaderMap) -> Result { + let namespace_enabled = headers + .get(azure_core::headers::NAMESPACE_ENABLED) + .ok_or_else(|| { + AzureError::HeaderNotFound(azure_core::headers::NAMESPACE_ENABLED.to_owned()) + })? + .to_str()?; + + let namespace_enabled = namespace_enabled.parse::()?; + Ok(namespace_enabled) +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.json b/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.json new file mode 100644 index 0000000000..c2376f7bdf --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.json @@ -0,0 +1,60 @@ +{ + "name": "CreateFilesystemBuilder", + "derive": "Debug, Clone", + "uses": [ + "crate::core::prelude::*", + "crate::filesystem::responses::CreateFilesystemResponse", + "crate::filesystem::{FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport}", + "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", + "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, TimeoutOption, TimeoutSupport}", + "azure_core::{No, ToAssign, Yes}", + "hyper::{Method, StatusCode}", + "std::marker::PhantomData" + ], + "inline": true, + "extra_types": [ + "'a", + "C" + ], + "extra_wheres": [ + "C: Client" + ], + "constructor_fields": [ + { + "name": "client", + "field_type": "&'a C", + "trait_get": "ClientRequired<'a, C>" + } + ], + "fields": [ + { + "name": "filesystem", + "field_type": "&'a str", + "builder_type": "ContainerNameSet", + "optional": false, + "trait_get": "FilesystemRequired<'a>", + "trait_set": "FilesystemSupport<'a>" + }, + { + "name": "timeout", + "field_type": "u64", + "optional": true, + "trait_get": "TimeoutOption", + "trait_set": "TimeoutSupport" + }, + { + "name": "properties", + "field_type": "&'a str", + "optional": true, + "trait_get": "PropertiesOption", + "trait_set": "PropertiesSupport" + }, + { + "name": "client_request_id", + "field_type": "&'a str", + "optional": true, + "trait_get": "ClientRequestIdOption<'a>", + "trait_set": "ClientRequestIdSupport<'a>" + } + ] +} \ No newline at end of file diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs new file mode 100644 index 0000000000..11c8a38cf0 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs @@ -0,0 +1,212 @@ +use crate::core::prelude::*; +use crate::filesystem::responses::CreateFilesystemResponse; +use crate::filesystem::{ + FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport, +}; +use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; +use azure_core::{ClientRequestIdOption, ClientRequestIdSupport, TimeoutOption, TimeoutSupport}; +use azure_core::{No, ToAssign, Yes}; +use hyper::{Method, StatusCode}; +use std::marker::PhantomData; + +#[derive(Debug, Clone)] +pub struct CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + client: &'a C, + p_filesystem: PhantomData, + filesystem: Option<&'a str>, + timeout: Option, + properties: Option<&'a str>, + client_request_id: Option<&'a str>, +} + +impl<'a, C> CreateFilesystemBuilder<'a, C, No> +where + C: Client, +{ + pub(crate) fn new(client: &'a C) -> CreateFilesystemBuilder<'a, C, No> { + CreateFilesystemBuilder { + client, + p_filesystem: PhantomData {}, + filesystem: None, + timeout: None, + properties: None, + client_request_id: None, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequired<'a, C> for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client(&self) -> &'a C { + self.client + } +} + +impl<'a, C> FilesystemRequired<'a> for CreateFilesystemBuilder<'a, C, Yes> +where + C: Client, +{ + #[inline] + fn filesystem(&self) -> &'a str { + self.filesystem.unwrap() + } +} + +impl<'a, C, FilesystemSet> TimeoutOption for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn timeout(&self) -> Option { + self.timeout + } +} + +impl<'a, C, FilesystemSet> PropertiesOption<'a> for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn properties(&self) -> Option<&'a str> { + self.properties + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client_request_id(&self) -> Option<&'a str> { + self.client_request_id + } +} + +impl<'a, C> FilesystemSupport<'a> for CreateFilesystemBuilder<'a, C, No> +where + C: Client, +{ + type O = CreateFilesystemBuilder<'a, C, Yes>; + + #[inline] + fn with_filesystem(self, filesystem: &'a str) -> Self::O { + CreateFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: Some(filesystem), + timeout: self.timeout, + properties: self.properties, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> TimeoutSupport for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = CreateFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_timeout(self, timeout: u64) -> Self::O { + CreateFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: Some(timeout), + properties: self.properties, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> PropertiesSupport<'a> for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = CreateFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_properties(self, properties: &'a str) -> Self::O { + CreateFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + properties: Some(properties), + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = CreateFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { + CreateFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + properties: self.properties, + client_request_id: Some(client_request_id), + } + } +} + +impl<'a, C, FilesystemSet> CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ +} + +impl<'a, C> CreateFilesystemBuilder<'a, C, Yes> +where + C: Client, +{ + pub async fn finalize(self) -> Result { + let mut uri = format!( + "{}/{}?resource=filesystem", + self.client().filesystem_uri(), + self.filesystem() + ); + + if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + let future_response = self.client().perform_request( + &uri, + &Method::PUT, + &|mut request| { + request = ClientRequestIdOption::add_header(&self, request); + request = PropertiesOption::add_header(&self, request); + request + }, + Some(&[]), + )?; + + let (headers, _body) = + check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; + CreateFilesystemResponse::from_headers(&headers) + } +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.json b/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.json new file mode 100644 index 0000000000..2b25785034 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.json @@ -0,0 +1,61 @@ +{ + "name": "DeleteFilesystemBuilder", + "derive": "Debug, Clone", + "uses": [ + "crate::core::prelude::*", + "crate::filesystem::responses::DeleteFilesystemResponse", + "crate::filesystem::{FilesystemRequired, FilesystemSupport}", + "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", + "azure_core::prelude::*", + "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, IfSinceConditionOption, IfSinceConditionSupport,TimeoutOption, TimeoutSupport}", + "azure_core::{No, ToAssign, Yes}", + "hyper::{Method, StatusCode}", + "std::marker::PhantomData" + ], + "inline": true, + "extra_types": [ + "'a", + "C" + ], + "extra_wheres": [ + "C: Client" + ], + "constructor_fields": [ + { + "name": "client", + "field_type": "&'a C", + "trait_get": "ClientRequired<'a, C>" + } + ], + "fields": [ + { + "name": "filesystem", + "field_type": "&'a str", + "builder_type": "ContainerNameSet", + "optional": false, + "trait_get": "FilesystemRequired<'a>", + "trait_set": "FilesystemSupport<'a>" + }, + { + "name": "timeout", + "field_type": "u64", + "optional": true, + "trait_get": "TimeoutOption", + "trait_set": "TimeoutSupport" + }, + { + "name": "if_since_condition", + "field_type": "IfSinceCondition", + "optional": true, + "trait_get": "IfSinceConditionOption", + "trait_set": "IfSinceConditionSupport" + }, + { + "name": "client_request_id", + "field_type": "&'a str", + "optional": true, + "trait_get": "ClientRequestIdOption<'a>", + "trait_set": "ClientRequestIdSupport<'a>" + } + ] +} \ No newline at end of file diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs new file mode 100644 index 0000000000..229de087fc --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs @@ -0,0 +1,214 @@ +use crate::core::prelude::*; +use crate::filesystem::responses::DeleteFilesystemResponse; +use crate::filesystem::{FilesystemRequired, FilesystemSupport}; +use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; +use azure_core::prelude::*; +use azure_core::{ + ClientRequestIdOption, ClientRequestIdSupport, IfSinceConditionOption, IfSinceConditionSupport, + TimeoutOption, TimeoutSupport, +}; +use azure_core::{No, ToAssign, Yes}; +use hyper::{Method, StatusCode}; +use std::marker::PhantomData; + +#[derive(Debug, Clone)] +pub struct DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + client: &'a C, + p_filesystem: PhantomData, + filesystem: Option<&'a str>, + timeout: Option, + if_since_condition: Option, + client_request_id: Option<&'a str>, +} + +impl<'a, C> DeleteFilesystemBuilder<'a, C, No> +where + C: Client, +{ + pub(crate) fn new(client: &'a C) -> DeleteFilesystemBuilder<'a, C, No> { + DeleteFilesystemBuilder { + client, + p_filesystem: PhantomData {}, + filesystem: None, + timeout: None, + if_since_condition: None, + client_request_id: None, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequired<'a, C> for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client(&self) -> &'a C { + self.client + } +} + +impl<'a, C> FilesystemRequired<'a> for DeleteFilesystemBuilder<'a, C, Yes> +where + C: Client, +{ + #[inline] + fn filesystem(&self) -> &'a str { + self.filesystem.unwrap() + } +} + +impl<'a, C, FilesystemSet> TimeoutOption for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn timeout(&self) -> Option { + self.timeout + } +} + +impl<'a, C, FilesystemSet> IfSinceConditionOption for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn if_since_condition(&self) -> Option { + self.if_since_condition + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client_request_id(&self) -> Option<&'a str> { + self.client_request_id + } +} + +impl<'a, C> FilesystemSupport<'a> for DeleteFilesystemBuilder<'a, C, No> +where + C: Client, +{ + type O = DeleteFilesystemBuilder<'a, C, Yes>; + + #[inline] + fn with_filesystem(self, filesystem: &'a str) -> Self::O { + DeleteFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: Some(filesystem), + timeout: self.timeout, + if_since_condition: self.if_since_condition, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> TimeoutSupport for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = DeleteFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_timeout(self, timeout: u64) -> Self::O { + DeleteFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: Some(timeout), + if_since_condition: self.if_since_condition, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> IfSinceConditionSupport for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = DeleteFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_if_since_condition(self, if_since_condition: IfSinceCondition) -> Self::O { + DeleteFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + if_since_condition: Some(if_since_condition), + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = DeleteFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { + DeleteFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + if_since_condition: self.if_since_condition, + client_request_id: Some(client_request_id), + } + } +} + +impl<'a, C, FilesystemSet> DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ +} + +impl<'a, C> DeleteFilesystemBuilder<'a, C, Yes> +where + C: Client, +{ + pub async fn finalize(self) -> Result { + let mut uri = format!( + "{}/{}?resource=filesystem", + self.client().filesystem_uri(), + self.filesystem() + ); + + if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + let future_response = self.client().perform_request( + &uri, + &Method::PUT, + &|mut request| { + request = IfSinceConditionOption::add_header(&self, request); + request = ClientRequestIdOption::add_header(&self, request); + request + }, + Some(&[]), + )?; + + let (headers, _body) = + check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; + DeleteFilesystemResponse::from_headers(&headers) + } +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.json b/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.json new file mode 100644 index 0000000000..4229ccfb82 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.json @@ -0,0 +1,54 @@ +{ + "name": "GetFilesystemPropertiesBuilder", + "derive": "Debug, Clone", + "uses": [ + "crate::core::prelude::*", + "crate::filesystem::responses::GetFilesystemPropertiesResponse", + "crate::filesystem::{FilesystemSupport, FilesystemRequired}", + "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", + "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, TimeoutOption, TimeoutSupport}", + "azure_core::{No, ToAssign, Yes}", + "azure_sdk_storage_core::prelude::*", + "hyper::{Method, StatusCode}", + "std::marker::PhantomData" + ], + "inline": true, + "extra_types": [ + "'a", + "C" + ], + "extra_wheres": [ + "C: Client" + ], + "constructor_fields": [ + { + "name": "client", + "field_type": "&'a C", + "trait_get": "ClientRequired<'a, C>" + } + ], + "fields": [ + { + "name": "filesystem", + "field_type": "&'a str", + "builder_type": "ContainerNameSet", + "optional": false, + "trait_get": "FilesystemRequired<'a>", + "trait_set": "FilesystemSupport<'a>" + }, + { + "name": "timeout", + "field_type": "u64", + "optional": true, + "trait_get": "TimeoutOption", + "trait_set": "TimeoutSupport" + }, + { + "name": "client_request_id", + "field_type": "&'a str", + "optional": true, + "trait_get": "ClientRequestIdOption<'a>", + "trait_set": "ClientRequestIdSupport<'a>" + } + ] +} \ No newline at end of file diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs new file mode 100644 index 0000000000..b4294db631 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs @@ -0,0 +1,173 @@ +use crate::core::prelude::*; +use crate::filesystem::responses::GetFilesystemPropertiesResponse; +use crate::filesystem::{FilesystemRequired, FilesystemSupport}; +use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; +use azure_core::{ClientRequestIdOption, ClientRequestIdSupport, TimeoutOption, TimeoutSupport}; +use azure_core::{No, ToAssign, Yes}; +use hyper::{Method, StatusCode}; +use std::marker::PhantomData; + +#[derive(Debug, Clone)] +pub struct GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + client: &'a C, + p_filesystem: PhantomData, + filesystem: Option<&'a str>, + timeout: Option, + client_request_id: Option<&'a str>, +} + +impl<'a, C> GetFilesystemPropertiesBuilder<'a, C, No> +where + C: Client, +{ + pub(crate) fn new(client: &'a C) -> GetFilesystemPropertiesBuilder<'a, C, No> { + GetFilesystemPropertiesBuilder { + client, + p_filesystem: PhantomData {}, + filesystem: None, + timeout: None, + client_request_id: None, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequired<'a, C> for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client(&self) -> &'a C { + self.client + } +} + +impl<'a, C> FilesystemRequired<'a> for GetFilesystemPropertiesBuilder<'a, C, Yes> +where + C: Client, +{ + #[inline] + fn filesystem(&self) -> &'a str { + self.filesystem.unwrap() + } +} + +impl<'a, C, FilesystemSet> TimeoutOption for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn timeout(&self) -> Option { + self.timeout + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client_request_id(&self) -> Option<&'a str> { + self.client_request_id + } +} + +impl<'a, C> FilesystemSupport<'a> for GetFilesystemPropertiesBuilder<'a, C, No> +where + C: Client, +{ + type O = GetFilesystemPropertiesBuilder<'a, C, Yes>; + + #[inline] + fn with_filesystem(self, filesystem: &'a str) -> Self::O { + GetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: Some(filesystem), + timeout: self.timeout, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> TimeoutSupport for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = GetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_timeout(self, timeout: u64) -> Self::O { + GetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: Some(timeout), + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = GetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { + GetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + client_request_id: Some(client_request_id), + } + } +} + +impl<'a, C, FilesystemSet> GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ +} + +impl<'a, C> GetFilesystemPropertiesBuilder<'a, C, Yes> +where + C: Client, +{ + pub async fn finalize(self) -> Result { + let mut uri = format!( + "{}/{}?resource=filesystem", + self.client().filesystem_uri(), + self.filesystem() + ); + + if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + let future_response = self.client().perform_request( + &uri, + &Method::PUT, + &|mut request| { + request = ClientRequestIdOption::add_header(&self, request); + request + }, + Some(&[]), + )?; + + let (headers, _body) = + check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; + GetFilesystemPropertiesResponse::from_headers(&headers) + } +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.json b/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.json new file mode 100644 index 0000000000..73d3d6c6be --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.json @@ -0,0 +1,65 @@ +{ + "name": "ListFilesystemsBuilder", + "derive": "Debug, Clone", + "uses": [ + "crate::core::prelude::*", + "crate::filesystem::responses::ListFilesystemResponse", + "crate::filesystem::{ContinuationOption, ContinuationSupport}", + "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", + "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, ContinuationOption, ContinuationSupport, MaxResultsOption, MaxResultsSupport, PrefixOption, PrefixSupport, TimeoutOption, TimeoutSupport}", + "futures::stream::{unfold, Stream}", + "hyper::{Method, StatusCode}" + ], + "inline": true, + "extra_types": [ + "'a", + "C" + ], + "extra_wheres": [ + "C: Client" + ], + "constructor_fields": [ + { + "name": "client", + "field_type": "&'a C", + "trait_get": "ClientRequired<'a, C>" + } + ], + "fields": [ + { + "name": "continuation", + "field_type": "&'a str", + "optional": true, + "trait_get": "ContinuationOption", + "trait_set": "ContinuationSupport" + }, + { + "name": "max_results", + "field_type": "u32", + "optional": true, + "trait_get": "MaxResultsOption", + "trait_set": "MaxResultsSupport" + }, + { + "name": "prefix", + "field_type": "&'a str", + "optional": true, + "trait_get": "PrefixOption", + "trait_set": "PrefixSupport" + }, + { + "name": "timeout", + "field_type": "u64", + "optional": true, + "trait_get": "TimeoutOption", + "trait_set": "TimeoutSupport" + }, + { + "name": "client_request_id", + "field_type": "&'a str", + "optional": true, + "trait_get": "ClientRequestIdOption<'a>", + "trait_set": "ClientRequestIdSupport<'a>" + } + ] +} \ No newline at end of file diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs new file mode 100644 index 0000000000..ab7092f4fb --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs @@ -0,0 +1,266 @@ +use crate::core::prelude::*; +use crate::filesystem::responses::ListFilesystemsResponse; +use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; +use azure_core::prelude::*; +use futures::stream::{unfold, Stream}; +use hyper::{Method, StatusCode}; + +#[derive(Debug, Clone)] +pub struct ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + client: &'a C, + continuation: Option<&'a str>, + max_results: Option, + prefix: Option<&'a str>, + timeout: Option, + client_request_id: Option<&'a str>, +} + +impl<'a, C> ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + pub(crate) fn new(client: &'a C) -> ListFilesystemsBuilder<'a, C> { + ListFilesystemsBuilder { + client, + continuation: None, + max_results: None, + prefix: None, + timeout: None, + client_request_id: None, + } + } +} + +impl<'a, C> ClientRequired<'a, C> for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + #[inline] + fn client(&self) -> &'a C { + self.client + } +} + +impl<'a, C> ContinuationOption<'a> for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + #[inline] + fn continuation(&self) -> Option<&'a str> { + self.continuation + } +} + +impl<'a, C> MaxResultsOption for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + #[inline] + fn max_results(&self) -> Option { + self.max_results + } +} + +impl<'a, C> PrefixOption<'a> for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + #[inline] + fn prefix(&self) -> Option<&'a str> { + self.prefix + } +} + +impl<'a, C> TimeoutOption for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + #[inline] + fn timeout(&self) -> Option { + self.timeout + } +} + +impl<'a, C> ClientRequestIdOption<'a> for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + #[inline] + fn client_request_id(&self) -> Option<&'a str> { + self.client_request_id + } +} + +impl<'a, C> ContinuationSupport<'a> for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + type O = ListFilesystemsBuilder<'a, C>; + + #[inline] + fn with_continuation(self, continuation: &'a str) -> Self::O { + ListFilesystemsBuilder { + client: self.client, + continuation: Some(continuation), + max_results: self.max_results, + prefix: self.prefix, + timeout: self.timeout, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C> MaxResultsSupport for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + type O = ListFilesystemsBuilder<'a, C>; + + #[inline] + fn with_max_results(self, max_results: u32) -> Self::O { + ListFilesystemsBuilder { + client: self.client, + continuation: self.continuation, + max_results: Some(max_results), + prefix: self.prefix, + timeout: self.timeout, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C> PrefixSupport<'a> for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + type O = ListFilesystemsBuilder<'a, C>; + + #[inline] + fn with_prefix(self, prefix: &'a str) -> Self::O { + ListFilesystemsBuilder { + client: self.client, + continuation: self.continuation, + max_results: self.max_results, + prefix: Some(prefix), + timeout: self.timeout, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C> TimeoutSupport for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + type O = ListFilesystemsBuilder<'a, C>; + + #[inline] + fn with_timeout(self, timeout: u64) -> Self::O { + ListFilesystemsBuilder { + client: self.client, + continuation: self.continuation, + max_results: self.max_results, + prefix: self.prefix, + timeout: Some(timeout), + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C> ClientRequestIdSupport<'a> for ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + type O = ListFilesystemsBuilder<'a, C>; + + #[inline] + fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { + ListFilesystemsBuilder { + client: self.client, + continuation: self.continuation, + max_results: self.max_results, + prefix: self.prefix, + timeout: self.timeout, + client_request_id: Some(client_request_id), + } + } +} + +impl<'a, C> ListFilesystemsBuilder<'a, C> +where + C: Client, +{ + pub async fn finalize(self) -> Result { + let mut uri = format!("{}/?resource=account", self.client().filesystem_uri(),); + + if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + if let Some(nm) = MaxResultsOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + if let Some(nm) = PrefixOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + let future_response = self.client().perform_request( + &uri, + &Method::PUT, + &|mut request| { + request = ClientRequestIdOption::add_header(&self, request); + request + }, + Some(&[]), + )?; + + let (headers, _body) = + check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; + ListFilesystemsResponse::from_headers(&headers) + } +} + +impl<'a, C> ListFilesystemsBuilder<'a, C> +where + C: Client + Clone, +{ + pub fn stream(self) -> impl Stream> + 'a { + #[derive(Debug, Clone, PartialEq)] + enum States { + Init, + Continuation(String), + }; + + unfold(Some(States::Init), move |continuation: Option| { + let req = self.clone(); + async move { + debug!("continuation == {:?}", &continuation); + let response = match continuation { + Some(States::Init) => req.finalize().await, + Some(States::Continuation(continuation)) => { + req.with_continuation(&continuation).finalize().await + } + None => return None, + }; + + // the ? operator does not work in async move (yet?) + // so we have to resort to this boilerplate + let response = match response { + Ok(response) => response, + Err(err) => return Some((Err(err), None)), + }; + + let continuation = match &response.continuation { + Some(ct) => Some(States::Continuation(ct.to_owned())), + None => None, + }; + + Some((Ok(response), continuation)) + } + }) + } +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/mod.rs b/sdk/storage/src/adls_gen2/filesystem/requests/mod.rs new file mode 100644 index 0000000000..6b8ba81ab3 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/mod.rs @@ -0,0 +1,10 @@ +mod create_filesystem_builder; +mod delete_filesystem_builder; +mod get_filesystem_properties_builder; +mod list_filesystems_builder; +mod set_filesystem_properties_builder; +pub use self::create_filesystem_builder::CreateFilesystemBuilder; +pub use self::delete_filesystem_builder::DeleteFilesystemBuilder; +pub use self::get_filesystem_properties_builder::GetFilesystemPropertiesBuilder; +pub use self::list_filesystems_builder::ListFilesystemsBuilder; +pub use self::set_filesystem_properties_builder::SetFilesystemPropertiesBuilder; diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.json b/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.json new file mode 100644 index 0000000000..ab9baaa974 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.json @@ -0,0 +1,68 @@ +{ + "name": "SetFilesystemPropertiesBuilder", + "derive": "Debug, Clone", + "uses": [ + "core::prelude::*", + "crate::filesystem::responses::SetFilesystemPropertiesResponse", + "crate::filesystem::{FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport}", + "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", + "azure_core::prelude::*", + "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, IfSinceConditionOption, IfSinceConditionSupport,TimeoutOption, TimeoutSupport}", + "azure_core::{No, ToAssign, Yes}", + "hyper::{Method, StatusCode}", + "std::marker::PhantomData" + ], + "inline": true, + "extra_types": [ + "'a", + "C" + ], + "extra_wheres": [ + "C: Client" + ], + "constructor_fields": [ + { + "name": "client", + "field_type": "&'a C", + "trait_get": "ClientRequired<'a, C>" + } + ], + "fields": [ + { + "name": "filesystem", + "field_type": "&'a str", + "builder_type": "ContainerNameSet", + "optional": false, + "trait_get": "FilesystemRequired<'a>", + "trait_set": "FilesystemSupport<'a>" + }, + { + "name": "timeout", + "field_type": "u64", + "optional": true, + "trait_get": "TimeoutOption", + "trait_set": "TimeoutSupport" + }, + { + "name": "properties", + "field_type": "&'a str", + "optional": true, + "trait_get": "PropertiesOption", + "trait_set": "PropertiesSupport" + }, + { + "name": "if_since_condition", + "field_type": "IfSinceCondition", + "optional": true, + "trait_get": "IfSinceConditionOption", + "trait_set": "IfSinceConditionSupport" + }, + { + "name": "client_request_id", + "field_type": "&'a str", + "optional": true, + "trait_get": "ClientRequestIdOption<'a>", + "trait_set": "ClientRequestIdSupport<'a>" + } + ] +} \ No newline at end of file diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs new file mode 100644 index 0000000000..9c74c81ff9 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs @@ -0,0 +1,255 @@ +use crate::core::prelude::*; +use crate::filesystem::responses::SetFilesystemPropertiesResponse; +use crate::filesystem::{ + FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport, +}; +use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; +use azure_core::prelude::*; +use azure_core::{ + ClientRequestIdOption, ClientRequestIdSupport, IfSinceConditionOption, IfSinceConditionSupport, + TimeoutOption, TimeoutSupport, +}; +use azure_core::{No, ToAssign, Yes}; +use hyper::{Method, StatusCode}; +use std::marker::PhantomData; + +#[derive(Debug, Clone)] +pub struct SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + client: &'a C, + p_filesystem: PhantomData, + filesystem: Option<&'a str>, + timeout: Option, + properties: Option<&'a str>, + if_since_condition: Option, + client_request_id: Option<&'a str>, +} + +impl<'a, C> SetFilesystemPropertiesBuilder<'a, C, No> +where + C: Client, +{ + pub(crate) fn new(client: &'a C) -> SetFilesystemPropertiesBuilder<'a, C, No> { + SetFilesystemPropertiesBuilder { + client, + p_filesystem: PhantomData {}, + filesystem: None, + timeout: None, + properties: None, + if_since_condition: None, + client_request_id: None, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequired<'a, C> for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client(&self) -> &'a C { + self.client + } +} + +impl<'a, C> FilesystemRequired<'a> for SetFilesystemPropertiesBuilder<'a, C, Yes> +where + C: Client, +{ + #[inline] + fn filesystem(&self) -> &'a str { + self.filesystem.unwrap() + } +} + +impl<'a, C, FilesystemSet> TimeoutOption for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn timeout(&self) -> Option { + self.timeout + } +} + +impl<'a, C, FilesystemSet> PropertiesOption<'a> for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn properties(&self) -> Option<&'a str> { + self.properties + } +} + +impl<'a, C, FilesystemSet> IfSinceConditionOption for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn if_since_condition(&self) -> Option { + self.if_since_condition + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client_request_id(&self) -> Option<&'a str> { + self.client_request_id + } +} + +impl<'a, C> FilesystemSupport<'a> for SetFilesystemPropertiesBuilder<'a, C, No> +where + C: Client, +{ + type O = SetFilesystemPropertiesBuilder<'a, C, Yes>; + + #[inline] + fn with_filesystem(self, filesystem: &'a str) -> Self::O { + SetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: Some(filesystem), + timeout: self.timeout, + properties: self.properties, + if_since_condition: self.if_since_condition, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> TimeoutSupport for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_timeout(self, timeout: u64) -> Self::O { + SetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: Some(timeout), + properties: self.properties, + if_since_condition: self.if_since_condition, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> PropertiesSupport<'a> for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_properties(self, properties: &'a str) -> Self::O { + SetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + properties: Some(properties), + if_since_condition: self.if_since_condition, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> IfSinceConditionSupport for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_if_since_condition(self, if_since_condition: IfSinceCondition) -> Self::O { + SetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + properties: self.properties, + if_since_condition: Some(if_since_condition), + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { + SetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + properties: self.properties, + if_since_condition: self.if_since_condition, + client_request_id: Some(client_request_id), + } + } +} + +impl<'a, C, FilesystemSet> SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ +} + +impl<'a, C> SetFilesystemPropertiesBuilder<'a, C, Yes> +where + C: Client, +{ + pub async fn finalize(self) -> Result { + let mut uri = format!( + "{}/{}?resource=filesystem", + self.client().filesystem_uri(), + self.filesystem() + ); + + if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + let future_response = self.client().perform_request( + &uri, + &Method::PUT, + &|mut request| { + request = IfSinceConditionOption::add_header(&self, request); + request = ClientRequestIdOption::add_header(&self, request); + request = PropertiesOption::add_header(&self, request); + request + }, + Some(&[]), + )?; + + let (headers, _body) = + check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; + SetFilesystemPropertiesResponse::from_headers(&headers) + } +} diff --git a/sdk/storage/src/adls_gen2/filesystem/responses/create_filesystem_response.rs b/sdk/storage/src/adls_gen2/filesystem/responses/create_filesystem_response.rs new file mode 100644 index 0000000000..5bc701150e --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/responses/create_filesystem_response.rs @@ -0,0 +1,12 @@ +use crate::filesystem::namespace_enabled_from_headers; +use azure_core::headers::*; +use azure_core::RequestId; +use chrono::{DateTime, Utc}; + +response_from_headers!(CreateFilesystemResponse, + date_from_headers => date: DateTime, + etag_from_headers => etag: String, + last_modified_from_headers => last_modified: DateTime, + request_id_from_headers => request_id: RequestId, + namespace_enabled_from_headers => namespace_enabled: bool +); diff --git a/sdk/storage/src/adls_gen2/filesystem/responses/delete_filesystem_response.rs b/sdk/storage/src/adls_gen2/filesystem/responses/delete_filesystem_response.rs new file mode 100644 index 0000000000..2d2fe3a91e --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/responses/delete_filesystem_response.rs @@ -0,0 +1,8 @@ +use azure_core::headers::*; +use azure_core::RequestId; +use chrono::{DateTime, Utc}; + +response_from_headers!(DeleteFilesystemResponse, + date_from_headers => date: DateTime, + request_id_from_headers => request_id: RequestId +); diff --git a/sdk/storage/src/adls_gen2/filesystem/responses/get_filesystem_properties_response.rs b/sdk/storage/src/adls_gen2/filesystem/responses/get_filesystem_properties_response.rs new file mode 100644 index 0000000000..c3077b1841 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/responses/get_filesystem_properties_response.rs @@ -0,0 +1,13 @@ +use crate::filesystem::{namespace_enabled_from_headers, properties_from_headers}; +use azure_core::headers::*; +use azure_core::RequestId; +use chrono::{DateTime, Utc}; + +response_from_headers!(GetFilesystemPropertiesResponse, + date_from_headers => date: DateTime, + etag_from_headers => etag: String, + last_modified_from_headers => last_modified: DateTime, + request_id_from_headers => request_id: RequestId, + properties_from_headers => properties: String, + namespace_enabled_from_headers => namespace_enabled: bool +); diff --git a/sdk/storage/src/adls_gen2/filesystem/responses/list_filesystems_response.rs b/sdk/storage/src/adls_gen2/filesystem/responses/list_filesystems_response.rs new file mode 100644 index 0000000000..43bb074418 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/responses/list_filesystems_response.rs @@ -0,0 +1,11 @@ +use azure_core::headers::*; +use azure_core::RequestId; +use chrono::{DateTime, Utc}; + +response_from_headers!(ListFilesystemsResponse, + date_from_headers => date: DateTime, + etag_from_headers => etag: String, + last_modified_from_headers => last_modified: DateTime, + request_id_from_headers => request_id: RequestId, + continuation_token_from_headers_optional => continuation: Option +); diff --git a/sdk/storage/src/adls_gen2/filesystem/responses/mod.rs b/sdk/storage/src/adls_gen2/filesystem/responses/mod.rs new file mode 100644 index 0000000000..2964dc46c7 --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/responses/mod.rs @@ -0,0 +1,10 @@ +mod create_filesystem_response; +mod delete_filesystem_response; +mod get_filesystem_properties_response; +mod list_filesystems_response; +mod set_filesystem_properties_response; +pub use self::create_filesystem_response::CreateFilesystemResponse; +pub use self::delete_filesystem_response::DeleteFilesystemResponse; +pub use self::get_filesystem_properties_response::GetFilesystemPropertiesResponse; +pub use self::list_filesystems_response::ListFilesystemsResponse; +pub use self::set_filesystem_properties_response::SetFilesystemPropertiesResponse; diff --git a/sdk/storage/src/adls_gen2/filesystem/responses/set_filesystem_properties_response.rs b/sdk/storage/src/adls_gen2/filesystem/responses/set_filesystem_properties_response.rs new file mode 100644 index 0000000000..da6f74314d --- /dev/null +++ b/sdk/storage/src/adls_gen2/filesystem/responses/set_filesystem_properties_response.rs @@ -0,0 +1,10 @@ +use azure_core::headers::*; +use azure_core::RequestId; +use chrono::{DateTime, Utc}; + +response_from_headers!(SetFilesystemPropertiesResponse, + date_from_headers => date: DateTime, + etag_from_headers => etag: String, + last_modified_from_headers => last_modified: DateTime, + request_id_from_headers => request_id: RequestId +); diff --git a/sdk/storage/src/adls_gen2/mod.rs b/sdk/storage/src/adls_gen2/mod.rs new file mode 100644 index 0000000000..b4846ed337 --- /dev/null +++ b/sdk/storage/src/adls_gen2/mod.rs @@ -0,0 +1,49 @@ +pub mod filesystem; +pub mod prelude; + +use crate::core::Client; +use azure_core::No; + +pub trait Filesystem +where + C: Client, +{ + fn create_filesystem<'a>(&'a self) -> filesystem::requests::CreateFilesystemBuilder<'a, C, No>; + fn delete_filesystem<'a>(&'a self) -> filesystem::requests::DeleteFilesystemBuilder<'a, C, No>; + fn get_filesystem_properties<'a>( + &'a self, + ) -> filesystem::requests::GetFilesystemPropertiesBuilder<'a, C, No>; + fn list_filesystems<'a>(&'a self) -> filesystem::requests::ListFilesystemsBuilder<'a, C>; + fn set_filesystem_properties<'a>( + &'a self, + ) -> filesystem::requests::SetFilesystemPropertiesBuilder<'a, C, No>; +} + +impl Filesystem for C +where + C: Client, +{ + fn create_filesystem<'a>(&'a self) -> filesystem::requests::CreateFilesystemBuilder<'a, C, No> { + filesystem::requests::CreateFilesystemBuilder::new(self) + } + + fn delete_filesystem<'a>(&'a self) -> filesystem::requests::DeleteFilesystemBuilder<'a, C, No> { + filesystem::requests::DeleteFilesystemBuilder::new(self) + } + + fn get_filesystem_properties<'a>( + &'a self, + ) -> filesystem::requests::GetFilesystemPropertiesBuilder<'a, C, No> { + filesystem::requests::GetFilesystemPropertiesBuilder::new(self) + } + + fn list_filesystems<'a>(&'a self) -> filesystem::requests::ListFilesystemsBuilder<'a, C> { + filesystem::requests::ListFilesystemsBuilder::new(self) + } + + fn set_filesystem_properties<'a>( + &'a self, + ) -> filesystem::requests::SetFilesystemPropertiesBuilder<'a, C, No> { + filesystem::requests::SetFilesystemPropertiesBuilder::new(self) + } +} diff --git a/sdk/storage/src/adls_gen2/prelude.rs b/sdk/storage/src/adls_gen2/prelude.rs new file mode 100644 index 0000000000..e631e33040 --- /dev/null +++ b/sdk/storage/src/adls_gen2/prelude.rs @@ -0,0 +1,4 @@ +pub use super::filesystem::{ + FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport, +}; +pub use super::Filesystem as FilesystemTrait; diff --git a/sdk/storage/src/core/bearer_token_client.rs b/sdk/storage/src/core/bearer_token_client.rs index 9374bf791d..906b4979bf 100644 --- a/sdk/storage/src/core/bearer_token_client.rs +++ b/sdk/storage/src/core/bearer_token_client.rs @@ -15,6 +15,7 @@ pub struct BearerTokenClient<'a> { blob_uri: String, table_uri: String, queue_uri: String, + filesystem_uri: String, } impl<'a> BearerTokenClient<'a> { @@ -27,6 +28,7 @@ impl<'a> BearerTokenClient<'a> { let blob_uri = format!("https://{}.blob.core.windows.net", account); let table_uri = format!("https://{}.table.core.windows.net", account); let queue_uri = format!("https://{}.queue.core.windows.net", account); + let filesystem_uri = format!("https://{}.dfs.core.windows.net", account); Self { account, @@ -35,6 +37,7 @@ impl<'a> BearerTokenClient<'a> { hc, blob_uri, table_uri, + filesystem_uri, } } @@ -98,6 +101,11 @@ impl<'a> Client for BearerTokenClient<'a> { &self.queue_uri } + #[inline] + fn filesystem_uri(&self) -> &str { + &self.filesystem_uri + } + #[inline] fn perform_request( &self, diff --git a/sdk/storage/src/core/client.rs b/sdk/storage/src/core/client.rs index 3e6e857632..039829b339 100644 --- a/sdk/storage/src/core/client.rs +++ b/sdk/storage/src/core/client.rs @@ -17,6 +17,7 @@ pub trait Client: std::fmt::Debug + Send + Sync { fn blob_uri(&self) -> &str; fn table_uri(&self) -> &str; fn queue_uri(&self) -> &str; + fn filesystem_uri(&self) -> &str; /// Uri scheme + authority e.g. http://myaccount.table.core.windows.net/ #[inline] @@ -57,6 +58,9 @@ where fn queue_uri(&self) -> &str { self.as_ref().queue_uri() } + fn filesystem_uri(&self) -> &str { + self.as_ref().filesystem_uri() + } fn perform_request( &self, @@ -94,6 +98,9 @@ where fn queue_uri(&self) -> &str { self.as_ref().queue_uri() } + fn filesystem_uri(&self) -> &str { + self.as_ref().filesystem_uri() + } fn perform_request( &self, @@ -141,6 +148,7 @@ pub fn with_azure_sas(account: &str, sas_token: &str) -> KeyClient { format!("https://{}.blob.core.windows.net", account), format!("https://{}.table.core.windows.net", account), format!("https://{}.queue.core.windows.net", account), + format!("https://{}.dfs.core.windows.net", account), ) } @@ -155,6 +163,7 @@ pub fn with_access_key(account: &str, key: &str) -> KeyClient { format!("https://{}.blob.core.windows.net", account), format!("https://{}.table.core.windows.net", account), format!("https://{}.queue.core.windows.net", account), + format!("https://{}.dfs.core.windows.net", account), ) } @@ -175,8 +184,9 @@ pub fn from_connection_string(connection_string: &str) -> Result Result Result { Err(AzureError::GenericErrorWithText( @@ -233,6 +245,8 @@ pub fn with_emulator(blob_storage_url: &Url, table_storage_url: &Url) -> KeyClie debug!("table_uri == {}", table_uri); let queue_uri = format!("{}devstoreaccount1", table_storage_url.as_str()); debug!("queue_uri == {}", queue_uri); + let filesystem_uri = format!("{}devstoreaccount1", blob_storage_url.as_str()); + debug!("filesystem_uri = {}", filesystem_uri); KeyClient::new( "devstoreaccount1".to_owned(), @@ -243,5 +257,6 @@ pub fn with_emulator(blob_storage_url: &Url, table_storage_url: &Url) -> KeyClie blob_uri, table_uri, queue_uri, + filesystem_uri, ) } diff --git a/sdk/storage/src/core/key_client.rs b/sdk/storage/src/core/key_client.rs index 07e47ee335..9e04ab1af3 100644 --- a/sdk/storage/src/core/key_client.rs +++ b/sdk/storage/src/core/key_client.rs @@ -15,6 +15,7 @@ pub struct KeyClient { blob_uri: String, table_uri: String, queue_uri: String, + filesystem_uri: String, } pub(crate) fn get_sas_token_parms(sas_token: &str) -> Vec<(String, String)> { @@ -39,6 +40,7 @@ impl KeyClient { blob_uri: String, table_uri: String, queue_uri: String, + filesystem_uri: String, ) -> Self { Self { account, @@ -48,6 +50,7 @@ impl KeyClient { blob_uri, table_uri, queue_uri, + filesystem_uri, } } @@ -75,6 +78,11 @@ impl Client for KeyClient { &self.queue_uri } + #[inline] + fn filesystem_uri(&self) -> &str { + &self.filesystem_uri + } + fn perform_request( &self, uri: &str, diff --git a/sdk/storage/src/lib.rs b/sdk/storage/src/lib.rs index 072c0bd782..fe76ea21be 100644 --- a/sdk/storage/src/lib.rs +++ b/sdk/storage/src/lib.rs @@ -12,6 +12,8 @@ extern crate quick_error; #[cfg(feature = "account")] pub mod account; +#[cfg(feature = "adls_gen2")] +pub mod adls_gen2; #[cfg(feature = "blob")] pub mod blob; pub mod core; @@ -23,6 +25,8 @@ pub mod table; pub use crate::core::*; #[cfg(feature = "account")] pub use account::*; +#[cfg(feature = "adls_gen2")] +pub use adls_gen2::*; #[cfg(feature = "blob")] pub use blob::*; #[cfg(feature = "queue")] From 328e58a52b18a0a7a74129f0dc7284a53f03fe87 Mon Sep 17 00:00:00 2001 From: Sam Wlody Date: Wed, 28 Oct 2020 00:08:00 -0400 Subject: [PATCH 2/4] Corrected support for List Filesystems using IncompleteVector Fix HTTP verbs for requests Fix expected status codes for responses --- sdk/core/src/headers/mod.rs | 2 +- sdk/core/src/headers/utilities.rs | 12 +- sdk/core/src/lib.rs | 2 +- sdk/cosmos/src/from_headers.rs | 10 - .../src/responses/get_attachment_response.rs | 4 +- sdk/storage/src/adls_gen2/filesystem/mod.rs | 55 +- .../requests/create_filesystem_builder.rs | 426 ++++++++------- .../requests/delete_filesystem_builder.rs | 430 +++++++-------- .../get_filesystem_properties_builder.rs | 349 ++++++------ .../requests/list_filesystems_builder.rs | 13 +- .../set_filesystem_properties_builder.rs | 517 +++++++++--------- .../responses/list_filesystems_response.rs | 43 +- 12 files changed, 980 insertions(+), 883 deletions(-) diff --git a/sdk/core/src/headers/mod.rs b/sdk/core/src/headers/mod.rs index f4a3af1a79..6fc98731e1 100644 --- a/sdk/core/src/headers/mod.rs +++ b/sdk/core/src/headers/mod.rs @@ -46,7 +46,7 @@ pub const APPEND_POSITION: &str = "x-ms-blob-condition-appendpos"; pub const CACHE_CONTROL: &str = "x-ms-blob-cache-control"; pub const CONTENT_DISPOSITION: &str = "x-ms-blob-content-disposition"; pub const ACTIVITY_ID: &str = "x-ms-activity-id"; -pub const HEADER_CONTINUATION: &str = "x-ms-continuation"; +pub const CONTINUATION: &str = "x-ms-continuation"; pub const SESSION_TOKEN: &str = "x-ms-session-token"; pub const REQUIRES_SYNC: &str = "x-ms-requires-sync"; pub const VERSION: &str = "x-ms-version"; diff --git a/sdk/core/src/headers/utilities.rs b/sdk/core/src/headers/utilities.rs index 34886c7eb3..3ed7c129d2 100644 --- a/sdk/core/src/headers/utilities.rs +++ b/sdk/core/src/headers/utilities.rs @@ -155,7 +155,7 @@ pub fn last_modified_from_headers(headers: &HeaderMap) -> Result, pub fn continuation_token_from_headers_optional( headers: &HeaderMap, ) -> Result, AzureError> { - if let Some(hc) = headers.get(HEADER_CONTINUATION) { + if let Some(hc) = headers.get(CONTINUATION) { Ok(Some(hc.to_str()?.to_owned())) } else { Ok(None) @@ -293,6 +293,16 @@ pub fn request_server_encrypted_from_headers(headers: &HeaderMap) -> Result Result<&str, AzureError> { + Ok(headers + .get(http::header::CONTENT_TYPE) + .ok_or_else(|| { + let header = http::header::CONTENT_TYPE; + AzureError::HeaderNotFound(header.as_str().to_owned()) + })? + .to_str()?) +} + pub async fn perform_http_request( client: &Client>, req: Request, diff --git a/sdk/core/src/lib.rs b/sdk/core/src/lib.rs index 87b0b6c671..204b991573 100644 --- a/sdk/core/src/lib.rs +++ b/sdk/core/src/lib.rs @@ -944,7 +944,7 @@ pub trait ContinuationOption<'a> { #[must_use] fn add_header(&self, builder: Builder) -> Builder { if let Some(continuation) = self.continuation() { - builder.header(HEADER_CONTINUATION, continuation) + builder.header(CONTINUATION, continuation) } else { builder } diff --git a/sdk/cosmos/src/from_headers.rs b/sdk/cosmos/src/from_headers.rs index 76dbd37fb8..3698664c32 100644 --- a/sdk/cosmos/src/from_headers.rs +++ b/sdk/cosmos/src/from_headers.rs @@ -277,16 +277,6 @@ pub(crate) fn content_location_from_headers(headers: &HeaderMap) -> Result<&str, .to_str()?) } -pub(crate) fn content_type_from_headers(headers: &HeaderMap) -> Result<&str, AzureError> { - Ok(headers - .get(http::header::CONTENT_TYPE) - .ok_or_else(|| { - let header = http::header::CONTENT_TYPE; - AzureError::HeaderNotFound(header.as_str().to_owned()) - })? - .to_str()?) -} - pub(crate) fn gateway_version_from_headers(headers: &HeaderMap) -> Result<&str, AzureError> { Ok(headers .get(HEADER_GATEWAY_VERSION) diff --git a/sdk/cosmos/src/responses/get_attachment_response.rs b/sdk/cosmos/src/responses/get_attachment_response.rs index 3404406f12..8e032f6dc7 100644 --- a/sdk/cosmos/src/responses/get_attachment_response.rs +++ b/sdk/cosmos/src/responses/get_attachment_response.rs @@ -1,7 +1,9 @@ use crate::from_headers::*; use crate::{Attachment, IndexingDirective, ResourceQuota}; use azure_core::errors::AzureError; -use azure_core::headers::{etag_from_headers, session_token_from_headers}; +use azure_core::headers::{ + content_type_from_headers, etag_from_headers, session_token_from_headers, +}; use azure_core::SessionToken; use chrono::{DateTime, Utc}; use hyper::header::HeaderMap; diff --git a/sdk/storage/src/adls_gen2/filesystem/mod.rs b/sdk/storage/src/adls_gen2/filesystem/mod.rs index 36b0a3b308..b9a1b7f0cc 100644 --- a/sdk/storage/src/adls_gen2/filesystem/mod.rs +++ b/sdk/storage/src/adls_gen2/filesystem/mod.rs @@ -1,10 +1,15 @@ pub mod requests; pub mod responses; +use std::convert::TryFrom; + use azure_core::errors::AzureError; -use azure_core::headers::PROPERTIES; +use azure_core::headers::{CONTINUATION, PROPERTIES}; +use azure_core::incompletevector::IncompleteVector; +use azure_core::parsing::{cast_must, traverse}; use azure_core::util::HeaderMapExt; use http::{request::Builder, HeaderMap}; +use xml::Element; pub trait FilesystemRequired<'a> { fn filesystem(&self) -> &'a str; @@ -50,3 +55,51 @@ pub(crate) fn namespace_enabled_from_headers(headers: &HeaderMap) -> Result()?; Ok(namespace_enabled) } + +#[derive(Debug, Clone)] +pub struct Filesystem { + etag: String, + last_modified: String, + name: String, +} + +impl TryFrom<&Element> for Filesystem { + type Error = AzureError; + + fn try_from(elem: &Element) -> Result { + let etag = cast_must::(elem, &["eTag"])?; + let last_modified = cast_must::(elem, &["lastModified"])?; + let name = cast_must::(elem, &["Name"])?; + + Ok(Filesystem { + etag, + last_modified, + name, + }) + } +} + +#[inline] +pub(crate) fn incomplete_vector_from_response( + headers: &HeaderMap, + body: &str, +) -> Result, AzureError> { + trace!("body = {}", body); + + let elem: Element = body.parse()?; + + let continuation = match headers.get_as_string(CONTINUATION) { + Some(ref ct) if ct == "" => None, + Some(ct) => Some(ct), + None => None, + }; + + debug!("continuation == {:?}", continuation); + + let mut v = Vec::new(); + for node_filesystem in traverse(&elem, &["Filesystems", "Filesystem"], true)? { + v.push(Filesystem::try_from(node_filesystem)?); + } + + Ok(IncompleteVector::::new(continuation, v)) +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs index 11c8a38cf0..8bce6427de 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs +++ b/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs @@ -1,212 +1,214 @@ -use crate::core::prelude::*; -use crate::filesystem::responses::CreateFilesystemResponse; -use crate::filesystem::{ - FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport, -}; -use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; -use azure_core::{ClientRequestIdOption, ClientRequestIdSupport, TimeoutOption, TimeoutSupport}; -use azure_core::{No, ToAssign, Yes}; -use hyper::{Method, StatusCode}; -use std::marker::PhantomData; - -#[derive(Debug, Clone)] -pub struct CreateFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - client: &'a C, - p_filesystem: PhantomData, - filesystem: Option<&'a str>, - timeout: Option, - properties: Option<&'a str>, - client_request_id: Option<&'a str>, -} - -impl<'a, C> CreateFilesystemBuilder<'a, C, No> -where - C: Client, -{ - pub(crate) fn new(client: &'a C) -> CreateFilesystemBuilder<'a, C, No> { - CreateFilesystemBuilder { - client, - p_filesystem: PhantomData {}, - filesystem: None, - timeout: None, - properties: None, - client_request_id: None, - } - } -} - -impl<'a, C, FilesystemSet> ClientRequired<'a, C> for CreateFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn client(&self) -> &'a C { - self.client - } -} - -impl<'a, C> FilesystemRequired<'a> for CreateFilesystemBuilder<'a, C, Yes> -where - C: Client, -{ - #[inline] - fn filesystem(&self) -> &'a str { - self.filesystem.unwrap() - } -} - -impl<'a, C, FilesystemSet> TimeoutOption for CreateFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn timeout(&self) -> Option { - self.timeout - } -} - -impl<'a, C, FilesystemSet> PropertiesOption<'a> for CreateFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn properties(&self) -> Option<&'a str> { - self.properties - } -} - -impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> for CreateFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn client_request_id(&self) -> Option<&'a str> { - self.client_request_id - } -} - -impl<'a, C> FilesystemSupport<'a> for CreateFilesystemBuilder<'a, C, No> -where - C: Client, -{ - type O = CreateFilesystemBuilder<'a, C, Yes>; - - #[inline] - fn with_filesystem(self, filesystem: &'a str) -> Self::O { - CreateFilesystemBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: Some(filesystem), - timeout: self.timeout, - properties: self.properties, - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> TimeoutSupport for CreateFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = CreateFilesystemBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_timeout(self, timeout: u64) -> Self::O { - CreateFilesystemBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: Some(timeout), - properties: self.properties, - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> PropertiesSupport<'a> for CreateFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = CreateFilesystemBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_properties(self, properties: &'a str) -> Self::O { - CreateFilesystemBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: self.timeout, - properties: Some(properties), - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> for CreateFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = CreateFilesystemBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { - CreateFilesystemBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: self.timeout, - properties: self.properties, - client_request_id: Some(client_request_id), - } - } -} - -impl<'a, C, FilesystemSet> CreateFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ -} - -impl<'a, C> CreateFilesystemBuilder<'a, C, Yes> -where - C: Client, -{ - pub async fn finalize(self) -> Result { - let mut uri = format!( - "{}/{}?resource=filesystem", - self.client().filesystem_uri(), - self.filesystem() - ); - - if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { - uri = format!("{}&{}", uri, nm); - } - - let future_response = self.client().perform_request( - &uri, - &Method::PUT, - &|mut request| { - request = ClientRequestIdOption::add_header(&self, request); - request = PropertiesOption::add_header(&self, request); - request - }, - Some(&[]), - )?; - - let (headers, _body) = - check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; - CreateFilesystemResponse::from_headers(&headers) - } -} +use crate::core::prelude::*; +use crate::filesystem::responses::CreateFilesystemResponse; +use crate::filesystem::{ + FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport, +}; +use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; +use azure_core::{ClientRequestIdOption, ClientRequestIdSupport, TimeoutOption, TimeoutSupport}; +use azure_core::{No, ToAssign, Yes}; +use hyper::{Method, StatusCode}; +use std::marker::PhantomData; + +#[derive(Debug, Clone)] +pub struct CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + client: &'a C, + p_filesystem: PhantomData, + filesystem: Option<&'a str>, + timeout: Option, + properties: Option<&'a str>, + client_request_id: Option<&'a str>, +} + +impl<'a, C> CreateFilesystemBuilder<'a, C, No> +where + C: Client, +{ + pub(crate) fn new(client: &'a C) -> CreateFilesystemBuilder<'a, C, No> { + CreateFilesystemBuilder { + client, + p_filesystem: PhantomData {}, + filesystem: None, + timeout: None, + properties: None, + client_request_id: None, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequired<'a, C> for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client(&self) -> &'a C { + self.client + } +} + +impl<'a, C> FilesystemRequired<'a> for CreateFilesystemBuilder<'a, C, Yes> +where + C: Client, +{ + #[inline] + fn filesystem(&self) -> &'a str { + self.filesystem.unwrap() + } +} + +impl<'a, C, FilesystemSet> TimeoutOption for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn timeout(&self) -> Option { + self.timeout + } +} + +impl<'a, C, FilesystemSet> PropertiesOption<'a> for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn properties(&self) -> Option<&'a str> { + self.properties + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> + for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client_request_id(&self) -> Option<&'a str> { + self.client_request_id + } +} + +impl<'a, C> FilesystemSupport<'a> for CreateFilesystemBuilder<'a, C, No> +where + C: Client, +{ + type O = CreateFilesystemBuilder<'a, C, Yes>; + + #[inline] + fn with_filesystem(self, filesystem: &'a str) -> Self::O { + CreateFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: Some(filesystem), + timeout: self.timeout, + properties: self.properties, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> TimeoutSupport for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = CreateFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_timeout(self, timeout: u64) -> Self::O { + CreateFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: Some(timeout), + properties: self.properties, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> PropertiesSupport<'a> for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = CreateFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_properties(self, properties: &'a str) -> Self::O { + CreateFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + properties: Some(properties), + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> + for CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = CreateFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { + CreateFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + properties: self.properties, + client_request_id: Some(client_request_id), + } + } +} + +impl<'a, C, FilesystemSet> CreateFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ +} + +impl<'a, C> CreateFilesystemBuilder<'a, C, Yes> +where + C: Client, +{ + pub async fn finalize(self) -> Result { + let mut uri = format!( + "{}/{}?resource=filesystem", + self.client().filesystem_uri(), + self.filesystem() + ); + + if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + let future_response = self.client().perform_request( + &uri, + &Method::DELETE, + &|mut request| { + request = ClientRequestIdOption::add_header(&self, request); + request = PropertiesOption::add_header(&self, request); + request + }, + Some(&[]), + )?; + + let (headers, _body) = + check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; + CreateFilesystemResponse::from_headers(&headers) + } +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs index 229de087fc..d36cabea42 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs +++ b/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs @@ -1,214 +1,216 @@ -use crate::core::prelude::*; -use crate::filesystem::responses::DeleteFilesystemResponse; -use crate::filesystem::{FilesystemRequired, FilesystemSupport}; -use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; -use azure_core::prelude::*; -use azure_core::{ - ClientRequestIdOption, ClientRequestIdSupport, IfSinceConditionOption, IfSinceConditionSupport, - TimeoutOption, TimeoutSupport, -}; -use azure_core::{No, ToAssign, Yes}; -use hyper::{Method, StatusCode}; -use std::marker::PhantomData; - -#[derive(Debug, Clone)] -pub struct DeleteFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - client: &'a C, - p_filesystem: PhantomData, - filesystem: Option<&'a str>, - timeout: Option, - if_since_condition: Option, - client_request_id: Option<&'a str>, -} - -impl<'a, C> DeleteFilesystemBuilder<'a, C, No> -where - C: Client, -{ - pub(crate) fn new(client: &'a C) -> DeleteFilesystemBuilder<'a, C, No> { - DeleteFilesystemBuilder { - client, - p_filesystem: PhantomData {}, - filesystem: None, - timeout: None, - if_since_condition: None, - client_request_id: None, - } - } -} - -impl<'a, C, FilesystemSet> ClientRequired<'a, C> for DeleteFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn client(&self) -> &'a C { - self.client - } -} - -impl<'a, C> FilesystemRequired<'a> for DeleteFilesystemBuilder<'a, C, Yes> -where - C: Client, -{ - #[inline] - fn filesystem(&self) -> &'a str { - self.filesystem.unwrap() - } -} - -impl<'a, C, FilesystemSet> TimeoutOption for DeleteFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn timeout(&self) -> Option { - self.timeout - } -} - -impl<'a, C, FilesystemSet> IfSinceConditionOption for DeleteFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn if_since_condition(&self) -> Option { - self.if_since_condition - } -} - -impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> for DeleteFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn client_request_id(&self) -> Option<&'a str> { - self.client_request_id - } -} - -impl<'a, C> FilesystemSupport<'a> for DeleteFilesystemBuilder<'a, C, No> -where - C: Client, -{ - type O = DeleteFilesystemBuilder<'a, C, Yes>; - - #[inline] - fn with_filesystem(self, filesystem: &'a str) -> Self::O { - DeleteFilesystemBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: Some(filesystem), - timeout: self.timeout, - if_since_condition: self.if_since_condition, - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> TimeoutSupport for DeleteFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = DeleteFilesystemBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_timeout(self, timeout: u64) -> Self::O { - DeleteFilesystemBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: Some(timeout), - if_since_condition: self.if_since_condition, - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> IfSinceConditionSupport for DeleteFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = DeleteFilesystemBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_if_since_condition(self, if_since_condition: IfSinceCondition) -> Self::O { - DeleteFilesystemBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: self.timeout, - if_since_condition: Some(if_since_condition), - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> for DeleteFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = DeleteFilesystemBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { - DeleteFilesystemBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: self.timeout, - if_since_condition: self.if_since_condition, - client_request_id: Some(client_request_id), - } - } -} - -impl<'a, C, FilesystemSet> DeleteFilesystemBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ -} - -impl<'a, C> DeleteFilesystemBuilder<'a, C, Yes> -where - C: Client, -{ - pub async fn finalize(self) -> Result { - let mut uri = format!( - "{}/{}?resource=filesystem", - self.client().filesystem_uri(), - self.filesystem() - ); - - if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { - uri = format!("{}&{}", uri, nm); - } - - let future_response = self.client().perform_request( - &uri, - &Method::PUT, - &|mut request| { - request = IfSinceConditionOption::add_header(&self, request); - request = ClientRequestIdOption::add_header(&self, request); - request - }, - Some(&[]), - )?; - - let (headers, _body) = - check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; - DeleteFilesystemResponse::from_headers(&headers) - } -} +use crate::core::prelude::*; +use crate::filesystem::responses::DeleteFilesystemResponse; +use crate::filesystem::{FilesystemRequired, FilesystemSupport}; +use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; +use azure_core::prelude::*; +use azure_core::{ + ClientRequestIdOption, ClientRequestIdSupport, IfSinceConditionOption, IfSinceConditionSupport, + TimeoutOption, TimeoutSupport, +}; +use azure_core::{No, ToAssign, Yes}; +use hyper::{Method, StatusCode}; +use std::marker::PhantomData; + +#[derive(Debug, Clone)] +pub struct DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + client: &'a C, + p_filesystem: PhantomData, + filesystem: Option<&'a str>, + timeout: Option, + if_since_condition: Option, + client_request_id: Option<&'a str>, +} + +impl<'a, C> DeleteFilesystemBuilder<'a, C, No> +where + C: Client, +{ + pub(crate) fn new(client: &'a C) -> DeleteFilesystemBuilder<'a, C, No> { + DeleteFilesystemBuilder { + client, + p_filesystem: PhantomData {}, + filesystem: None, + timeout: None, + if_since_condition: None, + client_request_id: None, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequired<'a, C> for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client(&self) -> &'a C { + self.client + } +} + +impl<'a, C> FilesystemRequired<'a> for DeleteFilesystemBuilder<'a, C, Yes> +where + C: Client, +{ + #[inline] + fn filesystem(&self) -> &'a str { + self.filesystem.unwrap() + } +} + +impl<'a, C, FilesystemSet> TimeoutOption for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn timeout(&self) -> Option { + self.timeout + } +} + +impl<'a, C, FilesystemSet> IfSinceConditionOption for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn if_since_condition(&self) -> Option { + self.if_since_condition + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> + for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client_request_id(&self) -> Option<&'a str> { + self.client_request_id + } +} + +impl<'a, C> FilesystemSupport<'a> for DeleteFilesystemBuilder<'a, C, No> +where + C: Client, +{ + type O = DeleteFilesystemBuilder<'a, C, Yes>; + + #[inline] + fn with_filesystem(self, filesystem: &'a str) -> Self::O { + DeleteFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: Some(filesystem), + timeout: self.timeout, + if_since_condition: self.if_since_condition, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> TimeoutSupport for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = DeleteFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_timeout(self, timeout: u64) -> Self::O { + DeleteFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: Some(timeout), + if_since_condition: self.if_since_condition, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> IfSinceConditionSupport for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = DeleteFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_if_since_condition(self, if_since_condition: IfSinceCondition) -> Self::O { + DeleteFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + if_since_condition: Some(if_since_condition), + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> + for DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = DeleteFilesystemBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { + DeleteFilesystemBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + if_since_condition: self.if_since_condition, + client_request_id: Some(client_request_id), + } + } +} + +impl<'a, C, FilesystemSet> DeleteFilesystemBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ +} + +impl<'a, C> DeleteFilesystemBuilder<'a, C, Yes> +where + C: Client, +{ + pub async fn finalize(self) -> Result { + let mut uri = format!( + "{}/{}?resource=filesystem", + self.client().filesystem_uri(), + self.filesystem() + ); + + if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + let future_response = self.client().perform_request( + &uri, + &Method::HEAD, + &|mut request| { + request = IfSinceConditionOption::add_header(&self, request); + request = ClientRequestIdOption::add_header(&self, request); + request + }, + Some(&[]), + )?; + + let (headers, _body) = + check_status_extract_headers_and_body(future_response, StatusCode::ACCEPTED).await?; + DeleteFilesystemResponse::from_headers(&headers) + } +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs index b4294db631..59fc3200b9 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs +++ b/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs @@ -1,173 +1,176 @@ -use crate::core::prelude::*; -use crate::filesystem::responses::GetFilesystemPropertiesResponse; -use crate::filesystem::{FilesystemRequired, FilesystemSupport}; -use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; -use azure_core::{ClientRequestIdOption, ClientRequestIdSupport, TimeoutOption, TimeoutSupport}; -use azure_core::{No, ToAssign, Yes}; -use hyper::{Method, StatusCode}; -use std::marker::PhantomData; - -#[derive(Debug, Clone)] -pub struct GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - client: &'a C, - p_filesystem: PhantomData, - filesystem: Option<&'a str>, - timeout: Option, - client_request_id: Option<&'a str>, -} - -impl<'a, C> GetFilesystemPropertiesBuilder<'a, C, No> -where - C: Client, -{ - pub(crate) fn new(client: &'a C) -> GetFilesystemPropertiesBuilder<'a, C, No> { - GetFilesystemPropertiesBuilder { - client, - p_filesystem: PhantomData {}, - filesystem: None, - timeout: None, - client_request_id: None, - } - } -} - -impl<'a, C, FilesystemSet> ClientRequired<'a, C> for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn client(&self) -> &'a C { - self.client - } -} - -impl<'a, C> FilesystemRequired<'a> for GetFilesystemPropertiesBuilder<'a, C, Yes> -where - C: Client, -{ - #[inline] - fn filesystem(&self) -> &'a str { - self.filesystem.unwrap() - } -} - -impl<'a, C, FilesystemSet> TimeoutOption for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn timeout(&self) -> Option { - self.timeout - } -} - -impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn client_request_id(&self) -> Option<&'a str> { - self.client_request_id - } -} - -impl<'a, C> FilesystemSupport<'a> for GetFilesystemPropertiesBuilder<'a, C, No> -where - C: Client, -{ - type O = GetFilesystemPropertiesBuilder<'a, C, Yes>; - - #[inline] - fn with_filesystem(self, filesystem: &'a str) -> Self::O { - GetFilesystemPropertiesBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: Some(filesystem), - timeout: self.timeout, - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> TimeoutSupport for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = GetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_timeout(self, timeout: u64) -> Self::O { - GetFilesystemPropertiesBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: Some(timeout), - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = GetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { - GetFilesystemPropertiesBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: self.timeout, - client_request_id: Some(client_request_id), - } - } -} - -impl<'a, C, FilesystemSet> GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ -} - -impl<'a, C> GetFilesystemPropertiesBuilder<'a, C, Yes> -where - C: Client, -{ - pub async fn finalize(self) -> Result { - let mut uri = format!( - "{}/{}?resource=filesystem", - self.client().filesystem_uri(), - self.filesystem() - ); - - if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { - uri = format!("{}&{}", uri, nm); - } - - let future_response = self.client().perform_request( - &uri, - &Method::PUT, - &|mut request| { - request = ClientRequestIdOption::add_header(&self, request); - request - }, - Some(&[]), - )?; - - let (headers, _body) = - check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; - GetFilesystemPropertiesResponse::from_headers(&headers) - } -} +use crate::core::prelude::*; +use crate::filesystem::responses::GetFilesystemPropertiesResponse; +use crate::filesystem::{FilesystemRequired, FilesystemSupport}; +use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; +use azure_core::{ClientRequestIdOption, ClientRequestIdSupport, TimeoutOption, TimeoutSupport}; +use azure_core::{No, ToAssign, Yes}; +use hyper::{Method, StatusCode}; +use std::marker::PhantomData; + +#[derive(Debug, Clone)] +pub struct GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + client: &'a C, + p_filesystem: PhantomData, + filesystem: Option<&'a str>, + timeout: Option, + client_request_id: Option<&'a str>, +} + +impl<'a, C> GetFilesystemPropertiesBuilder<'a, C, No> +where + C: Client, +{ + pub(crate) fn new(client: &'a C) -> GetFilesystemPropertiesBuilder<'a, C, No> { + GetFilesystemPropertiesBuilder { + client, + p_filesystem: PhantomData {}, + filesystem: None, + timeout: None, + client_request_id: None, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequired<'a, C> + for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client(&self) -> &'a C { + self.client + } +} + +impl<'a, C> FilesystemRequired<'a> for GetFilesystemPropertiesBuilder<'a, C, Yes> +where + C: Client, +{ + #[inline] + fn filesystem(&self) -> &'a str { + self.filesystem.unwrap() + } +} + +impl<'a, C, FilesystemSet> TimeoutOption for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn timeout(&self) -> Option { + self.timeout + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> + for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client_request_id(&self) -> Option<&'a str> { + self.client_request_id + } +} + +impl<'a, C> FilesystemSupport<'a> for GetFilesystemPropertiesBuilder<'a, C, No> +where + C: Client, +{ + type O = GetFilesystemPropertiesBuilder<'a, C, Yes>; + + #[inline] + fn with_filesystem(self, filesystem: &'a str) -> Self::O { + GetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: Some(filesystem), + timeout: self.timeout, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> TimeoutSupport for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = GetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_timeout(self, timeout: u64) -> Self::O { + GetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: Some(timeout), + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> + for GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = GetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { + GetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + client_request_id: Some(client_request_id), + } + } +} + +impl<'a, C, FilesystemSet> GetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ +} + +impl<'a, C> GetFilesystemPropertiesBuilder<'a, C, Yes> +where + C: Client, +{ + pub async fn finalize(self) -> Result { + let mut uri = format!( + "{}/{}?resource=filesystem", + self.client().filesystem_uri(), + self.filesystem() + ); + + if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + let future_response = self.client().perform_request( + &uri, + &Method::GET, + &|mut request| { + request = ClientRequestIdOption::add_header(&self, request); + request + }, + Some(&[]), + )?; + + let (headers, _body) = + check_status_extract_headers_and_body(future_response, StatusCode::OK).await?; + GetFilesystemPropertiesResponse::from_headers(&headers) + } +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs index ab7092f4fb..a2dc7b0f9f 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs +++ b/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs @@ -1,6 +1,6 @@ use crate::core::prelude::*; use crate::filesystem::responses::ListFilesystemsResponse; -use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; +use azure_core::errors::{check_status_extract_headers_and_body_as_string, AzureError}; use azure_core::prelude::*; use futures::stream::{unfold, Stream}; use hyper::{Method, StatusCode}; @@ -210,7 +210,7 @@ where let future_response = self.client().perform_request( &uri, - &Method::PUT, + &Method::PATCH, &|mut request| { request = ClientRequestIdOption::add_header(&self, request); request @@ -218,9 +218,10 @@ where Some(&[]), )?; - let (headers, _body) = - check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; - ListFilesystemsResponse::from_headers(&headers) + let (headers, body) = + check_status_extract_headers_and_body_as_string(future_response, StatusCode::OK) + .await?; + ListFilesystemsResponse::from_response(&headers, &body) } } @@ -254,7 +255,7 @@ where Err(err) => return Some((Err(err), None)), }; - let continuation = match &response.continuation { + let continuation = match response.incomplete_vector.token() { Some(ct) => Some(States::Continuation(ct.to_owned())), None => None, }; diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs index 9c74c81ff9..4f5e53af86 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs +++ b/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs @@ -1,255 +1,262 @@ -use crate::core::prelude::*; -use crate::filesystem::responses::SetFilesystemPropertiesResponse; -use crate::filesystem::{ - FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport, -}; -use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; -use azure_core::prelude::*; -use azure_core::{ - ClientRequestIdOption, ClientRequestIdSupport, IfSinceConditionOption, IfSinceConditionSupport, - TimeoutOption, TimeoutSupport, -}; -use azure_core::{No, ToAssign, Yes}; -use hyper::{Method, StatusCode}; -use std::marker::PhantomData; - -#[derive(Debug, Clone)] -pub struct SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - client: &'a C, - p_filesystem: PhantomData, - filesystem: Option<&'a str>, - timeout: Option, - properties: Option<&'a str>, - if_since_condition: Option, - client_request_id: Option<&'a str>, -} - -impl<'a, C> SetFilesystemPropertiesBuilder<'a, C, No> -where - C: Client, -{ - pub(crate) fn new(client: &'a C) -> SetFilesystemPropertiesBuilder<'a, C, No> { - SetFilesystemPropertiesBuilder { - client, - p_filesystem: PhantomData {}, - filesystem: None, - timeout: None, - properties: None, - if_since_condition: None, - client_request_id: None, - } - } -} - -impl<'a, C, FilesystemSet> ClientRequired<'a, C> for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn client(&self) -> &'a C { - self.client - } -} - -impl<'a, C> FilesystemRequired<'a> for SetFilesystemPropertiesBuilder<'a, C, Yes> -where - C: Client, -{ - #[inline] - fn filesystem(&self) -> &'a str { - self.filesystem.unwrap() - } -} - -impl<'a, C, FilesystemSet> TimeoutOption for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn timeout(&self) -> Option { - self.timeout - } -} - -impl<'a, C, FilesystemSet> PropertiesOption<'a> for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn properties(&self) -> Option<&'a str> { - self.properties - } -} - -impl<'a, C, FilesystemSet> IfSinceConditionOption for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn if_since_condition(&self) -> Option { - self.if_since_condition - } -} - -impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - #[inline] - fn client_request_id(&self) -> Option<&'a str> { - self.client_request_id - } -} - -impl<'a, C> FilesystemSupport<'a> for SetFilesystemPropertiesBuilder<'a, C, No> -where - C: Client, -{ - type O = SetFilesystemPropertiesBuilder<'a, C, Yes>; - - #[inline] - fn with_filesystem(self, filesystem: &'a str) -> Self::O { - SetFilesystemPropertiesBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: Some(filesystem), - timeout: self.timeout, - properties: self.properties, - if_since_condition: self.if_since_condition, - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> TimeoutSupport for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_timeout(self, timeout: u64) -> Self::O { - SetFilesystemPropertiesBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: Some(timeout), - properties: self.properties, - if_since_condition: self.if_since_condition, - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> PropertiesSupport<'a> for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_properties(self, properties: &'a str) -> Self::O { - SetFilesystemPropertiesBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: self.timeout, - properties: Some(properties), - if_since_condition: self.if_since_condition, - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> IfSinceConditionSupport for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_if_since_condition(self, if_since_condition: IfSinceCondition) -> Self::O { - SetFilesystemPropertiesBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: self.timeout, - properties: self.properties, - if_since_condition: Some(if_since_condition), - client_request_id: self.client_request_id, - } - } -} - -impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ - type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; - - #[inline] - fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { - SetFilesystemPropertiesBuilder { - client: self.client, - p_filesystem: PhantomData {}, - filesystem: self.filesystem, - timeout: self.timeout, - properties: self.properties, - if_since_condition: self.if_since_condition, - client_request_id: Some(client_request_id), - } - } -} - -impl<'a, C, FilesystemSet> SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> -where - FilesystemSet: ToAssign, - C: Client, -{ -} - -impl<'a, C> SetFilesystemPropertiesBuilder<'a, C, Yes> -where - C: Client, -{ - pub async fn finalize(self) -> Result { - let mut uri = format!( - "{}/{}?resource=filesystem", - self.client().filesystem_uri(), - self.filesystem() - ); - - if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { - uri = format!("{}&{}", uri, nm); - } - - let future_response = self.client().perform_request( - &uri, - &Method::PUT, - &|mut request| { - request = IfSinceConditionOption::add_header(&self, request); - request = ClientRequestIdOption::add_header(&self, request); - request = PropertiesOption::add_header(&self, request); - request - }, - Some(&[]), - )?; - - let (headers, _body) = - check_status_extract_headers_and_body(future_response, StatusCode::CREATED).await?; - SetFilesystemPropertiesResponse::from_headers(&headers) - } -} +use crate::core::prelude::*; +use crate::filesystem::responses::SetFilesystemPropertiesResponse; +use crate::filesystem::{ + FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport, +}; +use azure_core::errors::{check_status_extract_headers_and_body, AzureError}; +use azure_core::prelude::*; +use azure_core::{ + ClientRequestIdOption, ClientRequestIdSupport, IfSinceConditionOption, IfSinceConditionSupport, + TimeoutOption, TimeoutSupport, +}; +use azure_core::{No, ToAssign, Yes}; +use hyper::{Method, StatusCode}; +use std::marker::PhantomData; + +#[derive(Debug, Clone)] +pub struct SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + client: &'a C, + p_filesystem: PhantomData, + filesystem: Option<&'a str>, + timeout: Option, + properties: Option<&'a str>, + if_since_condition: Option, + client_request_id: Option<&'a str>, +} + +impl<'a, C> SetFilesystemPropertiesBuilder<'a, C, No> +where + C: Client, +{ + pub(crate) fn new(client: &'a C) -> SetFilesystemPropertiesBuilder<'a, C, No> { + SetFilesystemPropertiesBuilder { + client, + p_filesystem: PhantomData {}, + filesystem: None, + timeout: None, + properties: None, + if_since_condition: None, + client_request_id: None, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequired<'a, C> + for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client(&self) -> &'a C { + self.client + } +} + +impl<'a, C> FilesystemRequired<'a> for SetFilesystemPropertiesBuilder<'a, C, Yes> +where + C: Client, +{ + #[inline] + fn filesystem(&self) -> &'a str { + self.filesystem.unwrap() + } +} + +impl<'a, C, FilesystemSet> TimeoutOption for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn timeout(&self) -> Option { + self.timeout + } +} + +impl<'a, C, FilesystemSet> PropertiesOption<'a> + for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn properties(&self) -> Option<&'a str> { + self.properties + } +} + +impl<'a, C, FilesystemSet> IfSinceConditionOption + for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn if_since_condition(&self) -> Option { + self.if_since_condition + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdOption<'a> + for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + #[inline] + fn client_request_id(&self) -> Option<&'a str> { + self.client_request_id + } +} + +impl<'a, C> FilesystemSupport<'a> for SetFilesystemPropertiesBuilder<'a, C, No> +where + C: Client, +{ + type O = SetFilesystemPropertiesBuilder<'a, C, Yes>; + + #[inline] + fn with_filesystem(self, filesystem: &'a str) -> Self::O { + SetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: Some(filesystem), + timeout: self.timeout, + properties: self.properties, + if_since_condition: self.if_since_condition, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> TimeoutSupport for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_timeout(self, timeout: u64) -> Self::O { + SetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: Some(timeout), + properties: self.properties, + if_since_condition: self.if_since_condition, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> PropertiesSupport<'a> + for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_properties(self, properties: &'a str) -> Self::O { + SetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + properties: Some(properties), + if_since_condition: self.if_since_condition, + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> IfSinceConditionSupport + for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_if_since_condition(self, if_since_condition: IfSinceCondition) -> Self::O { + SetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + properties: self.properties, + if_since_condition: Some(if_since_condition), + client_request_id: self.client_request_id, + } + } +} + +impl<'a, C, FilesystemSet> ClientRequestIdSupport<'a> + for SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ + type O = SetFilesystemPropertiesBuilder<'a, C, FilesystemSet>; + + #[inline] + fn with_client_request_id(self, client_request_id: &'a str) -> Self::O { + SetFilesystemPropertiesBuilder { + client: self.client, + p_filesystem: PhantomData {}, + filesystem: self.filesystem, + timeout: self.timeout, + properties: self.properties, + if_since_condition: self.if_since_condition, + client_request_id: Some(client_request_id), + } + } +} + +impl<'a, C, FilesystemSet> SetFilesystemPropertiesBuilder<'a, C, FilesystemSet> +where + FilesystemSet: ToAssign, + C: Client, +{ +} + +impl<'a, C> SetFilesystemPropertiesBuilder<'a, C, Yes> +where + C: Client, +{ + pub async fn finalize(self) -> Result { + let mut uri = format!( + "{}/{}?resource=filesystem", + self.client().filesystem_uri(), + self.filesystem() + ); + + if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { + uri = format!("{}&{}", uri, nm); + } + + let future_response = self.client().perform_request( + &uri, + &Method::PUT, + &|mut request| { + request = IfSinceConditionOption::add_header(&self, request); + request = ClientRequestIdOption::add_header(&self, request); + request = PropertiesOption::add_header(&self, request); + request + }, + Some(&[]), + )?; + + let (headers, _body) = + check_status_extract_headers_and_body(future_response, StatusCode::OK).await?; + SetFilesystemPropertiesResponse::from_headers(&headers) + } +} diff --git a/sdk/storage/src/adls_gen2/filesystem/responses/list_filesystems_response.rs b/sdk/storage/src/adls_gen2/filesystem/responses/list_filesystems_response.rs index 43bb074418..036d07747b 100644 --- a/sdk/storage/src/adls_gen2/filesystem/responses/list_filesystems_response.rs +++ b/sdk/storage/src/adls_gen2/filesystem/responses/list_filesystems_response.rs @@ -1,11 +1,38 @@ -use azure_core::headers::*; +use crate::filesystem::{incomplete_vector_from_response, Filesystem}; +use azure_core::errors::AzureError; +use azure_core::headers::{ + content_type_from_headers, date_from_headers, request_id_from_headers, version_from_headers, +}; +use azure_core::incompletevector::IncompleteVector; use azure_core::RequestId; use chrono::{DateTime, Utc}; +use http::HeaderMap; -response_from_headers!(ListFilesystemsResponse, - date_from_headers => date: DateTime, - etag_from_headers => etag: String, - last_modified_from_headers => last_modified: DateTime, - request_id_from_headers => request_id: RequestId, - continuation_token_from_headers_optional => continuation: Option -); +pub struct ListFilesystemsResponse { + pub incomplete_vector: IncompleteVector, + pub date: DateTime, + pub request_id: RequestId, + pub version: String, + pub content_type: String, +} + +impl ListFilesystemsResponse { + pub(crate) fn from_response( + headers: &HeaderMap, + body: &str, + ) -> Result { + let incomplete_vector = incomplete_vector_from_response(headers, body)?; + let date = date_from_headers(&headers)?; + let request_id = request_id_from_headers(&headers)?; + let version = version_from_headers(&headers)?.to_owned(); + let content_type = content_type_from_headers(&headers)?.to_owned(); + + Ok(ListFilesystemsResponse { + incomplete_vector, + date, + request_id, + version, + content_type, + }) + } +} From f0c123664f73b61f6a0cad6588cd29cd5de34a34 Mon Sep 17 00:00:00 2001 From: Sam Wlody Date: Sat, 31 Oct 2020 01:46:36 -0400 Subject: [PATCH 3/4] Format json --- .../requests/create_filesystem_builder.json | 4 +- .../requests/delete_filesystem_builder.json | 2 +- .../get_filesystem_properties_builder.json | 108 +++++++------- .../requests/list_filesystems_builder.json | 130 ++++++++--------- .../set_filesystem_properties_builder.json | 136 +++++++++--------- 5 files changed, 190 insertions(+), 190 deletions(-) diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.json b/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.json index c2376f7bdf..46bbe70f74 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.json +++ b/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.json @@ -30,7 +30,7 @@ { "name": "filesystem", "field_type": "&'a str", - "builder_type": "ContainerNameSet", + "builder_type": "FilesystemSet", "optional": false, "trait_get": "FilesystemRequired<'a>", "trait_set": "FilesystemSupport<'a>" @@ -57,4 +57,4 @@ "trait_set": "ClientRequestIdSupport<'a>" } ] -} \ No newline at end of file +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.json b/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.json index 2b25785034..ffab5f61a7 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.json +++ b/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.json @@ -58,4 +58,4 @@ "trait_set": "ClientRequestIdSupport<'a>" } ] -} \ No newline at end of file +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.json b/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.json index 4229ccfb82..34c05ab90b 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.json +++ b/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.json @@ -1,54 +1,54 @@ -{ - "name": "GetFilesystemPropertiesBuilder", - "derive": "Debug, Clone", - "uses": [ - "crate::core::prelude::*", - "crate::filesystem::responses::GetFilesystemPropertiesResponse", - "crate::filesystem::{FilesystemSupport, FilesystemRequired}", - "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", - "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, TimeoutOption, TimeoutSupport}", - "azure_core::{No, ToAssign, Yes}", - "azure_sdk_storage_core::prelude::*", - "hyper::{Method, StatusCode}", - "std::marker::PhantomData" - ], - "inline": true, - "extra_types": [ - "'a", - "C" - ], - "extra_wheres": [ - "C: Client" - ], - "constructor_fields": [ - { - "name": "client", - "field_type": "&'a C", - "trait_get": "ClientRequired<'a, C>" - } - ], - "fields": [ - { - "name": "filesystem", - "field_type": "&'a str", - "builder_type": "ContainerNameSet", - "optional": false, - "trait_get": "FilesystemRequired<'a>", - "trait_set": "FilesystemSupport<'a>" - }, - { - "name": "timeout", - "field_type": "u64", - "optional": true, - "trait_get": "TimeoutOption", - "trait_set": "TimeoutSupport" - }, - { - "name": "client_request_id", - "field_type": "&'a str", - "optional": true, - "trait_get": "ClientRequestIdOption<'a>", - "trait_set": "ClientRequestIdSupport<'a>" - } - ] -} \ No newline at end of file +{ + "name": "GetFilesystemPropertiesBuilder", + "derive": "Debug, Clone", + "uses": [ + "crate::core::prelude::*", + "crate::filesystem::responses::GetFilesystemPropertiesResponse", + "crate::filesystem::{FilesystemSupport, FilesystemRequired}", + "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", + "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, TimeoutOption, TimeoutSupport}", + "azure_core::{No, ToAssign, Yes}", + "azure_sdk_storage_core::prelude::*", + "hyper::{Method, StatusCode}", + "std::marker::PhantomData" + ], + "inline": true, + "extra_types": [ + "'a", + "C" + ], + "extra_wheres": [ + "C: Client" + ], + "constructor_fields": [ + { + "name": "client", + "field_type": "&'a C", + "trait_get": "ClientRequired<'a, C>" + } + ], + "fields": [ + { + "name": "filesystem", + "field_type": "&'a str", + "builder_type": "ContainerNameSet", + "optional": false, + "trait_get": "FilesystemRequired<'a>", + "trait_set": "FilesystemSupport<'a>" + }, + { + "name": "timeout", + "field_type": "u64", + "optional": true, + "trait_get": "TimeoutOption", + "trait_set": "TimeoutSupport" + }, + { + "name": "client_request_id", + "field_type": "&'a str", + "optional": true, + "trait_get": "ClientRequestIdOption<'a>", + "trait_set": "ClientRequestIdSupport<'a>" + } + ] +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.json b/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.json index 73d3d6c6be..8063149327 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.json +++ b/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.json @@ -1,65 +1,65 @@ -{ - "name": "ListFilesystemsBuilder", - "derive": "Debug, Clone", - "uses": [ - "crate::core::prelude::*", - "crate::filesystem::responses::ListFilesystemResponse", - "crate::filesystem::{ContinuationOption, ContinuationSupport}", - "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", - "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, ContinuationOption, ContinuationSupport, MaxResultsOption, MaxResultsSupport, PrefixOption, PrefixSupport, TimeoutOption, TimeoutSupport}", - "futures::stream::{unfold, Stream}", - "hyper::{Method, StatusCode}" - ], - "inline": true, - "extra_types": [ - "'a", - "C" - ], - "extra_wheres": [ - "C: Client" - ], - "constructor_fields": [ - { - "name": "client", - "field_type": "&'a C", - "trait_get": "ClientRequired<'a, C>" - } - ], - "fields": [ - { - "name": "continuation", - "field_type": "&'a str", - "optional": true, - "trait_get": "ContinuationOption", - "trait_set": "ContinuationSupport" - }, - { - "name": "max_results", - "field_type": "u32", - "optional": true, - "trait_get": "MaxResultsOption", - "trait_set": "MaxResultsSupport" - }, - { - "name": "prefix", - "field_type": "&'a str", - "optional": true, - "trait_get": "PrefixOption", - "trait_set": "PrefixSupport" - }, - { - "name": "timeout", - "field_type": "u64", - "optional": true, - "trait_get": "TimeoutOption", - "trait_set": "TimeoutSupport" - }, - { - "name": "client_request_id", - "field_type": "&'a str", - "optional": true, - "trait_get": "ClientRequestIdOption<'a>", - "trait_set": "ClientRequestIdSupport<'a>" - } - ] -} \ No newline at end of file +{ + "name": "ListFilesystemsBuilder", + "derive": "Debug, Clone", + "uses": [ + "crate::core::prelude::*", + "crate::filesystem::responses::ListFilesystemResponse", + "crate::filesystem::{ContinuationOption, ContinuationSupport}", + "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", + "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, ContinuationOption, ContinuationSupport, MaxResultsOption, MaxResultsSupport, PrefixOption, PrefixSupport, TimeoutOption, TimeoutSupport}", + "futures::stream::{unfold, Stream}", + "hyper::{Method, StatusCode}" + ], + "inline": true, + "extra_types": [ + "'a", + "C" + ], + "extra_wheres": [ + "C: Client" + ], + "constructor_fields": [ + { + "name": "client", + "field_type": "&'a C", + "trait_get": "ClientRequired<'a, C>" + } + ], + "fields": [ + { + "name": "continuation", + "field_type": "&'a str", + "optional": true, + "trait_get": "ContinuationOption", + "trait_set": "ContinuationSupport" + }, + { + "name": "max_results", + "field_type": "u32", + "optional": true, + "trait_get": "MaxResultsOption", + "trait_set": "MaxResultsSupport" + }, + { + "name": "prefix", + "field_type": "&'a str", + "optional": true, + "trait_get": "PrefixOption", + "trait_set": "PrefixSupport" + }, + { + "name": "timeout", + "field_type": "u64", + "optional": true, + "trait_get": "TimeoutOption", + "trait_set": "TimeoutSupport" + }, + { + "name": "client_request_id", + "field_type": "&'a str", + "optional": true, + "trait_get": "ClientRequestIdOption<'a>", + "trait_set": "ClientRequestIdSupport<'a>" + } + ] +} diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.json b/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.json index ab9baaa974..964c531034 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.json +++ b/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.json @@ -1,68 +1,68 @@ -{ - "name": "SetFilesystemPropertiesBuilder", - "derive": "Debug, Clone", - "uses": [ - "core::prelude::*", - "crate::filesystem::responses::SetFilesystemPropertiesResponse", - "crate::filesystem::{FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport}", - "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", - "azure_core::prelude::*", - "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, IfSinceConditionOption, IfSinceConditionSupport,TimeoutOption, TimeoutSupport}", - "azure_core::{No, ToAssign, Yes}", - "hyper::{Method, StatusCode}", - "std::marker::PhantomData" - ], - "inline": true, - "extra_types": [ - "'a", - "C" - ], - "extra_wheres": [ - "C: Client" - ], - "constructor_fields": [ - { - "name": "client", - "field_type": "&'a C", - "trait_get": "ClientRequired<'a, C>" - } - ], - "fields": [ - { - "name": "filesystem", - "field_type": "&'a str", - "builder_type": "ContainerNameSet", - "optional": false, - "trait_get": "FilesystemRequired<'a>", - "trait_set": "FilesystemSupport<'a>" - }, - { - "name": "timeout", - "field_type": "u64", - "optional": true, - "trait_get": "TimeoutOption", - "trait_set": "TimeoutSupport" - }, - { - "name": "properties", - "field_type": "&'a str", - "optional": true, - "trait_get": "PropertiesOption", - "trait_set": "PropertiesSupport" - }, - { - "name": "if_since_condition", - "field_type": "IfSinceCondition", - "optional": true, - "trait_get": "IfSinceConditionOption", - "trait_set": "IfSinceConditionSupport" - }, - { - "name": "client_request_id", - "field_type": "&'a str", - "optional": true, - "trait_get": "ClientRequestIdOption<'a>", - "trait_set": "ClientRequestIdSupport<'a>" - } - ] -} \ No newline at end of file +{ + "name": "SetFilesystemPropertiesBuilder", + "derive": "Debug, Clone", + "uses": [ + "core::prelude::*", + "crate::filesystem::responses::SetFilesystemPropertiesResponse", + "crate::filesystem::{FilesystemRequired, FilesystemSupport, PropertiesOption, PropertiesSupport}", + "azure_core::errors::{check_status_extract_headers_and_body, AzureError}", + "azure_core::prelude::*", + "azure_core::{ClientRequestIdOption, ClientRequestIdSupport, IfSinceConditionOption, IfSinceConditionSupport,TimeoutOption, TimeoutSupport}", + "azure_core::{No, ToAssign, Yes}", + "hyper::{Method, StatusCode}", + "std::marker::PhantomData" + ], + "inline": true, + "extra_types": [ + "'a", + "C" + ], + "extra_wheres": [ + "C: Client" + ], + "constructor_fields": [ + { + "name": "client", + "field_type": "&'a C", + "trait_get": "ClientRequired<'a, C>" + } + ], + "fields": [ + { + "name": "filesystem", + "field_type": "&'a str", + "builder_type": "ContainerNameSet", + "optional": false, + "trait_get": "FilesystemRequired<'a>", + "trait_set": "FilesystemSupport<'a>" + }, + { + "name": "timeout", + "field_type": "u64", + "optional": true, + "trait_get": "TimeoutOption", + "trait_set": "TimeoutSupport" + }, + { + "name": "properties", + "field_type": "&'a str", + "optional": true, + "trait_get": "PropertiesOption", + "trait_set": "PropertiesSupport" + }, + { + "name": "if_since_condition", + "field_type": "IfSinceCondition", + "optional": true, + "trait_get": "IfSinceConditionOption", + "trait_set": "IfSinceConditionSupport" + }, + { + "name": "client_request_id", + "field_type": "&'a str", + "optional": true, + "trait_get": "ClientRequestIdOption<'a>", + "trait_set": "ClientRequestIdSupport<'a>" + } + ] +} From 5d786138c043a641ccdd9de90d71852ebbe98698 Mon Sep 17 00:00:00 2001 From: Sam Wlody Date: Sun, 1 Nov 2020 22:03:13 -0500 Subject: [PATCH 4/4] Add E2E tests and fix silly mistakes uncovered by them --- sdk/core/src/headers/mod.rs | 2 +- sdk/storage/src/adls_gen2/filesystem/mod.rs | 45 +++------ .../requests/create_filesystem_builder.rs | 2 +- .../requests/delete_filesystem_builder.rs | 2 +- .../get_filesystem_properties_builder.rs | 2 +- .../requests/list_filesystems_builder.rs | 2 +- .../set_filesystem_properties_builder.rs | 2 +- sdk/storage/tests/filesystem.rs | 92 +++++++++++++++++++ 8 files changed, 113 insertions(+), 36 deletions(-) create mode 100644 sdk/storage/tests/filesystem.rs diff --git a/sdk/core/src/headers/mod.rs b/sdk/core/src/headers/mod.rs index 6fc98731e1..6e89c079cd 100644 --- a/sdk/core/src/headers/mod.rs +++ b/sdk/core/src/headers/mod.rs @@ -51,4 +51,4 @@ pub const SESSION_TOKEN: &str = "x-ms-session-token"; pub const REQUIRES_SYNC: &str = "x-ms-requires-sync"; pub const VERSION: &str = "x-ms-version"; pub const PROPERTIES: &str = "x-ms-properties"; //=> [String] } -pub const NAMESPACE_ENABLED: &str = "x-ms-namespace_enabled"; //=> [String] } +pub const NAMESPACE_ENABLED: &str = "x-ms-namespace-enabled"; //=> [String] } diff --git a/sdk/storage/src/adls_gen2/filesystem/mod.rs b/sdk/storage/src/adls_gen2/filesystem/mod.rs index b9a1b7f0cc..3efd963495 100644 --- a/sdk/storage/src/adls_gen2/filesystem/mod.rs +++ b/sdk/storage/src/adls_gen2/filesystem/mod.rs @@ -1,15 +1,12 @@ pub mod requests; pub mod responses; -use std::convert::TryFrom; - use azure_core::errors::AzureError; use azure_core::headers::{CONTINUATION, PROPERTIES}; use azure_core::incompletevector::IncompleteVector; -use azure_core::parsing::{cast_must, traverse}; use azure_core::util::HeaderMapExt; use http::{request::Builder, HeaderMap}; -use xml::Element; +use serde::Deserialize; pub trait FilesystemRequired<'a> { fn filesystem(&self) -> &'a str; @@ -56,27 +53,12 @@ pub(crate) fn namespace_enabled_from_headers(headers: &HeaderMap) -> Result for Filesystem { - type Error = AzureError; - - fn try_from(elem: &Element) -> Result { - let etag = cast_must::(elem, &["eTag"])?; - let last_modified = cast_must::(elem, &["lastModified"])?; - let name = cast_must::(elem, &["Name"])?; - - Ok(Filesystem { - etag, - last_modified, - name, - }) - } + pub etag: String, + #[serde(rename = "lastModified")] + pub last_modified: String, + pub name: String, } #[inline] @@ -86,8 +68,6 @@ pub(crate) fn incomplete_vector_from_response( ) -> Result, AzureError> { trace!("body = {}", body); - let elem: Element = body.parse()?; - let continuation = match headers.get_as_string(CONTINUATION) { Some(ref ct) if ct == "" => None, Some(ct) => Some(ct), @@ -96,10 +76,15 @@ pub(crate) fn incomplete_vector_from_response( debug!("continuation == {:?}", continuation); - let mut v = Vec::new(); - for node_filesystem in traverse(&elem, &["Filesystems", "Filesystem"], true)? { - v.push(Filesystem::try_from(node_filesystem)?); + #[derive(Deserialize)] + struct Filesystems { + filesystems: Vec, } - Ok(IncompleteVector::::new(continuation, v)) + let Filesystems { filesystems } = serde_json::from_str(&body)?; + + Ok(IncompleteVector::::new( + continuation, + filesystems, + )) } diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs index 8bce6427de..f3f88a925a 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs +++ b/sdk/storage/src/adls_gen2/filesystem/requests/create_filesystem_builder.rs @@ -198,7 +198,7 @@ where let future_response = self.client().perform_request( &uri, - &Method::DELETE, + &Method::PUT, &|mut request| { request = ClientRequestIdOption::add_header(&self, request); request = PropertiesOption::add_header(&self, request); diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs index d36cabea42..ac074d8c35 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs +++ b/sdk/storage/src/adls_gen2/filesystem/requests/delete_filesystem_builder.rs @@ -200,7 +200,7 @@ where let future_response = self.client().perform_request( &uri, - &Method::HEAD, + &Method::DELETE, &|mut request| { request = IfSinceConditionOption::add_header(&self, request); request = ClientRequestIdOption::add_header(&self, request); diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs index 59fc3200b9..32bc1963b9 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs +++ b/sdk/storage/src/adls_gen2/filesystem/requests/get_filesystem_properties_builder.rs @@ -161,7 +161,7 @@ where let future_response = self.client().perform_request( &uri, - &Method::GET, + &Method::HEAD, &|mut request| { request = ClientRequestIdOption::add_header(&self, request); request diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs index a2dc7b0f9f..7003c93d0f 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs +++ b/sdk/storage/src/adls_gen2/filesystem/requests/list_filesystems_builder.rs @@ -210,7 +210,7 @@ where let future_response = self.client().perform_request( &uri, - &Method::PATCH, + &Method::GET, &|mut request| { request = ClientRequestIdOption::add_header(&self, request); request diff --git a/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs b/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs index 4f5e53af86..34e296b39e 100644 --- a/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs +++ b/sdk/storage/src/adls_gen2/filesystem/requests/set_filesystem_properties_builder.rs @@ -245,7 +245,7 @@ where let future_response = self.client().perform_request( &uri, - &Method::PUT, + &Method::PATCH, &|mut request| { request = IfSinceConditionOption::add_header(&self, request); request = ClientRequestIdOption::add_header(&self, request); diff --git a/sdk/storage/tests/filesystem.rs b/sdk/storage/tests/filesystem.rs new file mode 100644 index 0000000000..c1332d2e8b --- /dev/null +++ b/sdk/storage/tests/filesystem.rs @@ -0,0 +1,92 @@ +#![cfg(all(test, feature = "test_e2e"))] +use azure_storage::adls_gen2::prelude::*; +use azure_storage::core::prelude::*; + +#[tokio::test] +async fn create_and_delete() { + let filesystem_name1 = "azuresdkrustetoetsfs1"; + let filesystem_name2 = "azuresdkrustetoetsfs2"; + + let properties1 = "n1=eWVz,n2=bm8="; + let properties2 = "n1=bm8=,n2=eWVz"; + + let client = initialize(); + client + .create_filesystem() + .with_filesystem(filesystem_name1) + .finalize() + .await + .unwrap(); + client + .create_filesystem() + .with_filesystem(filesystem_name2) + .with_properties(properties2) + .finalize() + .await + .unwrap(); + + client + .set_filesystem_properties() + .with_filesystem(filesystem_name1) + .with_properties(properties1) + .finalize() + .await + .unwrap(); + + let properties1_response = client + .get_filesystem_properties() + .with_filesystem(filesystem_name1) + .finalize() + .await + .unwrap(); + let properties2_response = client + .get_filesystem_properties() + .with_filesystem(filesystem_name2) + .finalize() + .await + .unwrap(); + + assert_eq!(properties1, properties1_response.properties); + assert_eq!(properties2, properties2_response.properties); + + let (mut found1, mut found2) = (false, false); + for filesystem in client + .list_filesystems() + .finalize() + .await + .unwrap() + .incomplete_vector + .iter() + { + if filesystem.name == filesystem_name1 && !found1 { + found1 = true; + } else if filesystem.name == filesystem_name2 && !found2 { + found2 = true; + } else { + panic!("Unexpected filesystem name."); + } + } + assert!(found1 && found2); + + client + .delete_filesystem() + .with_filesystem(filesystem_name1) + .finalize() + .await + .unwrap(); + client + .delete_filesystem() + .with_filesystem(filesystem_name2) + .finalize() + .await + .unwrap(); +} + +fn initialize() -> Box { + let account = + std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); + let master_key = + std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); + + Box::new(client::with_access_key(&account, &master_key)) +}