in src/login/updateSubscriptions.ts [44:89]
async function loadTenants(): Promise<TenantIdDescription[]> {
const knownTenantIds: Set<string> = new Set();
const knownTenants: TenantIdDescription[] = [];
for (const session of ext.loginHelper.api.sessions) {
const client: SubscriptionClient = new SubscriptionClient(session.credentials2, { baseUri: session.environment.resourceManagerEndpointUrl });
let url: string | undefined = 'https://management.azure.com/tenants?api-version=2020-01-01';
do {
const options: RequestPrepareOptions = {
url,
method: 'GET'
};
const response: HttpOperationResponse = await client.sendRequest(options)
if (response.parsedBody && 'value' in response.parsedBody) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
const value: any = response.parsedBody.value;
if (Array.isArray(value)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const tenants: any[] = value as any[];
tenants.forEach(tenant => {
if ('tenantId' in tenant && 'displayName' in tenant) {
const sanitizedTenant: TenantIdDescription = tenant as TenantIdDescription;
if (!knownTenantIds.has(sanitizedTenant.tenantId)) {
knownTenantIds.add(sanitizedTenant.tenantId);
knownTenants.push(tenant);
}
}
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if ('nextLink' in response.parsedBody) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
url = response.parsedBody.nextLink as string | undefined;
} else {
url = undefined;
}
}
}
} while (url);
}
return knownTenants;
}