Skip to content

Commit

Permalink
logger component
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilde345 committed Nov 23, 2024
1 parent b25d691 commit f0cf18e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function buildYargs(argvInput) {
"components to emit diagnostic logs for; this takes precedence over the 'verbosity' flag",
type: "array",
default: [],
choices: ["fetch", "error", "argv"],
choices: ["fetch", "error", "argv", "client"],
},
// Whether authNZ middleware should run. Better way of doing this?
authRequired: {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/command-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ export async function getSimpleClient(argv) {
const { profile, secret } = argv;
const accountKey = getAccountKey(profile).accountKey;
if (secret) {
logger.debug("Using Database secret from command line flag");
logger.debug("Using Database secret from command line flag", "client");
} else if (process.env.FAUNA_SECRET) {
logger.debug(
"Using Database secret from FAUNA_SECRET environment variable",
"client",
);
}
const secretSource = secret ? "command line flag" : "environment variable";
Expand All @@ -59,6 +60,7 @@ export async function getSimpleClient(argv) {
} else {
logger.debug(
"No secret provided, checking for stored secret in credentials file",
"client",
);
client = await clientFromStoredSecret({
argv,
Expand Down Expand Up @@ -89,7 +91,7 @@ async function clientFromStoredSecret({ argv, accountKey }) {
const newArgs = [args[0], { ...args[1], secret: existingSecret }];
return originalQuery(...newArgs).then(async (result) => {
if (result.status === 401) {
logger.debug("stored secret is invalid, refreshing");
logger.debug("stored secret is invalid, refreshing", "client");
// Refresh the secret, store it, and use it to try again
const newSecret = await refreshDBKey(argv);
const newArgs = [args[0], { ...args[1], secret: newSecret.secret }];
Expand Down
6 changes: 5 additions & 1 deletion src/lib/fauna-account-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export class FaunaAccountClient {
result = await original(args);
} catch (e) {
if (e instanceof InvalidCredsError) {
logger.debug("401 in account api, attempting to refresh session");
logger.debug(
"401 in account api, attempting to refresh session",
"client",
);
try {
const { accountKey: newAccountKey, refreshToken: newRefreshToken } =
await refreshSession(this.profile);
Expand All @@ -36,6 +39,7 @@ export class FaunaAccountClient {
if (e instanceof InvalidCredsError) {
logger.debug(
"Failed to refresh session, expired or missing refresh token",
"client",
);
promptLogin();
} else {
Expand Down

0 comments on commit f0cf18e

Please sign in to comment.