@dataroadinc/setup-auth
Version:
CLI tool and programmatic API for automated OAuth setup across cloud platforms
22 lines (21 loc) • 772 B
JavaScript
export async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export async function waitForIamPropagation(checkFn, options) {
const timeoutMs = options?.timeoutMs ?? 30000;
const intervalMs = options?.intervalMs ?? 2000;
const description = options?.description ?? "IAM propagation";
const start = Date.now();
let firstWait = true;
while (Date.now() - start < timeoutMs) {
if (await checkFn()) {
return;
}
if (firstWait) {
console.log(`Waiting for ${description} to propagate...`);
firstWait = false;
}
await sleep(intervalMs);
}
throw new Error(`Timed out after ${timeoutMs / 1000}s waiting for ${description} to propagate.`);
}