Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions quetzal/src/actions/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
setup_script,
home_script,
set_authorized_keys,
is_user_created,
} from "../os/os_functions.js";
import markdown_message from "../blocks/markdown_message.js";

Expand Down Expand Up @@ -103,8 +104,21 @@ export function approve(app: Slack.App) {
}
console.log(`Password set for ${username}`);

// Delay 6 minutes to allow time for caching
await new Promise((resolve) => setTimeout(resolve, 1000 * 60 * 6));
let userCreated = is_user_created(username);
let checks = 0;
while (!userCreated) {
// Cancel and alert if it's been more than 10 minutes
if (checks >= 10) {
throw new Error(
`User ${username} is not on the Nest VM after 10 minutes`,
);
}

await new Promise((resolve) => setTimeout(resolve, 1000 * 60));
userCreated = is_user_created(username);

checks++;
}

await setup_script(username);
await home_script(username);
Expand Down
8 changes: 8 additions & 0 deletions quetzal/src/os/os_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ export async function set_authorized_keys(user: string, keys: string[]) {

console.log(stdout);
}

export async function is_user_created(username: string) {
const { stdout, stderr } = await execPromise(`id ${username}`);

if (stderr) console.error(stderr);

return !stdout.includes("no such user");
}