Skip to content

Commit

Permalink
don't compute role from key name string when calling frontdoor (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
wildemat authored Dec 9, 2024
1 parent de234ba commit 40242a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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

0 comments on commit 40242a4

Please sign in to comment.