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

don't compute role from key name string when calling frontdoor #493

Merged
merged 2 commits into from
Dec 9, 2024
Merged
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
14 changes: 8 additions & 6 deletions src/lib/auth/databaseKeys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const DEFAULT_ROLE = "admin";
*/
export class DatabaseKeys {
constructor(argv, accountKey) {
const { database } = argv;
this.path = argv.database;
this.role = argv.role || DEFAULT_ROLE;
this.keyName = DatabaseKeys.getKeyName(database, this.role);
this.keyName = DatabaseKeys.getKeyName(this.path, this.role);
this.keyStore = new SecretKeyStorage(accountKey);
this.ttlMs = TTL_DEFAULT_MS;

Expand Down Expand Up @@ -113,13 +113,15 @@ export class DatabaseKeys {
* @returns {string} - The new secret
*/
async refreshKey() {
this.logger.debug(`Creating new db key for ${this.keyName}`, "creds");
const [path, role] = this.keyName.split(":");
this.logger.debug(
`Creating new db key for path ${this.path} and role ${this.role}`,
"creds",
);
const expiration = this.getKeyExpiration();
const accountClient = new FaunaAccountClient();
const newSecret = await accountClient.createKey({
path,
role,
path: this.path,
role: this.role,
name: "System generated shell key",
ttl: new Date(expiration).toISOString(),
});
Expand Down
12 changes: 12 additions & 0 deletions test/credentials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ describe("credentials", function () {
},
},
},
{
command: `query "Database.all()" -d us-std/test:badpath --no-color`,
localCreds: defaultLocalCreds,
expected: {
databaseKeys: {
role: "admin",
path: "us-std/test:badpath",
key: undefined,
keySource: "credentials-file",
},
},
},
].forEach(({ command, expected, localCreds }) => {
it(`builds credentials from: '${command}'`, async () => {
setCredsFiles(localCreds.accountKeys, localCreds.databaseKeys);
Expand Down
Loading