Skip to content

Commit 1c1dfb2

Browse files
committed
Add az CLI shim for DefaultAzureCredential support in Codespaces
1 parent 9223123 commit 1c1dfb2

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/artifacts-helper/NOTES.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
This installs [Azure Artifacts Credential Provider](https://github.com/microsoft/artifacts-credprovider)
2-
and optionally configures shims which shadow `dotnet`, `nuget`, `npm`, `yarn`, `rush`, and `pnpm`.
3-
These dynamically sets an authentication token for pulling artifacts from a feed before running the command.
2+
and optionally configures shims which shadow `dotnet`, `nuget`, `npm`, `yarn`, `rush`, `pnpm`, and `az`.
3+
These dynamically set an authentication token for pulling artifacts from a feed before running the command.
4+
5+
The `az` shim specifically intercepts `az account get-access-token` requests and uses the `azure-auth-helper`
6+
to acquire tokens via the ado-codespaces-auth VS Code extension. This enables `DefaultAzureCredential`'s
7+
`AzureCliCredential` to work in Codespaces without requiring `az login`.
48

59
For `npm`, `yarn`, `rush`, and `pnpm` this requires that your `~/.npmrc` file is configured to use the ${ARTIFACTS_ACCESSTOKEN}
610
environment variable for the `authToken`. A helper script has been added that you can use to write your `~/.npmrc`

src/artifacts-helper/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Configures Codespace to authenticate with Azure Artifact feeds
2424
| npxAlias | Create alias for npx | boolean | true |
2525
| rushAlias | Create alias for rush | boolean | true |
2626
| pnpmAlias | Create alias for pnpm | boolean | true |
27+
| azAlias | Create alias for az (Azure CLI) | boolean | true |
2728
| shimDirectory | Directory where the shims will be installed. This must be in $PATH, and needs to be as early as possible in priority for the scripts to override the base executables. | string | /usr/local/share/codespace-shims |
2829
| targetFiles | Comma separated list of files to write to. Default is '/etc/bash.bashrc,/etc/zsh/zshrc' for root and '~/.bashrc,~/.zshrc' for non-root | string | DEFAULT |
2930
| python | Install Python keyring helper for pip | boolean | false |
@@ -35,8 +36,12 @@ Configures Codespace to authenticate with Azure Artifact feeds
3536
- `ms-codespaces-tools.ado-codespaces-auth`
3637

3738
This installs [Azure Artifacts Credential Provider](https://github.com/microsoft/artifacts-credprovider)
38-
and optionally configures shims which shadow `dotnet`, `nuget`, `npm`, `yarn`, `rush`, and `pnpm`.
39-
These dynamically sets an authentication token for pulling artifacts from a feed before running the command.
39+
and optionally configures shims which shadow `dotnet`, `nuget`, `npm`, `yarn`, `rush`, `pnpm`, and `az`.
40+
These dynamically set an authentication token for pulling artifacts from a feed before running the command.
41+
42+
The `az` shim specifically intercepts `az account get-access-token` requests and uses the `azure-auth-helper`
43+
to acquire tokens via the ado-codespaces-auth VS Code extension. This enables `DefaultAzureCredential`'s
44+
`AzureCliCredential` to work in Codespaces without requiring `az login`.
4045

4146
For `npm`, `yarn`, `rush`, and `pnpm` this requires that your `~/.npmrc` file is configured to use the ${ARTIFACTS_ACCESSTOKEN}
4247
environment variable for the `authToken`. A helper script has been added that you can use to write your `~/.npmrc`

src/artifacts-helper/devcontainer-feature.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
"default": true,
5050
"description": "Create alias for pnpm"
5151
},
52+
"azAlias": {
53+
"type": "boolean",
54+
"default": true,
55+
"description": "Create alias for az (Azure CLI)"
56+
},
5257
"shimDirectory": {
5358
"type": "string",
5459
"default": "/usr/local/share/codespace-shims",

src/artifacts-helper/install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ALIAS_YARN="${YARNALIAS:-"true"}"
1111
ALIAS_NPX="${NPXALIAS:-"true"}"
1212
ALIAS_RUSH="${RUSHALIAS:-"true"}"
1313
ALIAS_PNPM="${PNPMALIAS:-"true"}"
14+
ALIAS_AZ="${AZALIAS:-"true"}"
1415
INSTALL_PIP_HELPER="${PYTHON:-"false"}"
1516
SHIM_DIRECTORY="${SHIMDIRECTORY:-"/usr/local/share/codespace-shims/"}"
1617

@@ -39,6 +40,9 @@ if [ "${ALIAS_PNPM}" = "true" ]; then
3940
ALIASES_ARR+=('pnpm')
4041
ALIASES_ARR+=('pnpx')
4142
fi
43+
if [ "${ALIAS_AZ}" = "true" ]; then
44+
ALIASES_ARR+=('az')
45+
fi
4246

4347
# Source /etc/os-release to get OS info
4448
. /etc/os-release

0 commit comments

Comments
 (0)