I have an Azure subscription and I am using Azure Container Registry.
I need to docker login
to access my repository. This is easily done using the CLIs [docs]:
TOKEN=$(az acr login --name <acrName> --expose-token --output tsv --query accessToken)
docker login myregistry.azurecr.io --username 00000000-0000-0000-0000-000000000000 --password-stdin <<< $TOKEN
Is there a way to get this token using the official SDK? Specifically javascript SDK.
I instantiate the ACR client this way, but I don't see a way to retrieve the token. Yet the CLI tool is clearly capable of doing that :)
const credential = new DefaultAzureCredential();
const client = new ContainerRegistryClient(endpoint, credential);
For context, in AWS ECR this is achieved with GetAuthorizationTokenCommand
command on ECR client [docs]. The response includes the token:
{ // GetAuthorizationTokenResponse
authorizationData: [ // AuthorizationDataList
{ // AuthorizationData
authorizationToken: "STRING_VALUE",
expiresAt: new Date("TIMESTAMP"),
proxyEndpoint: "STRING_VALUE",
},
],
};
I was looking up the same for .NET SDK, however it doesn't seem like SDKs support this at this point (get a ACR specific access token with the right scope). I ended up calling the REST APIs referring to this nice post by Brandon Mitchell - https://tobiasfenster.io/getting-oci-annotations--docker-image-labels-from-an-azure-container-registry-in-kubernetes
Here is the associated github issue - https://github.com/Azure/azure-sdk-for-js/issues/27635