Skip to content

Commit

Permalink
handle accountKey arg with user and secret (#500)
Browse files Browse the repository at this point in the history
* handle accountKey arg with user and secret

* Update src/lib/command-helpers.mjs

Co-authored-by: James Rodewig <[email protected]>

* use camel case

---------

Co-authored-by: James Rodewig <[email protected]>
  • Loading branch information
mwilde345 and jrodewig authored Dec 10, 2024
1 parent 4eed51c commit 42d02d6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
27 changes: 18 additions & 9 deletions src/lib/auth/credentials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ import { AccountKeys } from "./accountKeys.mjs";
import { DatabaseKeys } from "./databaseKeys.mjs";

const validateCredentialArgs = (argv) => {
if (argv.database && argv.secret && !argv.local) {
throw new ValidationError(
"Cannot use both the '--secret' and '--database' options together. Please specify only one.",
);
} else if (argv.role && argv.secret && !argv.local) {
// The '--role' option is not supported when using a secret. Secrets have an
// implicit role.
throw new ValidationError(
"The '--role' option is not supported when using a '--secret'. Please specify only one.",
const logger = container.resolve("logger");
const illegalArgCombos = [
["accountKey", "secret", "local"],
["secret", "database", "local"],
["secret", "role", "local"],
];
for (const [first, second, conditional] of illegalArgCombos) {
if (argv[first] && argv[second] && !argv[conditional]) {
throw new ValidationError(
`Cannot use both the '--${first}' and '--${second}' options together. Please specify only one.`,
);
}
}

if (argv.user && argv.accountKey) {
logger.debug(
"Both 'user' and 'accountKey' arguments were specified. 'accountKey' will be used to mint database secrets. 'user' will be ignored.",
"creds",
);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib/auth/databaseKeys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class DatabaseKeys {
// argv.secret comes from flag, config, or FAUNA_SECRET
if (argv.secret) {
key = argv.secret;
keySource = "--secret";
keySource = "user";
} else {
key = storedKey;
keySource = "credentials-file";
Expand Down
4 changes: 3 additions & 1 deletion src/lib/command-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ const COMMON_QUERY_OPTIONS = {
},
accountKey: {
type: "string",
description: "The account key to use when calling Fauna",
description:
"Fauna account key used for authentication. Negates the need for a user login. The key is used to generate short-lived database secrets for the CLI. Mutually exclusive with `--user` and `--secret`.",
required: false,
group: "API:",
},
database: {
alias: "d",
Expand Down
2 changes: 1 addition & 1 deletion test/credentials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe("credentials", function () {
databaseKeys: {
role: undefined,
key: "user-secret",
keySource: "--secret",
keySource: "user",
},
},
},
Expand Down

0 comments on commit 42d02d6

Please sign in to comment.