Skip to content

Commit

Permalink
Allow token to be passed for pregen
Browse files Browse the repository at this point in the history
  • Loading branch information
dokempf committed Sep 24, 2024
1 parent 0349642 commit d07a037
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
5 changes: 4 additions & 1 deletion src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ export class PrefetchCommand extends Command {
multiple: true,
exclusive: ['exclude_mask'],
}),
token: Flags.string({
description: 'A session token to use for the prefetch',
}),
}

async run() {
const { flags } = await this.parse(PrefetchCommand);
const instance = flags.instance;

const data = await accessInstance(instance);
const data = await accessInstance(instance, flags.token);

data.masks = filterMasks(data.masks, flags.include_mask, flags.exclude_mask);

Expand Down
42 changes: 22 additions & 20 deletions src/lib/easydbData.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@ function reorganize_schemas(schemadata) {
return newdata;
}

export async function accessInstance(instance) {
// Get a session token from the EasyDB instance
const token_response = await fetch(`${instance}/api/session`);
if(token_response.status != 200) {
throw new Error("Could not get a session token from the EasyDB instance.");
}
const token_json = await token_response.json();
const token = token_json.token;
export async function accessInstance(instance, token = null) {
if(token === null) {
// Get a session token from the EasyDB instance
const token_response = await fetch(`${instance}/api/session`);
if(token_response.status != 200) {
throw new Error("Could not get a session token from the EasyDB instance.");
}
const token_json = await token_response.json();
token = token_json.token;

// Authenticcate the session token
const auth_response = await fetch(
`${instance}/api/session/authenticate?` +
new URLSearchParams({
token: token,
method: 'anonymous',
}),
{
method: 'POST',
// Authenticcate the session token
const auth_response = await fetch(
`${instance}/api/session/authenticate?` +
new URLSearchParams({
token: token,
method: 'anonymous',
}),
{
method: 'POST',
}
);
if(auth_response.status != 200) {
throw new Error("Could not authenticate the session token.");
}
);
if(auth_response.status != 200) {
throw new Error("Could not authenticate the session token.");
}

// Fetch all the masks for this instance
Expand Down

0 comments on commit d07a037

Please sign in to comment.