Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into SpecificAzureCredential2
Browse files Browse the repository at this point in the history
  • Loading branch information
cataggar committed Jan 10, 2024
2 parents dd78724 + 9cd67ba commit 6d49499
Show file tree
Hide file tree
Showing 57 changed files with 213 additions and 112 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: eng/scripts/sdk_tests.sh ${{ matrix.build }}

test-docs-sdk:
name: SDK docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: eng/scripts/verify-docs.sh sdk
test-docs-svc:
name: SDK docs - svc
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: eng/scripts/verify-docs.sh svc
test-docs-mgmt:
name: SDK docs - mgmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: eng/scripts/verify-docs.sh mgmt

test-wasm:
name: WASM Tests
runs-on: ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion eng/scripts/check_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ rustup update --no-self-update ${BUILD}
rustup target add --toolchain ${BUILD} wasm32-unknown-unknown

export RUSTFLAGS="-Dwarnings"
cargo +${BUILD} check --target=wasm32-unknown-unknown --no-default-features
cargo +${BUILD} check --target=wasm32-unknown-unknown
49 changes: 49 additions & 0 deletions eng/scripts/verify-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/bash
#
# simple script to check docs using `cargo-docs-rs`
#

set -eux -o pipefail

BUILD=${1:-all}

cd $(dirname ${BASH_SOURCE[0]})/../../

SDK=$(cargo metadata --format-version=1 --no-deps | jq -r -c '.packages | .[] | select(.publish == null) | .name')
SERVICES=$(cd services; cargo metadata --format-version=1 --no-deps | jq -r -c '.packages | .[] | select(.publish == null) | .name')


for i in ${SDK}; do
case ${BUILD} in
all | sdk )
cargo +nightly docs-rs -p ${i}
;;
svc | mgmt )
;;
*)
echo "unsupported build. (${BUILD}) use all, sdk, svc, or mgmt"
exit 1
;;
esac
done

for i in ${SERVICES}; do
case ${BUILD} in
all | svc )
if [[ ${i} =~ "azure_svc_" ]]; then
cargo +nightly docs-rs -p ${i} --manifest-path services/Cargo.toml
fi
;;
all | mgmt )
if [[ ${i} =~ "azure_mgmt_" ]]; then
cargo +nightly docs-rs -p ${i} --manifest-path services/Cargo.toml
fi
;;
sdk )
;;
*)
echo "unsupported build (${BUILD}) use all, sdk, svc, or mgmt"
exit 1
;;
esac
done
2 changes: 1 addition & 1 deletion sdk/core/src/http_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ where
S: AsRef<[u8]>,
T: DeserializeOwned,
{
serde_json::from_slice(body.as_ref()).map_err(|e| e.into())
serde_json::from_slice(body.as_ref()).map_err(Into::into)
}
8 changes: 8 additions & 0 deletions sdk/core/src/http_client/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ pub fn new_reqwest_client() -> Arc<dyn HttpClient> {
// `hyper` library that causes the `reqwest` client to hang in some cases.
//
// See <https://github.com/hyperium/hyper/issues/2312> for more details.
#[cfg(not(target_arch = "wasm32"))]
let client = ::reqwest::ClientBuilder::new()
.pool_max_idle_per_host(0)
.build()
.expect("failed to build `reqwest` client");

// `reqwest` does not implement `pool_max_idle_per_host()` on WASM.
#[cfg(target_arch = "wasm32")]
let client = ::reqwest::ClientBuilder::new()
.build()
.expect("failed to build `reqwest` client");

Arc::new(client)
}

Expand Down
8 changes: 4 additions & 4 deletions sdk/core/src/policies/retry_policies/retry_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DateTimeFn = fn() -> OffsetDateTime;
/// Get the duration to delay between retry attempts, provided by the headers from the response.
///
/// This function checks for retry-after headers in the following order, following the
/// JS Azure SDK implementation: https://github.com/Azure/azure-sdk-for-js/blob/17de1a2b7f3ad61f34ff62876eced7d077c10d4b/sdk/core/core-rest-pipeline/src/retryStrategies/throttlingRetryStrategy.ts#L35
/// JS Azure SDK implementation: <https://github.com/Azure/azure-sdk-for-js/blob/17de1a2b7f3ad61f34ff62876eced7d077c10d4b/sdk/core/core-rest-pipeline/src/retryStrategies/throttlingRetryStrategy.ts#L35>
/// * `retry-after-ms`
/// * `x-ms-retry-after-ms`
/// * `Retry-After`
Expand Down Expand Up @@ -76,9 +76,9 @@ pub trait RetryPolicy: std::fmt::Debug + Send + Sync {
async fn wait(&self, _error: &Error, retry_count: u32, retry_after: Option<Duration>) {
let policy_sleep_duration = self.sleep_duration(retry_count);
// If the server provided a retry-after header, use the max of that and the policy sleep duration
let sleep_duration = retry_after
.map(|retry_after| std::cmp::max(retry_after, policy_sleep_duration))
.unwrap_or(policy_sleep_duration);
let sleep_duration = retry_after.map_or(policy_sleep_duration, |retry_after| {
std::cmp::max(retry_after, policy_sleep_duration)
});
sleep(sleep_duration).await;
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl CollectedResponse {
}

#[cfg(feature = "xml")]
pub async fn xml<T>(&self) -> crate::Result<T>
pub fn xml<T>(&self) -> crate::Result<T>
where
T: DeserializeOwned,
{
Expand Down
4 changes: 2 additions & 2 deletions sdk/data_cosmos/src/operations/delete_attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl DeleteAttachmentBuilder {
)
.await?;

DeleteAttachmentResponse::try_from(response).await
DeleteAttachmentResponse::try_from(response)
})
}
}
Expand Down Expand Up @@ -70,7 +70,7 @@ pub struct DeleteAttachmentResponse {
}

impl DeleteAttachmentResponse {
pub async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
pub fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
let headers = response.headers();

Ok(Self {
Expand Down
4 changes: 2 additions & 2 deletions sdk/data_cosmos/src/operations/delete_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl DeleteCollectionBuilder {
)
.await?;

DeleteCollectionResponse::try_from(response).await
DeleteCollectionResponse::try_from(response)
})
}
}
Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct DeleteCollectionResponse {
}

impl DeleteCollectionResponse {
pub async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
pub fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
let (_status_code, headers, _pinned_stream) = response.deconstruct();

Ok(Self {
Expand Down
4 changes: 2 additions & 2 deletions sdk/data_cosmos/src/operations/delete_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl DeleteDatabaseBuilder {
.cosmos_client()
.send(request, self.context.clone(), ResourceType::Databases)
.await?;
DeleteDatabaseResponse::try_from(response).await
DeleteDatabaseResponse::try_from(response)
})
}
}
Expand All @@ -38,7 +38,7 @@ pub struct DeleteDatabaseResponse {
}

impl DeleteDatabaseResponse {
pub async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
pub fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
let headers = response.headers();

let charge = request_charge_from_headers(headers)?;
Expand Down
4 changes: 2 additions & 2 deletions sdk/data_cosmos/src/operations/delete_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl DeleteDocumentBuilder {
)
.await?;

DeleteDocumentResponse::try_from(response).await
DeleteDocumentResponse::try_from(response)
})
}
}
Expand All @@ -58,7 +58,7 @@ pub struct DeleteDocumentResponse {
}

impl DeleteDocumentResponse {
pub async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
pub fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
let (_status_code, headers, _pinned_stream) = response.deconstruct();

let charge = request_charge_from_headers(&headers)?;
Expand Down
4 changes: 2 additions & 2 deletions sdk/data_cosmos/src/operations/delete_permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl DeletePermissionBuilder {
)
.await?;

DeletePermissionResponse::try_from(response).await
DeletePermissionResponse::try_from(response)
})
}
}
Expand All @@ -43,7 +43,7 @@ pub struct DeletePermissionResponse {
}

impl DeletePermissionResponse {
pub async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
pub fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
let (_status_code, headers, _pinned_stream) = response.deconstruct();

Ok(Self {
Expand Down
4 changes: 2 additions & 2 deletions sdk/data_cosmos/src/operations/delete_stored_procedure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl DeleteStoredProcedureBuilder {
)
.await?;

DeleteStoredProcedureResponse::try_from(response).await
DeleteStoredProcedureResponse::try_from(response)
})
}
}
Expand All @@ -47,7 +47,7 @@ pub struct DeleteStoredProcedureResponse {
}

impl DeleteStoredProcedureResponse {
pub async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
pub fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
let headers = response.headers();

Ok(Self {
Expand Down
4 changes: 2 additions & 2 deletions sdk/data_cosmos/src/operations/delete_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl DeleteTriggerBuilder {
)
.await?;

DeleteTriggerResponse::try_from(response).await
DeleteTriggerResponse::try_from(response)
})
}
}
Expand Down Expand Up @@ -63,7 +63,7 @@ pub struct DeleteTriggerResponse {
pub date: OffsetDateTime,
}
impl DeleteTriggerResponse {
pub async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
pub fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
let (_status_code, headers, _pinned_stream) = response.deconstruct();

Ok(Self {
Expand Down
4 changes: 2 additions & 2 deletions sdk/data_cosmos/src/operations/delete_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl DeleteUserBuilder {
)
.await?;

DeleteUserResponse::try_from(response).await
DeleteUserResponse::try_from(response)
})
}
}
Expand All @@ -38,7 +38,7 @@ pub struct DeleteUserResponse {
}

impl DeleteUserResponse {
pub async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
pub fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
let (_status_code, headers, _pinned_stream) = response.deconstruct();

Ok(Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl DeleteUserDefinedFunctionBuilder {
)
.await?;

DeleteUserDefinedFunctionResponse::try_from(response).await
DeleteUserDefinedFunctionResponse::try_from(response)
})
}
}
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct DeleteUserDefinedFunctionResponse {
}

impl DeleteUserDefinedFunctionResponse {
pub async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
pub fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
let (_status_code, headers, _pinned_stream) = response.deconstruct();

Ok(Self {
Expand Down
12 changes: 6 additions & 6 deletions sdk/data_cosmos/src/operations/get_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ where
status_code == StatusCode::Ok || status_code == StatusCode::NotModified;

if has_been_found {
Ok(GetDocumentResponse::Found(
FoundDocumentResponse::try_from(&headers, body).await?,
))
Ok(GetDocumentResponse::Found(FoundDocumentResponse::try_from(
&headers, body,
)?))
} else {
Ok(GetDocumentResponse::NotFound(
NotFoundDocumentResponse::try_from(&headers).await?,
NotFoundDocumentResponse::try_from(&headers)?,
))
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<T> FoundDocumentResponse<T>
where
T: DeserializeOwned,
{
async fn try_from(headers: &Headers, body: bytes::Bytes) -> azure_core::Result<Self> {
fn try_from(headers: &Headers, body: bytes::Bytes) -> azure_core::Result<Self> {
Ok(Self {
document: from_json(&body)?,
content_location: content_location_from_headers(headers)?,
Expand Down Expand Up @@ -203,7 +203,7 @@ pub struct NotFoundDocumentResponse {
}

impl NotFoundDocumentResponse {
async fn try_from(headers: &Headers) -> azure_core::Result<Self> {
fn try_from(headers: &Headers) -> azure_core::Result<Self> {
Ok(Self {
content_location: content_location_from_headers(headers)?,
last_state_change: last_state_change_from_headers(headers)?,
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/src/operations/list_triggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl ListTriggersResponse {
let response: Response = body.json().await?;

Ok(Self {
rid: response.rid.to_owned(),
rid: response.rid.clone(),
triggers: response.triggers,
content_location: content_location_from_headers(&headers)?,
server: server_from_headers(&headers)?,
Expand Down
5 changes: 4 additions & 1 deletion sdk/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ openssl = { version = "0.10.46", optional=true }
uuid = { version = "1.0", features = ["v4"] }
pin-project = "1.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
async-process = "2.0"

[target.'cfg(unix)'.dependencies]
tz-rs = { version = "0.6", optional = true }

Expand All @@ -36,7 +39,7 @@ tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
env_logger = "0.10"
serde_test = "1"
azure_security_keyvault = { path = "../security_keyvault", default-features = false }
serial_test = "2.0"
serial_test = "3.0"

[features]
default = ["development", "enable_reqwest", "old_azure_cli"]
Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/examples/azure_cli_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use url::Url;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let sub_id = AzureCliCredential::get_subscription()?;
let sub_id = AzureCliCredential::get_subscription().await?;
println!("Azure cli subscription: {sub_id}");

let creds = AzureCliCredential::new();
Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/src/authorization_code_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn start(
// Create a PKCE code verifier and SHA-256 encode it as a code challenge.
let (pkce_code_challenge, pkce_code_verifier) = oauth2::PkceCodeChallenge::new_random_sha256();

let scopes = scopes.iter().map(|s| Scope::new(s.to_string()));
let scopes = scopes.iter().map(ToString::to_string).map(Scope::new);

// Generate the authorization URL to which we'll redirect the user.
let (authorize_url, csrf_state) = client
Expand Down
Loading

0 comments on commit 6d49499

Please sign in to comment.