Skip to content

call az through cmd on windows #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions sdks/auth_aad/src/token_credentials/cli_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,33 @@ pub struct AzureCliCredential;
#[async_trait::async_trait]
impl TokenCredential for AzureCliCredential {
async fn get_token(&self, resource: &str) -> Result<TokenResponse, AzureError> {
let az_command = Command::new("az")
.args(&[
"account",
"get-access-token",
"--output",
"json",
"--resource",
resource,
])
.output();
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",
"json",
"--resource",
resource,
])
.output()
} else {
Command::new("az")
.args(&[
"account",
"get-access-token",
"--output",
"json",
"--resource",
resource,
])
.output()
};

let res = match az_command {
Ok(az_output) => {
Expand Down