From 6919a3681cabede27829f13bdba8fa3813a7296b Mon Sep 17 00:00:00 2001 From: gzp Date: Fri, 9 Oct 2020 17:36:40 +0200 Subject: [PATCH 1/3] call az through cmd on windows --- .../src/token_credentials/cli_credentials.rs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sdks/auth_aad/src/token_credentials/cli_credentials.rs b/sdks/auth_aad/src/token_credentials/cli_credentials.rs index 4fadcf173d..ce0de90863 100644 --- a/sdks/auth_aad/src/token_credentials/cli_credentials.rs +++ b/sdks/auth_aad/src/token_credentials/cli_credentials.rs @@ -39,8 +39,13 @@ pub struct AzureCliCredential; #[async_trait::async_trait] impl TokenCredential for AzureCliCredential { async fn get_token(&self, resource: &str) -> Result { - let az_command = Command::new("az") + let az_command = if cfg!(target_os = "windows") { + // on window az is a cmd and it should be called like this + // see https://doc.rust-lang.org/nightly/std/process/struct.Command.html + Command::new("cmd") .args(&[ + "/C", + "az", "account", "get-access-token", "--output", @@ -48,7 +53,18 @@ impl TokenCredential for AzureCliCredential { "--resource", resource, ]) - .output(); + } else { + Command::new("az") + .args(&[ + "account", + "get-access-token", + "--output", + "json", + "--resource", + resource, + ]) + }; + let az_command = az_command.output(); let res = match az_command { Ok(az_output) => { From 56c749c8a52db1e87346105cca4f82bea8d64f0e Mon Sep 17 00:00:00 2001 From: gzp Date: Fri, 9 Oct 2020 17:40:11 +0200 Subject: [PATCH 2/3] call az through cmd on windows --- sdks/auth_aad/src/token_credentials/cli_credentials.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdks/auth_aad/src/token_credentials/cli_credentials.rs b/sdks/auth_aad/src/token_credentials/cli_credentials.rs index ce0de90863..1f1e2cf665 100644 --- a/sdks/auth_aad/src/token_credentials/cli_credentials.rs +++ b/sdks/auth_aad/src/token_credentials/cli_credentials.rs @@ -52,7 +52,7 @@ impl TokenCredential for AzureCliCredential { "json", "--resource", resource, - ]) + ]).output() } else { Command::new("az") .args(&[ @@ -62,9 +62,8 @@ impl TokenCredential for AzureCliCredential { "json", "--resource", resource, - ]) + ]).output() }; - let az_command = az_command.output(); let res = match az_command { Ok(az_output) => { From e2c52871a9400f7f1e809bb2c1eda517407b3392 Mon Sep 17 00:00:00 2001 From: gzp Date: Mon, 12 Oct 2020 09:01:37 +0200 Subject: [PATCH 3/3] cargo fmt --- .../src/token_credentials/cli_credentials.rs | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/sdks/auth_aad/src/token_credentials/cli_credentials.rs b/sdks/auth_aad/src/token_credentials/cli_credentials.rs index 1f1e2cf665..1aba7d4c1d 100644 --- a/sdks/auth_aad/src/token_credentials/cli_credentials.rs +++ b/sdks/auth_aad/src/token_credentials/cli_credentials.rs @@ -43,26 +43,28 @@ impl TokenCredential for AzureCliCredential { // on window az is a cmd and it should be called like this // see https://doc.rust-lang.org/nightly/std/process/struct.Command.html Command::new("cmd") - .args(&[ - "/C", - "az", - "account", - "get-access-token", - "--output", - "json", - "--resource", - resource, - ]).output() + .args(&[ + "/C", + "az", + "account", + "get-access-token", + "--output", + "json", + "--resource", + resource, + ]) + .output() } else { Command::new("az") - .args(&[ - "account", - "get-access-token", - "--output", - "json", - "--resource", - resource, - ]).output() + .args(&[ + "account", + "get-access-token", + "--output", + "json", + "--resource", + resource, + ]) + .output() }; let res = match az_command {