├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE ├── README.md ├── _config.yml ├── azure_sdk_auth_aad ├── Cargo.toml ├── README.md ├── examples │ ├── cli_credentials.rs │ ├── client_credentials_flow.rs │ ├── client_credentials_flow_blob.rs │ ├── code_flow.rs │ ├── code_flow_blob.rs │ ├── default_credentials.rs │ ├── device_code_flow.rs │ └── environment_credentials.rs └── src │ ├── device_code_flow.rs │ ├── device_code_responses.rs │ ├── errors.rs │ ├── lib.rs │ ├── login_response.rs │ ├── naive_server.rs │ ├── prelude.rs │ ├── refresh_token.rs │ ├── responses │ ├── mod.rs │ └── refresh_token_response.rs │ ├── token_credentials │ ├── cli_credentials.rs │ ├── client_secret_credentials.rs │ ├── default_credentials.rs │ ├── environment_credentials.rs │ ├── managed_identity_credentials.rs │ └── mod.rs │ └── traits.rs ├── azure_sdk_core ├── .rustfmt.toml ├── Cargo.toml ├── README.md └── src │ ├── ba512_range.rs │ ├── enumerations.rs │ ├── errors.rs │ ├── headers.rs │ ├── incompletevector.rs │ ├── lease.rs │ ├── lib.rs │ ├── modify_conditions.rs │ ├── parsing.rs │ ├── prelude.rs │ ├── range.rs │ ├── stored_access_policy.rs │ └── util.rs ├── azure_sdk_cosmos ├── Cargo.toml ├── README.md ├── examples │ ├── attachments_00.rs │ ├── collection.rs │ ├── create_delete_database.rs │ ├── database_00.rs │ ├── database_01.rs │ ├── document_00.rs │ ├── document_entries_00.rs │ ├── document_entries_01.rs │ ├── key_ranges_00.rs │ ├── permission_00.rs │ ├── query_document_00.rs │ ├── readme.rs │ ├── remove_all_documents.rs │ ├── stored_proc_00.rs │ ├── stored_proc_01.rs │ ├── trigger_00.rs │ ├── user_00.rs │ ├── user_defined_function_00.rs │ └── user_permission_token.rs ├── src │ ├── attachment │ │ ├── attachment_name.rs │ │ └── mod.rs │ ├── authorization_token.rs │ ├── clients │ │ ├── attachment_struct.rs │ │ ├── collection_struct.rs │ │ ├── cosmos_struct.rs │ │ ├── database_struct.rs │ │ ├── document_struct.rs │ │ ├── mod.rs │ │ ├── permission_struct.rs │ │ ├── stored_procedure_struct.rs │ │ ├── trigger_struct.rs │ │ ├── user_defined_function_struct.rs │ │ └── user_struct.rs │ ├── collection.rs │ ├── consistency_level.rs │ ├── database.rs │ ├── document.rs │ ├── document_attributes.rs │ ├── document_options.rs │ ├── errors.rs │ ├── from_headers.rs │ ├── headers.rs │ ├── indexing_directive.rs │ ├── lib.rs │ ├── offer.rs │ ├── partition_key_range.rs │ ├── partition_keys.rs │ ├── permission.rs │ ├── permission_resource.rs │ ├── permission_token.rs │ ├── prelude.rs │ ├── query.rs │ ├── requests │ │ ├── create_collection_builder.json │ │ ├── create_collection_builder.rs │ │ ├── create_database_builder.json │ │ ├── create_database_builder.rs │ │ ├── create_document_builder.json │ │ ├── create_document_builder.rs │ │ ├── create_or_replace_trigger_builder.json │ │ ├── create_or_replace_trigger_builder.rs │ │ ├── create_or_replace_user_defined_function_builder.json │ │ ├── create_or_replace_user_defined_function_builder.rs │ │ ├── create_permission_builder.json │ │ ├── create_permission_builder.rs │ │ ├── create_reference_attachment_builder.json │ │ ├── create_reference_attachment_builder.rs │ │ ├── create_slug_attachment_builder.json │ │ ├── create_slug_attachment_builder.rs │ │ ├── create_stored_procedure_builder.json │ │ ├── create_stored_procedure_builder.rs │ │ ├── create_user_builder.json │ │ ├── create_user_builder.rs │ │ ├── delete_attachment_builder.json │ │ ├── delete_attachment_builder.rs │ │ ├── delete_collection_builder.json │ │ ├── delete_collection_builder.rs │ │ ├── delete_database_builder.json │ │ ├── delete_database_builder.rs │ │ ├── delete_document_builder.json │ │ ├── delete_document_builder.rs │ │ ├── delete_permission_builder.json │ │ ├── delete_permission_builder.rs │ │ ├── delete_stored_procedure_builder.json │ │ ├── delete_stored_procedure_builder.rs │ │ ├── delete_trigger_builder.json │ │ ├── delete_trigger_builder.rs │ │ ├── delete_user_builder.json │ │ ├── delete_user_builder.rs │ │ ├── delete_user_defined_function_builder.json │ │ ├── delete_user_defined_function_builder.rs │ │ ├── execute_stored_procedure_builder.json │ │ ├── execute_stored_procedure_builder.rs │ │ ├── get_attachment_builder.json │ │ ├── get_attachment_builder.rs │ │ ├── get_collection_builder.json │ │ ├── get_collection_builder.rs │ │ ├── get_database_builder.json │ │ ├── get_database_builder.rs │ │ ├── get_document_builder.json │ │ ├── get_document_builder.rs │ │ ├── get_partition_key_ranges_builder.json │ │ ├── get_partition_key_ranges_builder.rs │ │ ├── get_permission_builer.json │ │ ├── get_permission_builer.rs │ │ ├── get_user_builder.json │ │ ├── get_user_builder.rs │ │ ├── list_attachments_builder.json │ │ ├── list_attachments_builder.rs │ │ ├── list_collections_builder.json │ │ ├── list_collections_builder.rs │ │ ├── list_databases_builder.json │ │ ├── list_databases_builder.rs │ │ ├── list_documents_builder.json │ │ ├── list_documents_builder.rs │ │ ├── list_permissions_builder.json │ │ ├── list_permissions_builder.rs │ │ ├── list_stored_procedures_builder.json │ │ ├── list_stored_procedures_builder.rs │ │ ├── list_triggers_builder.json │ │ ├── list_triggers_builder.rs │ │ ├── list_user_defined_functions_builder.json │ │ ├── list_user_defined_functions_builder.rs │ │ ├── list_users_builder.json │ │ ├── list_users_builder.rs │ │ ├── mod.rs │ │ ├── query_documents_builder.json │ │ ├── query_documents_builder.rs │ │ ├── replace_collection_builder.json │ │ ├── replace_collection_builder.rs │ │ ├── replace_document_builder.json │ │ ├── replace_document_builder.rs │ │ ├── replace_permission_builder.json │ │ ├── replace_permission_builder.rs │ │ ├── replace_reference_attachment_builder.json │ │ ├── replace_reference_attachment_builder.rs │ │ ├── replace_slug_attachment_builder.json │ │ ├── replace_slug_attachment_builder.rs │ │ ├── replace_stored_procedure_builder.json │ │ ├── replace_stored_procedure_builder.rs │ │ ├── replace_user_builder.json │ │ └── replace_user_builder.rs │ ├── resource.rs │ ├── resource_quota.rs │ ├── responses │ │ ├── create_collection_response.rs │ │ ├── create_database_response.rs │ │ ├── create_document_response.rs │ │ ├── create_permission_response.rs │ │ ├── create_reference_attachment_response.rs │ │ ├── create_slug_attachment_response.rs │ │ ├── create_stored_procedure_response.rs │ │ ├── create_trigger_response.rs │ │ ├── create_user_defined_function_response.rs │ │ ├── create_user_response.rs │ │ ├── delete_attachment_response.rs │ │ ├── delete_collection_response.rs │ │ ├── delete_database_response.rs │ │ ├── delete_document_response.rs │ │ ├── delete_permission_response.rs │ │ ├── delete_stored_procedure_response.rs │ │ ├── delete_trigger_response.rs │ │ ├── delete_user_defined_function_response.rs │ │ ├── delete_user_response.rs │ │ ├── execute_stored_procedure_response.rs │ │ ├── get_attachment_response.rs │ │ ├── get_collection_response.rs │ │ ├── get_database_response.rs │ │ ├── get_document_response.rs │ │ ├── get_partition_key_ranges_response.rs │ │ ├── get_permission_response.rs │ │ ├── list_attachments_response.rs │ │ ├── list_collections_response.rs │ │ ├── list_databases_response.rs │ │ ├── list_documents_response.rs │ │ ├── list_permissions_response.rs │ │ ├── list_stored_procedures_response.rs │ │ ├── list_triggers_response.rs │ │ ├── list_user_defined_functions_response.rs │ │ ├── list_users_response.rs │ │ ├── mod.rs │ │ ├── query_documents_response.rs │ │ ├── replace_document_response.rs │ │ ├── replace_permission_response.rs │ │ ├── replace_reference_attachment_response.rs │ │ └── replace_stored_procedure_response.rs │ ├── stored_procedure │ │ ├── mod.rs │ │ ├── parameters.rs │ │ └── stored_procedure_name.rs │ ├── to_json_vector.rs │ ├── traits.rs │ ├── trigger.rs │ ├── user.rs │ └── user_defined_function │ │ ├── mod.rs │ │ └── user_defined_function_name.rs └── tests │ ├── attachment_00.rs │ ├── cosmos_collection.rs │ ├── cosmos_database.rs │ ├── cosmos_document.rs │ ├── permission.rs │ ├── permission_token_usage.rs │ ├── setup.rs │ ├── trigger.rs │ ├── user.rs │ └── user_defined_function00.rs ├── azure_sdk_service_bus ├── .rustfmt.toml ├── Cargo.toml ├── README.md ├── examples │ └── service_bus00.rs ├── src │ ├── event_hub │ │ ├── client.rs │ │ └── mod.rs │ ├── lib.rs │ └── prelude.rs └── tests │ └── event_hub.rs ├── azure_sdk_storage_account ├── .rustfmt.toml ├── Cargo.toml ├── README.md ├── examples │ └── account00.rs ├── src │ ├── account │ │ ├── mod.rs │ │ ├── requests │ │ │ ├── get_account_information_builder.json │ │ │ ├── get_account_information_builder.rs │ │ │ └── mod.rs │ │ └── responses │ │ │ ├── get_account_information_response.rs │ │ │ └── mod.rs │ ├── lib.rs │ └── prelude.rs └── tests │ └── account.rs ├── azure_sdk_storage_blob ├── Cargo.toml ├── README.md ├── examples │ ├── blob_00.rs │ ├── blob_01.rs │ ├── blob_02_bearer_token.rs │ ├── blob_03_boxed_client.rs │ ├── blob_04.rs │ ├── blob_05_default_credential.rs │ ├── blob_range.rs │ ├── connection_string.rs │ ├── container_00.rs │ ├── container_01.rs │ ├── container_and_blob.rs │ ├── copy_blob_from_url.rs │ ├── count_blobs.rs │ ├── emulator_00.rs │ ├── list_blobs_00.rs │ ├── put_append_blob_00.rs │ ├── put_block_blob_00.rs │ ├── put_page_blob_00.rs │ ├── shared_access_signature.rs │ └── stream_blob_00.rs ├── src │ ├── blob │ │ ├── blob_block_type.rs │ │ ├── blob_block_with_size.rs │ │ ├── block_list.rs │ │ ├── block_list_type.rs │ │ ├── block_with_size_list.rs │ │ ├── lease_blob_options.rs │ │ ├── mod.rs │ │ ├── requests │ │ │ ├── acquire_blob_lease_builder.json │ │ │ ├── acquire_blob_lease_builder.rs │ │ │ ├── blob_stream_builder.json │ │ │ ├── blob_stream_builder.rs │ │ │ ├── break_blob_lease_builder.json │ │ │ ├── break_blob_lease_builder.rs │ │ │ ├── change_blob_lease_builder.json │ │ │ ├── change_blob_lease_builder.rs │ │ │ ├── clear_page_builder.json │ │ │ ├── clear_page_builder.rs │ │ │ ├── copy_blob_from_url_builder.json │ │ │ ├── copy_blob_from_url_builder.rs │ │ │ ├── delete_blob_builder.json │ │ │ ├── delete_blob_builder.rs │ │ │ ├── delete_blob_snapshot_builder.json │ │ │ ├── delete_blob_snapshot_builder.rs │ │ │ ├── get_blob_builder.json │ │ │ ├── get_blob_builder.rs │ │ │ ├── get_block_list_builder.json │ │ │ ├── get_block_list_builder.rs │ │ │ ├── mod.rs │ │ │ ├── put_append_blob_builder.json │ │ │ ├── put_append_blob_builder.rs │ │ │ ├── put_append_block_builder.json │ │ │ ├── put_append_block_builder.rs │ │ │ ├── put_block_blob_builder.json │ │ │ ├── put_block_blob_builder.rs │ │ │ ├── put_block_builder.json │ │ │ ├── put_block_builder.rs │ │ │ ├── put_block_list_builder.json │ │ │ ├── put_block_list_builder.rs │ │ │ ├── put_page_blob_builder.json │ │ │ ├── put_page_blob_builder.rs │ │ │ ├── release_blob_lease_builder.json │ │ │ ├── release_blob_lease_builder.rs │ │ │ ├── renew_blob_lease_builder.json │ │ │ ├── renew_blob_lease_builder.rs │ │ │ ├── signed_url_builder.rs │ │ │ ├── update_page_builder.json │ │ │ └── update_page_builder.rs │ │ └── responses │ │ │ ├── acquire_blob_lease_response.rs │ │ │ ├── break_blob_lease_response.rs │ │ │ ├── change_blob_lease_response.rs │ │ │ ├── clear_page_response.rs │ │ │ ├── copy_blob_from_url_response.rs │ │ │ ├── delete_blob_response.rs │ │ │ ├── get_blob_response.rs │ │ │ ├── get_block_list_response.rs │ │ │ ├── list_blobs_response.rs │ │ │ ├── mod.rs │ │ │ ├── put_blob_response.rs │ │ │ ├── put_block_blob_response.rs │ │ │ ├── put_block_list_response.rs │ │ │ ├── put_block_response.rs │ │ │ ├── release_blob_lease_response.rs │ │ │ ├── renew_blob_lease_response.rs │ │ │ └── update_page_response.rs │ ├── container │ │ ├── mod.rs │ │ ├── requests │ │ │ ├── acquire_lease_builder.json │ │ │ ├── acquire_lease_builder.rs │ │ │ ├── break_lease_builder.json │ │ │ ├── break_lease_builder.rs │ │ │ ├── create_builder.json │ │ │ ├── create_builder.rs │ │ │ ├── delete_builder.json │ │ │ ├── delete_builder.rs │ │ │ ├── get_acl_builder.json │ │ │ ├── get_acl_builder.rs │ │ │ ├── get_properties_builder.json │ │ │ ├── get_properties_builder.rs │ │ │ ├── list_blobs_builder.json │ │ │ ├── list_blobs_builder.rs │ │ │ ├── list_builder.json │ │ │ ├── list_builder.rs │ │ │ ├── mod.rs │ │ │ ├── release_lease_builder.json │ │ │ ├── release_lease_builder.rs │ │ │ ├── renew_lease_builder.json │ │ │ ├── renew_lease_builder.rs │ │ │ ├── set_acl_builder.json │ │ │ └── set_acl_builder.rs │ │ └── responses │ │ │ ├── acquire_lease_response.rs │ │ │ ├── break_lease_response.rs │ │ │ ├── get_acl_response.rs │ │ │ ├── get_properties_response.rs │ │ │ ├── list_containers_response.rs │ │ │ ├── mod.rs │ │ │ ├── release_lease_response.rs │ │ │ └── renew_lease_response.rs │ ├── lib.rs │ └── prelude.rs └── tests │ ├── append_blob.rs │ ├── blob.rs │ ├── container.rs │ ├── page_blob.rs │ ├── stream_blob00.rs │ └── stream_list_blobs.rs ├── azure_sdk_storage_core ├── .rustfmt.toml ├── Cargo.toml ├── README.md ├── examples │ ├── box.rs │ ├── connection_string_builder.rs │ └── sas00.rs └── src │ ├── bearer_token_client.rs │ ├── blob_sas_builder.rs │ ├── client.rs │ ├── client_endpoint.rs │ ├── connection_string.rs │ ├── connection_string_builder.rs │ ├── container_sas_builder.rs │ ├── hyper_client_endpoint.rs │ ├── into_azure_path.rs │ ├── key_client.rs │ ├── lib.rs │ ├── prelude.rs │ ├── rest_client.rs │ └── shared_access_signature.rs ├── azure_sdk_storage_queue ├── Cargo.toml ├── README.md ├── examples │ ├── list_queues.rs │ └── put_message.rs └── src │ ├── clients │ ├── mod.rs │ ├── queue_name_client.rs │ └── queue_service_client.rs │ ├── lib.rs │ ├── prelude.rs │ ├── requests │ ├── list_queues_builder.json │ ├── list_queues_builder.rs │ ├── mod.rs │ ├── put_message_builder.json │ └── put_message_builder.rs │ └── responses │ ├── list_queues_response.rs │ ├── mod.rs │ └── put_message_response.rs ├── azure_sdk_storage_table ├── .rustfmt.toml ├── Cargo.toml ├── README.md ├── examples │ ├── cloud_table.rs │ ├── copy_table.rs │ ├── entities.rs │ └── tables.rs └── src │ ├── batch.rs │ ├── cloud_table.rs │ ├── de.rs │ ├── lib.rs │ ├── table_client.rs │ └── table_entity.rs ├── rustfmt.toml └── scripts ├── build.sh ├── clippy_all.sh └── publish_all.sh /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | Cargo.lock 3 | *.rs.bk 4 | .vscode 5 | sample/ 6 | /.project 7 | \#*\# 8 | \.#* 9 | *~ 10 | *.swp 11 | 12 | *.vim 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: rust 3 | # necessary for `travis-cargo coveralls --no-sudo` 4 | addons: 5 | apt: 6 | packages: 7 | - libcurl4-openssl-dev 8 | - libelf-dev 9 | - libdw-dev 10 | - binutils-dev # optional: only required for the --verify flag of coveralls 11 | 12 | # run builds for all the trains (and more) 13 | rust: 14 | - nightly 15 | #- beta 16 | # check it compiles on the latest stable compiler 17 | #- stable 18 | 19 | # load travis-cargo 20 | before_script: 21 | - | 22 | pip install 'travis-cargo<0.2' --user && 23 | export PATH=$HOME/.local/bin:$PATH 24 | # the main build 25 | script: ./scripts/build.sh 26 | after_success: 27 | # upload the documentation from the build with stable (automatically only actually 28 | # runs on the master branch, not individual PRs) 29 | - travis-cargo --only stable doc-upload 30 | # measure code coverage and upload to coveralls.io (the verify 31 | # argument mitigates kcov crashes due to malformed debuginfo, at the 32 | # cost of some speed ) 33 | - travis-cargo coveralls --no-sudo 34 | #--verify 35 | 36 | env: 37 | global: 38 | # override the default `--features unstable` used for the nightly branch (optional) 39 | - TRAVIS_CARGO_NIGHTLY_FEATURE="" 40 | # encrypted github token for doc upload (see `GH_TOKEN` link above) 41 | - secure: "${GH_TOKEN}" 42 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "azure_sdk_auth_aad", 4 | "azure_sdk_core", 5 | "azure_sdk_service_bus", 6 | "azure_sdk_storage_account", 7 | "azure_sdk_storage_blob", 8 | "azure_sdk_storage_core", 9 | "azure_sdk_storage_table", 10 | "azure_sdk_cosmos", 11 | "azure_sdk_storage_queue" 12 | ] 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Microsoft Azure SDK for Rust 2 | 3 | Given the success of Rust in general and this repository in particular, we at Microsoft decided it was due time to migrate it in the [Microsoft Azure 4 | ](https://github.com/Azure) organization. The new repo - still unofficial and unsupported - is here [https://github.com/Azure/azure-sdk-for-rust](https://github.com/Azure/azure-sdk-for-rust). While unoffical and unsupported this step marks the "adulthood" of this repository and it will hopefully attract more talent from the community. 5 | 6 | I took care to migrate all the commits so you will find all the code history there, **along with your contributions** of course! 7 | 8 | > :construction: :construction: Please refer to the [new repository](https://github.com/Azure/azure-sdk-for-rust) from now on. 9 | 10 | This repository have been made read-only for your convenience. 11 | 12 | ## :two_hearts: Thank you for your involvement and effort, this important step would not have been possible without **you**! :two_hearts: 13 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-hacker -------------------------------------------------------------------------------- /azure_sdk_auth_aad/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "azure_sdk_auth_aad" 3 | version = "0.47.0" 4 | description = "Rust wrappers around Microsoft Azure REST APIs - Azure OAuth2 helper crate" 5 | readme = "README.md" 6 | authors = ["Francesco Cogno "] 7 | license = "Apache-2.0" 8 | repository = "https://github.com/MindFlavor/AzureSDKForRust" 9 | documentation = "http://mindflavor.github.io/AzureSDKForRust/azure_sdk_for_rust/index.html" 10 | homepage = "https://github.com/MindFlavor/AzureSDKForRust" 11 | 12 | keywords = ["sdk", "azure", "rest", "iot", "cloud"] 13 | categories = ["api-bindings"] 14 | 15 | edition = "2018" 16 | 17 | [dependencies] 18 | azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" } 19 | oauth2 = { version = "3.0.0", features = ["reqwest-010", "futures-03"], default-features = false} 20 | url = "2.1" 21 | futures = "0.3" 22 | serde = "1.0" 23 | serde_derive = "1.0" 24 | chrono = { version = "0.4", features = ["serde"] } 25 | serde_json = "1.0" 26 | log = "0.4" 27 | reqwest = { version = "0.10", features = ["json"] } 28 | async-timer = { version = "1.0.0-beta.3" } 29 | thiserror = "1.0" 30 | async-trait = "0.1.36" 31 | 32 | [dev-dependencies] 33 | tokio = { version = "0.2", features = ["macros"] } 34 | azure_sdk_storage_core = { version = "0.44" } 35 | azure_sdk_storage_blob = { version = "0.44" } 36 | env_logger = "0.7.1" 37 | 38 | [features] 39 | test_e2e = [] 40 | -------------------------------------------------------------------------------- /azure_sdk_auth_aad/README.md: -------------------------------------------------------------------------------- 1 | # Azure SDK for Rust - Azure OAuth2 helper crate 2 | 3 | Azure OAuth2 helper crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to [https://github.com/MindFlavor/AzureSDKForRust](https://github.com/MindFlavor/AzureSDKForRust). 4 | -------------------------------------------------------------------------------- /azure_sdk_auth_aad/examples/cli_credentials.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_auth_aad::*; 2 | use std::error::Error; 3 | use url::Url; 4 | 5 | #[tokio::main] 6 | async fn main() -> Result<(), Box> { 7 | let sub_id = std::env::var("AZURE_SUBSCRIPTION_ID")?; 8 | let creds = AzureCliCredential {}; 9 | let res = creds 10 | .get_token("https://management.azure.com/") 11 | .await 12 | .unwrap(); 13 | println!("Azure cli response == {:?}", res); 14 | // Let's enumerate the Azure storage accounts 15 | // in the subscription. Note: this way of calling the REST API 16 | // will be different (and easier) using other Azure Rust SDK 17 | // crates, this is just an example. 18 | let url = Url::parse(&format!( 19 | "https://management.azure.com/subscriptions/{}/providers/Microsoft.Storage/storageAccounts?api-version=2019-06-01", 20 | sub_id 21 | ))?; 22 | 23 | let resp = reqwest::Client::new() 24 | .get(url) 25 | .header("Authorization", format!("Bearer {}", res.token.secret())) 26 | .send() 27 | .await? 28 | .text() 29 | .await?; 30 | 31 | println!("\n\nresp {:?}", resp); 32 | Ok(()) 33 | } 34 | -------------------------------------------------------------------------------- /azure_sdk_auth_aad/examples/default_credentials.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_auth_aad::*; 2 | use std::error::Error; 3 | use url::Url; 4 | 5 | #[tokio::main] 6 | async fn main() -> Result<(), Box> { 7 | env_logger::init(); 8 | 9 | let sub_id = std::env::var("AZURE_SUBSCRIPTION_ID")?; 10 | let creds = DefaultCredential::default(); 11 | let res = creds 12 | .get_token("https://management.azure.com/") 13 | .await 14 | .unwrap(); 15 | println!("Azure token response == {:?}", res); 16 | // Let's enumerate the Azure storage accounts 17 | // in the subscription. Note: this way of calling the REST API 18 | // will be different (and easier) using other Azure Rust SDK 19 | // crates, this is just an example. 20 | let url = Url::parse(&format!( 21 | "https://management.azure.com/subscriptions/{}/providers/Microsoft.Storage/storageAccounts?api-version=2019-06-01", 22 | sub_id 23 | ))?; 24 | 25 | let resp = reqwest::Client::new() 26 | .get(url) 27 | .header("Authorization", format!("Bearer {}", res.token.secret())) 28 | .send() 29 | .await? 30 | .text() 31 | .await?; 32 | 33 | println!("\n\nresp {:?}", resp); 34 | Ok(()) 35 | } 36 | -------------------------------------------------------------------------------- /azure_sdk_auth_aad/examples/environment_credentials.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_auth_aad::*; 2 | use std::error::Error; 3 | use url::Url; 4 | 5 | #[tokio::main] 6 | async fn main() -> Result<(), Box> { 7 | let sub_id = std::env::var("AZURE_SUBSCRIPTION_ID")?; 8 | let creds = EnvironmentCredential {}; 9 | let res = creds 10 | .get_token("https://management.azure.com/") 11 | .await 12 | .unwrap(); 13 | println!("Azure cli response == {:?}", res); 14 | // Let's enumerate the Azure storage accounts 15 | // in the subscription. Note: this way of calling the REST API 16 | // will be different (and easier) using other Azure Rust SDK 17 | // crates, this is just an example. 18 | let url = Url::parse(&format!( 19 | "https://management.azure.com/subscriptions/{}/providers/Microsoft.Storage/storageAccounts?api-version=2019-06-01", 20 | sub_id 21 | ))?; 22 | 23 | let resp = reqwest::Client::new() 24 | .get(url) 25 | .header("Authorization", format!("Bearer {}", res.token.secret())) 26 | .send() 27 | .await? 28 | .text() 29 | .await?; 30 | 31 | println!("\n\nresp {:?}", resp); 32 | Ok(()) 33 | } 34 | -------------------------------------------------------------------------------- /azure_sdk_auth_aad/src/errors.rs: -------------------------------------------------------------------------------- 1 | use thiserror::Error; 2 | 3 | #[derive(Debug, Error)] 4 | pub enum ServerReceiveError { 5 | #[error("unexpected redirect url: {}", url)] 6 | UnexpectedRedirectUrl { url: String }, 7 | #[error("query pair not found: {}", query_pair)] 8 | QueryPairNotFound { query_pair: String }, 9 | #[error( 10 | "State secret mismatch: expected {}, recieved: {}", 11 | expected_state_secret, 12 | received_state_secret 13 | )] 14 | StateSecretMismatch { 15 | expected_state_secret: String, 16 | received_state_secret: String, 17 | }, 18 | } 19 | 20 | #[derive(Debug, Error, Serialize, Deserialize)] 21 | #[serde(untagged)] 22 | pub enum ErrorResponse { 23 | #[error("Unrecognized Azure error response:\n{}\n", error_description)] 24 | GenericError { error_description: String }, 25 | } 26 | -------------------------------------------------------------------------------- /azure_sdk_auth_aad/src/prelude.rs: -------------------------------------------------------------------------------- 1 | pub use crate::traits::*; 2 | -------------------------------------------------------------------------------- /azure_sdk_auth_aad/src/refresh_token.rs: -------------------------------------------------------------------------------- 1 | use crate::responses::RefreshTokenResponse; 2 | use azure_sdk_core::errors::AzureError; 3 | use log::debug; 4 | use oauth2::{AccessToken, ClientId, ClientSecret}; 5 | use std::convert::TryInto; 6 | use url::form_urlencoded; 7 | 8 | pub async fn exchange_refresh_token( 9 | client: &reqwest::Client, 10 | tenant_id: &str, 11 | client_id: &ClientId, 12 | client_secret: Option<&ClientSecret>, 13 | refresh_token: &AccessToken, 14 | ) -> Result { 15 | let mut encoded = form_urlencoded::Serializer::new(String::new()); 16 | let encoded = encoded.append_pair("grant_type", "refresh_token"); 17 | let encoded = encoded.append_pair("client_id", client_id.as_str()); 18 | // optionally add the client secret 19 | let encoded = if let Some(client_secret) = client_secret { 20 | encoded.append_pair("client_secret", client_secret.secret()) 21 | } else { 22 | encoded 23 | }; 24 | let encoded = encoded.append_pair("refresh_token", refresh_token.secret()); 25 | let encoded = encoded.finish(); 26 | 27 | debug!("encoded ==> {}", encoded); 28 | 29 | let url = url::Url::parse(&format!( 30 | "https://login.microsoftonline.com/{}/oauth2/v2.0/token", 31 | tenant_id 32 | ))?; 33 | 34 | let ret = client 35 | .post(url) 36 | .header("ContentType", "application/x-www-form-urlencoded") 37 | .body(encoded) 38 | .send() 39 | .await 40 | .map_err(|e| AzureError::GenericErrorWithText(e.to_string()))? 41 | .text() 42 | .await 43 | .map_err(|e| AzureError::GenericErrorWithText(e.to_string()))?; 44 | debug!("{}", ret); 45 | 46 | Ok(ret.try_into()?) 47 | } 48 | -------------------------------------------------------------------------------- /azure_sdk_auth_aad/src/responses/mod.rs: -------------------------------------------------------------------------------- 1 | mod refresh_token_response; 2 | pub use refresh_token_response::RefreshTokenResponse; 3 | -------------------------------------------------------------------------------- /azure_sdk_auth_aad/src/token_credentials/mod.rs: -------------------------------------------------------------------------------- 1 | mod cli_credentials; 2 | mod client_secret_credentials; 3 | mod default_credentials; 4 | mod environment_credentials; 5 | mod managed_identity_credentials; 6 | pub use crate::token_credentials::cli_credentials::*; 7 | pub use crate::token_credentials::client_secret_credentials::*; 8 | pub use crate::token_credentials::default_credentials::*; 9 | pub use crate::token_credentials::environment_credentials::*; 10 | pub use crate::token_credentials::managed_identity_credentials::*; 11 | use azure_sdk_core::errors::AzureError; 12 | use chrono::{DateTime, Utc}; 13 | use oauth2::AccessToken; 14 | 15 | /// Represents an Azure service bearer access token with expiry information. 16 | #[derive(Debug, Clone)] 17 | pub struct TokenResponse { 18 | /// Get the access token value. 19 | pub token: AccessToken, 20 | /// Gets the time when the provided token expires. 21 | pub expires_on: DateTime, 22 | } 23 | 24 | impl TokenResponse { 25 | pub(crate) fn new(token: AccessToken, expires_on: DateTime) -> Self { 26 | TokenResponse { token, expires_on } 27 | } 28 | } 29 | /// Represents a credential capable of providing an OAuth token. 30 | #[async_trait::async_trait] 31 | pub trait TokenCredential { 32 | /// Gets a `TokenResponse` for the specified resource 33 | async fn get_token(&self, resource: &str) -> Result; 34 | } 35 | -------------------------------------------------------------------------------- /azure_sdk_auth_aad/src/traits.rs: -------------------------------------------------------------------------------- 1 | use oauth2::AccessToken; 2 | 3 | pub trait BearerToken { 4 | fn token_type(&self) -> &str; 5 | fn scopes(&self) -> &[String]; 6 | fn expires_in(&self) -> u64; 7 | fn access_token(&self) -> &AccessToken; 8 | } 9 | 10 | pub trait RefreshToken { 11 | fn refresh_token(&self) -> &AccessToken; 12 | } 13 | 14 | pub trait ExtExpiresIn { 15 | fn ext_expires_in(&self) -> u64; 16 | } 17 | -------------------------------------------------------------------------------- /azure_sdk_core/.rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition="2018" 2 | -------------------------------------------------------------------------------- /azure_sdk_core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "azure_sdk_core" 3 | version = "0.43.7" 4 | description = "Rust wrappers around Microsoft Azure REST APIs - Core crate" 5 | readme = "README.md" 6 | authors = ["Francesco Cogno ", "Max Gortman ", "Dong Liu "] 7 | license = "Apache-2.0" 8 | repository = "https://github.com/MindFlavor/AzureSDKForRust" 9 | documentation = "http://mindflavor.github.io/AzureSDKForRust/azure_sdk_for_rust/index.html" 10 | homepage = "https://github.com/MindFlavor/AzureSDKForRust" 11 | 12 | keywords = ["sdk", "azure", "rest", "iot", "cloud"] 13 | categories = ["api-bindings"] 14 | 15 | edition = "2018" 16 | 17 | [dependencies] 18 | RustyXML = "0.3" 19 | base64 = "0.12" 20 | chrono = "0.4" 21 | http = "0.2" 22 | futures = "0.3" 23 | hyper = "0.13" 24 | log = "0.4" 25 | quick-error = "1.2" 26 | serde = "1.0" 27 | serde_derive = "1.0" 28 | serde_json = "1.0" 29 | serde-xml-rs = "0.4" 30 | url = "2.1" 31 | uuid = { version = "0.8", features = ["v4"] } 32 | bytes = "0.5" 33 | hyper-rustls = "0.20" 34 | failure = "0.1" 35 | 36 | [dev-dependencies] 37 | tokio = "0.2" 38 | env_logger = "0.7" 39 | 40 | [features] 41 | test_e2e = [] 42 | azurite_workaround = [] 43 | -------------------------------------------------------------------------------- /azure_sdk_core/README.md: -------------------------------------------------------------------------------- 1 | # Azure SDK for Rust - Core crate 2 | 3 | Core crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to [https://github.com/MindFlavor/AzureSDKForRust](https://github.com/MindFlavor/AzureSDKForRust). 4 | -------------------------------------------------------------------------------- /azure_sdk_core/src/incompletevector.rs: -------------------------------------------------------------------------------- 1 | use std::ops::{Deref, DerefMut}; 2 | 3 | pub type ContinuationToken = String; 4 | 5 | #[derive(Debug, Clone, PartialEq)] 6 | pub struct IncompleteVector { 7 | pub token: Option, 8 | pub vector: Vec, 9 | } 10 | 11 | impl IncompleteVector { 12 | pub fn new(token: Option, vector: Vec) -> IncompleteVector { 13 | IncompleteVector { token, vector } 14 | } 15 | 16 | pub fn is_complete(&self) -> bool { 17 | self.token().is_none() 18 | } 19 | 20 | pub fn token(&self) -> Option<&str> { 21 | if let Some(ref t) = self.token { 22 | Some(t) 23 | } else { 24 | None 25 | } 26 | } 27 | } 28 | 29 | impl DerefMut for IncompleteVector { 30 | fn deref_mut(&mut self) -> &mut [T] { 31 | &mut self.vector 32 | } 33 | } 34 | 35 | impl Deref for IncompleteVector { 36 | type Target = [T]; 37 | 38 | fn deref(&self) -> &[T] { 39 | &self.vector 40 | } 41 | } 42 | 43 | #[cfg(test)] 44 | mod test { 45 | #[allow(unused_imports)] 46 | use super::IncompleteVector; 47 | 48 | #[test] 49 | fn test_incomplete_vector_complete() { 50 | let v = vec![0, 1, 2, 3, 4, 5]; 51 | let ic = IncompleteVector::new(None, v); 52 | 53 | assert_eq!(ic.is_complete(), true); 54 | } 55 | 56 | #[test] 57 | fn test_incomplete_vector_incomplete() { 58 | let v = vec![0, 1, 2, 3, 4, 5]; 59 | let ic = IncompleteVector::new(Some("aaa".to_owned()), v); 60 | 61 | assert_eq!(ic.is_complete(), false); 62 | } 63 | 64 | #[test] 65 | fn test_incomplete_vector_deref() { 66 | let v = vec![0, 1, 2, 3, 4, 5]; 67 | let ic = IncompleteVector::new(None, v); 68 | assert_eq!(ic[0], 0); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /azure_sdk_core/src/lease.rs: -------------------------------------------------------------------------------- 1 | use uuid::Uuid; 2 | 3 | create_enum!(LeaseStatus, (Locked, "locked"), (Unlocked, "unlocked")); 4 | 5 | create_enum!( 6 | LeaseState, 7 | (Available, "available"), 8 | (Leased, "leased"), 9 | (Expired, "expired"), 10 | (Breaking, "breaking"), 11 | (Broken, "broken") 12 | ); 13 | 14 | create_enum!(LeaseDuration, (Infinite, "infinite"), (Fixed, "fixed")); 15 | 16 | create_enum!( 17 | LeaseAction, 18 | (Acquire, "acquire"), 19 | (Renew, "renew "), 20 | (Change, "change"), 21 | (Release, "release "), 22 | (Break, "break") 23 | ); 24 | 25 | pub type LeaseId = Uuid; 26 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "azure_sdk_cosmos" 3 | version = "0.100.3" 4 | description = "Rust wrappers around Microsoft Azure REST APIs - Azure Cosmos DB crate" 5 | readme = "README.md" 6 | authors = ["Francesco Cogno ", "Max Gortman "] 7 | license = "Apache-2.0" 8 | repository = "https://github.com/MindFlavor/AzureSDKForRust" 9 | documentation = "http://mindflavor.github.io/AzureSDKForRust/azure_sdk_for_rust/index.html" 10 | homepage = "https://github.com/MindFlavor/AzureSDKForRust" 11 | 12 | keywords = ["sdk", "azure", "rest", "iot", "cloud"] 13 | categories = ["api-bindings"] 14 | 15 | edition = "2018" 16 | 17 | [dependencies] 18 | azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" } 19 | ring = "0.16" 20 | base64 = "0.12" 21 | chrono = "0.4" 22 | http = "0.2" 23 | futures = "0.3" 24 | hyper = "0.13" 25 | log = "0.4" 26 | serde = "1.0" 27 | serde_derive = "1.0" 28 | serde_json = "1.0" 29 | url = "2.1" 30 | uuid = { version = "0.8", features = ["v4"] } 31 | hyper-rustls = "0.20" 32 | failure = "0.1" 33 | 34 | [dev-dependencies] 35 | env_logger = "0.7" 36 | tokio = { version = "0.2", features = ["macros"] } 37 | serde = { version = "1.0", features = ["derive"] } 38 | 39 | [features] 40 | test_e2e = [] 41 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/README.md: -------------------------------------------------------------------------------- 1 | # Azure SDK for Rust - Azure Cosmos DB crate 2 | 3 | Azure Cosmos DB crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to [https://github.com/MindFlavor/AzureSDKForRust](https://github.com/MindFlavor/AzureSDKForRust). 4 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/examples/database_01.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_cosmos::prelude::*; 2 | use std::error::Error; 3 | 4 | #[tokio::main] 5 | async fn main() -> Result<(), Box> { 6 | // First we retrieve the account name and master key from environment variables. 7 | // We expect master keys (ie, not resource constrained) 8 | let master_key = 9 | std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!"); 10 | let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!"); 11 | 12 | let authorization_token = AuthorizationToken::new_master(&master_key)?; 13 | let cosmos_client = ClientBuilder::new(&account, authorization_token)?; 14 | //let databases = cosmos_client.list_databases().execute().await?; 15 | //println!("databases == {:#?}", databases); 16 | 17 | let database_client = cosmos_client.with_database_client("pollo"); 18 | println!("database_name == {}", database_client.database_name()); 19 | 20 | let collections = database_client.list_collections().execute().await?; 21 | println!("collections == {:#?}", collections); 22 | 23 | let collection_client = database_client.with_collection_client("cnt"); 24 | let collection = collection_client.get_collection().execute().await?; 25 | println!("collection == {:#?}", collection); 26 | 27 | //let collection_client = database_client.with_collection(&"cnt"); 28 | 29 | Ok(()) 30 | } 31 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/examples/key_ranges_00.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_cosmos::prelude::*; 2 | use std::error::Error; 3 | 4 | #[tokio::main] 5 | async fn main() -> Result<(), Box> { 6 | let database = std::env::args() 7 | .nth(1) 8 | .expect("please specify database name as first command line parameter"); 9 | let collection = std::env::args() 10 | .nth(2) 11 | .expect("please specify collection name as second command line parameter"); 12 | 13 | let master_key = 14 | std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!"); 15 | let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!"); 16 | 17 | let authorization_token = AuthorizationToken::new_master(&master_key)?; 18 | let client = ClientBuilder::new(account, authorization_token.clone())?; 19 | let client = client.into_database_client(database); 20 | let client = client.into_collection_client(collection); 21 | 22 | let resp = client.get_partition_key_ranges().execute().await?; 23 | println!("resp == {:#?}", resp); 24 | 25 | Ok(()) 26 | } 27 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/examples/stored_proc_00.rs: -------------------------------------------------------------------------------- 1 | /// This sample showcases execution of stored procedure 2 | /// Create stored procedure called test_proc, like so: 3 | /// function f(personToGreet) { 4 | /// var context = getContext(); 5 | /// var response = context.getResponse(); 6 | /// response.setBody("Hello, " + personToGreet); 7 | /// } 8 | use azure_sdk_cosmos::prelude::*; 9 | use azure_sdk_cosmos::stored_procedure::Parameters; 10 | use std::error::Error; 11 | 12 | #[tokio::main] 13 | async fn main() -> Result<(), Box> { 14 | let database = std::env::args() 15 | .nth(1) 16 | .expect("please specify database name as first command line parameter"); 17 | let collection = std::env::args() 18 | .nth(2) 19 | .expect("please specify collection name as second command line parameter"); 20 | 21 | let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!"); 22 | let master_key = 23 | std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!"); 24 | 25 | let authorization_token = AuthorizationToken::new_master(&master_key)?; 26 | 27 | let client = ClientBuilder::new(account, authorization_token)?; 28 | 29 | let ret = client 30 | .into_database_client(&database) 31 | .into_collection_client(&collection) 32 | .into_stored_procedure_client("test_proc") 33 | .execute_stored_procedure() 34 | .with_parameters(Parameters::new().push("Robert")?) 35 | .execute::() 36 | .await?; 37 | 38 | println!("Response object:\n{:#?}", ret); 39 | println!("Response as JSON:\n{}", ret.payload.to_string()); 40 | 41 | Ok(()) 42 | } 43 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/attachment/attachment_name.rs: -------------------------------------------------------------------------------- 1 | pub trait AttachmentName: std::fmt::Debug { 2 | fn name(&self) -> &str; 3 | } 4 | 5 | impl AttachmentName for &str { 6 | fn name(&self) -> &str { 7 | self 8 | } 9 | } 10 | 11 | impl AttachmentName for String { 12 | fn name(&self) -> &str { 13 | self.as_ref() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/attachment/mod.rs: -------------------------------------------------------------------------------- 1 | mod attachment_name; 2 | 3 | pub use self::attachment_name::AttachmentName; 4 | 5 | #[derive(Debug, Clone, PartialEq, Deserialize)] 6 | pub struct Attachment { 7 | #[serde(rename = "contentType")] 8 | pub content_type: String, 9 | pub id: String, 10 | pub media: String, 11 | #[serde(rename = "_rid")] 12 | pub rid: String, 13 | #[serde(rename = "_ts")] 14 | pub ts: u64, 15 | pub _self: String, 16 | #[serde(rename = "_etag")] 17 | pub etag: String, 18 | } 19 | 20 | impl crate::attachment::AttachmentName for Attachment { 21 | fn name(&self) -> &str { 22 | &self.id 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/authorization_token.rs: -------------------------------------------------------------------------------- 1 | use crate::PermissionToken; 2 | use base64; 3 | use std::fmt::{Debug, Error, Formatter}; 4 | 5 | #[derive(PartialEq, Clone)] 6 | pub enum AuthorizationToken { 7 | Master(Vec), 8 | Resource(String), 9 | } 10 | 11 | impl AuthorizationToken { 12 | pub fn new_master(base64_encoded: &str) -> Result { 13 | let key = base64::decode(&base64_encoded)?; 14 | Ok(AuthorizationToken::Master(key)) 15 | } 16 | 17 | pub fn new_resource(resource: String) -> AuthorizationToken { 18 | AuthorizationToken::Resource(resource) 19 | } 20 | } 21 | 22 | impl Debug for AuthorizationToken { 23 | //! We provide a custom implementation to hide the key value. 24 | fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { 25 | write!( 26 | f, 27 | "{}", 28 | match self { 29 | AuthorizationToken::Master(_) => "AuthorizationToken::Master(***hidden***)", 30 | AuthorizationToken::Resource(_) => "AuthorizationToken::Resource(***hidden***)", 31 | } 32 | ) 33 | } 34 | } 35 | 36 | impl std::convert::From for AuthorizationToken { 37 | fn from(permission_token: PermissionToken) -> Self { 38 | trace!( 39 | "Converting permission_token into AuthorizationToken: {:#?}", 40 | permission_token 41 | ); 42 | Self::new_resource(permission_token.signature) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/clients/mod.rs: -------------------------------------------------------------------------------- 1 | mod attachment_struct; 2 | mod collection_struct; 3 | mod cosmos_struct; 4 | mod database_struct; 5 | mod document_struct; 6 | mod permission_struct; 7 | mod stored_procedure_struct; 8 | mod trigger_struct; 9 | mod user_defined_function_struct; 10 | mod user_struct; 11 | pub use attachment_struct::AttachmentStruct; 12 | pub use collection_struct::CollectionStruct; 13 | pub use cosmos_struct::*; 14 | pub use database_struct::DatabaseStruct; 15 | pub use document_struct::DocumentStruct; 16 | pub use permission_struct::PermissionStruct; 17 | pub use stored_procedure_struct::StoredProcedureStruct; 18 | pub use trigger_struct::TriggerStruct; 19 | pub use user_defined_function_struct::UserDefinedFunctionStruct; 20 | pub use user_struct::UserStruct; 21 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/database.rs: -------------------------------------------------------------------------------- 1 | #[derive(Serialize, Clone, PartialEq, PartialOrd, Deserialize, Debug)] 2 | pub struct Database { 3 | pub id: String, 4 | #[serde(rename = "_rid")] 5 | pub rid: String, 6 | #[serde(rename = "_ts")] 7 | pub ts: u64, 8 | #[serde(rename = "_self")] 9 | pub _self: String, 10 | #[serde(rename = "_etag")] 11 | pub etag: String, 12 | #[serde(rename = "_colls")] 13 | pub colls: String, 14 | #[serde(rename = "_users")] 15 | pub users: String, 16 | } 17 | 18 | pub trait DatabaseName: std::fmt::Debug { 19 | fn name(&self) -> &str; 20 | } 21 | 22 | impl DatabaseName for Database { 23 | fn name(&self) -> &str { 24 | &self.id 25 | } 26 | } 27 | 28 | impl DatabaseName for R 29 | where 30 | R: AsRef + std::fmt::Debug, 31 | { 32 | fn name(&self) -> &str { 33 | self.as_ref() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/document.rs: -------------------------------------------------------------------------------- 1 | use crate::DocumentAttributes; 2 | use azure_sdk_core::errors::AzureError; 3 | use hyper::header::HeaderMap; 4 | use serde::de::DeserializeOwned; 5 | 6 | pub trait DocumentName: std::fmt::Debug { 7 | fn name(&self) -> &str; 8 | } 9 | 10 | #[derive(Debug, Clone, Serialize, Deserialize)] 11 | pub struct Document { 12 | #[serde(flatten)] 13 | pub document_attributes: DocumentAttributes, 14 | #[serde(flatten)] 15 | pub document: T, // raw, id not included 16 | } 17 | 18 | impl Document { 19 | pub fn new(t: T) -> Self { 20 | let document_attributes = DocumentAttributes::default(); 21 | 22 | Self { 23 | document_attributes, 24 | document: t, 25 | } 26 | } 27 | } 28 | 29 | impl DocumentName for &str { 30 | fn name(&self) -> &str { 31 | self 32 | } 33 | } 34 | 35 | impl DocumentName for String { 36 | fn name(&self) -> &str { 37 | self.as_ref() 38 | } 39 | } 40 | 41 | impl DocumentName for std::borrow::Cow<'_, str> { 42 | fn name(&self) -> &str { 43 | self.as_ref() 44 | } 45 | } 46 | 47 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for Document 48 | where 49 | T: DeserializeOwned, 50 | { 51 | type Error = AzureError; 52 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 53 | let _headers = value.0; 54 | let body = value.1; 55 | 56 | Ok(serde_json::from_slice(body)?) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/indexing_directive.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::enumerations::ParsingError; 2 | use std::fmt; 3 | 4 | #[derive(Debug, Clone, Copy, PartialEq)] 5 | pub enum IndexingDirective { 6 | Default, 7 | Include, 8 | Exclude, 9 | } 10 | 11 | impl std::convert::Into<&str> for &IndexingDirective { 12 | fn into(self) -> &'static str { 13 | match self { 14 | IndexingDirective::Default => "Default", 15 | IndexingDirective::Exclude => "Exclude", 16 | IndexingDirective::Include => "Include", 17 | } 18 | } 19 | } 20 | 21 | impl std::str::FromStr for IndexingDirective { 22 | type Err = ParsingError; 23 | 24 | fn from_str(s: &str) -> Result { 25 | match s { 26 | "Default" => Ok(IndexingDirective::Default), 27 | "Exclude" => Ok(IndexingDirective::Exclude), 28 | "Include" => Ok(IndexingDirective::Include), 29 | _ => Err(ParsingError::ElementNotFound(s.to_owned())), 30 | } 31 | } 32 | } 33 | 34 | // TODO: Remove this code smell 35 | impl fmt::Display for IndexingDirective { 36 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 37 | let s: &'static str = self.into(); 38 | write!(f, "{}", s) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/offer.rs: -------------------------------------------------------------------------------- 1 | /// This specifies the collection performance level. It can either be custom or fixed. For 2 | /// more details see 3 | /// [https://docs.microsoft.com/en-us/rest/api/cosmos-db/create-a-collection](https://docs.microsoft.com/en-us/rest/api/cosmos-db/create-a-collection). 4 | #[derive(Debug, Clone, PartialEq, Copy)] 5 | pub enum Offer { 6 | Throughput(u64), 7 | S1, 8 | S2, 9 | S3, 10 | } 11 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/partition_key_range.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug, PartialEq, PartialOrd, Clone, Deserialize)] 2 | pub struct PartitionKeyRange { 3 | #[serde(rename = "_rid")] 4 | pub rid: String, 5 | pub id: String, 6 | #[serde(rename = "_etag")] 7 | pub etag: String, 8 | #[serde(rename = "minInclusive")] 9 | pub min_exclusive: String, 10 | #[serde(rename = "maxExclusive")] 11 | pub max_exclusive: String, 12 | #[serde(rename = "ridPrefix")] 13 | pub rid_prefix: u64, 14 | pub _self: String, 15 | #[serde(rename = "throughputFraction")] 16 | pub throughput_fraction: u64, 17 | pub status: String, 18 | // TODO: parents 19 | #[serde(rename = "_ts")] 20 | pub ts: u64, 21 | } 22 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/partition_keys.rs: -------------------------------------------------------------------------------- 1 | pub type PartitionKeys = crate::to_json_vector::ToJsonVector; 2 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/permission_resource.rs: -------------------------------------------------------------------------------- 1 | use crate::Collection; 2 | use crate::Document; 3 | use crate::Resource; 4 | use crate::User; 5 | 6 | /// This trait must be implemented by 7 | /// every resource that can have permissions 8 | /// associated with it. For example, you can 9 | /// grant read access to a collection but not to a 10 | /// database. So database does not implement 11 | /// PermissionResource but collection does. 12 | pub trait PermissionResource: Resource {} 13 | 14 | impl PermissionResource for String {} 15 | 16 | impl PermissionResource for &str {} 17 | 18 | impl<'a> PermissionResource for std::borrow::Cow<'a, str> {} 19 | 20 | impl PermissionResource for Document {} 21 | impl PermissionResource for &Document {} 22 | 23 | impl PermissionResource for Collection {} 24 | impl PermissionResource for &Collection {} 25 | 26 | impl PermissionResource for User {} 27 | impl PermissionResource for &User {} 28 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/create_database_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CreateDatabaseBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 6 | "azure_sdk_core::prelude::*", 7 | "crate::prelude::*", 8 | "hyper::StatusCode", 9 | "std::marker::PhantomData", 10 | "azure_sdk_core::{Yes,No,ToAssign}" 11 | ], 12 | "extra_types": [ "'a" ], 13 | "extra_wheres": [ ], 14 | "constructor_fields": [ 15 | { 16 | "name": "cosmos_client", 17 | "field_type": "&'a dyn CosmosClient", 18 | "trait_get": "CosmosClientRequired<'a>" 19 | } 20 | ], 21 | "fields": [ 22 | { 23 | "name": "database_name", 24 | "field_type": "&'a dyn DatabaseName", 25 | "builder_type": "DatabaseNameSet", 26 | "optional": false, 27 | "trait_get": "DatabaseNameRequired<'a>", 28 | "trait_set": "DatabaseNameSupport<'a>" 29 | }, 30 | { 31 | "name": "user_agent", 32 | "field_type": "&'a str", 33 | "optional": true, 34 | "trait_get": "UserAgentOption<'a>", 35 | "trait_set": "UserAgentSupport<'a>" 36 | }, 37 | { 38 | "name": "activity_id", 39 | "field_type": "&'a str", 40 | "optional": true, 41 | "trait_get": "ActivityIdOption<'a>", 42 | "trait_set": "ActivityIdSupport<'a>" 43 | }, 44 | { 45 | "name": "consistency_level", 46 | "field_type": "ConsistencyLevel<'a>", 47 | "optional": true, 48 | "trait_get": "ConsistencyLevelOption<'a>", 49 | "trait_set": "ConsistencyLevelSupport<'a>", 50 | "get_via_clone": true 51 | } 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/create_or_replace_user_defined_function_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CreateOrReplaceUserDefinedFunctionBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "azure_sdk_core::{Yes,No,ToAssign}", 9 | "std::marker::PhantomData", 10 | "hyper::StatusCode", 11 | "crate::responses::CreateUserDefinedFunctionResponse", 12 | "std::convert::TryInto" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "'b", "C", "D", "COLL" ], 16 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "COLL: CollectionClient" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "user_defined_function_client", 20 | "field_type": "&'a dyn UserDefinedFunctionClient", 21 | "trait_get": "UserDefinedFunctionClientRequired<'a, C, D, COLL>" 22 | }, 23 | { 24 | "name": "is_create", 25 | "field_type": "bool" 26 | } 27 | ], 28 | "fields": [ 29 | { 30 | "name": "body", 31 | "field_type": "&'b str", 32 | "builder_type": "BodySet", 33 | "optional": false, 34 | "trait_get": "UserDefinedFunctionBodyRequired<'b>", 35 | "trait_set": "UserDefinedFunctionBodySupport<'b>" 36 | }, 37 | { 38 | "name": "user_agent", 39 | "field_type": "&'b str", 40 | "optional": true, 41 | "trait_get": "UserAgentOption<'b>", 42 | "trait_set": "UserAgentSupport<'b>" 43 | }, 44 | { 45 | "name": "activity_id", 46 | "field_type": "&'b str", 47 | "optional": true, 48 | "trait_get": "ActivityIdOption<'b>", 49 | "trait_set": "ActivityIdSupport<'b>" 50 | }, 51 | { 52 | "name": "consistency_level", 53 | "field_type": "ConsistencyLevel<'b>", 54 | "optional": true, 55 | "trait_get": "ConsistencyLevelOption<'b>", 56 | "trait_set": "ConsistencyLevelSupport<'b>", 57 | "get_via_clone": true 58 | } 59 | ] 60 | } 61 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/create_permission_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CreatePermissionBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "crate::ResourceType", 8 | "crate::responses::CreatePermissionResponse", 9 | "crate::{PermissionMode, PermissionResource}", 10 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 11 | "hyper::StatusCode", 12 | "std::convert::TryInto" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "'b", "C", "D", "USER" ], 16 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "USER: UserClient" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "permission_client", 20 | "field_type": "&'a dyn PermissionClient", 21 | "trait_get": "PermissionClientRequired<'a, C, D, USER>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "expiry_seconds", 27 | "field_type": "u64", 28 | "optional": true, 29 | "initializer": "3600", 30 | "trait_get": "ExpirySecondsOption", 31 | "trait_set": "ExpirySecondsSupport" 32 | }, 33 | { 34 | "name": "user_agent", 35 | "field_type": "&'b str", 36 | "optional": true, 37 | "trait_get": "UserAgentOption<'b>", 38 | "trait_set": "UserAgentSupport<'b>" 39 | }, 40 | { 41 | "name": "activity_id", 42 | "field_type": "&'b str", 43 | "optional": true, 44 | "trait_get": "ActivityIdOption<'b>", 45 | "trait_set": "ActivityIdSupport<'b>" 46 | }, 47 | { 48 | "name": "consistency_level", 49 | "field_type": "ConsistencyLevel<'b>", 50 | "optional": true, 51 | "trait_get": "ConsistencyLevelOption<'b>", 52 | "trait_set": "ConsistencyLevelSupport<'b>", 53 | "get_via_clone": true 54 | } 55 | ] 56 | } 57 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/create_reference_attachment_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CreateReferenceAttachmentBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "azure_sdk_core::prelude::*", 8 | "azure_sdk_core::{Yes, No, ToAssign}", 9 | "std::marker::PhantomData", 10 | "hyper::StatusCode", 11 | "std::convert::TryInto" 12 | ], 13 | "inline": true, 14 | "extra_types": [ "'a", "'b", "C", "D", "COLL", "DOC" ], 15 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "COLL: CollectionClient", "DOC: DocumentClient" ], 16 | "constructor_fields": [ 17 | { 18 | "name": "attachment_client", 19 | "field_type": "&'a dyn AttachmentClient", 20 | "trait_get": "AttachmentClientRequired<'a, C, D, COLL, DOC>" 21 | } 22 | ], 23 | "fields": [ 24 | { 25 | "name": "content_type", 26 | "field_type": "&'b str", 27 | "builder_type": "ContentTypeSet", 28 | "optional": false, 29 | "trait_get": "ContentTypeRequired<'b>", 30 | "trait_set": "ContentTypeSupport<'b>" 31 | }, 32 | { 33 | "name": "media", 34 | "field_type": "&'b str", 35 | "builder_type": "MediaSet", 36 | "optional": false, 37 | "trait_get": "MediaRequired<'b>", 38 | "trait_set": "MediaSupport<'b>" 39 | }, 40 | { 41 | "name": "user_agent", 42 | "field_type": "&'b str", 43 | "optional": true, 44 | "trait_get": "UserAgentOption<'b>", 45 | "trait_set": "UserAgentSupport<'b>" 46 | }, 47 | { 48 | "name": "activity_id", 49 | "field_type": "&'b str", 50 | "optional": true, 51 | "trait_get": "ActivityIdOption<'b>", 52 | "trait_set": "ActivityIdSupport<'b>" 53 | }, 54 | { 55 | "name": "consistency_level", 56 | "field_type": "ConsistencyLevel<'b>", 57 | "optional": true, 58 | "trait_get": "ConsistencyLevelOption<'b>", 59 | "trait_set": "ConsistencyLevelSupport<'b>", 60 | "get_via_clone": true 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/create_stored_procedure_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CreateStoredProcedureBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "azure_sdk_core::{Yes, No, ToAssign}", 8 | "std::marker::PhantomData", 9 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 10 | "hyper::StatusCode", 11 | "crate::responses::CreateStoredProcedureResponse", 12 | "std::convert::TryInto" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "'b", "C", "D", "COLL" ], 16 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "COLL: CollectionClient" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "stored_procedure_client", 20 | "field_type": "&'a dyn StoredProcedureClient", 21 | "trait_get": "StoredProcedureClientRequired<'a, C, D, COLL>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "body", 27 | "field_type": "&'a str", 28 | "builder_type": "BodySet", 29 | "optional": false, 30 | "trait_get": "StoredProcedureBodyRequired<'a>", 31 | "trait_set": "StoredProcedureBodySupport<'a>" 32 | }, 33 | { 34 | "name": "user_agent", 35 | "field_type": "&'b str", 36 | "optional": true, 37 | "trait_get": "UserAgentOption<'b>", 38 | "trait_set": "UserAgentSupport<'b>" 39 | }, 40 | { 41 | "name": "activity_id", 42 | "field_type": "&'b str", 43 | "optional": true, 44 | "trait_get": "ActivityIdOption<'b>", 45 | "trait_set": "ActivityIdSupport<'b>" 46 | }, 47 | { 48 | "name": "consistency_level", 49 | "field_type": "ConsistencyLevel<'b>", 50 | "optional": true, 51 | "trait_get": "ConsistencyLevelOption<'b>", 52 | "trait_set": "ConsistencyLevelSupport<'b>", 53 | "get_via_clone": true 54 | } 55 | ] 56 | } 57 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/create_user_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CreateUserBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "crate::responses::CreateUserResponse", 8 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 9 | "hyper::StatusCode", 10 | "std::convert::TryInto" 11 | ], 12 | "inline": true, 13 | "extra_types": [ "'a", "'b", "C", "D" ], 14 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient" ], 15 | "constructor_fields": [ 16 | { 17 | "name": "user_client", 18 | "field_type": "&'a dyn UserClient", 19 | "trait_get": "UserClientRequired<'a, C, D>" 20 | } 21 | ], 22 | "fields": [ 23 | { 24 | "name": "user_agent", 25 | "field_type": "&'b str", 26 | "optional": true, 27 | "trait_get": "UserAgentOption<'b>", 28 | "trait_set": "UserAgentSupport<'b>" 29 | }, 30 | { 31 | "name": "activity_id", 32 | "field_type": "&'b str", 33 | "optional": true, 34 | "trait_get": "ActivityIdOption<'b>", 35 | "trait_set": "ActivityIdSupport<'b>" 36 | }, 37 | { 38 | "name": "consistency_level", 39 | "field_type": "ConsistencyLevel<'b>", 40 | "optional": true, 41 | "trait_get": "ConsistencyLevelOption<'b>", 42 | "trait_set": "ConsistencyLevelSupport<'b>", 43 | "get_via_clone": true 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/delete_attachment_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DeleteAttachmentBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "azure_sdk_core::prelude::*", 8 | "hyper::StatusCode", 9 | "std::convert::TryInto" 10 | ], 11 | "inline": true, 12 | "extra_types": [ "'a", "'b", "C", "D", "COLL", "DOC" ], 13 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "COLL: CollectionClient", "DOC: DocumentClient" ], 14 | "constructor_fields": [ 15 | { 16 | "name": "attachment_client", 17 | "field_type": "&'a dyn AttachmentClient", 18 | "trait_get": "AttachmentClientRequired<'a, C, D, COLL, DOC>" 19 | } 20 | ], 21 | "fields": [ 22 | { 23 | "name": "if_match_condition", 24 | "field_type": "IfMatchCondition<'b>", 25 | "optional": true, 26 | "trait_get": "IfMatchConditionOption<'b>", 27 | "trait_set": "IfMatchConditionSupport<'b>" 28 | }, 29 | { 30 | "name": "user_agent", 31 | "field_type": "&'b str", 32 | "optional": true, 33 | "trait_get": "UserAgentOption<'b>", 34 | "trait_set": "UserAgentSupport<'b>" 35 | }, 36 | { 37 | "name": "activity_id", 38 | "field_type": "&'b str", 39 | "optional": true, 40 | "trait_get": "ActivityIdOption<'b>", 41 | "trait_set": "ActivityIdSupport<'b>" 42 | }, 43 | { 44 | "name": "consistency_level", 45 | "field_type": "ConsistencyLevel<'b>", 46 | "optional": true, 47 | "trait_get": "ConsistencyLevelOption<'b>", 48 | "trait_set": "ConsistencyLevelSupport<'b>", 49 | "get_via_clone": true 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/delete_collection_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DeleteCollectionBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "crate::responses::DeleteCollectionResponse", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "hyper::StatusCode", 9 | "azure_sdk_core::prelude::*", 10 | "std::convert::TryInto" 11 | ], 12 | "inline": true, 13 | "extra_types": [ "'a", "C", "D" ], 14 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient" ], 15 | "constructor_fields": [ 16 | { 17 | "name": "collection_client", 18 | "field_type": "&'a dyn CollectionClient", 19 | "trait_get": "CollectionClientRequired<'a, C, D>" 20 | } 21 | ], 22 | "fields": [ 23 | { 24 | "name": "user_agent", 25 | "field_type": "&'a str", 26 | "optional": true, 27 | "trait_get": "UserAgentOption<'a>", 28 | "trait_set": "UserAgentSupport<'a>" 29 | }, 30 | { 31 | "name": "activity_id", 32 | "field_type": "&'a str", 33 | "optional": true, 34 | "trait_get": "ActivityIdOption<'a>", 35 | "trait_set": "ActivityIdSupport<'a>" 36 | }, 37 | { 38 | "name": "consistency_level", 39 | "field_type": "ConsistencyLevel<'a>", 40 | "optional": true, 41 | "trait_get": "ConsistencyLevelOption<'a>", 42 | "trait_set": "ConsistencyLevelSupport<'a>", 43 | "get_via_clone": true 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/delete_database_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DeleteDatabaseBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::responses::DeleteDatabaseResponse", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "azure_sdk_core::prelude::*", 8 | "crate::prelude::*", 9 | "std::convert::TryInto", 10 | "hyper::StatusCode" 11 | ], 12 | "extra_types": [ "'a", "C" ], 13 | "extra_wheres": [ "C: CosmosClient" ], 14 | "constructor_fields": [ 15 | { 16 | "name": "database_client", 17 | "field_type": "&'a dyn DatabaseClient", 18 | "trait_get": "DatabaseClientRequired<'a, C>" 19 | } 20 | ], 21 | "fields": [ 22 | { 23 | "name": "user_agent", 24 | "field_type": "&'a str", 25 | "optional": true, 26 | "trait_get": "UserAgentOption<'a>", 27 | "trait_set": "UserAgentSupport<'a>" 28 | }, 29 | { 30 | "name": "activity_id", 31 | "field_type": "&'a str", 32 | "optional": true, 33 | "trait_get": "ActivityIdOption<'a>", 34 | "trait_set": "ActivityIdSupport<'a>" 35 | }, 36 | { 37 | "name": "consistency_level", 38 | "field_type": "ConsistencyLevel<'a>", 39 | "optional": true, 40 | "trait_get": "ConsistencyLevelOption<'a>", 41 | "trait_set": "ConsistencyLevelSupport<'a>", 42 | "get_via_clone": true 43 | } 44 | 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/delete_permission_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DeletePermissionsBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "crate::responses::DeletePermissionResponse", 8 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 9 | "hyper::StatusCode", 10 | "std::convert::TryInto" 11 | ], 12 | "inline": true, 13 | "extra_types": [ "'a", "'b", "C", "D", "USER" ], 14 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "USER: UserClient" ], 15 | "constructor_fields": [ 16 | { 17 | "name": "permission_client", 18 | "field_type": "&'a dyn PermissionClient", 19 | "trait_get": "PermissionClientRequired<'a, C, D, USER>" 20 | } 21 | ], 22 | "fields": [ 23 | { 24 | "name": "user_agent", 25 | "field_type": "&'b str", 26 | "optional": true, 27 | "trait_get": "UserAgentOption<'b>", 28 | "trait_set": "UserAgentSupport<'b>" 29 | }, 30 | { 31 | "name": "activity_id", 32 | "field_type": "&'b str", 33 | "optional": true, 34 | "trait_get": "ActivityIdOption<'b>", 35 | "trait_set": "ActivityIdSupport<'b>" 36 | }, 37 | { 38 | "name": "consistency_level", 39 | "field_type": "ConsistencyLevel<'b>", 40 | "optional": true, 41 | "trait_get": "ConsistencyLevelOption<'b>", 42 | "trait_set": "ConsistencyLevelSupport<'b>", 43 | "get_via_clone": true 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/delete_stored_procedure_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DeleteStoredProcedureBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "hyper::StatusCode", 9 | "crate::responses::DeleteStoredProcedureResponse", 10 | "std::convert::TryInto" 11 | ], 12 | "inline": true, 13 | "extra_types": [ "'a", "'b", "C", "D", "COLL" ], 14 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "COLL: CollectionClient" ], 15 | "constructor_fields": [ 16 | { 17 | "name": "stored_procedure_client", 18 | "field_type": "&'a dyn StoredProcedureClient", 19 | "trait_get": "StoredProcedureClientRequired<'a, C, D, COLL>" 20 | } 21 | ], 22 | "fields": [ 23 | { 24 | "name": "user_agent", 25 | "field_type": "&'b str", 26 | "optional": true, 27 | "trait_get": "UserAgentOption<'b>", 28 | "trait_set": "UserAgentSupport<'b>" 29 | }, 30 | { 31 | "name": "activity_id", 32 | "field_type": "&'b str", 33 | "optional": true, 34 | "trait_get": "ActivityIdOption<'b>", 35 | "trait_set": "ActivityIdSupport<'b>" 36 | }, 37 | { 38 | "name": "consistency_level", 39 | "field_type": "ConsistencyLevel<'b>", 40 | "optional": true, 41 | "trait_get": "ConsistencyLevelOption<'b>", 42 | "trait_set": "ConsistencyLevelSupport<'b>", 43 | "get_via_clone": true 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/delete_trigger_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DeleteTriggerBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "hyper::StatusCode", 9 | "crate::responses::DeleteTriggerResponse", 10 | "std::convert::TryInto" 11 | ], 12 | "inline": true, 13 | "extra_types": [ "'a", "'b", "C", "D", "COLL" ], 14 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "COLL: CollectionClient" ], 15 | "constructor_fields": [ 16 | { 17 | "name": "trigger_client", 18 | "field_type": "&'a dyn TriggerClient", 19 | "trait_get": "TriggerClientRequired<'a, C, D, COLL>" 20 | } 21 | ], 22 | "fields": [ 23 | { 24 | "name": "user_agent", 25 | "field_type": "&'b str", 26 | "optional": true, 27 | "trait_get": "UserAgentOption<'b>", 28 | "trait_set": "UserAgentSupport<'b>" 29 | }, 30 | { 31 | "name": "activity_id", 32 | "field_type": "&'b str", 33 | "optional": true, 34 | "trait_get": "ActivityIdOption<'b>", 35 | "trait_set": "ActivityIdSupport<'b>" 36 | }, 37 | { 38 | "name": "consistency_level", 39 | "field_type": "ConsistencyLevel<'b>", 40 | "optional": true, 41 | "trait_get": "ConsistencyLevelOption<'b>", 42 | "trait_set": "ConsistencyLevelSupport<'b>", 43 | "get_via_clone": true 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/delete_user_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DeleteUserBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "crate::responses::DeleteUserResponse", 8 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 9 | "hyper::StatusCode", 10 | "std::convert::TryInto" 11 | ], 12 | "inline": true, 13 | "extra_types": [ "'a", "'b", "C", "D" ], 14 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient" ], 15 | "constructor_fields": [ 16 | { 17 | "name": "user_client", 18 | "field_type": "&'a dyn UserClient", 19 | "trait_get": "UserClientRequired<'a, C, D>" 20 | } 21 | ], 22 | "fields": [ 23 | { 24 | "name": "user_agent", 25 | "field_type": "&'b str", 26 | "optional": true, 27 | "trait_get": "UserAgentOption<'b>", 28 | "trait_set": "UserAgentSupport<'b>" 29 | }, 30 | { 31 | "name": "activity_id", 32 | "field_type": "&'b str", 33 | "optional": true, 34 | "trait_get": "ActivityIdOption<'b>", 35 | "trait_set": "ActivityIdSupport<'b>" 36 | }, 37 | { 38 | "name": "consistency_level", 39 | "field_type": "ConsistencyLevel<'b>", 40 | "optional": true, 41 | "trait_get": "ConsistencyLevelOption<'b>", 42 | "trait_set": "ConsistencyLevelSupport<'b>", 43 | "get_via_clone": true 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/delete_user_defined_function_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DeleteUserDefinedFunctionBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "hyper::StatusCode", 9 | "crate::responses::DeleteUserDefinedFunctionResponse", 10 | "std::convert::TryInto" 11 | ], 12 | "inline": true, 13 | "extra_types": [ "'a", "'b", "C", "D", "COLL" ], 14 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "COLL: CollectionClient" ], 15 | "constructor_fields": [ 16 | { 17 | "name": "user_defined_function_client", 18 | "field_type": "&'a dyn UserDefinedFunctionClient", 19 | "trait_get": "UserDefinedFunctionClientRequired<'a, C, D, COLL>" 20 | } 21 | ], 22 | "fields": [ 23 | { 24 | "name": "user_agent", 25 | "field_type": "&'b str", 26 | "optional": true, 27 | "trait_get": "UserAgentOption<'b>", 28 | "trait_set": "UserAgentSupport<'b>" 29 | }, 30 | { 31 | "name": "activity_id", 32 | "field_type": "&'b str", 33 | "optional": true, 34 | "trait_get": "ActivityIdOption<'b>", 35 | "trait_set": "ActivityIdSupport<'b>" 36 | }, 37 | { 38 | "name": "consistency_level", 39 | "field_type": "ConsistencyLevel<'b>", 40 | "optional": true, 41 | "trait_get": "ConsistencyLevelOption<'b>", 42 | "trait_set": "ConsistencyLevelSupport<'b>", 43 | "get_via_clone": true 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/get_attachment_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GetAttachmentBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "azure_sdk_core::prelude::*", 8 | "hyper::StatusCode", 9 | "std::convert::TryInto" 10 | ], 11 | "inline": true, 12 | "extra_types": [ "'a", "'b", "C", "D", "COLL", "DOC" ], 13 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "COLL: CollectionClient", "DOC: DocumentClient" ], 14 | "constructor_fields": [ 15 | { 16 | "name": "attachment_client", 17 | "field_type": "&'a dyn AttachmentClient", 18 | "trait_get": "AttachmentClientRequired<'a, C, D, COLL, DOC>" 19 | } 20 | ], 21 | "fields": [ 22 | { 23 | "name": "if_match_condition", 24 | "field_type": "IfMatchCondition<'b>", 25 | "optional": true, 26 | "trait_get": "IfMatchConditionOption<'b>", 27 | "trait_set": "IfMatchConditionSupport<'b>" 28 | }, 29 | { 30 | "name": "user_agent", 31 | "field_type": "&'b str", 32 | "optional": true, 33 | "trait_get": "UserAgentOption<'b>", 34 | "trait_set": "UserAgentSupport<'b>" 35 | }, 36 | { 37 | "name": "activity_id", 38 | "field_type": "&'b str", 39 | "optional": true, 40 | "trait_get": "ActivityIdOption<'b>", 41 | "trait_set": "ActivityIdSupport<'b>" 42 | }, 43 | { 44 | "name": "consistency_level", 45 | "field_type": "ConsistencyLevel<'b>", 46 | "optional": true, 47 | "trait_get": "ConsistencyLevelOption<'b>", 48 | "trait_set": "ConsistencyLevelSupport<'b>", 49 | "get_via_clone": true 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/get_collection_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GetCollectionBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "crate::responses::GetCollectionResponse", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "hyper::StatusCode", 9 | "azure_sdk_core::prelude::*", 10 | "std::convert::TryInto" 11 | ], 12 | "inline": true, 13 | "extra_types": [ "'a", "C", "D" ], 14 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient" ], 15 | "constructor_fields": [ 16 | { 17 | "name": "collection_client", 18 | "field_type": "&'a dyn CollectionClient", 19 | "trait_get": "CollectionClientRequired<'a, C, D>" 20 | } 21 | ], 22 | "fields": [ 23 | { 24 | "name": "user_agent", 25 | "field_type": "&'a str", 26 | "optional": true, 27 | "trait_get": "UserAgentOption<'a>", 28 | "trait_set": "UserAgentSupport<'a>" 29 | }, 30 | { 31 | "name": "activity_id", 32 | "field_type": "&'a str", 33 | "optional": true, 34 | "trait_get": "ActivityIdOption<'a>", 35 | "trait_set": "ActivityIdSupport<'a>" 36 | }, 37 | { 38 | "name": "consistency_level", 39 | "field_type": "ConsistencyLevel<'a>", 40 | "optional": true, 41 | "trait_get": "ConsistencyLevelOption<'a>", 42 | "trait_set": "ConsistencyLevelSupport<'a>", 43 | "get_via_clone": true 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/get_database_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GetDatabaseBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::responses::GetDatabaseResponse", 6 | "crate::prelude::*", 7 | "azure_sdk_core::prelude::*", 8 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 9 | "hyper::StatusCode", 10 | "std::convert::TryInto" 11 | ], 12 | "extra_types": [ "'a", "'b", "C" ], 13 | "extra_wheres": ["C: CosmosClient" ], 14 | "constructor_fields": [ 15 | { 16 | "name": "database_client", 17 | "field_type": "&'a dyn DatabaseClient", 18 | "trait_get": "DatabaseClientRequired<'a, C>" 19 | } 20 | ], 21 | "fields": [ 22 | { 23 | "name": "user_agent", 24 | "field_type": "&'b str", 25 | "optional": true, 26 | "trait_get": "UserAgentOption<'b>", 27 | "trait_set": "UserAgentSupport<'b>" 28 | }, 29 | { 30 | "name": "activity_id", 31 | "field_type": "&'b str", 32 | "optional": true, 33 | "trait_get": "ActivityIdOption<'b>", 34 | "trait_set": "ActivityIdSupport<'b>" 35 | }, 36 | { 37 | "name": "consistency_level", 38 | "field_type": "ConsistencyLevel<'b>", 39 | "optional": true, 40 | "trait_get": "ConsistencyLevelOption<'b>", 41 | "trait_set": "ConsistencyLevelSupport<'b>", 42 | "get_via_clone": true 43 | } 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/get_partition_key_ranges_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GetPartitionKeyRangesBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "crate::responses::GetPartitionKeyRangesResponse", 9 | "chrono::{DateTime, Utc}", 10 | "hyper::StatusCode", 11 | "crate::ResourceType", 12 | "std::convert::TryInto" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "'b", "C", "D" ], 16 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "collection_client", 20 | "field_type": "&'a dyn CollectionClient", 21 | "trait_get": "CollectionClientRequired<'a, C, D>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "if_match_condition", 27 | "field_type": "IfMatchCondition<'b>", 28 | "optional": true, 29 | "trait_get": "IfMatchConditionOption<'b>", 30 | "trait_set": "IfMatchConditionSupport<'b>" 31 | }, 32 | { 33 | "name": "if_modified_since", 34 | "field_type": "&'b DateTime", 35 | "optional": true, 36 | "trait_get": "IfModifiedSinceOption<'b>", 37 | "trait_set": "IfModifiedSinceSupport<'b>" 38 | }, 39 | { 40 | "name": "user_agent", 41 | "field_type": "&'b str", 42 | "optional": true, 43 | "trait_get": "UserAgentOption<'b>", 44 | "trait_set": "UserAgentSupport<'b>" 45 | }, 46 | { 47 | "name": "activity_id", 48 | "field_type": "&'b str", 49 | "optional": true, 50 | "trait_get": "ActivityIdOption<'b>", 51 | "trait_set": "ActivityIdSupport<'b>" 52 | }, 53 | { 54 | "name": "consistency_level", 55 | "field_type": "ConsistencyLevel<'b>", 56 | "optional": true, 57 | "trait_get": "ConsistencyLevelOption<'b>", 58 | "trait_set": "ConsistencyLevelSupport<'b>", 59 | "get_via_clone": true 60 | } 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/get_permission_builer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GetPermissionBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "crate::responses::GetPermissionResponse", 8 | "azure_sdk_core::errors::{UnexpectedHTTPResult, extract_status_headers_and_body, AzureError}", 9 | "hyper::StatusCode", 10 | "std::convert::TryInto" 11 | ], 12 | "inline": true, 13 | "extra_types": [ "'a", "'b", "C", "D", "USER" ], 14 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "USER: UserClient" ], 15 | "constructor_fields": [ 16 | { 17 | "name": "permission_client", 18 | "field_type": "&'a dyn PermissionClient", 19 | "trait_get": "PermissionClientRequired<'a, C, D, USER>" 20 | } 21 | ], 22 | "fields": [ 23 | { 24 | "name": "user_agent", 25 | "field_type": "&'b str", 26 | "optional": true, 27 | "trait_get": "UserAgentOption<'b>", 28 | "trait_set": "UserAgentSupport<'b>" 29 | }, 30 | { 31 | "name": "activity_id", 32 | "field_type": "&'b str", 33 | "optional": true, 34 | "trait_get": "ActivityIdOption<'b>", 35 | "trait_set": "ActivityIdSupport<'b>" 36 | }, 37 | { 38 | "name": "consistency_level", 39 | "field_type": "ConsistencyLevel<'b>", 40 | "optional": true, 41 | "trait_get": "ConsistencyLevelOption<'b>", 42 | "trait_set": "ConsistencyLevelSupport<'b>", 43 | "get_via_clone": true 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/get_user_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GetUserBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "crate::responses::CreateUserResponse", 8 | "azure_sdk_core::errors::UnexpectedHTTPResult", 9 | "azure_sdk_core::errors::{extract_status_headers_and_body, AzureError}", 10 | "hyper::StatusCode", 11 | "std::convert::TryInto" 12 | ], 13 | "inline": true, 14 | "extra_types": [ "'a", "'b", "C", "D" ], 15 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient" ], 16 | "constructor_fields": [ 17 | { 18 | "name": "user_client", 19 | "field_type": "&'a dyn UserClient", 20 | "trait_get": "UserClientRequired<'a, C, D>" 21 | } 22 | ], 23 | "fields": [ 24 | { 25 | "name": "user_agent", 26 | "field_type": "&'b str", 27 | "optional": true, 28 | "trait_get": "UserAgentOption<'b>", 29 | "trait_set": "UserAgentSupport<'b>" 30 | }, 31 | { 32 | "name": "activity_id", 33 | "field_type": "&'b str", 34 | "optional": true, 35 | "trait_get": "ActivityIdOption<'b>", 36 | "trait_set": "ActivityIdSupport<'b>" 37 | }, 38 | { 39 | "name": "consistency_level", 40 | "field_type": "ConsistencyLevel<'b>", 41 | "optional": true, 42 | "trait_get": "ConsistencyLevelOption<'b>", 43 | "trait_set": "ConsistencyLevelSupport<'b>", 44 | "get_via_clone": true 45 | } 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/list_collections_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ListCollectionsBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::responses::ListCollectionsResponse", 6 | "azure_sdk_core::prelude::*", 7 | "crate::{DatabaseClientRequired, ResourceType}", 8 | "crate::prelude::*", 9 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 10 | "futures::stream::{unfold, Stream}", 11 | "hyper::StatusCode", 12 | "std::convert::TryInto" 13 | ], 14 | "extra_types": [ "'a", "C" ], 15 | "extra_wheres": ["C: CosmosClient" ], 16 | "constructor_fields": [ 17 | { 18 | "name": "database_client", 19 | "field_type": "&'a dyn DatabaseClient", 20 | "trait_get": "DatabaseClientRequired<'a, C>" 21 | } 22 | ], 23 | "fields": [ 24 | { 25 | "name": "user_agent", 26 | "field_type": "&'a str", 27 | "optional": true, 28 | "trait_get": "UserAgentOption<'a>", 29 | "trait_set": "UserAgentSupport<'a>" 30 | }, 31 | { 32 | "name": "activity_id", 33 | "field_type": "&'a str", 34 | "optional": true, 35 | "trait_get": "ActivityIdOption<'a>", 36 | "trait_set": "ActivityIdSupport<'a>" 37 | }, 38 | { 39 | "name": "consistency_level", 40 | "field_type": "ConsistencyLevel<'a>", 41 | "optional": true, 42 | "trait_get": "ConsistencyLevelOption<'a>", 43 | "trait_set": "ConsistencyLevelSupport<'a>", 44 | "get_via_clone": true 45 | }, 46 | { 47 | "name": "continuation", 48 | "field_type": "&'a str", 49 | "optional": true, 50 | "trait_get": "ContinuationOption<'a>", 51 | "trait_set": "ContinuationSupport<'a>" 52 | }, 53 | { 54 | "name": "max_item_count", 55 | "field_type": "i32", 56 | "optional": true, 57 | "initializer": "-1", 58 | "trait_get": "MaxItemCountOption", 59 | "trait_set": "MaxItemCountSupport" 60 | } 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/list_databases_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ListDatabasesBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::responses::ListDatabasesResponse", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "hyper::StatusCode", 8 | "crate::prelude::*", 9 | "crate::ResourceType", 10 | "azure_sdk_core::prelude::*", 11 | "std::convert::TryInto", 12 | "futures::stream::{unfold, Stream}" 13 | ], 14 | "extra_types": [ "'a" ], 15 | "extra_wheres": [ ], 16 | "constructor_fields": [ 17 | { 18 | "name": "cosmos_client", 19 | "field_type": "&'a dyn CosmosClient", 20 | "trait_get": "CosmosClientRequired<'a>" 21 | } 22 | ], 23 | "fields": [ 24 | { 25 | "name": "user_agent", 26 | "field_type": "&'a str", 27 | "optional": true, 28 | "trait_get": "UserAgentOption<'a>", 29 | "trait_set": "UserAgentSupport<'a>" 30 | }, 31 | { 32 | "name": "activity_id", 33 | "field_type": "&'a str", 34 | "optional": true, 35 | "trait_get": "ActivityIdOption<'a>", 36 | "trait_set": "ActivityIdSupport<'a>" 37 | }, 38 | { 39 | "name": "consistency_level", 40 | "field_type": "ConsistencyLevel<'a>", 41 | "optional": true, 42 | "trait_get": "ConsistencyLevelOption<'a>", 43 | "trait_set": "ConsistencyLevelSupport<'a>", 44 | "get_via_clone": true 45 | }, 46 | { 47 | "name": "continuation", 48 | "field_type": "&'a str", 49 | "optional": true, 50 | "trait_get": "ContinuationOption<'a>", 51 | "trait_set": "ContinuationSupport<'a>" 52 | }, 53 | { 54 | "name": "max_item_count", 55 | "field_type": "i32", 56 | "optional": true, 57 | "initializer": "-1", 58 | "trait_get": "MaxItemCountOption", 59 | "trait_set": "MaxItemCountSupport" 60 | } 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/list_permissions_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ListPermissionsBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "crate::ResourceType", 8 | "crate::responses::ListPermissionsResponse", 9 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 10 | "hyper::StatusCode", 11 | "futures::stream::{unfold, Stream}", 12 | "std::convert::TryInto" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "'b", "C", "D" ], 16 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "user_client", 20 | "field_type": "&'a dyn UserClient", 21 | "trait_get": "UserClientRequired<'a, C, D>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "user_agent", 27 | "field_type": "&'b str", 28 | "optional": true, 29 | "trait_get": "UserAgentOption<'b>", 30 | "trait_set": "UserAgentSupport<'b>" 31 | }, 32 | { 33 | "name": "activity_id", 34 | "field_type": "&'b str", 35 | "optional": true, 36 | "trait_get": "ActivityIdOption<'b>", 37 | "trait_set": "ActivityIdSupport<'b>" 38 | }, 39 | { 40 | "name": "consistency_level", 41 | "field_type": "ConsistencyLevel<'b>", 42 | "optional": true, 43 | "trait_get": "ConsistencyLevelOption<'b>", 44 | "trait_set": "ConsistencyLevelSupport<'b>", 45 | "get_via_clone": true 46 | }, 47 | { 48 | "name": "continuation", 49 | "field_type": "&'b str", 50 | "optional": true, 51 | "trait_get": "ContinuationOption<'b>", 52 | "trait_set": "ContinuationSupport<'b>" 53 | }, 54 | { 55 | "name": "max_item_count", 56 | "field_type": "i32", 57 | "optional": true, 58 | "initializer": "-1", 59 | "trait_get": "MaxItemCountOption", 60 | "trait_set": "MaxItemCountSupport" 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/list_stored_procedures_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ListStoredProceduresBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "crate::ResourceType", 9 | "hyper::StatusCode", 10 | "futures::stream::{unfold, Stream}", 11 | "crate::responses::ListStoredProceduresResponse", 12 | "std::convert::TryInto" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "'b", "C", "D" ], 16 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "collection_client", 20 | "field_type": "&'a dyn CollectionClient", 21 | "trait_get": "CollectionClientRequired<'a, C, D>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "user_agent", 27 | "field_type": "&'b str", 28 | "optional": true, 29 | "trait_get": "UserAgentOption<'b>", 30 | "trait_set": "UserAgentSupport<'b>" 31 | }, 32 | { 33 | "name": "activity_id", 34 | "field_type": "&'b str", 35 | "optional": true, 36 | "trait_get": "ActivityIdOption<'b>", 37 | "trait_set": "ActivityIdSupport<'b>" 38 | }, 39 | { 40 | "name": "consistency_level", 41 | "field_type": "ConsistencyLevel<'b>", 42 | "optional": true, 43 | "trait_get": "ConsistencyLevelOption<'b>", 44 | "trait_set": "ConsistencyLevelSupport<'b>", 45 | "get_via_clone": true 46 | }, 47 | { 48 | "name": "continuation", 49 | "field_type": "&'b str", 50 | "optional": true, 51 | "trait_get": "ContinuationOption<'b>", 52 | "trait_set": "ContinuationSupport<'b>" 53 | }, 54 | { 55 | "name": "max_item_count", 56 | "field_type": "i32", 57 | "optional": true, 58 | "initializer": "-1", 59 | "trait_get": "MaxItemCountOption", 60 | "trait_set": "MaxItemCountSupport" 61 | } 62 | 63 | ] 64 | } 65 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/list_users_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ListUsersBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "crate::ResourceType", 8 | "crate::responses::ListUsersResponse", 9 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 10 | "hyper::StatusCode", 11 | "std::convert::TryInto", 12 | "futures::stream::{unfold, Stream}" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "'b", "C" ], 16 | "extra_wheres": [ "C: CosmosClient" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "database_client", 20 | "field_type": "&'a dyn DatabaseClient", 21 | "trait_get": "DatabaseClientRequired<'a, C>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "user_agent", 27 | "field_type": "&'b str", 28 | "optional": true, 29 | "trait_get": "UserAgentOption<'b>", 30 | "trait_set": "UserAgentSupport<'b>" 31 | }, 32 | { 33 | "name": "activity_id", 34 | "field_type": "&'b str", 35 | "optional": true, 36 | "trait_get": "ActivityIdOption<'b>", 37 | "trait_set": "ActivityIdSupport<'b>" 38 | }, 39 | { 40 | "name": "consistency_level", 41 | "field_type": "ConsistencyLevel<'b>", 42 | "optional": true, 43 | "trait_get": "ConsistencyLevelOption<'b>", 44 | "trait_set": "ConsistencyLevelSupport<'b>", 45 | "get_via_clone": true 46 | }, 47 | { 48 | "name": "continuation", 49 | "field_type": "&'b str", 50 | "optional": true, 51 | "trait_get": "ContinuationOption<'b>", 52 | "trait_set": "ContinuationSupport<'b>" 53 | }, 54 | { 55 | "name": "max_item_count", 56 | "field_type": "i32", 57 | "optional": true, 58 | "initializer": "-1", 59 | "trait_get": "MaxItemCountOption", 60 | "trait_set": "MaxItemCountSupport" 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/replace_permission_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ReplacePermissionBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "crate::responses::ReplacePermissionResponse", 8 | "crate::{PermissionMode, PermissionResource}", 9 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 10 | "hyper::StatusCode", 11 | "std::convert::TryInto" 12 | ], 13 | "inline": true, 14 | "extra_types": [ "'a", "'b", "C", "D", "USER" ], 15 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "USER: UserClient" ], 16 | "constructor_fields": [ 17 | { 18 | "name": "permission_client", 19 | "field_type": "&'a dyn PermissionClient", 20 | "trait_get": "PermissionClientRequired<'a, C, D, USER>" 21 | } 22 | ], 23 | "fields": [ 24 | { 25 | "name": "expiry_seconds", 26 | "field_type": "u64", 27 | "optional": true, 28 | "initializer": "3600", 29 | "trait_get": "ExpirySecondsOption", 30 | "trait_set": "ExpirySecondsSupport" 31 | }, 32 | { 33 | "name": "user_agent", 34 | "field_type": "&'b str", 35 | "optional": true, 36 | "trait_get": "UserAgentOption<'b>", 37 | "trait_set": "UserAgentSupport<'b>" 38 | }, 39 | { 40 | "name": "activity_id", 41 | "field_type": "&'b str", 42 | "optional": true, 43 | "trait_get": "ActivityIdOption<'b>", 44 | "trait_set": "ActivityIdSupport<'b>" 45 | }, 46 | { 47 | "name": "consistency_level", 48 | "field_type": "ConsistencyLevel<'b>", 49 | "optional": true, 50 | "trait_get": "ConsistencyLevelOption<'b>", 51 | "trait_set": "ConsistencyLevelSupport<'b>", 52 | "get_via_clone": true 53 | } 54 | ] 55 | } 56 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/replace_stored_procedure_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ReplaceStoredProcedureBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "azure_sdk_core::{Yes,No,ToAssign}", 9 | "std::marker::PhantomData", 10 | "hyper::StatusCode", 11 | "crate::responses::ReplaceStoredProcedureResponse", 12 | "std::convert::TryInto" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "'b", "C", "D", "COLL" ], 16 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient", "COLL: CollectionClient" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "stored_procedure_client", 20 | "field_type": "&'a dyn StoredProcedureClient", 21 | "trait_get": "StoredProcedureClientRequired<'a, C, D, COLL>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "body", 27 | "field_type": "&'b str", 28 | "builder_type": "BodySet", 29 | "optional": false, 30 | "trait_get": "StoredProcedureBodyRequired<'b>", 31 | "trait_set": "StoredProcedureBodySupport<'b>" 32 | }, 33 | { 34 | "name": "user_agent", 35 | "field_type": "&'b str", 36 | "optional": true, 37 | "trait_get": "UserAgentOption<'b>", 38 | "trait_set": "UserAgentSupport<'b>" 39 | }, 40 | { 41 | "name": "activity_id", 42 | "field_type": "&'b str", 43 | "optional": true, 44 | "trait_get": "ActivityIdOption<'b>", 45 | "trait_set": "ActivityIdSupport<'b>" 46 | }, 47 | { 48 | "name": "consistency_level", 49 | "field_type": "ConsistencyLevel<'b>", 50 | "optional": true, 51 | "trait_get": "ConsistencyLevelOption<'b>", 52 | "trait_set": "ConsistencyLevelSupport<'b>", 53 | "get_via_clone": true 54 | } 55 | ] 56 | } 57 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/requests/replace_user_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ReplaceUserBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "azure_sdk_core::prelude::*", 7 | "crate::responses::CreateUserResponse", 8 | "azure_sdk_core::errors::{UnexpectedHTTPResult, extract_status_headers_and_body, AzureError}", 9 | "hyper::StatusCode", 10 | "std::convert::TryInto", 11 | "std::marker::PhantomData", 12 | "azure_sdk_core::{Yes,No,ToAssign}" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "'b", "C", "D" ], 16 | "extra_wheres": [ "C: CosmosClient", "D: DatabaseClient" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "user_client", 20 | "field_type": "&'a dyn UserClient", 21 | "trait_get": "UserClientRequired<'a, C, D>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "user_name", 27 | "field_type": "&'a dyn UserName", 28 | "builder_type": "UserNameSet", 29 | "optional": false, 30 | "trait_get": "UserNameRequired<'a>", 31 | "trait_set": "UserNameSupport<'a>" 32 | }, 33 | { 34 | "name": "user_agent", 35 | "field_type": "&'b str", 36 | "optional": true, 37 | "trait_get": "UserAgentOption<'b>", 38 | "trait_set": "UserAgentSupport<'b>" 39 | }, 40 | { 41 | "name": "activity_id", 42 | "field_type": "&'b str", 43 | "optional": true, 44 | "trait_get": "ActivityIdOption<'b>", 45 | "trait_set": "ActivityIdSupport<'b>" 46 | }, 47 | { 48 | "name": "consistency_level", 49 | "field_type": "ConsistencyLevel<'b>", 50 | "optional": true, 51 | "trait_get": "ConsistencyLevelOption<'b>", 52 | "trait_set": "ConsistencyLevelSupport<'b>", 53 | "get_via_clone": true 54 | } 55 | ] 56 | } 57 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/resource.rs: -------------------------------------------------------------------------------- 1 | use crate::Collection; 2 | use crate::Database; 3 | use crate::Document; 4 | use crate::User; 5 | 6 | pub trait Resource { 7 | fn uri(&self) -> &str; 8 | } 9 | 10 | impl Resource for String { 11 | fn uri(&self) -> &str { 12 | &self 13 | } 14 | } 15 | 16 | impl Resource for &str { 17 | fn uri(&self) -> &str { 18 | self 19 | } 20 | } 21 | 22 | impl<'a> Resource for std::borrow::Cow<'a, str> { 23 | fn uri(&self) -> &str { 24 | &self 25 | } 26 | } 27 | 28 | impl Resource for Document { 29 | fn uri(&self) -> &str { 30 | self.document_attributes._self() 31 | } 32 | } 33 | 34 | impl Resource for &Document { 35 | fn uri(&self) -> &str { 36 | self.document_attributes._self() 37 | } 38 | } 39 | 40 | impl Resource for Database { 41 | fn uri(&self) -> &str { 42 | &self._self 43 | } 44 | } 45 | 46 | impl Resource for &Database { 47 | fn uri(&self) -> &str { 48 | &self._self 49 | } 50 | } 51 | 52 | impl Resource for Collection { 53 | fn uri(&self) -> &str { 54 | &self._self 55 | } 56 | } 57 | 58 | impl Resource for &Collection { 59 | fn uri(&self) -> &str { 60 | &self._self 61 | } 62 | } 63 | 64 | impl Resource for User { 65 | fn uri(&self) -> &str { 66 | &self._self 67 | } 68 | } 69 | 70 | impl Resource for &User { 71 | fn uri(&self) -> &str { 72 | &self._self 73 | } 74 | } 75 | 76 | // TODO: Missing StoredProcedure, Attachment, UDF, Trigger, Permission 77 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/create_permission_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use crate::Permission; 3 | use azure_sdk_core::errors::AzureError; 4 | use azure_sdk_core::{etag_from_headers, session_token_from_headers}; 5 | use http::HeaderMap; 6 | use std::borrow::Cow; 7 | use std::convert::TryInto; 8 | 9 | #[derive(Debug, Clone, PartialEq)] 10 | pub struct CreatePermissionResponse<'a> { 11 | pub permission: Permission<'a, Cow<'a, str>>, 12 | pub charge: f64, 13 | pub activity_id: uuid::Uuid, 14 | pub etag: String, 15 | pub session_token: String, 16 | pub content_path: String, 17 | pub alt_content_path: String, 18 | } 19 | 20 | impl<'a> std::convert::TryFrom<(&HeaderMap, &[u8])> for CreatePermissionResponse<'a> { 21 | type Error = AzureError; 22 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 23 | let headers = value.0; 24 | let body = value.1; 25 | 26 | debug!("headers == {:#?}", headers); 27 | debug!("body == {:#?}", std::str::from_utf8(body)?); 28 | 29 | Ok(Self { 30 | permission: body.try_into()?, 31 | charge: request_charge_from_headers(headers)?, 32 | activity_id: activity_id_from_headers(headers)?, 33 | etag: etag_from_headers(headers)?, 34 | session_token: session_token_from_headers(headers)?, 35 | content_path: content_path_from_headers(headers)?.to_owned(), 36 | alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), 37 | }) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/create_stored_procedure_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use crate::stored_procedure::StoredProcedure; 3 | use crate::ResourceQuota; 4 | use azure_sdk_core::errors::AzureError; 5 | use azure_sdk_core::etag_from_headers; 6 | use azure_sdk_core::session_token_from_headers; 7 | use chrono::{DateTime, Utc}; 8 | use http::HeaderMap; 9 | 10 | #[derive(Debug, Clone, PartialEq)] 11 | pub struct CreateStoredProcedureResponse { 12 | pub stored_procedure: StoredProcedure, 13 | pub charge: f64, 14 | pub activity_id: uuid::Uuid, 15 | pub etag: String, 16 | pub session_token: String, 17 | pub last_change: DateTime, 18 | pub resource_quota: Vec, 19 | pub resource_usage: Vec, 20 | pub quorum_acked_lsn: u64, 21 | pub current_write_quorum: u64, 22 | pub current_replica_set_size: u64, 23 | } 24 | 25 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for CreateStoredProcedureResponse { 26 | type Error = AzureError; 27 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 28 | let headers = value.0; 29 | let body = value.1; 30 | 31 | Ok(Self { 32 | stored_procedure: serde_json::from_slice(body)?, 33 | charge: request_charge_from_headers(headers)?, 34 | activity_id: activity_id_from_headers(headers)?, 35 | etag: etag_from_headers(headers)?, 36 | session_token: session_token_from_headers(headers)?, 37 | last_change: last_state_change_from_headers(headers)?, 38 | resource_quota: resource_quota_from_headers(headers)?, 39 | resource_usage: resource_usage_from_headers(headers)?, 40 | quorum_acked_lsn: quorum_acked_lsn_from_headers(headers)?, 41 | current_write_quorum: current_write_quorum_from_headers(headers)?, 42 | current_replica_set_size: current_replica_set_size_from_headers(headers)?, 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/create_user_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use crate::User; 3 | use azure_sdk_core::errors::AzureError; 4 | use azure_sdk_core::{etag_from_headers, session_token_from_headers}; 5 | use http::HeaderMap; 6 | use std::convert::TryInto; 7 | 8 | #[derive(Debug, Clone, PartialEq)] 9 | pub struct CreateUserResponse { 10 | pub user: User, 11 | pub charge: f64, 12 | pub activity_id: uuid::Uuid, 13 | pub etag: String, 14 | pub session_token: String, 15 | } 16 | 17 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for CreateUserResponse { 18 | type Error = AzureError; 19 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 20 | let headers = value.0; 21 | let body = value.1; 22 | 23 | Ok(Self { 24 | user: body.try_into()?, 25 | charge: request_charge_from_headers(headers)?, 26 | activity_id: activity_id_from_headers(headers)?, 27 | etag: etag_from_headers(headers)?, 28 | session_token: session_token_from_headers(headers)?, 29 | }) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/delete_collection_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use azure_sdk_core::errors::AzureError; 3 | use hyper::header::HeaderMap; 4 | 5 | #[derive(Debug, Clone)] 6 | pub struct DeleteCollectionResponse { 7 | pub charge: f64, 8 | pub activity_id: uuid::Uuid, 9 | } 10 | 11 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for DeleteCollectionResponse { 12 | type Error = AzureError; 13 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 14 | let headers = value.0; 15 | let _body = value.1; 16 | 17 | let charge = request_charge_from_headers(headers)?; 18 | let activity_id = activity_id_from_headers(headers)?; 19 | 20 | Ok(Self { 21 | charge, 22 | activity_id, 23 | }) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/delete_database_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use crate::ResourceQuota; 3 | use azure_sdk_core::errors::AzureError; 4 | use azure_sdk_core::session_token_from_headers; 5 | use hyper::header::HeaderMap; 6 | 7 | #[derive(Debug, Clone)] 8 | pub struct DeleteDatabaseResponse { 9 | pub charge: f64, 10 | pub activity_id: uuid::Uuid, 11 | pub session_token: String, 12 | pub resource_quota: Vec, 13 | pub resource_usage: Vec, 14 | } 15 | 16 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for DeleteDatabaseResponse { 17 | type Error = AzureError; 18 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 19 | let headers = value.0; 20 | let _body = value.1; 21 | 22 | let charge = request_charge_from_headers(headers)?; 23 | let activity_id = activity_id_from_headers(headers)?; 24 | 25 | Ok(Self { 26 | charge, 27 | activity_id, 28 | session_token: session_token_from_headers(headers)?, 29 | resource_quota: resource_quota_from_headers(headers)?, 30 | resource_usage: resource_usage_from_headers(headers)?, 31 | }) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/delete_document_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use azure_sdk_core::errors::AzureError; 3 | use azure_sdk_core::session_token_from_headers; 4 | use hyper::header::HeaderMap; 5 | 6 | #[derive(Debug, Clone)] 7 | pub struct DeleteDocumentResponse { 8 | pub charge: f64, 9 | pub activity_id: uuid::Uuid, 10 | pub session_token: String, 11 | } 12 | 13 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for DeleteDocumentResponse { 14 | type Error = AzureError; 15 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 16 | let headers = value.0; 17 | let _body = value.1; 18 | 19 | let charge = request_charge_from_headers(headers)?; 20 | let activity_id = activity_id_from_headers(headers)?; 21 | let session_token = session_token_from_headers(headers)?; 22 | 23 | Ok(Self { 24 | charge, 25 | activity_id, 26 | session_token, 27 | }) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/delete_permission_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use azure_sdk_core::errors::AzureError; 3 | use azure_sdk_core::session_token_from_headers; 4 | use http::HeaderMap; 5 | 6 | #[derive(Debug, Clone, PartialEq)] 7 | pub struct DeletePermissionResponse { 8 | pub charge: f64, 9 | pub activity_id: uuid::Uuid, 10 | pub session_token: String, 11 | pub content_path: String, 12 | pub alt_content_path: String, 13 | } 14 | 15 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for DeletePermissionResponse { 16 | type Error = AzureError; 17 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 18 | let headers = value.0; 19 | let _body = value.1; 20 | 21 | debug!("headers == {:#?}", headers); 22 | debug!("_body == {:#?}", std::str::from_utf8(_body)?); 23 | 24 | Ok(Self { 25 | charge: request_charge_from_headers(headers)?, 26 | activity_id: activity_id_from_headers(headers)?, 27 | session_token: session_token_from_headers(headers)?, 28 | content_path: content_path_from_headers(headers)?.to_owned(), 29 | alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), 30 | }) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/delete_stored_procedure_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use crate::ResourceQuota; 3 | use azure_sdk_core::errors::AzureError; 4 | use azure_sdk_core::session_token_from_headers; 5 | use chrono::{DateTime, Utc}; 6 | use http::HeaderMap; 7 | 8 | #[derive(Debug, Clone, PartialEq)] 9 | pub struct DeleteStoredProcedureResponse { 10 | pub charge: f64, 11 | pub activity_id: uuid::Uuid, 12 | pub session_token: String, 13 | pub last_change: DateTime, 14 | pub resource_quota: Vec, 15 | pub resource_usage: Vec, 16 | } 17 | 18 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for DeleteStoredProcedureResponse { 19 | type Error = AzureError; 20 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 21 | let headers = value.0; 22 | let _body = value.1; 23 | 24 | Ok(Self { 25 | charge: request_charge_from_headers(headers)?, 26 | activity_id: activity_id_from_headers(headers)?, 27 | session_token: session_token_from_headers(headers)?, 28 | last_change: last_state_change_from_headers(headers)?, 29 | resource_quota: resource_quota_from_headers(headers)?, 30 | resource_usage: resource_usage_from_headers(headers)?, 31 | }) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/delete_user_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use azure_sdk_core::errors::AzureError; 3 | use http::HeaderMap; 4 | 5 | #[derive(Debug, Clone, PartialEq)] 6 | pub struct DeleteUserResponse { 7 | pub charge: f64, 8 | pub activity_id: uuid::Uuid, 9 | } 10 | 11 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for DeleteUserResponse { 12 | type Error = AzureError; 13 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 14 | let headers = value.0; 15 | let _body = value.1; 16 | 17 | Ok(Self { 18 | charge: request_charge_from_headers(headers)?, 19 | activity_id: activity_id_from_headers(headers)?, 20 | }) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/get_database_response.rs: -------------------------------------------------------------------------------- 1 | use crate::database::Database; 2 | use crate::from_headers::*; 3 | use crate::ResourceQuota; 4 | use azure_sdk_core::errors::AzureError; 5 | use azure_sdk_core::{etag_from_headers, session_token_from_headers}; 6 | use chrono::{DateTime, Utc}; 7 | use hyper::header::HeaderMap; 8 | 9 | #[derive(Debug, Clone)] 10 | pub struct GetDatabaseResponse { 11 | pub database: Database, 12 | pub charge: f64, 13 | pub activity_id: uuid::Uuid, 14 | pub session_token: String, 15 | pub etag: String, 16 | pub last_state_change: DateTime, 17 | pub resource_quota: Vec, 18 | pub resource_usage: Vec, 19 | pub schema_version: String, 20 | pub service_version: String, 21 | pub gateway_version: String, 22 | } 23 | 24 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for GetDatabaseResponse { 25 | type Error = AzureError; 26 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 27 | let headers = value.0; 28 | let body = value.1; 29 | 30 | debug!("get database response == {}", std::str::from_utf8(body)?); 31 | 32 | Ok(Self { 33 | database: serde_json::from_slice(body)?, 34 | charge: request_charge_from_headers(headers)?, 35 | activity_id: activity_id_from_headers(headers)?, 36 | session_token: session_token_from_headers(headers)?, 37 | etag: etag_from_headers(headers)?, 38 | last_state_change: last_state_change_from_headers(headers)?, 39 | resource_quota: resource_quota_from_headers(headers)?, 40 | resource_usage: resource_usage_from_headers(headers)?, 41 | schema_version: schema_version_from_headers(headers)?.to_owned(), 42 | service_version: service_version_from_headers(headers)?.to_owned(), 43 | gateway_version: gateway_version_from_headers(headers)?.to_owned(), 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/get_permission_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use crate::permission::CosmosPermission; 3 | use crate::Permission; 4 | use azure_sdk_core::errors::AzureError; 5 | use azure_sdk_core::{etag_from_headers, session_token_from_headers}; 6 | use http::HeaderMap; 7 | use std::borrow::Cow; 8 | 9 | #[derive(Debug, Clone, PartialEq)] 10 | pub struct GetPermissionResponse<'a> { 11 | pub permission: Permission<'a, Cow<'a, str>>, 12 | pub charge: f64, 13 | pub etag: String, 14 | pub activity_id: uuid::Uuid, 15 | pub session_token: String, 16 | pub content_path: String, 17 | pub alt_content_path: String, 18 | } 19 | 20 | impl<'a> std::convert::TryFrom<(&HeaderMap, &[u8])> for GetPermissionResponse<'a> { 21 | type Error = AzureError; 22 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 23 | let headers = value.0; 24 | let body = value.1; 25 | 26 | debug!("headers == {:#?}", headers); 27 | debug!("body == {:#?}", std::str::from_utf8(body)?); 28 | 29 | // first get the Cosmos REST API permission 30 | let cosmos_permission: CosmosPermission<'_> = serde_json::from_slice(body)?; 31 | debug!("cosmos_permission== {:#?}", cosmos_permission); 32 | 33 | // now convert into the SDK struct 34 | let permission = Permission::try_from(cosmos_permission)?; 35 | 36 | Ok(Self { 37 | permission, 38 | charge: request_charge_from_headers(headers)?, 39 | etag: etag_from_headers(headers)?, 40 | activity_id: activity_id_from_headers(headers)?, 41 | session_token: session_token_from_headers(headers)?, 42 | content_path: content_path_from_headers(headers)?.to_owned(), 43 | alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/list_users_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use crate::User; 3 | use azure_sdk_core::errors::AzureError; 4 | use azure_sdk_core::{ 5 | continuation_token_from_headers_optional, session_token_from_headers, SessionToken, 6 | }; 7 | use http::HeaderMap; 8 | use serde::Deserialize; 9 | 10 | #[derive(Debug, Clone, Deserialize, PartialEq)] 11 | pub struct ListUsersResponse { 12 | #[serde(rename = "Users")] 13 | pub users: Vec, 14 | #[serde(rename = "_rid")] 15 | pub rid: String, 16 | #[serde(rename = "_count")] 17 | pub count: u64, 18 | 19 | #[serde(skip_deserializing)] 20 | pub charge: f64, 21 | #[serde(skip_deserializing)] 22 | pub activity_id: uuid::Uuid, 23 | #[serde(skip_deserializing)] 24 | pub session_token: SessionToken, 25 | #[serde(skip_deserializing)] 26 | pub continuation_token: Option, 27 | } 28 | 29 | impl std::convert::TryFrom<(&HeaderMap, &[u8])> for ListUsersResponse { 30 | type Error = AzureError; 31 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 32 | let headers = value.0; 33 | let body = value.1; 34 | 35 | let mut list_users_response: ListUsersResponse = serde_json::from_slice(body)?; 36 | list_users_response.charge = request_charge_from_headers(headers)?; 37 | list_users_response.activity_id = activity_id_from_headers(headers)?; 38 | list_users_response.continuation_token = continuation_token_from_headers_optional(headers)?; 39 | list_users_response.session_token = session_token_from_headers(headers)?; 40 | 41 | Ok(list_users_response) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/replace_permission_response.rs: -------------------------------------------------------------------------------- 1 | use crate::from_headers::*; 2 | use crate::Permission; 3 | use azure_sdk_core::errors::AzureError; 4 | use azure_sdk_core::{etag_from_headers, session_token_from_headers}; 5 | use http::HeaderMap; 6 | use std::borrow::Cow; 7 | use std::convert::TryInto; 8 | 9 | #[derive(Debug, Clone, PartialEq)] 10 | pub struct ReplacePermissionResponse<'a> { 11 | pub permission: Permission<'a, Cow<'a, str>>, 12 | pub charge: f64, 13 | pub activity_id: uuid::Uuid, 14 | pub etag: String, 15 | pub session_token: String, 16 | pub content_path: String, 17 | pub alt_content_path: String, 18 | } 19 | 20 | impl<'a> std::convert::TryFrom<(&HeaderMap, &[u8])> for ReplacePermissionResponse<'a> { 21 | type Error = AzureError; 22 | fn try_from(value: (&HeaderMap, &[u8])) -> Result { 23 | let headers = value.0; 24 | let body = value.1; 25 | 26 | debug!("headers == {:#?}", headers); 27 | debug!("body == {:#?}", std::str::from_utf8(body)?); 28 | 29 | Ok(Self { 30 | permission: body.try_into()?, 31 | charge: request_charge_from_headers(headers)?, 32 | activity_id: activity_id_from_headers(headers)?, 33 | etag: etag_from_headers(headers)?, 34 | session_token: session_token_from_headers(headers)?, 35 | content_path: content_path_from_headers(headers)?.to_owned(), 36 | alt_content_path: alt_content_path_from_headers(headers)?.to_owned(), 37 | }) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/responses/replace_stored_procedure_response.rs: -------------------------------------------------------------------------------- 1 | pub type ReplaceStoredProcedureResponse = crate::responses::CreateStoredProcedureResponse; 2 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/stored_procedure/mod.rs: -------------------------------------------------------------------------------- 1 | mod parameters; 2 | mod stored_procedure_name; 3 | 4 | pub use self::parameters::Parameters; 5 | pub use self::stored_procedure_name::StoredProcedureName; 6 | 7 | #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] 8 | pub struct StoredProcedure { 9 | pub id: String, 10 | #[serde(rename = "_rid")] 11 | pub rid: String, 12 | #[serde(rename = "_ts")] 13 | pub ts: u64, 14 | #[serde(rename = "_self")] 15 | pub _self: String, 16 | #[serde(rename = "_etag")] 17 | pub etag: String, 18 | pub body: String, 19 | } 20 | 21 | impl StoredProcedureName for StoredProcedure { 22 | fn name(&self) -> &str { 23 | &self.id 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/stored_procedure/parameters.rs: -------------------------------------------------------------------------------- 1 | pub type Parameters = crate::to_json_vector::ToJsonVector; 2 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/stored_procedure/stored_procedure_name.rs: -------------------------------------------------------------------------------- 1 | pub trait StoredProcedureName: std::fmt::Debug { 2 | fn name(&self) -> &str; 3 | } 4 | 5 | impl StoredProcedureName for &str { 6 | fn name(&self) -> &str { 7 | self 8 | } 9 | } 10 | 11 | impl StoredProcedureName for String { 12 | fn name(&self) -> &str { 13 | self.as_ref() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/trigger.rs: -------------------------------------------------------------------------------- 1 | create_enum!( 2 | TriggerOperation, 3 | (All, "All"), 4 | (Create, "Create"), 5 | (Replace, "Replace"), 6 | (Delete, "Delete") 7 | ); 8 | 9 | create_enum!(TriggerType, (Pre, "Pre"), (Post, "Post")); 10 | 11 | #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] 12 | pub struct Trigger { 13 | #[serde(rename = "_rid")] 14 | pub rid: String, 15 | #[serde(rename = "_ts")] 16 | pub ts: u64, 17 | pub _self: String, 18 | #[serde(rename = "_etag")] 19 | pub etag: String, 20 | 21 | pub id: String, 22 | #[serde(rename = "triggerOperation")] 23 | pub trigger_operation: TriggerOperation, 24 | #[serde(rename = "triggerType")] 25 | pub trigger_type: TriggerType, 26 | pub body: String, 27 | } 28 | 29 | pub trait TriggerName: std::fmt::Debug { 30 | fn name(&self) -> &str; 31 | } 32 | 33 | impl TriggerName for &str { 34 | fn name(&self) -> &str { 35 | self 36 | } 37 | } 38 | 39 | impl TriggerName for String { 40 | fn name(&self) -> &str { 41 | self.as_ref() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/user.rs: -------------------------------------------------------------------------------- 1 | pub trait UserName: std::fmt::Debug { 2 | fn id(&self) -> &str; 3 | } 4 | 5 | impl UserName for User { 6 | fn id(&self) -> &str { 7 | &self.id 8 | } 9 | } 10 | 11 | impl UserName for String { 12 | fn id(&self) -> &str { 13 | &self 14 | } 15 | } 16 | 17 | impl UserName for &str { 18 | fn id(&self) -> &str { 19 | self 20 | } 21 | } 22 | 23 | #[derive(Serialize, Deserialize, Clone, Debug, PartialOrd, PartialEq)] 24 | pub struct User { 25 | pub id: String, 26 | #[serde(skip_serializing)] 27 | #[serde(rename = "_rid")] 28 | pub rid: String, 29 | #[serde(skip_serializing)] 30 | #[serde(rename = "_ts")] 31 | pub ts: u64, 32 | #[serde(skip_serializing)] 33 | #[serde(rename = "_self")] 34 | pub _self: String, 35 | #[serde(skip_serializing)] 36 | #[serde(rename = "_etag")] 37 | pub etag: String, 38 | #[serde(skip_serializing)] 39 | #[serde(rename = "_permissions")] 40 | pub permissions: String, 41 | } 42 | 43 | impl std::convert::TryFrom<&[u8]> for User { 44 | type Error = serde_json::Error; 45 | fn try_from(body: &[u8]) -> Result { 46 | serde_json::from_slice(body) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/user_defined_function/mod.rs: -------------------------------------------------------------------------------- 1 | mod user_defined_function_name; 2 | 3 | pub use self::user_defined_function_name::UserDefinedFunctionName; 4 | 5 | #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] 6 | pub struct UserDefinedFunction { 7 | pub id: String, 8 | #[serde(rename = "_rid")] 9 | pub rid: String, 10 | #[serde(rename = "_ts")] 11 | pub ts: u64, 12 | #[serde(rename = "_self")] 13 | pub _self: String, 14 | #[serde(rename = "_etag")] 15 | pub etag: String, 16 | pub body: String, 17 | } 18 | 19 | impl UserDefinedFunctionName for UserDefinedFunction { 20 | fn name(&self) -> &str { 21 | &self.id 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/src/user_defined_function/user_defined_function_name.rs: -------------------------------------------------------------------------------- 1 | pub trait UserDefinedFunctionName: std::fmt::Debug { 2 | fn name(&self) -> &str; 3 | } 4 | 5 | impl UserDefinedFunctionName for &str { 6 | fn name(&self) -> &str { 7 | self 8 | } 9 | } 10 | 11 | impl UserDefinedFunctionName for String { 12 | fn name(&self) -> &str { 13 | self.as_ref() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/tests/cosmos_database.rs: -------------------------------------------------------------------------------- 1 | #![cfg(all(test, feature = "test_e2e"))] 2 | use azure_sdk_cosmos::prelude::*; 3 | 4 | mod setup; 5 | 6 | #[tokio::test] 7 | async fn create_and_delete_database() { 8 | const DATABASE_NAME: &str = "cosmos-test-db-create-and-delete-database"; 9 | 10 | let client = setup::initialize().unwrap(); 11 | 12 | // list existing databases and remember their number 13 | let databases = client.list_databases().execute().await.unwrap(); 14 | let database_count_before = databases.databases.len(); 15 | 16 | // create a new database and check if the number of DBs increased 17 | let database = client 18 | .create_database() 19 | .with_database_name(&DATABASE_NAME) 20 | .execute() 21 | .await 22 | .unwrap(); 23 | let databases = client.list_databases().execute().await.unwrap(); 24 | assert!(databases.databases.len() == database_count_before + 1); 25 | 26 | // get the previously created database 27 | let database_after_get = client 28 | .with_database_client(DATABASE_NAME) 29 | .get_database() 30 | .execute() 31 | .await 32 | .unwrap(); 33 | assert!(database.database.rid == database_after_get.database.rid); 34 | 35 | // delete the database 36 | client 37 | .with_database_client(DATABASE_NAME) 38 | .delete_database() 39 | .execute() 40 | .await 41 | .unwrap(); 42 | let databases = client.list_databases().execute().await.unwrap(); 43 | assert!(databases.databases.len() == database_count_before); 44 | } 45 | -------------------------------------------------------------------------------- /azure_sdk_cosmos/tests/setup.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::errors::AzureError; 2 | use azure_sdk_cosmos::clients::DefaultCosmosUri; 3 | use azure_sdk_cosmos::prelude::*; 4 | use azure_sdk_cosmos::AuthorizationToken; 5 | 6 | pub fn initialize() -> Result, AzureError> { 7 | let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!"); 8 | let key = 9 | std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!"); 10 | 11 | let authorization_token = AuthorizationToken::new_master(&key)?; 12 | let client = ClientBuilder::new(account, authorization_token)?; 13 | 14 | Ok(client) 15 | } 16 | -------------------------------------------------------------------------------- /azure_sdk_service_bus/.rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition="2018" 2 | -------------------------------------------------------------------------------- /azure_sdk_service_bus/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "azure_sdk_service_bus" 3 | version = "0.44.2" 4 | description = "Rust wrappers around Microsoft Azure REST APIs - Service Bus crate" 5 | readme = "README.md" 6 | authors = ["Francesco Cogno ", "Max Gortman ", "Dong Liu "] 7 | license = "Apache-2.0" 8 | repository = "https://github.com/MindFlavor/AzureSDKForRust" 9 | documentation = "http://mindflavor.github.io/AzureSDKForRust/azure_sdk_for_rust/index.html" 10 | homepage = "https://github.com/MindFlavor/AzureSDKForRust" 11 | 12 | keywords = ["sdk", "azure", "rest", "iot", "cloud"] 13 | categories = ["api-bindings"] 14 | 15 | edition = "2018" 16 | 17 | [dependencies] 18 | azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" } 19 | ring = "0.16" 20 | base64 = "0.12" 21 | chrono = "0.4" 22 | hyper = "0.13" 23 | log = "0.4" 24 | url = "2.1" 25 | hyper-rustls = "0.20" 26 | 27 | [dev-dependencies] 28 | futures = "0.3" 29 | tokio = { version = "0.2", features = ["macros"] } 30 | env_logger = "0.7" 31 | 32 | [features] 33 | test_e2e = [] 34 | -------------------------------------------------------------------------------- /azure_sdk_service_bus/README.md: -------------------------------------------------------------------------------- 1 | # Azure SDK for Rust - Azure service bus crate 2 | 3 | Azure service bus crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to [https://github.com/MindFlavor/AzureSDKForRust](https://github.com/MindFlavor/AzureSDKForRust). 4 | -------------------------------------------------------------------------------- /azure_sdk_service_bus/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![recursion_limit = "128"] 2 | 3 | #[macro_use] 4 | extern crate log; 5 | 6 | pub mod event_hub; 7 | pub mod prelude; 8 | -------------------------------------------------------------------------------- /azure_sdk_service_bus/src/prelude.rs: -------------------------------------------------------------------------------- 1 | pub use crate::event_hub::Client; 2 | -------------------------------------------------------------------------------- /azure_sdk_service_bus/tests/event_hub.rs: -------------------------------------------------------------------------------- 1 | #![cfg(all(test, feature = "test_e2e"))] 2 | #[macro_use] 3 | extern crate log; 4 | 5 | use azure_sdk_core::errors::AzureError; 6 | use azure_sdk_service_bus::event_hub::Client; 7 | use chrono::Duration; 8 | 9 | #[tokio::test] 10 | async fn send_events_to_event_hub() { 11 | let mut eh_client = create_client().unwrap(); 12 | 13 | for i in 0..2 { 14 | info!("Sending message {}", i); 15 | send_event(&mut eh_client).await; 16 | } 17 | } 18 | 19 | async fn send_event(cli: &mut Client) { 20 | debug!("running send_event"); 21 | 22 | let text_to_send = "{ numero: 100, testo: \"sample\" }"; 23 | cli.send_event(&text_to_send, Duration::hours(1)) 24 | .await 25 | .unwrap(); 26 | } 27 | 28 | fn create_client() -> Result { 29 | let policy_name = std::env::var("AZURE_POLICY_NAME") 30 | .expect("Please set AZURE_POLICY_NAME env variable first!"); 31 | 32 | let policy_key = 33 | std::env::var("AZURE_POLICY_KEY").expect("Please set AZURE_POLICY_KEY env variable first!"); 34 | 35 | let service_bus_namespace = std::env::var("AZURE_SERVICE_BUS_NAMESPACE") 36 | .expect("Please set AZURE_SERVICE_BUS_NAMESPACE env variable first!"); 37 | 38 | let event_hub_name = std::env::var("AZURE_EVENT_HUB_NAME") 39 | .expect("Please set AZURE_EVENT_HUB_NAME env variable first!"); 40 | 41 | Ok(Client::new( 42 | service_bus_namespace, 43 | event_hub_name, 44 | policy_name, 45 | policy_key, 46 | )?) 47 | } 48 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/.rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition="2018" 2 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "azure_sdk_storage_account" 3 | version = "0.41.3" 4 | description = "Rust wrappers around Microsoft Azure REST APIs - Blob storage account crate" 5 | readme = "README.md" 6 | authors = ["Francesco Cogno ", "Max Gortman "] 7 | license = "Apache-2.0" 8 | repository = "https://github.com/MindFlavor/AzureSDKForRust" 9 | documentation = "http://mindflavor.github.io/AzureSDKForRust/azure_sdk_for_rust/index.html" 10 | homepage = "https://github.com/MindFlavor/AzureSDKForRust" 11 | 12 | keywords = ["sdk", "azure", "rest", "iot", "cloud"] 13 | categories = ["api-bindings"] 14 | 15 | edition = "2018" 16 | 17 | [dependencies] 18 | azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" } 19 | azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.3" } 20 | chrono = "0.4" 21 | http = "0.2" 22 | hyper = "0.13" 23 | log = "0.4" 24 | 25 | [dev-dependencies] 26 | futures = "0.3" 27 | tokio = { version = "0.2", features = ["macros"] } 28 | env_logger = "0.7" 29 | 30 | [features] 31 | test_e2e = [] 32 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/README.md: -------------------------------------------------------------------------------- 1 | # Azure SDK for Rust - Azure blob storage account crate 2 | 3 | Azure blob storage account crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to [https://github.com/MindFlavor/AzureSDKForRust](https://github.com/MindFlavor/AzureSDKForRust). 4 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/examples/account00.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_storage_account::prelude::*; 2 | use azure_sdk_storage_core::prelude::*; 3 | use std::error::Error; 4 | 5 | #[tokio::main] 6 | async fn main() -> Result<(), Box> { 7 | // First we retrieve the account name and master key from environment variables. 8 | let account = 9 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 10 | let master_key = 11 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 12 | 13 | let client = client::with_access_key(&account, &master_key); 14 | 15 | let response = client.get_account_information().finalize().await?; 16 | println!("{:?}", response); 17 | 18 | Ok(()) 19 | } 20 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/src/account/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod requests; 2 | pub mod responses; 3 | 4 | #[derive(Debug, Clone, PartialEq)] 5 | pub struct Account { 6 | pub sku_name: String, 7 | pub kind: String, 8 | } 9 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/src/account/requests/get_account_information_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GetAccountInformationBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::account::responses::GetAccountInformationResponse", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "azure_sdk_storage_core::prelude::*", 8 | "hyper::{Method, StatusCode}" 9 | ], 10 | "inline": true, 11 | "extra_types": [ "'a", "C" ], 12 | "extra_wheres": [ "C: Client" ], 13 | "constructor_fields": [ 14 | { 15 | "name": "client", 16 | "field_type": "&'a C", 17 | "trait_get": "ClientRequired<'a, C>" 18 | } 19 | ], 20 | "fields": [ 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/src/account/requests/get_account_information_builder.rs: -------------------------------------------------------------------------------- 1 | use crate::account::responses::GetAccountInformationResponse; 2 | use azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}; 3 | use azure_sdk_storage_core::prelude::*; 4 | use hyper::{Method, StatusCode}; 5 | 6 | #[derive(Debug, Clone)] 7 | pub struct GetAccountInformationBuilder<'a, C> 8 | where 9 | C: Client, 10 | { 11 | client: &'a C, 12 | } 13 | 14 | impl<'a, C> GetAccountInformationBuilder<'a, C> 15 | where 16 | C: Client, 17 | { 18 | #[inline] 19 | pub(crate) fn new(client: &'a C) -> GetAccountInformationBuilder<'a, C> { 20 | GetAccountInformationBuilder { client } 21 | } 22 | } 23 | 24 | impl<'a, C> ClientRequired<'a, C> for GetAccountInformationBuilder<'a, C> 25 | where 26 | C: Client, 27 | { 28 | #[inline] 29 | fn client(&self) -> &'a C { 30 | self.client 31 | } 32 | } 33 | 34 | // methods callable only when every mandatory field has been filled 35 | impl<'a, C> GetAccountInformationBuilder<'a, C> 36 | where 37 | C: Client, 38 | { 39 | #[inline] 40 | pub async fn finalize(self) -> Result { 41 | let uri = format!( 42 | "{}/?restype=account&comp=properties", 43 | self.client.blob_uri() 44 | ); 45 | trace!("uri == {:?}", uri); 46 | 47 | let req = self 48 | .client() 49 | .perform_request(&uri, &Method::GET, &|request| request, None); 50 | let (headers, _) = check_status_extract_headers_and_body(req?, StatusCode::OK).await?; 51 | GetAccountInformationResponse::from_headers(&headers) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/src/account/requests/mod.rs: -------------------------------------------------------------------------------- 1 | mod get_account_information_builder; 2 | pub use self::get_account_information_builder::GetAccountInformationBuilder; 3 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/src/account/responses/get_account_information_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::errors::AzureError; 2 | use azure_sdk_core::{ 3 | account_kind_from_headers, date_from_headers, request_id_from_headers, sku_name_from_headers, 4 | RequestId, 5 | }; 6 | use chrono::{DateTime, Utc}; 7 | use http::HeaderMap; 8 | 9 | #[derive(Debug, Clone)] 10 | pub struct GetAccountInformationResponse { 11 | pub request_id: RequestId, 12 | pub date: DateTime, 13 | pub sku_name: String, 14 | pub account_kind: String, 15 | } 16 | 17 | impl GetAccountInformationResponse { 18 | pub(crate) fn from_headers( 19 | headers: &HeaderMap, 20 | ) -> Result { 21 | let request_id = request_id_from_headers(headers)?; 22 | let date = date_from_headers(headers)?; 23 | let sku_name = sku_name_from_headers(headers)?; 24 | let account_kind = account_kind_from_headers(headers)?; 25 | 26 | Ok(GetAccountInformationResponse { 27 | request_id, 28 | date, 29 | sku_name, 30 | account_kind, 31 | }) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/src/account/responses/mod.rs: -------------------------------------------------------------------------------- 1 | mod get_account_information_response; 2 | pub use get_account_information_response::GetAccountInformationResponse; 3 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![recursion_limit = "128"] 2 | 3 | #[macro_use] 4 | extern crate log; 5 | pub mod account; 6 | pub mod prelude; 7 | 8 | use azure_sdk_storage_core::client::Client; 9 | 10 | pub trait Account 11 | where 12 | C: Client, 13 | { 14 | #[allow(clippy::needless_lifetimes)] 15 | fn get_account_information<'a>( 16 | &'a self, 17 | ) -> account::requests::GetAccountInformationBuilder<'a, C>; 18 | } 19 | 20 | impl Account for C 21 | where 22 | C: Client, 23 | { 24 | #[allow(clippy::needless_lifetimes)] 25 | fn get_account_information<'a>( 26 | &'a self, 27 | ) -> account::requests::GetAccountInformationBuilder<'a, C> { 28 | account::requests::GetAccountInformationBuilder::new(self) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/src/prelude.rs: -------------------------------------------------------------------------------- 1 | pub use crate::Account as AccountTrait; 2 | -------------------------------------------------------------------------------- /azure_sdk_storage_account/tests/account.rs: -------------------------------------------------------------------------------- 1 | #![cfg(all(test, feature = "test_e2e"))] 2 | use azure_sdk_storage_account::prelude::*; 3 | use azure_sdk_storage_core::prelude::*; 4 | 5 | #[tokio::test] 6 | async fn get_account_information() { 7 | let account = 8 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 9 | let master_key = 10 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 11 | 12 | let client = client::with_access_key(&account, &master_key); 13 | 14 | // we just test the call works, we don't check the return value since the 15 | // values depend on the Azure storage account 16 | client.get_account_information().finalize().await.unwrap(); 17 | } 18 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "azure_sdk_storage_blob" 3 | version = "0.45.3" 4 | description = "Rust wrappers around Microsoft Azure REST APIs - Blob storage crate" 5 | readme = "README.md" 6 | authors = ["Francesco Cogno ", "Max Gortman ", "Dong Liu "] 7 | license = "Apache-2.0" 8 | repository = "https://github.com/MindFlavor/AzureSDKForRust" 9 | documentation = "http://mindflavor.github.io/AzureSDKForRust/azure_sdk_for_rust/index.html" 10 | homepage = "https://github.com/MindFlavor/AzureSDKForRust" 11 | 12 | keywords = ["sdk", "azure", "rest", "iot", "cloud"] 13 | categories = ["api-bindings"] 14 | 15 | edition = "2018" 16 | 17 | [dependencies] 18 | azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.6", optional = true } 19 | azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.3" } 20 | md5 = "0.7" 21 | RustyXML = "0.3" 22 | base64 = "0.12" 23 | chrono = "0.4" 24 | http = "0.2" 25 | futures = "0.3" 26 | hyper = "0.13" 27 | log = "0.4" 28 | serde = "1.0" 29 | serde_derive = "1.0" 30 | serde-xml-rs = "0.4" 31 | uuid = { version = "0.8", features = ["v4"] } 32 | percent-encoding = "2.1" 33 | 34 | [dev-dependencies] 35 | env_logger = "0.7" 36 | tokio = { version = "0.2", features = ["macros"] } 37 | azure_sdk_auth_aad = { path = "../azure_sdk_auth_aad" } 38 | url = "2.1" 39 | 40 | [features] 41 | default = [ "azure_sdk_core" ] 42 | test_e2e = [ "azure_sdk_core" ] 43 | azurite_workaround = [ "azure_sdk_core/azurite_workaround" ] 44 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/README.md: -------------------------------------------------------------------------------- 1 | # Azure SDK for Rust - Azure blob storage crate 2 | 3 | Azure blob storage crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to [https://github.com/MindFlavor/AzureSDKForRust](https://github.com/MindFlavor/AzureSDKForRust). 4 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/examples/blob_00.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate log; 3 | 4 | use azure_sdk_core::prelude::*; 5 | use azure_sdk_storage_blob::prelude::*; 6 | use azure_sdk_storage_core::prelude::*; 7 | use std::error::Error; 8 | 9 | #[tokio::main] 10 | async fn main() -> Result<(), Box> { 11 | // First we retrieve the account name and master key from environment variables. 12 | let account = 13 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 14 | let master_key = 15 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 16 | 17 | let container = std::env::args() 18 | .nth(1) 19 | .expect("please specify container name as command line parameter"); 20 | let blob = std::env::args() 21 | .nth(2) 22 | .expect("please specify blob name as command line parameter"); 23 | 24 | let client = client::with_access_key(&account, &master_key); 25 | 26 | trace!("Requesting blob"); 27 | 28 | let response = client 29 | .get_blob() 30 | .with_container_name(&container) 31 | .with_blob_name(&blob) 32 | .finalize() 33 | .await?; 34 | 35 | let s_content = String::from_utf8(response.data)?; 36 | println!("blob == {:?}", blob); 37 | println!("s_content == {}", s_content); 38 | 39 | Ok(()) 40 | } 41 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/examples/blob_01.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::prelude::*; 2 | use azure_sdk_storage_blob::prelude::*; 3 | use azure_sdk_storage_core::prelude::*; 4 | use std::error::Error; 5 | 6 | #[tokio::main] 7 | async fn main() -> Result<(), Box> { 8 | env_logger::init(); 9 | 10 | // First we retrieve the account name and master key from environment variables. 11 | let account = 12 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 13 | let master_key = 14 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 15 | 16 | let container_name = std::env::args() 17 | .nth(1) 18 | .expect("please specify container name as command line parameter"); 19 | 20 | let client = client::with_access_key(&account, &master_key); 21 | 22 | let _res = client 23 | .list_blobs() 24 | .with_container_name(&container_name) 25 | .with_include_copy() 26 | .with_include_deleted() 27 | .with_include_metadata() 28 | .with_include_snapshots() 29 | .with_include_uncommitted_blobs() 30 | .finalize() 31 | .await?; 32 | 33 | let result = client 34 | .get_blob() 35 | .with_container_name(&container_name) 36 | .with_blob_name("SorgeniaReorganizeRebuildIndexes.zip") 37 | .finalize() 38 | .await?; 39 | 40 | println!("{:?}", result); 41 | 42 | Ok(()) 43 | } 44 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/examples/blob_02_bearer_token.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate log; 3 | 4 | use azure_sdk_core::prelude::*; 5 | use azure_sdk_storage_blob::prelude::*; 6 | use azure_sdk_storage_core::prelude::*; 7 | use std::error::Error; 8 | 9 | #[tokio::main] 10 | async fn main() -> Result<(), Box> { 11 | // First we retrieve the account name and master key from environment variables. 12 | 13 | let account = std::env::args() 14 | .nth(1) 15 | .expect("please specify the account name as first command line parameter"); 16 | let container = std::env::args() 17 | .nth(2) 18 | .expect("please specify the container name as second command line parameter"); 19 | let blob = std::env::args() 20 | .nth(3) 21 | .expect("please specify the blob name as third command line parameter"); 22 | let bearer_token = std::env::args() 23 | .nth(4) 24 | .expect("please specify the bearer token as fourth command line parameter"); 25 | 26 | let client = client::with_bearer_token(account, bearer_token); 27 | 28 | trace!("Requesting blob"); 29 | 30 | let response = client 31 | .get_blob() 32 | .with_container_name(&container) 33 | .with_blob_name(&blob) 34 | .finalize() 35 | .await?; 36 | 37 | let s_content = String::from_utf8(response.data)?; 38 | println!("blob == {:?}", blob); 39 | println!("s_content == {}", s_content); 40 | 41 | Ok(()) 42 | } 43 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/examples/blob_04.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::prelude::*; 2 | use azure_sdk_storage_blob::prelude::*; 3 | use azure_sdk_storage_core::prelude::*; 4 | use std::error::Error; 5 | 6 | #[tokio::main] 7 | async fn main() -> Result<(), Box> { 8 | env_logger::init(); 9 | 10 | // First we retrieve the account name and master key from environment variables. 11 | let account = 12 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 13 | let master_key = 14 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 15 | 16 | let container_name = std::env::args() 17 | .nth(1) 18 | .expect("please specify container name as command line parameter"); 19 | 20 | let client = client::with_access_key(&account, &master_key); 21 | 22 | let data = b"1337 azure blob test"; 23 | let blob = "test1"; 24 | let mut block_ids = Vec::new(); 25 | for (i, block) in data.chunks(64 * 1024 * 1024 /* 64 MiB */).enumerate() { 26 | block_ids.push(i.to_be_bytes()); 27 | let digest = md5::compute(block); 28 | let put_block_response = client 29 | .put_block() 30 | .with_container_name(&container_name) 31 | .with_blob_name(blob) 32 | .with_body(block) 33 | .with_block_id(&i.to_be_bytes()[..]) 34 | .with_content_md5(&digest[..]) 35 | .finalize() 36 | .await?; 37 | 38 | println!("put_block_response == {:#?}", put_block_response); 39 | } 40 | 41 | let mut block_list = BlockList::default(); 42 | for id in block_ids.iter() { 43 | block_list.blocks.push(BlobBlockType::Uncommitted(&id[..])); 44 | } 45 | 46 | Ok(()) 47 | } 48 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/examples/blob_05_default_credential.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate log; 3 | 4 | use azure_sdk_auth_aad::{DefaultCredential, TokenCredential}; 5 | use azure_sdk_core::prelude::*; 6 | use azure_sdk_storage_blob::prelude::*; 7 | use azure_sdk_storage_core::prelude::*; 8 | use std::error::Error; 9 | 10 | #[tokio::main] 11 | async fn main() -> Result<(), Box> { 12 | env_logger::init(); 13 | // First we retrieve the account name, container and blob name from command line args 14 | 15 | let account = std::env::args() 16 | .nth(1) 17 | .expect("please specify the account name as first command line parameter"); 18 | let container = std::env::args() 19 | .nth(2) 20 | .expect("please specify the container name as second command line parameter"); 21 | let blob = std::env::args() 22 | .nth(3) 23 | .expect("please specify the blob name as third command line parameter"); 24 | 25 | let bearer_token = DefaultCredential::default() 26 | .get_token("https://storage.azure.com/") 27 | .await?; 28 | 29 | let client = client::with_bearer_token(account, bearer_token.token.secret()); 30 | 31 | trace!("Requesting blob"); 32 | 33 | let response = client 34 | .get_blob() 35 | .with_container_name(&container) 36 | .with_blob_name(&blob) 37 | .finalize() 38 | .await?; 39 | 40 | let s_content = String::from_utf8(response.data)?; 41 | println!("blob == {:?}", blob); 42 | println!("s_content == {}", s_content); 43 | 44 | Ok(()) 45 | } 46 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/examples/container_00.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::prelude::*; 2 | use azure_sdk_storage_blob::prelude::*; 3 | use azure_sdk_storage_core::prelude::*; 4 | use std::error::Error; 5 | 6 | #[tokio::main] 7 | async fn main() -> Result<(), Box> { 8 | // First we retrieve the account name and master key from environment variables. 9 | let account = 10 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 11 | let master_key = 12 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 13 | 14 | let container = std::env::args() 15 | .nth(1) 16 | .expect("please specify container name as command line parameter"); 17 | 18 | let client = client::with_access_key(&account, &master_key); 19 | 20 | let iv = client 21 | .list_containers() 22 | .with_max_results(2) 23 | .finalize() 24 | .await?; 25 | println!( 26 | "List containers returned {} containers.", 27 | iv.incomplete_vector.len() 28 | ); 29 | for cont in iv.incomplete_vector.iter() { 30 | println!("\t{}", cont.name); 31 | } 32 | 33 | let iv = client 34 | .list_blobs() 35 | .with_container_name(&container) 36 | .with_max_results(2) 37 | .finalize() 38 | .await?; 39 | 40 | println!("List blob returned {} blobs.", iv.incomplete_vector.len()); 41 | for cont in iv.incomplete_vector.iter() { 42 | println!( 43 | "\t{}\t{} MB", 44 | cont.name, 45 | cont.content_length / (1024 * 1024) 46 | ); 47 | } 48 | 49 | Ok(()) 50 | } 51 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/examples/copy_blob_from_url.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::prelude::*; 2 | use azure_sdk_storage_blob::Blob; 3 | use azure_sdk_storage_core::prelude::*; 4 | use std::error::Error; 5 | 6 | #[tokio::main] 7 | async fn main() -> Result<(), Box> { 8 | // First we retrieve the account name and master key from environment variables. 9 | let account = 10 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 11 | let master_key = 12 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 13 | 14 | let source_container = std::env::args() 15 | .nth(1) 16 | .expect("please specify source container name as first command line parameter"); 17 | let source_blob = std::env::args() 18 | .nth(2) 19 | .expect("please specify source blob name as second command line parameter"); 20 | let destination_container = std::env::args() 21 | .nth(3) 22 | .expect("please specify destination container name as third command line parameter"); 23 | let destination_blob = std::env::args() 24 | .nth(4) 25 | .expect("please specify destination blob name as fourth command line parameter"); 26 | 27 | let client = client::with_access_key(&account, &master_key); 28 | 29 | let source_url = format!("{}/{}/{}", client.blob_uri(), source_container, source_blob); 30 | 31 | let response = client 32 | .copy_blob_from_url() 33 | .with_container_name(&destination_container) 34 | .with_blob_name(&destination_blob) 35 | .with_source_url(&source_url as &str) 36 | .with_is_synchronous(true) 37 | .finalize() 38 | .await?; 39 | 40 | println!("response == {:?}", response); 41 | 42 | Ok(()) 43 | } 44 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/examples/count_blobs.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::prelude::*; 2 | use azure_sdk_storage_blob::prelude::*; 3 | use azure_sdk_storage_core::prelude::*; 4 | use futures::stream::StreamExt; 5 | use std::error::Error; 6 | 7 | #[tokio::main] 8 | async fn main() -> Result<(), Box> { 9 | let account = 10 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 11 | let master_key = 12 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 13 | 14 | let container = std::env::args() 15 | .nth(1) 16 | .expect("please specify container name as command line parameter"); 17 | 18 | let client = client::with_access_key(&account, &master_key); 19 | 20 | let mut count: u32 = 0; 21 | let mut list_blobs = Box::pin(client.list_blobs().with_container_name(&container).stream()); 22 | while let Some(_blob) = list_blobs.next().await { 23 | count += 1; 24 | } 25 | 26 | println!("blob count {}", count); 27 | 28 | Ok(()) 29 | } 30 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/examples/emulator_00.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::prelude::*; 2 | use azure_sdk_storage_blob::prelude::*; 3 | use azure_sdk_storage_core::prelude::*; 4 | use std::error::Error; 5 | use url::Url; 6 | 7 | #[tokio::main] 8 | async fn main() -> Result<(), Box> { 9 | env_logger::init(); 10 | 11 | // this is how you use the emulator. 12 | let blob_storage_url = "http://127.0.0.1:10000"; 13 | let table_storage_url = "http://127.0.0.1:10002"; 14 | let client = client::with_emulator( 15 | &Url::parse(blob_storage_url)?, 16 | &Url::parse(table_storage_url)?, 17 | ); 18 | 19 | // create container 20 | let res = client 21 | .create_container() 22 | .with_container_name("emulcont") 23 | .with_public_access(PublicAccess::None) 24 | .finalize() 25 | .await?; 26 | println!("{:?}", res); 27 | 28 | let res = client 29 | .list_blobs() 30 | .with_container_name("emulcont") 31 | .with_include_metadata() 32 | .finalize() 33 | .await?; 34 | println!("{:?}", res); 35 | 36 | Ok(()) 37 | } 38 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/examples/shared_access_signature.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::prelude::*; 2 | use azure_sdk_storage_blob::prelude::*; 3 | use azure_sdk_storage_core::prelude::*; 4 | use chrono::{Duration, Utc}; 5 | use std::error::Error; 6 | 7 | fn main() { 8 | env_logger::init(); 9 | code().unwrap(); 10 | } 11 | 12 | fn code() -> Result<(), Box> { 13 | // First we retrieve the account name and master key from environment variables. 14 | let account = 15 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 16 | let master_key = 17 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 18 | 19 | let container_name = std::env::args() 20 | .nth(1) 21 | .expect("please specify container name as command line parameter"); 22 | let blob_name = std::env::args() 23 | .nth(2) 24 | .expect("please specify blob name as command line parameter"); 25 | 26 | let client = client::with_access_key(&account, &master_key); 27 | 28 | let now = Utc::now(); 29 | let later = now + Duration::hours(1); 30 | let sas = client 31 | .shared_access_signature() 32 | .with_resource(SasResource::Blob) 33 | .with_resource_type(SasResourceType::Object) 34 | .with_start(now) 35 | .with_expiry(later) 36 | .with_permissions(SasPermissions::Read) 37 | .with_protocol(SasProtocol::HttpHttps) 38 | .finalize(); 39 | println!("token: '{}'", sas.token()); 40 | 41 | let url = client 42 | .generate_signed_blob_url() 43 | .with_container_name(&container_name) 44 | .with_blob_name(&blob_name) 45 | .with_shared_access_signature(&sas) 46 | .finalize(); 47 | println!("url: '{}'", url); 48 | 49 | Ok(()) 50 | } 51 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/blob_block_type.rs: -------------------------------------------------------------------------------- 1 | use std::borrow::Borrow; 2 | 3 | #[derive(Debug, Clone, PartialEq)] 4 | pub enum BlobBlockType 5 | where 6 | T: Borrow<[u8]>, 7 | { 8 | Committed(T), 9 | Uncommitted(T), 10 | Latest(T), 11 | } 12 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/blob_block_with_size.rs: -------------------------------------------------------------------------------- 1 | use crate::blob::BlobBlockType; 2 | use std::borrow::Borrow; 3 | 4 | #[derive(Debug, Clone, PartialEq)] 5 | pub struct BlobBlockWithSize 6 | where 7 | T: Borrow<[u8]>, 8 | { 9 | pub block_list_type: BlobBlockType, 10 | pub size_in_bytes: u64, 11 | } 12 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/block_list_type.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug, Clone, Copy, PartialEq)] 2 | pub enum BlockListType { 3 | Committed, 4 | Uncommitted, 5 | All, 6 | } 7 | 8 | impl BlockListType { 9 | pub fn to_str(&self) -> &str { 10 | match self { 11 | BlockListType::All => "all", 12 | BlockListType::Committed => "committed", 13 | BlockListType::Uncommitted => "uncommitted", 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/lease_blob_options.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::lease::LeaseId; 2 | 3 | #[derive(Debug, Clone, PartialEq)] 4 | pub struct LeaseBlobOptions { 5 | pub lease_id: Option, 6 | pub timeout: Option, 7 | pub lease_break_period: Option, 8 | pub lease_duration: Option, 9 | pub proposed_lease_id: Option, 10 | pub request_id: Option, 11 | } 12 | 13 | pub const LEASE_BLOB_OPTIONS_DEFAULT: LeaseBlobOptions = LeaseBlobOptions { 14 | lease_id: None, 15 | timeout: None, 16 | lease_break_period: None, 17 | lease_duration: None, 18 | proposed_lease_id: None, 19 | request_id: None, 20 | }; 21 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/requests/break_blob_lease_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BreakBlobLeaseBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::blob::generate_blob_uri", 6 | "crate::blob::responses::BreakBlobLeaseResponse", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "azure_sdk_core::headers::LEASE_ACTION", 9 | "azure_sdk_core::{No, ToAssign, Yes}", 10 | "hyper::{Method, StatusCode}", 11 | "azure_sdk_core::prelude::*", 12 | "azure_sdk_storage_core::prelude::*", 13 | "std::marker::PhantomData" 14 | ], 15 | "inline": true, 16 | "extra_types": [ "'a", "C" ], 17 | "extra_wheres": [ "C: Client" ], 18 | "constructor_fields": [ 19 | { 20 | "name": "client", 21 | "field_type": "&'a C", 22 | "trait_get": "ClientRequired<'a, C>" 23 | } 24 | ], 25 | "fields": [ 26 | { 27 | "name": "container_name", 28 | "field_type": "&'a str", 29 | "builder_type": "ContainerNameSet", 30 | "optional": false, 31 | "trait_get": "ContainerNameRequired<'a>", 32 | "trait_set": "ContainerNameSupport<'a>" 33 | }, 34 | { 35 | "name": "blob_name", 36 | "field_type": "&'a str", 37 | "builder_type": "BlobNameSet", 38 | "optional": false, 39 | "trait_get": "BlobNameRequired<'a>", 40 | "trait_set": "BlobNameSupport<'a>" 41 | }, 42 | { 43 | "name": "lease_break_period", 44 | "field_type": "u8", 45 | "builder_type": "BreakPeriodSet", 46 | "optional": false, 47 | "initializer": "0", 48 | "trait_get": "LeaseBreakPeriodRequired", 49 | "trait_set": "LeaseBreakPeriodSupport" 50 | }, 51 | { 52 | "name": "timeout", 53 | "field_type": "u64", 54 | "optional": true, 55 | "trait_get": "TimeoutOption", 56 | "trait_set": "TimeoutSupport" 57 | }, 58 | { 59 | "name": "client_request_id", 60 | "field_type": "&'a str", 61 | "optional": true, 62 | "trait_get": "ClientRequestIdOption<'a>", 63 | "trait_set": "ClientRequestIdSupport<'a>" 64 | } 65 | ] 66 | } 67 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/requests/mod.rs: -------------------------------------------------------------------------------- 1 | mod acquire_blob_lease_builder; 2 | mod blob_stream_builder; 3 | mod break_blob_lease_builder; 4 | mod change_blob_lease_builder; 5 | mod clear_page_builder; 6 | mod copy_blob_from_url_builder; 7 | mod delete_blob_builder; 8 | mod delete_blob_snapshot_builder; 9 | mod get_blob_builder; 10 | mod get_block_list_builder; 11 | mod put_append_blob_builder; 12 | mod put_append_block_builder; 13 | mod put_block_blob_builder; 14 | mod put_block_builder; 15 | mod put_block_list_builder; 16 | mod put_page_blob_builder; 17 | mod release_blob_lease_builder; 18 | mod renew_blob_lease_builder; 19 | mod signed_url_builder; 20 | mod update_page_builder; 21 | pub use self::acquire_blob_lease_builder::AcquireBlobLeaseBuilder; 22 | pub use self::blob_stream_builder::BlobStreamBuilder; 23 | pub use self::break_blob_lease_builder::BreakBlobLeaseBuilder; 24 | pub use self::change_blob_lease_builder::ChangeBlobLeaseBuilder; 25 | pub use self::clear_page_builder::ClearPageBuilder; 26 | pub use self::delete_blob_builder::DeleteBlobBuilder; 27 | pub use self::delete_blob_snapshot_builder::DeleteBlobSnapshotBuilder; 28 | pub use self::get_blob_builder::GetBlobBuilder; 29 | pub use self::get_block_list_builder::GetBlockListBuilder; 30 | pub use self::put_append_blob_builder::PutAppendBlobBuilder; 31 | pub use self::put_append_block_builder::PutAppendBlockBuilder; 32 | pub use self::put_block_blob_builder::PutBlockBlobBuilder; 33 | pub use self::put_block_builder::PutBlockBuilder; 34 | pub use self::put_block_list_builder::PutBlockListBuilder; 35 | pub use self::put_page_blob_builder::PutPageBlobBuilder; 36 | pub use self::release_blob_lease_builder::ReleaseBlobLeaseBuilder; 37 | pub use self::renew_blob_lease_builder::RenewBlobLeaseBuilder; 38 | pub use self::signed_url_builder::SignedUrlBuilder; 39 | pub use self::update_page_builder::UpdatePageBuilder; 40 | pub use copy_blob_from_url_builder::CopyBlobFromUrlBuilder; 41 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/requests/release_blob_lease_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ReleaseBlobLeaseBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::blob::generate_blob_uri", 6 | "crate::blob::responses::ReleaseBlobLeaseResponse", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "azure_sdk_core::headers::LEASE_ACTION", 9 | "azure_sdk_core::lease::LeaseId", 10 | "azure_sdk_core::prelude::*", 11 | "azure_sdk_core::{No, ToAssign, Yes}", 12 | "azure_sdk_storage_core::prelude::*", 13 | "hyper::{Method, StatusCode}", 14 | "std::marker::PhantomData" 15 | ], 16 | "inline": true, 17 | "extra_types": [ "'a", "C" ], 18 | "extra_wheres": [ "C: Client" ], 19 | "constructor_fields": [ 20 | { 21 | "name": "client", 22 | "field_type": "&'a C", 23 | "trait_get": "ClientRequired<'a, C>" 24 | } 25 | ], 26 | "fields": [ 27 | { 28 | "name": "container_name", 29 | "field_type": "&'a str", 30 | "builder_type": "ContainerNameSet", 31 | "optional": false, 32 | "trait_get": "ContainerNameRequired<'a>", 33 | "trait_set": "ContainerNameSupport<'a>" 34 | }, 35 | { 36 | "name": "blob_name", 37 | "field_type": "&'a str", 38 | "builder_type": "BlobNameSet", 39 | "optional": false, 40 | "trait_get": "BlobNameRequired<'a>", 41 | "trait_set": "BlobNameSupport<'a>" 42 | }, 43 | { 44 | "name": "lease_id", 45 | "field_type": "&'a LeaseId", 46 | "builder_type": "LeaseIdSet", 47 | "optional": false, 48 | "trait_get": "LeaseIdRequired<'a>", 49 | "trait_set": "LeaseIdSupport<'a>" 50 | }, 51 | { 52 | "name": "timeout", 53 | "field_type": "u64", 54 | "optional": true, 55 | "trait_get": "TimeoutOption", 56 | "trait_set": "TimeoutSupport" 57 | }, 58 | { 59 | "name": "client_request_id", 60 | "field_type": "&'a str", 61 | "optional": true, 62 | "trait_get": "ClientRequestIdOption<'a>", 63 | "trait_set": "ClientRequestIdSupport<'a>" 64 | } 65 | ] 66 | } 67 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/requests/renew_blob_lease_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RenewBlobLeaseBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::blob::generate_blob_uri", 6 | "crate::blob::responses::RenewBlobLeaseResponse", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "azure_sdk_core::headers::LEASE_ACTION", 9 | "azure_sdk_core::lease::LeaseId", 10 | "azure_sdk_core::prelude::*", 11 | "azure_sdk_core::{No, ToAssign, Yes}", 12 | "azure_sdk_storage_core::prelude::*", 13 | "hyper::{Method, StatusCode}", 14 | "std::marker::PhantomData" 15 | ], 16 | "inline": true, 17 | "extra_types": [ "'a", "C" ], 18 | "extra_wheres": [ "C: Client" ], 19 | "constructor_fields": [ 20 | { 21 | "name": "client", 22 | "field_type": "&'a C", 23 | "trait_get": "ClientRequired<'a, C>" 24 | } 25 | ], 26 | "fields": [ 27 | { 28 | "name": "container_name", 29 | "field_type": "&'a str", 30 | "builder_type": "ContainerNameSet", 31 | "optional": false, 32 | "trait_get": "ContainerNameRequired<'a>", 33 | "trait_set": "ContainerNameSupport<'a>" 34 | }, 35 | { 36 | "name": "blob_name", 37 | "field_type": "&'a str", 38 | "builder_type": "BlobNameSet", 39 | "optional": false, 40 | "trait_get": "BlobNameRequired<'a>", 41 | "trait_set": "BlobNameSupport<'a>" 42 | }, 43 | { 44 | "name": "lease_id", 45 | "field_type": "&'a LeaseId", 46 | "builder_type": "LeaseIdSet", 47 | "optional": false, 48 | "trait_get": "LeaseIdRequired<'a>", 49 | "trait_set": "LeaseIdSupport<'a>" 50 | }, 51 | { 52 | "name": "timeout", 53 | "field_type": "u64", 54 | "optional": true, 55 | "trait_get": "TimeoutOption", 56 | "trait_set": "TimeoutSupport" 57 | }, 58 | { 59 | "name": "client_request_id", 60 | "field_type": "&'a str", 61 | "optional": true, 62 | "trait_get": "ClientRequestIdOption<'a>", 63 | "trait_set": "ClientRequestIdSupport<'a>" 64 | } 65 | ] 66 | } 67 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/acquire_blob_lease_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::lease::LeaseId; 2 | use azure_sdk_core::RequestId; 3 | use chrono::{DateTime, Utc}; 4 | 5 | response_from_headers!(AcquireBlobLeaseResponse, 6 | 7 | etag_from_headers -> etag: String, 8 | last_modified_from_headers -> last_modified: DateTime, 9 | lease_id_from_headers -> lease_id: LeaseId, 10 | request_id_from_headers -> request_id: RequestId, 11 | date_from_headers -> date: DateTime 12 | ); 13 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/break_blob_lease_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::RequestId; 2 | use chrono::{DateTime, Utc}; 3 | 4 | response_from_headers!(BreakBlobLeaseResponse , 5 | 6 | etag_from_headers -> etag: String, 7 | last_modified_from_headers -> last_modified: DateTime, 8 | lease_time_from_headers -> lease_time: u8, 9 | request_id_from_headers -> request_id: RequestId, 10 | date_from_headers -> date: DateTime 11 | ); 12 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/change_blob_lease_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::lease::LeaseId; 2 | use azure_sdk_core::RequestId; 3 | use chrono::{DateTime, Utc}; 4 | 5 | response_from_headers!(ChangeBlobLeaseResponse , 6 | 7 | etag_from_headers -> etag: String, 8 | last_modified_from_headers -> last_modified: DateTime, 9 | lease_id_from_headers -> lease_id: LeaseId, 10 | request_id_from_headers -> request_id: RequestId, 11 | date_from_headers -> date: DateTime 12 | ); 13 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/clear_page_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::RequestId; 2 | use chrono::{DateTime, Utc}; 3 | 4 | response_from_headers!(ClearPageResponse, 5 | 6 | etag_from_headers -> etag: String, 7 | last_modified_from_headers -> last_modified: DateTime, 8 | sequence_number_from_headers -> sequence_number: u64, 9 | request_id_from_headers -> request_id: RequestId, 10 | date_from_headers -> date: DateTime 11 | ); 12 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/copy_blob_from_url_response.rs: -------------------------------------------------------------------------------- 1 | use crate::blob::{copy_status_from_headers, CopyStatus}; 2 | use azure_sdk_core::errors::AzureError; 3 | use azure_sdk_core::{ 4 | content_md5_from_headers_optional, date_from_headers, etag_from_headers, 5 | last_modified_from_headers, request_id_from_headers, server_from_headers, version_from_headers, 6 | RequestId, 7 | }; 8 | use azure_sdk_storage_core::copy_id_from_headers; 9 | use azure_sdk_storage_core::CopyId; 10 | use chrono::{DateTime, Utc}; 11 | use http::HeaderMap; 12 | use std::convert::TryFrom; 13 | 14 | #[derive(Debug, Clone, PartialEq)] 15 | pub struct CopyBlobFromUrlResponse { 16 | pub content_md5: Option<[u8; 16]>, 17 | pub last_modified: DateTime, 18 | pub etag: String, 19 | pub server: String, 20 | pub request_id: RequestId, 21 | pub version: String, 22 | pub copy_id: CopyId, 23 | pub copy_status: CopyStatus, 24 | pub date: DateTime, 25 | } 26 | 27 | impl TryFrom<&HeaderMap> for CopyBlobFromUrlResponse { 28 | type Error = AzureError; 29 | fn try_from(headers: &HeaderMap) -> Result { 30 | debug!("headers == {:#?}", headers); 31 | Ok(Self { 32 | content_md5: content_md5_from_headers_optional(headers)?, 33 | last_modified: last_modified_from_headers(headers)?, 34 | etag: etag_from_headers(headers)?, 35 | server: server_from_headers(headers)?.to_owned(), 36 | request_id: request_id_from_headers(headers)?, 37 | version: version_from_headers(headers)?.to_owned(), 38 | copy_id: copy_id_from_headers(headers)?, 39 | copy_status: copy_status_from_headers(headers)?, 40 | date: date_from_headers(headers)?, 41 | }) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/delete_blob_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::RequestId; 2 | use chrono::{DateTime, Utc}; 3 | 4 | response_from_headers!(DeleteBlobResponse , 5 | 6 | delete_type_permanent_from_headers -> delete_type_permanent: bool, 7 | request_id_from_headers -> request_id: RequestId, 8 | date_from_headers -> date: DateTime 9 | ); 10 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/get_blob_response.rs: -------------------------------------------------------------------------------- 1 | use crate::blob::Blob; 2 | use azure_sdk_core::errors::AzureError; 3 | use azure_sdk_core::{date_from_headers, request_id_from_headers, RequestId}; 4 | use chrono::{DateTime, Utc}; 5 | use http::HeaderMap; 6 | 7 | #[derive(Debug, Clone)] 8 | pub struct GetBlobResponse { 9 | pub blob: Blob, 10 | pub request_id: RequestId, 11 | pub data: Vec, 12 | pub date: DateTime, 13 | } 14 | 15 | impl GetBlobResponse { 16 | pub(crate) fn from_response( 17 | headers: &HeaderMap, 18 | blob: Blob, 19 | body: &[u8], 20 | ) -> Result { 21 | debug!("headers == {:#?}", headers); 22 | 23 | let request_id = request_id_from_headers(headers)?; 24 | let date = date_from_headers(headers)?; 25 | 26 | Ok(GetBlobResponse { 27 | blob, 28 | request_id, 29 | data: body.to_vec(), 30 | date, 31 | }) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/get_block_list_response.rs: -------------------------------------------------------------------------------- 1 | use crate::blob::BlockWithSizeList; 2 | use azure_sdk_core::errors::AzureError; 3 | use azure_sdk_core::{ 4 | date_from_headers, etag_from_headers_optional, last_modified_from_headers_optional, 5 | request_id_from_headers, RequestId, 6 | }; 7 | use chrono::{DateTime, Utc}; 8 | use http::HeaderMap; 9 | use std::str::from_utf8; 10 | 11 | #[derive(Debug, Clone, PartialEq)] 12 | pub struct GetBlockListResponse { 13 | pub etag: Option, 14 | pub last_modified: Option>, 15 | pub request_id: RequestId, 16 | pub date: DateTime, 17 | pub block_with_size_list: BlockWithSizeList>, 18 | } 19 | 20 | impl GetBlockListResponse { 21 | pub(crate) fn from_response( 22 | headers: &HeaderMap, 23 | body: &[u8], 24 | ) -> Result { 25 | let etag = etag_from_headers_optional(headers)?; 26 | let last_modified = last_modified_from_headers_optional(headers)?; 27 | let request_id = request_id_from_headers(headers)?; 28 | let date = date_from_headers(headers)?; 29 | 30 | let body = from_utf8(body)?; 31 | let block_with_size_list = BlockWithSizeList::try_from(&body[3..] as &str)?; 32 | 33 | Ok(GetBlockListResponse { 34 | etag, 35 | last_modified, 36 | request_id, 37 | date, 38 | block_with_size_list, 39 | }) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/list_blobs_response.rs: -------------------------------------------------------------------------------- 1 | use crate::blob::{incomplete_vector_from_response, Blob}; 2 | use azure_sdk_core::errors::AzureError; 3 | use azure_sdk_core::incompletevector::IncompleteVector; 4 | use azure_sdk_core::{date_from_headers, request_id_from_headers, RequestId}; 5 | use chrono::{DateTime, Utc}; 6 | use http::HeaderMap; 7 | 8 | #[derive(Debug, Clone, PartialEq)] 9 | pub struct ListBlobsResponse { 10 | pub incomplete_vector: IncompleteVector, 11 | pub request_id: RequestId, 12 | pub date: DateTime, 13 | } 14 | 15 | impl ListBlobsResponse { 16 | pub(crate) fn from_response( 17 | container_name: &str, 18 | headers: &HeaderMap, 19 | body: &str, 20 | ) -> Result { 21 | let incomplete_vector = incomplete_vector_from_response(body, container_name)?; 22 | let request_id = request_id_from_headers(headers)?; 23 | let date = date_from_headers(headers)?; 24 | 25 | Ok(ListBlobsResponse { 26 | incomplete_vector, 27 | request_id, 28 | date, 29 | }) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/mod.rs: -------------------------------------------------------------------------------- 1 | mod delete_blob_response; 2 | pub use self::delete_blob_response::DeleteBlobResponse; 3 | mod release_blob_lease_response; 4 | pub use self::release_blob_lease_response::ReleaseBlobLeaseResponse; 5 | mod change_blob_lease_response; 6 | pub use self::change_blob_lease_response::ChangeBlobLeaseResponse; 7 | mod renew_blob_lease_response; 8 | pub use self::renew_blob_lease_response::RenewBlobLeaseResponse; 9 | mod acquire_blob_lease_response; 10 | pub use self::acquire_blob_lease_response::AcquireBlobLeaseResponse; 11 | mod get_block_list_response; 12 | pub use self::get_block_list_response::GetBlockListResponse; 13 | mod put_block_list_response; 14 | pub use self::put_block_list_response::PutBlockListResponse; 15 | mod put_block_response; 16 | pub use self::put_block_response::PutBlockResponse; 17 | mod clear_page_response; 18 | pub use self::clear_page_response::ClearPageResponse; 19 | mod put_block_blob_response; 20 | pub use self::put_block_blob_response::PutBlockBlobResponse; 21 | mod list_blobs_response; 22 | pub use self::list_blobs_response::ListBlobsResponse; 23 | mod get_blob_response; 24 | pub use self::get_blob_response::GetBlobResponse; 25 | mod put_blob_response; 26 | pub use self::put_blob_response::PutBlobResponse; 27 | mod update_page_response; 28 | pub use self::update_page_response::UpdatePageResponse; 29 | mod break_blob_lease_response; 30 | pub use self::break_blob_lease_response::BreakBlobLeaseResponse; 31 | mod copy_blob_from_url_response; 32 | pub use copy_blob_from_url_response::CopyBlobFromUrlResponse; 33 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/put_blob_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::errors::AzureError; 2 | use azure_sdk_core::{ 3 | date_from_headers, etag_from_headers, last_modified_from_headers, request_id_from_headers, 4 | request_server_encrypted_from_headers, RequestId, 5 | }; 6 | use chrono::{DateTime, Utc}; 7 | use http::HeaderMap; 8 | 9 | #[derive(Debug, Clone)] 10 | pub struct PutBlobResponse { 11 | pub etag: String, 12 | pub last_modified: DateTime, 13 | pub request_id: RequestId, 14 | pub date: DateTime, 15 | pub request_server_encrypted: bool, 16 | } 17 | 18 | impl PutBlobResponse { 19 | pub fn from_headers(headers: &HeaderMap) -> Result { 20 | debug!("{:#?}", headers); 21 | 22 | let etag = etag_from_headers(headers)?; 23 | let last_modified = last_modified_from_headers(headers)?; 24 | let request_id = request_id_from_headers(headers)?; 25 | let date = date_from_headers(headers)?; 26 | let request_server_encrypted = request_server_encrypted_from_headers(headers)?; 27 | 28 | Ok(PutBlobResponse { 29 | etag, 30 | last_modified, 31 | request_id, 32 | date, 33 | request_server_encrypted, 34 | }) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/put_block_blob_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::errors::AzureError; 2 | use azure_sdk_core::{ 3 | consistency_from_headers, date_from_headers, etag_from_headers, last_modified_from_headers, 4 | request_id_from_headers, request_server_encrypted_from_headers, Consistency, RequestId, 5 | }; 6 | use chrono::{DateTime, Utc}; 7 | use http::HeaderMap; 8 | 9 | #[derive(Debug, Clone)] 10 | pub struct PutBlockBlobResponse { 11 | pub etag: String, 12 | pub last_modified: DateTime, 13 | pub consistency: Consistency, 14 | pub request_id: RequestId, 15 | pub date: DateTime, 16 | pub request_server_encrypted: bool, 17 | } 18 | 19 | impl PutBlockBlobResponse { 20 | pub fn from_headers(headers: &HeaderMap) -> Result { 21 | debug!("headers == {:#?}", headers); 22 | 23 | let etag = etag_from_headers(headers)?; 24 | let last_modified = last_modified_from_headers(headers)?; 25 | let consistency = consistency_from_headers(headers)?; 26 | let request_id = request_id_from_headers(headers)?; 27 | let date = date_from_headers(headers)?; 28 | let request_server_encrypted = request_server_encrypted_from_headers(headers)?; 29 | 30 | Ok(PutBlockBlobResponse { 31 | etag, 32 | last_modified, 33 | consistency, 34 | request_id, 35 | date, 36 | request_server_encrypted, 37 | }) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/put_block_list_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::errors::AzureError; 2 | use azure_sdk_core::{ 3 | content_md5_from_headers, date_from_headers, etag_from_headers, last_modified_from_headers, 4 | request_id_from_headers, request_server_encrypted_from_headers, RequestId, 5 | }; 6 | use chrono::{DateTime, Utc}; 7 | use http::HeaderMap; 8 | 9 | #[derive(Debug, Clone, PartialEq)] 10 | pub struct PutBlockListResponse { 11 | pub etag: String, 12 | pub last_modified: DateTime, 13 | pub content_md5: [u8; 16], 14 | pub request_id: RequestId, 15 | pub date: DateTime, 16 | pub request_server_encrypted: bool, 17 | } 18 | 19 | impl PutBlockListResponse { 20 | pub(crate) fn from_headers(headers: &HeaderMap) -> Result { 21 | debug!("headers == {:#?}", headers); 22 | 23 | let etag = etag_from_headers(headers)?; 24 | let last_modified = last_modified_from_headers(headers)?; 25 | let content_md5 = content_md5_from_headers(headers)?; 26 | let request_id = request_id_from_headers(headers)?; 27 | let date = date_from_headers(headers)?; 28 | let request_server_encrypted = request_server_encrypted_from_headers(headers)?; 29 | 30 | Ok(PutBlockListResponse { 31 | etag, 32 | last_modified, 33 | content_md5, 34 | request_id, 35 | date, 36 | request_server_encrypted, 37 | }) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/put_block_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::errors::AzureError; 2 | use azure_sdk_core::{ 3 | consistency_from_headers, date_from_headers, request_id_from_headers, 4 | request_server_encrypted_from_headers, Consistency, RequestId, 5 | }; 6 | use chrono::{DateTime, Utc}; 7 | use http::HeaderMap; 8 | 9 | #[derive(Debug, Clone, PartialEq)] 10 | pub struct PutBlockResponse { 11 | pub consistency: Consistency, 12 | pub request_id: RequestId, 13 | pub date: DateTime, 14 | pub request_server_encrypted: bool, 15 | } 16 | 17 | impl PutBlockResponse { 18 | pub(crate) fn from_headers(headers: &HeaderMap) -> Result { 19 | debug!("{:#?}", headers); 20 | 21 | let consistency = consistency_from_headers(headers)?; 22 | let request_id = request_id_from_headers(headers)?; 23 | let date = date_from_headers(headers)?; 24 | let request_server_encrypted = request_server_encrypted_from_headers(headers)?; 25 | 26 | Ok(PutBlockResponse { 27 | consistency, 28 | request_id, 29 | date, 30 | request_server_encrypted, 31 | }) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/release_blob_lease_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::RequestId; 2 | use chrono::{DateTime, Utc}; 3 | 4 | response_from_headers!(ReleaseBlobLeaseResponse , 5 | 6 | etag_from_headers -> etag: String, 7 | last_modified_from_headers -> last_modified: DateTime, 8 | request_id_from_headers -> request_id: RequestId, 9 | date_from_headers -> date: DateTime 10 | ); 11 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/renew_blob_lease_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::lease::LeaseId; 2 | use azure_sdk_core::RequestId; 3 | use chrono::{DateTime, Utc}; 4 | 5 | response_from_headers!(RenewBlobLeaseResponse, 6 | 7 | etag_from_headers -> etag: String, 8 | last_modified_from_headers -> last_modified: DateTime, 9 | lease_id_from_headers -> lease_id: LeaseId, 10 | request_id_from_headers -> request_id: RequestId, 11 | date_from_headers -> date: DateTime 12 | ); 13 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/blob/responses/update_page_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::errors::AzureError; 2 | use azure_sdk_core::{ 3 | content_md5_from_headers, date_from_headers, etag_from_headers, last_modified_from_headers, 4 | request_id_from_headers, request_server_encrypted_from_headers, sequence_number_from_headers, 5 | RequestId, 6 | }; 7 | use chrono::{DateTime, Utc}; 8 | use http::HeaderMap; 9 | 10 | #[derive(Debug, Clone, PartialEq)] 11 | pub struct UpdatePageResponse { 12 | pub etag: String, 13 | pub last_modified: DateTime, 14 | pub content_md5: [u8; 16], 15 | pub sequence_number: u64, 16 | pub request_id: RequestId, 17 | pub date: DateTime, 18 | pub request_server_encrypted: bool, 19 | } 20 | 21 | impl UpdatePageResponse { 22 | pub(crate) fn from_headers(headers: &HeaderMap) -> Result { 23 | let etag = etag_from_headers(headers)?; 24 | let last_modified = last_modified_from_headers(headers)?; 25 | let content_md5 = content_md5_from_headers(headers)?; 26 | let sequence_number = sequence_number_from_headers(headers)?; 27 | let request_id = request_id_from_headers(headers)?; 28 | let date = date_from_headers(headers)?; 29 | let request_server_encrypted = request_server_encrypted_from_headers(headers)?; 30 | 31 | Ok(UpdatePageResponse { 32 | etag, 33 | last_modified, 34 | content_md5, 35 | sequence_number, 36 | request_id, 37 | date, 38 | request_server_encrypted, 39 | }) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/requests/break_lease_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BreakLeaseBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::container::responses::BreakLeaseResponse", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "azure_sdk_core::headers::LEASE_ACTION", 8 | "azure_sdk_core::lease::LeaseId", 9 | "azure_sdk_core::prelude::*", 10 | "azure_sdk_core::{No, ToAssign, Yes}", 11 | "azure_sdk_storage_core::prelude::*", 12 | "hyper::{Method, StatusCode}", 13 | "std::marker::PhantomData" 14 | ], 15 | "inline": true, 16 | "extra_types": [ "'a", "C" ], 17 | "extra_wheres": [ "C: Client" ], 18 | "constructor_fields": [ 19 | { 20 | "name": "client", 21 | "field_type": "&'a C", 22 | "trait_get": "ClientRequired<'a, C>" 23 | } 24 | ], 25 | "fields": [ 26 | { 27 | "name": "container_name", 28 | "field_type": "&'a str", 29 | "builder_type": "ContainerNameSet", 30 | "optional": false, 31 | "trait_get": "ContainerNameRequired<'a>", 32 | "trait_set": "ContainerNameSupport<'a>" 33 | }, 34 | { 35 | "name": "client_request_id", 36 | "field_type": "&'a str", 37 | "optional": true, 38 | "trait_get": "ClientRequestIdOption<'a>", 39 | "trait_set": "ClientRequestIdSupport<'a>" 40 | }, 41 | { 42 | "name": "timeout", 43 | "field_type": "u64", 44 | "optional": true, 45 | "trait_get": "TimeoutOption", 46 | "trait_set": "TimeoutSupport" 47 | }, 48 | { 49 | "name": "lease_break_period", 50 | "field_type": "u8", 51 | "optional": true, 52 | "trait_get": "LeaseBreakPeriodOption", 53 | "trait_set": "LeaseBreakPeriodSupport" 54 | }, 55 | { 56 | "name": "lease_id", 57 | "field_type": "&'a LeaseId", 58 | "optional": true, 59 | "trait_get": "LeaseIdOption<'a>", 60 | "trait_set": "LeaseIdSupport<'a>" 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/requests/create_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CreateBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "std::collections::HashMap", 6 | "crate::container::{PublicAccess, PublicAccessRequired, PublicAccessSupport}", 7 | "azure_sdk_core::errors::{check_status_extract_body, AzureError}", 8 | "azure_sdk_core::prelude::*", 9 | "azure_sdk_core::{No, ToAssign, Yes}", 10 | "azure_sdk_storage_core::prelude::*", 11 | "hyper::{Method, StatusCode}", 12 | "std::marker::PhantomData" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "C" ], 16 | "extra_wheres": [ "C: Client" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "client", 20 | "field_type": "&'a C", 21 | "trait_get": "ClientRequired<'a, C>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "container_name", 27 | "field_type": "&'a str", 28 | "builder_type": "ContainerNameSet", 29 | "optional": false, 30 | "trait_get": "ContainerNameRequired<'a>", 31 | "trait_set": "ContainerNameSupport<'a>" 32 | }, 33 | { 34 | "name": "public_access", 35 | "field_type": "PublicAccess", 36 | "builder_type": "PublicAccessSet", 37 | "optional": false, 38 | "initializer": "PublicAccess::None", 39 | "trait_get": "PublicAccessRequired", 40 | "trait_set": "PublicAccessSupport" 41 | }, 42 | { 43 | "name": "metadata", 44 | "field_type": "&'a HashMap<&'a str, &'a str>", 45 | "optional": true, 46 | "trait_get": "MetadataOption<'a>", 47 | "trait_set": "MetadataSupport<'a>" 48 | }, 49 | { 50 | "name": "client_request_id", 51 | "field_type": "&'a str", 52 | "optional": true, 53 | "trait_get": "ClientRequestIdOption<'a>", 54 | "trait_set": "ClientRequestIdSupport<'a>" 55 | }, 56 | { 57 | "name": "timeout", 58 | "field_type": "u64", 59 | "optional": true, 60 | "trait_get": "TimeoutOption", 61 | "trait_set": "TimeoutSupport" 62 | } 63 | ] 64 | } 65 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/requests/delete_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DeleteBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 6 | "azure_sdk_core::lease::LeaseId", 7 | "azure_sdk_core::prelude::*", 8 | "azure_sdk_core::{No, ToAssign, Yes}", 9 | "azure_sdk_storage_core::prelude::*", 10 | "hyper::{Method, StatusCode}", 11 | "std::marker::PhantomData" 12 | ], 13 | "inline": true, 14 | "extra_types": [ "'a", "C" ], 15 | "extra_wheres": [ "C: Client" ], 16 | "constructor_fields": [ 17 | { 18 | "name": "client", 19 | "field_type": "&'a C", 20 | "trait_get": "ClientRequired<'a, C>" 21 | } 22 | ], 23 | "fields": [ 24 | { 25 | "name": "container_name", 26 | "field_type": "&'a str", 27 | "builder_type": "ContainerNameSet", 28 | "optional": false, 29 | "trait_get": "ContainerNameRequired<'a>", 30 | "trait_set": "ContainerNameSupport<'a>" 31 | }, 32 | { 33 | "name": "client_request_id", 34 | "field_type": "&'a str", 35 | "optional": true, 36 | "trait_get": "ClientRequestIdOption<'a>", 37 | "trait_set": "ClientRequestIdSupport<'a>" 38 | }, 39 | { 40 | "name": "timeout", 41 | "field_type": "u64", 42 | "optional": true, 43 | "trait_get": "TimeoutOption", 44 | "trait_set": "TimeoutSupport" 45 | }, 46 | { 47 | "name": "lease_id", 48 | "field_type": "&'a LeaseId", 49 | "optional": true, 50 | "trait_get": "LeaseIdOption<'a>", 51 | "trait_set": "LeaseIdSupport<'a>" 52 | } 53 | ] 54 | } 55 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/requests/get_acl_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GetACLBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::container::responses::GetACLResponse", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "azure_sdk_core::lease::LeaseId", 8 | "azure_sdk_core::prelude::*", 9 | "azure_sdk_core::{No, ToAssign, Yes}", 10 | "azure_sdk_storage_core::prelude::*", 11 | "hyper::{Method, StatusCode}", 12 | "std::marker::PhantomData" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "C" ], 16 | "extra_wheres": [ "C: Client" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "client", 20 | "field_type": "&'a C", 21 | "trait_get": "ClientRequired<'a, C>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "container_name", 27 | "field_type": "&'a str", 28 | "builder_type": "ContainerNameSet", 29 | "optional": false, 30 | "trait_get": "ContainerNameRequired<'a>", 31 | "trait_set": "ContainerNameSupport<'a>" 32 | }, 33 | { 34 | "name": "client_request_id", 35 | "field_type": "&'a str", 36 | "optional": true, 37 | "trait_get": "ClientRequestIdOption<'a>", 38 | "trait_set": "ClientRequestIdSupport<'a>" 39 | }, 40 | { 41 | "name": "timeout", 42 | "field_type": "u64", 43 | "optional": true, 44 | "trait_get": "TimeoutOption", 45 | "trait_set": "TimeoutSupport" 46 | }, 47 | { 48 | "name": "lease_id", 49 | "field_type": "&'a LeaseId", 50 | "optional": true, 51 | "trait_get": "LeaseIdOption<'a>", 52 | "trait_set": "LeaseIdSupport<'a>" 53 | } 54 | ] 55 | } 56 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/requests/get_properties_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GetPropertiesBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::container::responses::GetPropertiesResponse", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "azure_sdk_core::lease::LeaseId", 8 | "azure_sdk_core::prelude::*", 9 | "azure_sdk_core::{No, ToAssign, Yes}", 10 | "azure_sdk_storage_core::prelude::*", 11 | "hyper::{Method, StatusCode}", 12 | "std::marker::PhantomData" 13 | ], 14 | "inline": true, 15 | "extra_types": [ "'a", "C" ], 16 | "extra_wheres": [ "C: Client" ], 17 | "constructor_fields": [ 18 | { 19 | "name": "client", 20 | "field_type": "&'a C", 21 | "trait_get": "ClientRequired<'a, C>" 22 | } 23 | ], 24 | "fields": [ 25 | { 26 | "name": "container_name", 27 | "field_type": "&'a str", 28 | "builder_type": "ContainerNameSet", 29 | "optional": false, 30 | "trait_get": "ContainerNameRequired<'a>", 31 | "trait_set": "ContainerNameSupport<'a>" 32 | }, 33 | { 34 | "name": "client_request_id", 35 | "field_type": "&'a str", 36 | "optional": true, 37 | "trait_get": "ClientRequestIdOption<'a>", 38 | "trait_set": "ClientRequestIdSupport<'a>" 39 | }, 40 | { 41 | "name": "timeout", 42 | "field_type": "u64", 43 | "optional": true, 44 | "trait_get": "TimeoutOption", 45 | "trait_set": "TimeoutSupport" 46 | }, 47 | { 48 | "name": "lease_id", 49 | "field_type": "&'a LeaseId", 50 | "optional": true, 51 | "trait_get": "LeaseIdOption<'a>", 52 | "trait_set": "LeaseIdSupport<'a>" 53 | } 54 | ] 55 | } 56 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/requests/list_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ListBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "azure_sdk_core::request_id_from_headers", 6 | "crate::container::incomplete_vector_from_container_response", 7 | "crate::container::responses::ListContainersResponse", 8 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 9 | "azure_sdk_core::prelude::*", 10 | "azure_sdk_storage_core::prelude::*", 11 | "hyper::{Method, StatusCode}" 12 | ], 13 | "inline": true, 14 | "extra_types": [ "'a", "C" ], 15 | "extra_wheres": [ "C: Client" ], 16 | "constructor_fields": [ 17 | { 18 | "name": "client", 19 | "field_type": "&'a C", 20 | "trait_get": "ClientRequired<'a, C>" 21 | } 22 | ], 23 | "fields": [ 24 | { 25 | "name": "prefix", 26 | "field_type": "&'a str", 27 | "optional": true, 28 | "trait_get": "PrefixOption<'a>", 29 | "trait_set": "PrefixSupport<'a>" 30 | }, 31 | { 32 | "name": "next_marker", 33 | "field_type": "&'a str", 34 | "optional": true, 35 | "trait_get": "NextMarkerOption<'a>", 36 | "trait_set": "NextMarkerSupport<'a>" 37 | }, 38 | { 39 | "name": "include_metadata", 40 | "field_type": "bool", 41 | "optional": true, 42 | "initializer": "false", 43 | "trait_get": "IncludeMetadataOption", 44 | "trait_set": "IncludeMetadataSupport" 45 | }, 46 | { 47 | "name": "max_results", 48 | "field_type": "u32", 49 | "optional": true, 50 | "trait_get": "MaxResultsOption", 51 | "trait_set": "MaxResultsSupport" 52 | }, 53 | { 54 | "name": "client_request_id", 55 | "field_type": "&'a str", 56 | "optional": true, 57 | "trait_get": "ClientRequestIdOption<'a>", 58 | "trait_set": "ClientRequestIdSupport<'a>" 59 | }, 60 | { 61 | "name": "timeout", 62 | "field_type": "u64", 63 | "optional": true, 64 | "trait_get": "TimeoutOption", 65 | "trait_set": "TimeoutSupport" 66 | } 67 | ] 68 | } 69 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/requests/mod.rs: -------------------------------------------------------------------------------- 1 | mod acquire_lease_builder; 2 | mod break_lease_builder; 3 | mod create_builder; 4 | mod delete_builder; 5 | mod get_acl_builder; 6 | mod get_properties_builder; 7 | mod list_blobs_builder; 8 | mod list_builder; 9 | mod release_lease_builder; 10 | mod renew_lease_builder; 11 | mod set_acl_builder; 12 | pub use self::acquire_lease_builder::AcquireLeaseBuilder; 13 | pub use self::break_lease_builder::BreakLeaseBuilder; 14 | pub use self::create_builder::CreateBuilder; 15 | pub use self::delete_builder::DeleteBuilder; 16 | pub use self::get_acl_builder::GetACLBuilder; 17 | pub use self::get_properties_builder::GetPropertiesBuilder; 18 | pub use self::list_blobs_builder::ListBlobBuilder; 19 | pub use self::list_builder::ListBuilder; 20 | pub use self::release_lease_builder::ReleaseLeaseBuilder; 21 | pub use self::renew_lease_builder::RenewLeaseBuilder; 22 | pub use self::set_acl_builder::SetACLBuilder; 23 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/requests/release_lease_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ReleaseLeaseBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::container::responses::ReleaseLeaseResponse", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "azure_sdk_core::lease::LeaseId", 8 | "azure_sdk_core::prelude::*", 9 | "azure_sdk_core::{No, ToAssign, Yes}", 10 | "azure_sdk_core::headers::LEASE_ACTION", 11 | "azure_sdk_storage_core::prelude::*", 12 | "hyper::{Method, StatusCode}", 13 | "std::marker::PhantomData" 14 | ], 15 | "inline": true, 16 | "extra_types": [ "'a", "C" ], 17 | "extra_wheres": [ "C: Client" ], 18 | "constructor_fields": [ 19 | { 20 | "name": "client", 21 | "field_type": "&'a C", 22 | "trait_get": "ClientRequired<'a, C>" 23 | } 24 | ], 25 | "fields": [ 26 | { 27 | "name": "container_name", 28 | "field_type": "&'a str", 29 | "builder_type": "ContainerNameSet", 30 | "optional": false, 31 | "trait_get": "ContainerNameRequired<'a>", 32 | "trait_set": "ContainerNameSupport<'a>" 33 | }, 34 | { 35 | "name": "client_request_id", 36 | "field_type": "&'a str", 37 | "optional": true, 38 | "trait_get": "ClientRequestIdOption<'a>", 39 | "trait_set": "ClientRequestIdSupport<'a>" 40 | }, 41 | { 42 | "name": "timeout", 43 | "field_type": "u64", 44 | "optional": true, 45 | "trait_get": "TimeoutOption", 46 | "trait_set": "TimeoutSupport" 47 | }, 48 | { 49 | "name": "lease_id", 50 | "field_type": "&'a LeaseId", 51 | "builder_type": "LeaseIdSet", 52 | "optional": false, 53 | "trait_get": "LeaseIdRequired<'a>", 54 | "trait_set": "LeaseIdSupport<'a>" 55 | } 56 | ] 57 | } 58 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/requests/renew_lease_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RenewLeaseBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::container::responses::RenewLeaseResponse", 6 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 7 | "azure_sdk_core::lease::LeaseId", 8 | "azure_sdk_core::prelude::*", 9 | "azure_sdk_core::{No, ToAssign, Yes}", 10 | "azure_sdk_core::headers::LEASE_ACTION", 11 | "azure_sdk_storage_core::prelude::*", 12 | "hyper::{Method, StatusCode}", 13 | "std::marker::PhantomData" 14 | ], 15 | "inline": true, 16 | "extra_types": [ "'a", "C" ], 17 | "extra_wheres": [ "C: Client" ], 18 | "constructor_fields": [ 19 | { 20 | "name": "client", 21 | "field_type": "&'a C", 22 | "trait_get": "ClientRequired<'a, C>" 23 | } 24 | ], 25 | "fields": [ 26 | { 27 | "name": "container_name", 28 | "field_type": "&'a str", 29 | "builder_type": "ContainerNameSet", 30 | "optional": false, 31 | "trait_get": "ContainerNameRequired<'a>", 32 | "trait_set": "ContainerNameSupport<'a>" 33 | }, 34 | { 35 | "name": "client_request_id", 36 | "field_type": "&'a str", 37 | "optional": true, 38 | "trait_get": "ClientRequestIdOption<'a>", 39 | "trait_set": "ClientRequestIdSupport<'a>" 40 | }, 41 | { 42 | "name": "timeout", 43 | "field_type": "u64", 44 | "optional": true, 45 | "trait_get": "TimeoutOption", 46 | "trait_set": "TimeoutSupport" 47 | }, 48 | { 49 | "name": "lease_id", 50 | "field_type": "&'a LeaseId", 51 | "builder_type": "LeaseIdSet", 52 | "optional": false, 53 | "trait_get": "LeaseIdRequired<'a>", 54 | "trait_set": "LeaseIdSupport<'a>" 55 | } 56 | ] 57 | } 58 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/responses/acquire_lease_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::lease::LeaseId; 2 | use azure_sdk_core::RequestId; 3 | use chrono::{DateTime, Utc}; 4 | 5 | response_from_headers!(AcquireLeaseResponse , 6 | 7 | etag_from_headers -> etag: String, 8 | last_modified_from_headers -> last_modified: DateTime, 9 | lease_id_from_headers -> lease_id: LeaseId, 10 | request_id_from_headers -> request_id: RequestId, 11 | date_from_headers -> date: DateTime 12 | ); 13 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/responses/break_lease_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::RequestId; 2 | use chrono::{DateTime, Utc}; 3 | 4 | response_from_headers!(BreakLeaseResponse, 5 | 6 | etag_from_headers -> etag: String, 7 | last_modified_from_headers -> last_modified: DateTime, 8 | lease_time_from_headers -> lease_time: u8, 9 | request_id_from_headers -> request_id: RequestId, 10 | date_from_headers -> date: DateTime 11 | ); 12 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/responses/get_properties_response.rs: -------------------------------------------------------------------------------- 1 | use crate::container::Container; 2 | use azure_sdk_core::errors::AzureError; 3 | use azure_sdk_core::headers::REQUEST_ID; 4 | use azure_sdk_core::RequestId; 5 | use chrono::{DateTime, FixedOffset}; 6 | use http::HeaderMap; 7 | use hyper::header; 8 | use uuid::Uuid; 9 | 10 | #[derive(Debug, Clone)] 11 | pub struct GetPropertiesResponse { 12 | pub container: Container, 13 | pub request_id: RequestId, 14 | pub date: DateTime, 15 | } 16 | 17 | impl GetPropertiesResponse { 18 | pub(crate) fn from_response( 19 | container_name: String, 20 | headers: &HeaderMap, 21 | ) -> Result { 22 | let request_id = match headers.get(REQUEST_ID) { 23 | Some(request_id) => Uuid::parse_str(request_id.to_str()?)?, 24 | None => return Err(AzureError::MissingHeaderError(REQUEST_ID.to_owned())), 25 | }; 26 | 27 | let date = match headers.get(header::DATE) { 28 | Some(date) => DateTime::parse_from_rfc2822(date.to_str()?)?, 29 | None => { 30 | static D: header::HeaderName = header::DATE; 31 | return Err(AzureError::MissingHeaderError(D.as_str().to_owned())); 32 | } 33 | }; 34 | 35 | let container = Container::from_response(container_name, headers)?; 36 | 37 | Ok(GetPropertiesResponse { 38 | container, 39 | request_id, 40 | date, 41 | }) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/responses/list_containers_response.rs: -------------------------------------------------------------------------------- 1 | use crate::container::Container; 2 | use azure_sdk_core::incompletevector::IncompleteVector; 3 | use azure_sdk_core::RequestId; 4 | 5 | #[derive(Debug, Clone)] 6 | pub struct ListContainersResponse { 7 | pub incomplete_vector: IncompleteVector, 8 | pub request_id: RequestId, 9 | } 10 | 11 | impl ListContainersResponse { 12 | pub fn is_complete(&self) -> bool { 13 | self.incomplete_vector.is_complete() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/responses/mod.rs: -------------------------------------------------------------------------------- 1 | mod acquire_lease_response; 2 | pub use self::acquire_lease_response::AcquireLeaseResponse; 3 | mod break_lease_response; 4 | pub use self::break_lease_response::BreakLeaseResponse; 5 | mod get_acl_response; 6 | pub use self::get_acl_response::GetACLResponse; 7 | mod get_properties_response; 8 | pub use self::get_properties_response::GetPropertiesResponse; 9 | mod list_containers_response; 10 | pub use self::list_containers_response::ListContainersResponse; 11 | mod release_lease_response; 12 | pub use self::release_lease_response::ReleaseLeaseResponse; 13 | mod renew_lease_response; 14 | pub use self::renew_lease_response::RenewLeaseResponse; 15 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/responses/release_lease_response.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_core::RequestId; 2 | use chrono::{DateTime, Utc}; 3 | 4 | response_from_headers!(ReleaseLeaseResponse , 5 | 6 | etag_from_headers -> etag: String, 7 | last_modified_from_headers -> last_modified: DateTime, 8 | request_id_from_headers -> request_id: RequestId, 9 | date_from_headers -> date: DateTime 10 | ); 11 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/container/responses/renew_lease_response.rs: -------------------------------------------------------------------------------- 1 | use crate::container::responses::AcquireLeaseResponse; 2 | 3 | pub type RenewLeaseResponse = AcquireLeaseResponse; 4 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/src/prelude.rs: -------------------------------------------------------------------------------- 1 | pub use crate::blob::{ 2 | BlobBlockType, BlockList, BlockListRequired, BlockListSupport, BlockListType, 3 | BlockListTypeRequired, BlockListTypeSupport, 4 | }; 5 | pub use crate::container::{ 6 | PublicAccess, PublicAccessRequired, PublicAccessSupport, StoredAccessPolicyListOption, 7 | StoredAccessPolicyListSupport, 8 | }; 9 | pub use crate::Blob as BlobTrait; 10 | pub use crate::Container as ContainerTrait; 11 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/tests/append_blob.rs: -------------------------------------------------------------------------------- 1 | #![cfg(all(test, feature = "test_e2e"))] 2 | #[macro_use] 3 | extern crate log; 4 | 5 | use azure_sdk_core::prelude::*; 6 | use azure_sdk_storage_blob::container::PublicAccess; 7 | use azure_sdk_storage_blob::prelude::*; 8 | use azure_sdk_storage_core::prelude::*; 9 | use std::collections::HashMap; 10 | 11 | #[tokio::test] 12 | async fn put_append_blob() { 13 | let account = 14 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 15 | let master_key = 16 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 17 | 18 | let client = client::with_access_key(&account, &master_key); 19 | 20 | let blob_name: &'static str = "append_blob.txt"; 21 | let container_name: &'static str = "rust-upload-test"; 22 | let data = b"abcdef"; 23 | 24 | if client 25 | .list_containers() 26 | .finalize() 27 | .await 28 | .unwrap() 29 | .incomplete_vector 30 | .iter() 31 | .find(|x| x.name == container_name) 32 | .is_none() 33 | { 34 | client 35 | .create_container() 36 | .with_container_name(container_name) 37 | .with_public_access(PublicAccess::Blob) 38 | .finalize() 39 | .await 40 | .unwrap(); 41 | } 42 | 43 | let mut metadata = HashMap::new(); 44 | metadata.insert("attrib", "value"); 45 | metadata.insert("second", "something"); 46 | 47 | // calculate md5 too! 48 | let _digest = md5::compute(&data[..]); 49 | 50 | client 51 | .put_append_blob() 52 | .with_container_name(&container_name) 53 | .with_blob_name(&blob_name) 54 | .with_content_type("text/plain") 55 | .with_metadata(&metadata) 56 | .finalize() 57 | .await 58 | .unwrap(); 59 | 60 | trace!("created {:?}", blob_name); 61 | } 62 | -------------------------------------------------------------------------------- /azure_sdk_storage_blob/tests/page_blob.rs: -------------------------------------------------------------------------------- 1 | #![cfg(all(test, feature = "test_e2e"))] 2 | #[macro_use] 3 | extern crate log; 4 | use azure_sdk_core::prelude::*; 5 | use azure_sdk_storage_blob::prelude::*; 6 | use azure_sdk_storage_core::prelude::*; 7 | use std::collections::HashMap; 8 | 9 | #[tokio::test] 10 | async fn put_page_blob() { 11 | let client = initialize(); 12 | 13 | let blob_name: &'static str = "page_blob.txt"; 14 | let container_name: &'static str = "rust-upload-test"; 15 | let data = b"abcdef"; 16 | 17 | if client 18 | .list_containers() 19 | .finalize() 20 | .await 21 | .unwrap() 22 | .incomplete_vector 23 | .iter() 24 | .find(|x| x.name == container_name) 25 | .is_none() 26 | { 27 | client 28 | .create_container() 29 | .with_container_name(container_name) 30 | .with_public_access(PublicAccess::Blob) 31 | .finalize() 32 | .await 33 | .unwrap(); 34 | } 35 | 36 | let mut metadata = HashMap::new(); 37 | metadata.insert("attrib", "value"); 38 | metadata.insert("second", "something"); 39 | 40 | // calculate md5 too! 41 | let _digest = md5::compute(&data[..]); 42 | 43 | client 44 | .put_page_blob() 45 | .with_container_name(&container_name) 46 | .with_blob_name(&blob_name) 47 | .with_content_type("text/plain") 48 | .with_metadata(&metadata) 49 | .with_content_length(1024 * 64) 50 | .finalize() 51 | .await 52 | .unwrap(); 53 | 54 | trace!("created {:?}", blob_name); 55 | } 56 | 57 | fn initialize() -> Box { 58 | let account = 59 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 60 | let master_key = 61 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 62 | 63 | Box::new(client::with_access_key(&account, &master_key)) 64 | } 65 | -------------------------------------------------------------------------------- /azure_sdk_storage_core/.rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition="2018" 2 | -------------------------------------------------------------------------------- /azure_sdk_storage_core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "azure_sdk_storage_core" 3 | version = "0.44.4" 4 | description = "Rust wrappers around Microsoft Azure REST APIs - Core storage crate" 5 | readme = "README.md" 6 | authors = ["Francesco Cogno ", "Max Gortman ", "Dong Liu "] 7 | license = "Apache-2.0" 8 | repository = "https://github.com/MindFlavor/AzureSDKForRust" 9 | documentation = "http://mindflavor.github.io/AzureSDKForRust/azure_sdk_for_rust/index.html" 10 | homepage = "https://github.com/MindFlavor/AzureSDKForRust" 11 | 12 | keywords = ["sdk", "azure", "rest", "iot", "cloud"] 13 | categories = ["api-bindings"] 14 | 15 | edition = "2018" 16 | 17 | [dependencies] 18 | azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.6" } 19 | ring = "0.16" 20 | base64 = "0.12" 21 | chrono = "0.4" 22 | http = "0.2" 23 | futures = "0.3" 24 | hyper = "0.13" 25 | log = "0.4" 26 | mime = "0.3" 27 | quick-error = "1.2" 28 | serde = "1.0" 29 | serde_derive = "1.0" 30 | serde_json = "1.0" 31 | serde-xml-rs = "0.4" 32 | time = "0.2" 33 | url = "2.1" 34 | uuid = { version = "0.8", features = ["v4"] } 35 | smallvec = { version = "1.0", features = ["serde"] } 36 | bytes = "0.5" 37 | hyper-rustls = "0.20" 38 | 39 | [dev-dependencies] 40 | tokio = { version = "0.2", features = ["macros"] } 41 | env_logger = "0.7" 42 | 43 | [features] 44 | test_e2e = [] 45 | -------------------------------------------------------------------------------- /azure_sdk_storage_core/README.md: -------------------------------------------------------------------------------- 1 | # Azure SDK for Rust - Azure storage core crate 2 | 3 | Azure storage core crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to [https://github.com/MindFlavor/AzureSDKForRust](https://github.com/MindFlavor/AzureSDKForRust). 4 | -------------------------------------------------------------------------------- /azure_sdk_storage_core/examples/box.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_storage_core::prelude::*; 2 | use std::sync::Arc; 3 | use std::thread; 4 | 5 | fn get_box() -> Box { 6 | Box::new(client::with_access_key("fake", "fake")) 7 | } 8 | 9 | fn get_box_send() -> Box { 10 | Box::new(client::with_access_key("send", "fake")) 11 | } 12 | 13 | fn get_arc() -> Arc { 14 | Arc::new(client::with_access_key("arc", "fake")) 15 | } 16 | 17 | pub fn main() { 18 | let client = get_box(); 19 | println!("client.blob_uri() == {}", client.blob_uri()); 20 | 21 | let client_send = get_box_send(); 22 | 23 | let handler = thread::spawn(move || { 24 | println!("client_send.blob_uri() == {}", client_send.blob_uri()); 25 | }); 26 | handler.join().unwrap(); 27 | 28 | let client_arc = get_arc(); 29 | println!("client_arc.blob_uri() == {}", client_arc.blob_uri()); 30 | } 31 | -------------------------------------------------------------------------------- /azure_sdk_storage_core/examples/connection_string_builder.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_storage_core::{EndpointProtocol, ConnectionStringBuilder}; 2 | 3 | pub fn main() { 4 | let account_name = 5 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 6 | let account_key = std::env::var("ACCOUNT_KEY").expect("Set env variable ACCOUNT_KEY first!"); 7 | let default_endpoints_protocol = std::env::var("DEFAULT_ENDPOINTS_PROTOCOL") 8 | .expect("Set env variable DEFAULT_ENDPOINTS_PROTOCOL first!"); 9 | let default_endpoints_protocol = match &default_endpoints_protocol[..] { 10 | "https" => EndpointProtocol::Https, 11 | "http" => EndpointProtocol::Http, 12 | _ => panic!("Invalid default endpoints protocol") 13 | }; 14 | 15 | let connection_string = ConnectionStringBuilder::new() 16 | .with_account_name(&account_name) 17 | .with_account_key(&account_key) 18 | .with_default_endpoints_protocol(default_endpoints_protocol) 19 | .build(); 20 | 21 | println!("The connection string is: '{}'", connection_string); 22 | } 23 | -------------------------------------------------------------------------------- /azure_sdk_storage_core/examples/sas00.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_storage_core::prelude::*; 2 | use chrono::*; 3 | use url::Url; 4 | 5 | pub fn main() { 6 | let master_key = 7 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 8 | 9 | let start = Utc::now() - Duration::days(1); 10 | let end = Utc::now() + Duration::days(1); 11 | 12 | let path = 13 | Url::parse("https://azureskdforrust.blob.core.windows.net/test/ERRORLOG.1.cut").unwrap(); 14 | 15 | let ip_range = IPRange { 16 | start: std::net::IpAddr::V4(::new(0, 0, 0, 0)), 17 | end: std::net::IpAddr::V4(::new(255, 255, 255, 255)), 18 | }; 19 | 20 | let sas = BlobSASBuilder::new(&path) 21 | .with_key(&master_key) 22 | .with_validity_start(&start) 23 | .with_validity_end(&end) 24 | .with_ip_range(&ip_range) 25 | .with_content_type("text/plain") 26 | .allow_read() 27 | .finalize(); 28 | 29 | println!("SAS == {}", sas); 30 | 31 | let path = Url::parse( 32 | "https://azureskdforrust.blob.core.windows.net/test?restype=container&comp=list", 33 | ) 34 | .unwrap(); 35 | 36 | let sas = ContainerSASBuilder::new(&path) 37 | .with_key(&master_key) 38 | .with_validity_start(&start) 39 | .with_validity_end(&end) 40 | .with_ip_range(&ip_range) 41 | .allow_read() 42 | .allow_list() 43 | .allow_write() 44 | .allow_add() 45 | .allow_create() 46 | .allow_delete() 47 | .finalize(); 48 | 49 | println!("SAS == {}", sas); 50 | } 51 | -------------------------------------------------------------------------------- /azure_sdk_storage_core/src/client_endpoint.rs: -------------------------------------------------------------------------------- 1 | pub trait ClientEndpoint { 2 | fn account(&self) -> &str; 3 | fn key(&self) -> &str; 4 | } 5 | -------------------------------------------------------------------------------- /azure_sdk_storage_core/src/hyper_client_endpoint.rs: -------------------------------------------------------------------------------- 1 | use crate::ClientEndpoint; 2 | use hyper_rustls::HttpsConnector; 3 | 4 | pub trait HyperClientEndpoint: ClientEndpoint { 5 | fn hyper_client(&self) -> &hyper::Client>; 6 | } 7 | -------------------------------------------------------------------------------- /azure_sdk_storage_core/src/prelude.rs: -------------------------------------------------------------------------------- 1 | pub use crate::blob_sas_builder::BlobSASBuilder; 2 | pub use crate::client::HttpHeaderAdder; 3 | pub use crate::container_sas_builder::ContainerSASBuilder; 4 | pub use crate::{client, CopyId, IPRange}; 5 | pub use crate::{Client, ClientRequired, KeyClientRequired}; 6 | 7 | pub use crate::SharedAccessSignatureSupport; 8 | 9 | pub use crate::shared_access_signature::{ 10 | ClientSharedAccessSignature, SasExpirySupport, SasIpSupport, SasPermissions, 11 | SasPermissionsSupport, SasProtocol, SasProtocolSupport, SasResource, SasResourceSupport, 12 | SasResourceType, SasResourceTypeSupport, SasService, SasStartSupport, SasVersion, 13 | }; 14 | -------------------------------------------------------------------------------- /azure_sdk_storage_queue/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "azure_sdk_storage_queue" 3 | version = "0.1.0" 4 | description = "Rust wrappers around Microsoft Azure REST APIs - Azure Storage Queue crate" 5 | readme = "README.md" 6 | authors = ["Francesco Cogno "] 7 | license = "Apache-2.0" 8 | repository = "https://github.com/MindFlavor/AzureSDKForRust" 9 | documentation = "http://mindflavor.github.io/AzureSDKForRust/azure_sdk_for_rust/index.html" 10 | homepage = "https://github.com/MindFlavor/AzureSDKForRust" 11 | 12 | keywords = ["sdk", "azure", "rest", "iot", "cloud"] 13 | categories = ["api-bindings"] 14 | 15 | edition = "2018" 16 | 17 | [dependencies] 18 | azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.7" } 19 | azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.4" } 20 | ring = "0.16" 21 | base64 = "0.12" 22 | chrono = "0.4" 23 | http = "0.2" 24 | futures = "0.3" 25 | hyper = "0.13" 26 | log = "0.4" 27 | serde = "1.0" 28 | serde_derive = "1.0" 29 | serde_json = "1.0" 30 | serde-xml-rs = "0.4" 31 | url = "2.1" 32 | uuid = { version = "0.8", features = ["v4"] } 33 | hyper-rustls = "0.20" 34 | failure = "0.1" 35 | 36 | [dev-dependencies] 37 | env_logger = "0.7" 38 | tokio = { version = "0.2", features = ["macros"] } 39 | serde = { version = "1.0", features = ["derive"] } 40 | 41 | [features] 42 | test_e2e = [] 43 | -------------------------------------------------------------------------------- /azure_sdk_storage_queue/README.md: -------------------------------------------------------------------------------- 1 | # Azure SDK for Rust - Azure queue storage crate 2 | 3 | Azure queue storage crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to [https://github.com/MindFlavor/AzureSDKForRust](https://github.com/MindFlavor/AzureSDKForRust). 4 | -------------------------------------------------------------------------------- /azure_sdk_storage_queue/examples/list_queues.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate log; 3 | 4 | use azure_sdk_core::prelude::*; 5 | use azure_sdk_storage_core::prelude::*; 6 | use azure_sdk_storage_queue::prelude::*; 7 | use std::error::Error; 8 | 9 | #[tokio::main] 10 | async fn main() -> Result<(), Box> { 11 | // First we retrieve the account name and master key from environment variables. 12 | let account = 13 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 14 | let master_key = 15 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 16 | 17 | let client = client::with_access_key(&account, &master_key).into_queue_service_client(); 18 | 19 | trace!("enumerating queues"); 20 | 21 | let response = client 22 | .list_queues() 23 | .with_prefix("a") 24 | .with_include_metadata() 25 | .with_max_results(2) 26 | .execute() 27 | .await?; 28 | 29 | println!("response == {:#?}", response); 30 | 31 | Ok(()) 32 | } 33 | -------------------------------------------------------------------------------- /azure_sdk_storage_queue/examples/put_message.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate log; 3 | use azure_sdk_core::prelude::*; 4 | use azure_sdk_storage_core::prelude::*; 5 | use azure_sdk_storage_queue::prelude::*; 6 | use std::error::Error; 7 | 8 | #[tokio::main] 9 | async fn main() -> Result<(), Box> { 10 | // First we retrieve the account name and master key from environment variables. 11 | let account = 12 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 13 | let master_key = 14 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 15 | 16 | let queue_name = std::env::args() 17 | .nth(1) 18 | .expect("Please pass the queue name as first parameter"); 19 | 20 | let client = client::with_access_key(&account, &master_key).into_queue_service_client(); 21 | 22 | trace!("enumerating queues"); 23 | 24 | let response = client 25 | .with_queue_name_client(&queue_name) 26 | .put_message() 27 | .with_client_request_id("optional correlation token") 28 | .with_message_body("Azure SDK for Rust rocks!") 29 | .execute() 30 | .await?; 31 | 32 | println!("response == {:#?}", response); 33 | 34 | Ok(()) 35 | } 36 | -------------------------------------------------------------------------------- /azure_sdk_storage_queue/src/clients/mod.rs: -------------------------------------------------------------------------------- 1 | mod queue_name_client; 2 | mod queue_service_client; 3 | pub use queue_name_client::QueueNameClient; 4 | pub use queue_service_client::QueueServiceClient; 5 | -------------------------------------------------------------------------------- /azure_sdk_storage_queue/src/clients/queue_service_client.rs: -------------------------------------------------------------------------------- 1 | use crate::requests; 2 | use crate::{HasStorageClient, IntoQueueServiceClient, QueueService, WithQueueServiceClient}; 3 | use azure_sdk_storage_core::Client; 4 | use std::borrow::Cow; 5 | use std::fmt::Debug; 6 | 7 | #[derive(Debug, Clone)] 8 | pub struct QueueServiceClient<'a, C> 9 | where 10 | C: Client + Clone, 11 | { 12 | pub storage_client: Cow<'a, C>, 13 | } 14 | 15 | impl<'a, C> HasStorageClient for QueueServiceClient<'a, C> 16 | where 17 | C: Client + Clone, 18 | { 19 | type StorageClient = C; 20 | 21 | fn storage_client(&self) -> &C { 22 | self.storage_client.as_ref() 23 | } 24 | } 25 | 26 | impl<'a, C> WithQueueServiceClient<'a> for C 27 | where 28 | C: Client + 'a + Clone, 29 | { 30 | type QueueServiceClient = QueueServiceClient<'a, C>; 31 | 32 | fn with_queue_service_client(&'a self) -> Self::QueueServiceClient { 33 | QueueServiceClient { 34 | storage_client: Cow::Borrowed(self), 35 | } 36 | } 37 | } 38 | 39 | impl IntoQueueServiceClient for C 40 | where 41 | C: Client + 'static + Clone, 42 | { 43 | type QueueServiceClient = QueueServiceClient<'static, C>; 44 | 45 | fn into_queue_service_client(self) -> Self::QueueServiceClient { 46 | QueueServiceClient { 47 | storage_client: Cow::Owned(self), 48 | } 49 | } 50 | } 51 | 52 | impl<'a, C> QueueService for QueueServiceClient<'a, C> 53 | where 54 | C: Client + Clone, 55 | { 56 | fn list_queues(&self) -> requests::ListQueuesBuilder<'_, '_, Self::StorageClient> { 57 | crate::requests::ListQueuesBuilder::new(self) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /azure_sdk_storage_queue/src/prelude.rs: -------------------------------------------------------------------------------- 1 | pub use crate::{ 2 | IntoQueueNameClient, IntoQueueServiceClient, MessageBodyRequired, MessageBodySupport, 3 | MessageTTLRequired, MessageTTLSupport, QueueNameService, QueueService, 4 | VisibilityTimeoutRequired, VisibilityTimeoutSupport, WithQueueNameClient, 5 | WithQueueServiceClient, 6 | }; 7 | -------------------------------------------------------------------------------- /azure_sdk_storage_queue/src/requests/list_queues_builder.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ListQueuesBuilder", 3 | "derive": "Debug, Clone", 4 | "uses": [ 5 | "crate::prelude::*", 6 | "crate::responses::*", 7 | "azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError}", 8 | "azure_sdk_core::prelude::*", 9 | "azure_sdk_storage_core::prelude::*", 10 | "hyper::StatusCode", 11 | "std::convert::TryInto" 12 | ], 13 | "inline": true, 14 | "extra_types": [ "'a", "'b", "C" ], 15 | "extra_wheres": [ "C: Client" ], 16 | "constructor_fields": [ 17 | { 18 | "name": "queue_service", 19 | "field_type": "&'a dyn QueueService" 20 | } 21 | ], 22 | "fields": [ 23 | { 24 | "name": "prefix", 25 | "field_type": "&'b str", 26 | "optional": true, 27 | "trait_get": "PrefixOption<'b>", 28 | "trait_set": "PrefixSupport<'b>" 29 | }, 30 | { 31 | "name": "next_marker", 32 | "field_type": "&'b str", 33 | "optional": true, 34 | "trait_get": "NextMarkerOption<'b>", 35 | "trait_set": "NextMarkerSupport<'b>" 36 | }, 37 | { 38 | "name": "max_results", 39 | "field_type": "u32", 40 | "optional": true, 41 | "trait_get": "MaxResultsOption", 42 | "trait_set": "MaxResultsSupport" 43 | }, 44 | { 45 | "name": "include_metadata", 46 | "field_type": "bool", 47 | "optional": true, 48 | "initializer": "false", 49 | "trait_get": "IncludeMetadataOption", 50 | "trait_set": "IncludeMetadataSupport" 51 | }, 52 | { 53 | "name": "timeout", 54 | "field_type": "u64", 55 | "optional": true, 56 | "trait_get": "TimeoutOption", 57 | "trait_set": "TimeoutSupport" 58 | }, 59 | { 60 | "name": "client_request_id", 61 | "field_type": "&'a str", 62 | "optional": true, 63 | "trait_get": "ClientRequestIdOption<'a>", 64 | "trait_set": "ClientRequestIdSupport<'a>" 65 | } 66 | ] 67 | } 68 | -------------------------------------------------------------------------------- /azure_sdk_storage_queue/src/requests/mod.rs: -------------------------------------------------------------------------------- 1 | mod put_message_builder; 2 | pub use put_message_builder::PutMessageBuilder; 3 | mod list_queues_builder; 4 | pub use list_queues_builder::ListQueuesBuilder; 5 | -------------------------------------------------------------------------------- /azure_sdk_storage_queue/src/responses/mod.rs: -------------------------------------------------------------------------------- 1 | mod list_queues_response; 2 | pub use list_queues_response::ListQueuesResponse; 3 | mod put_message_response; 4 | pub use put_message_response::PutMessageResponse; 5 | -------------------------------------------------------------------------------- /azure_sdk_storage_table/.rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition="2018" 2 | -------------------------------------------------------------------------------- /azure_sdk_storage_table/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "azure_sdk_storage_table" 3 | version = "0.41.3" 4 | description = "Rust wrappers around Microsoft Azure REST APIs - Table storage crate" 5 | readme = "README.md" 6 | authors = ["Francesco Cogno ", "gzp-crey", "Max Gortman ", "Dong Liu "] 7 | license = "Apache-2.0" 8 | repository = "https://github.com/MindFlavor/AzureSDKForRust" 9 | documentation = "https://docs.rs/azure_sdk_storage_table/" 10 | homepage = "https://mindflavor.github.io/AzureSDKForRust/" 11 | 12 | keywords = ["sdk", "azure", "rest", "iot", "cloud"] 13 | categories = ["api-bindings"] 14 | 15 | edition = "2018" 16 | 17 | [dependencies] 18 | azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" } 19 | azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.3" } 20 | chrono = "0.4" 21 | http = "0.2" 22 | hyper = "0.13" 23 | log = "0.4" 24 | quick-error = "1.2" 25 | serde = "1.0" 26 | serde_derive = "1.0" 27 | serde_json = "1.0" 28 | futures = "0.3" 29 | 30 | [dev-dependencies] 31 | tokio = { version = "0.2", features = ["macros"] } 32 | env_logger = "0.7" 33 | 34 | [features] 35 | test_e2e = [] 36 | -------------------------------------------------------------------------------- /azure_sdk_storage_table/README.md: -------------------------------------------------------------------------------- 1 | # Azure SDK for Rust - Azure storage table crate 2 | 3 | Azure storage table crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to [https://github.com/MindFlavor/AzureSDKForRust](https://github.com/MindFlavor/AzureSDKForRust). 4 | -------------------------------------------------------------------------------- /azure_sdk_storage_table/examples/tables.rs: -------------------------------------------------------------------------------- 1 | use azure_sdk_storage_table::TableClient; 2 | use std::error::Error; 3 | 4 | #[tokio::main] 5 | async fn main() -> Result<(), Box> { 6 | // First we retrieve the account name and master key from environment variables. 7 | let account = 8 | std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); 9 | let master_key = 10 | std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); 11 | 12 | let client = TableClient::new(&account, &master_key); 13 | let tables = client.list_tables().await?; 14 | 15 | println!("Account {} has {} tables(s)", account, tables.len()); 16 | for ref table in tables { 17 | println!("{}", table); 18 | } 19 | Ok(()) 20 | } 21 | -------------------------------------------------------------------------------- /azure_sdk_storage_table/src/de.rs: -------------------------------------------------------------------------------- 1 | use chrono::{DateTime, Utc}; 2 | use serde::{ 3 | de::{Error, Visitor}, 4 | Deserializer, 5 | }; 6 | use std::fmt; 7 | 8 | /// Serde visitor to deserialize Timestamp 9 | struct TimestampVisitor; 10 | 11 | pub fn deserialize<'de, D>(d: D) -> Result, D::Error> 12 | where 13 | D: Deserializer<'de>, 14 | { 15 | d.deserialize_str(TimestampVisitor) 16 | } 17 | 18 | impl<'de> Visitor<'de> for TimestampVisitor { 19 | type Value = DateTime; 20 | 21 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 22 | write!(formatter, "a timestamp string") 23 | } 24 | 25 | fn visit_str(self, value: &str) -> Result 26 | where 27 | E: Error, 28 | { 29 | match value.parse::>() { 30 | Ok(date) => Ok(date), 31 | Err(e) => Err(E::custom(format!("Parse error {} for {}", e, value))), 32 | } 33 | } 34 | } 35 | 36 | /// Serde visitor to deserialize Option 37 | struct OptionalTimestampVisitor; 38 | 39 | impl<'de> Visitor<'de> for OptionalTimestampVisitor { 40 | type Value = Option>; 41 | 42 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 43 | write!(formatter, "null or a timestamp string") 44 | } 45 | 46 | fn visit_none(self) -> Result 47 | where 48 | E: Error, 49 | { 50 | Ok(None) 51 | } 52 | 53 | fn visit_some(self, d: D) -> Result>, D::Error> 54 | where 55 | D: Deserializer<'de>, 56 | { 57 | Ok(Some(d.deserialize_str(TimestampVisitor)?)) 58 | } 59 | } 60 | 61 | pub fn optional_timestamp<'de, D>(d: D) -> Result>, D::Error> 62 | where 63 | D: Deserializer<'de>, 64 | { 65 | d.deserialize_option(OptionalTimestampVisitor) 66 | } 67 | -------------------------------------------------------------------------------- /azure_sdk_storage_table/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![recursion_limit = "128"] 2 | 3 | extern crate log; 4 | #[macro_use] 5 | extern crate serde_derive; 6 | #[macro_use] 7 | extern crate quick_error; 8 | 9 | pub mod table_client; 10 | pub use table_client::*; 11 | mod cloud_table; 12 | pub use cloud_table::*; 13 | mod table_entity; 14 | pub use table_entity::*; 15 | mod batch; 16 | pub use batch::*; 17 | pub mod de; 18 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition = "2018" 2 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ev 4 | 5 | for i in azure_sdk* ; do 6 | cd $i 7 | travis-cargo build 8 | travis-cargo test 9 | travis-cargo bench 10 | travis-cargo --only stable doc 11 | cd .. 12 | done 13 | 14 | 15 | -------------------------------------------------------------------------------- /scripts/clippy_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ev 4 | 5 | for i in azure_sdk* ; do 6 | cd $i 7 | cargo clean 8 | cd .. 9 | done 10 | 11 | cargo clippy 12 | 13 | 14 | -------------------------------------------------------------------------------- /scripts/publish_all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd azure_sdk_core 4 | cargo publish 5 | cd .. 6 | 7 | sleep 20 8 | 9 | cd azure_sdk_storage_core 10 | cargo publish 11 | cd .. 12 | 13 | sleep 20 14 | 15 | cd azure_sdk_storage_account 16 | cargo publish 17 | cd .. 18 | 19 | cd azure_sdk_storage_blob 20 | cargo publish 21 | cd .. 22 | 23 | cd azure_sdk_storage_table 24 | cargo publish 25 | cd .. 26 | 27 | cd azure_sdk_storage_queue 28 | cargo publish 29 | cd .. 30 | 31 | cd azure_sdk_auth_aad 32 | cargo publish 33 | cd .. 34 | 35 | cd azure_sdk_cosmos 36 | cargo publish 37 | cd .. 38 | 39 | cd azure_sdk_service_bus 40 | cargo publish 41 | cd .. 42 | --------------------------------------------------------------------------------