How generate passwords when creating a token for Container Registry auth

228 Views Asked by At

I'm trying to generate a new auth token with beginCreateAndWait, but passwords are not being generated with the token, I'm getting an empty array in token.credentials.passwords and when looking in the Portal, no passwords were generated for the token. I tried to provoke generation of these credentials by including values in the tokenCreateParameters parameter as such:

      credentials: {
        passwords: [{ name: 'password1' }],
      },

However this causes an error to be thrown: "New passwords can be added only through 'generateCredentials'. For more information on repository permissions, please visit https://aka.ms/acr/repo-permissions."

Following the link brings you to the CLI documentation.

The docs describe how to generate these passwords with the CLI here, but I'm using the JavaScript SDK, for which the documentation is sorely lacking. I've been searching for over an hour now and can't find any documentation about how to generate passwords for tokens with the SDK.

Can I somehow just generate the passwords at the same time as the token? If not, how do I generate them programmatically with the SDK?

1

There are 1 best solutions below

0
On

Through scouring the docs, I finally found the method for generating credentials here in the Registries interface. You can use beginGenerateCredentialsAndWait:

function beginGenerateCredentialsAndWait(
  resourceGroupName: string,
  registryName: string,
  generateCredentialsParameters: GenerateCredentialsParameters,
  options?: RegistriesGenerateCredentialsOptionalParams
): Promise<GenerateCredentialsResult>

where GenerateCredentialsParameters has these properties:

{
  expiry?: Date, // The expiry date of the generated credentials after which the credentials become invalid.
  name?: string, // Specifies name of the password which should be regenerated if any -- password1 or password2.
  tokenId?: string, // The resource ID of the token for which credentials have to be generated.
}