Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customttl #503

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 5 additions & 1 deletion src/lib/auth/databaseKeys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class DatabaseKeys {
this.role = argv.role || DEFAULT_ROLE;
this.keyName = DatabaseKeys.getKeyName(this.path, this.role);
this.keyStore = new SecretKeyStorage(accountKey);
this.ttlMs = TTL_DEFAULT_MS;
this.ttlMs = Math.min(argv.keyTtlSeconds * 1000, TTL_DEFAULT_MS);

const storedKey = this.keyStore.get(this.keyName)?.secret;
const { key, keySource } = DatabaseKeys.resolveKeySources(argv, storedKey);
Expand Down Expand Up @@ -70,6 +70,10 @@ export class DatabaseKeys {
}

getKeyExpiration() {
this.logger.debug(
`Refreshing database key with a ttl of ${this.ttlMs} milliseconds`,
"creds",
);
return Date.now() + this.ttlMs;
}

Expand Down
9 changes: 9 additions & 0 deletions src/lib/command-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ const COMMON_QUERY_OPTIONS = {
required: false,
group: "API:",
},
keyTtlSeconds: {
type: "number",
description:
"The time-to-live for generated database keys, in seconds. Maximum of 900",
required: false,
hidden: true,
default: 900,
group: "API:",
},
database: {
alias: "d",
type: "string",
Expand Down
2 changes: 0 additions & 2 deletions src/lib/fauna-account-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import { container } from "../cli.mjs";
import { InvalidCredsError } from "./misc.mjs";

// const KEY_TTL_DEFAULT_MS = 1000 * 60 * 60 * 24;

/**
* Class representing a client for interacting with the Fauna account API.
*/
Expand Down Expand Up @@ -132,7 +130,7 @@
* @throws {Error} - Throws an error if there is an issue during session retrieval.
*/

// TODO: get/set expiration details

Check warning on line 133 in src/lib/fauna-account-client.mjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO: get/set expiration details'
static async getSession(accessToken) {
const makeAccountRequest = container.resolve("makeAccountRequest");
try {
Expand All @@ -149,7 +147,7 @@
}
}

// TODO: get/set expiration details

Check warning on line 150 in src/lib/fauna-account-client.mjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO: get/set expiration details'
/**
* Uses refreshToken to get a new accountKey and refreshToken.
* @param {*} refreshToken
Expand Down
Loading