2024-04-09 18:55:08 +01:00
|
|
|
import { AzureCliCredentials } from "@azure/ms-rest-nodeauth";
|
2020-09-30 21:42:33 +01:00
|
|
|
import crypto from "crypto";
|
|
|
|
|
2020-11-02 19:33:14 +00:00
|
|
|
export function generateUniqueName(baseName = "", length = 4): string {
|
2020-09-30 21:42:33 +01:00
|
|
|
return `${baseName}${crypto.randomBytes(length).toString("hex")}`;
|
|
|
|
}
|
2021-02-18 13:40:58 +00:00
|
|
|
|
2021-04-21 18:45:34 +01:00
|
|
|
export function generateDatabaseNameWithTimestamp(baseName = "db", length = 1): string {
|
2021-03-05 00:12:31 +00:00
|
|
|
return `${baseName}${crypto.randomBytes(length).toString("hex")}-${Date.now()}`;
|
|
|
|
}
|
2024-04-09 18:55:08 +01:00
|
|
|
|
|
|
|
export async function getAzureCLICredentials(): Promise<AzureCliCredentials> {
|
|
|
|
return await AzureCliCredentials.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getAzureCLICredentialsToken(): Promise<string> {
|
|
|
|
const credentials = await getAzureCLICredentials();
|
|
|
|
const token = (await credentials.getToken()).accessToken;
|
|
|
|
return token;
|
|
|
|
}
|