Skip to content

Commit

Permalink
run prettify, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-bravo-yahoo authored and cleve-fauna committed Dec 5, 2024
1 parent 622a945 commit 05c286e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 36 deletions.
27 changes: 13 additions & 14 deletions src/commands/key/create.mjs
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
import { DateTime, Settings } from "luxon";

import { container } from "../../cli.mjs";
import { FaunaAccountClient } from "../../lib/fauna-account-client.mjs";
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
import { Settings, DateTime } from "luxon";
import { FaunaAccountClient } from "../../lib/fauna-account-client.mjs";
import { formatObject } from "../../lib/misc.mjs";

Settings.defaultZone = "utc";

async function createKey(argv) {
console.log("createKey");
if (argv.secret) {
return createKeyWithSecret(argv);
}
return createKeyWithAccountApi(argv);
}

async function createKeyWithSecret(argv) {
async function createKeyWithSecret(/*argv*/) {
const logger = container.resolve("logger");
logger.stderr("TODO");
}

async function createKeyWithAccountApi(argv) {
console.log("createKeyWithAccountApi");
const AccountClient = new FaunaAccountClient();
const { database, role, ttl, name, json, color } = argv;
const { database, role, ttl, name /*json, color*/ } = argv;
const databaseKey = await AccountClient.createKey({
path: database,
role,
ttl,
name,
});
const { path: _, ...rest } = databaseKey;
const { /*path: _,*/ ...rest } = databaseKey;
container.resolve("logger").stdout(formatObject(rest));
}

function buildCreateCommand(yargs) {
console.log("buildCreateCommand");
return yargsWithCommonQueryOptions(yargs)
.options({
name: {
Expand All @@ -45,16 +43,17 @@ function buildCreateCommand(yargs) {
ttl: {
type: "string",
required: false,
description: "The time-to-live for the key. Provide as an ISO 8601 date time string.",
}
description:
"The time-to-live for the key. Provide as an ISO 8601 date time string.",
},
})
.default("role", "admin")
.demandOption(["database"])
.check((argv) => {
console.log("Checking");
if (argv.ttl && !DateTime.fromISO(argv.ttl).isValid) {
console.log("no bueno");
throw new Error(`Invalid ttl '${argv.ttl}'. Provide as an ISO 8601 date time string.`);
throw new Error(
`Invalid ttl '${argv.ttl}'. Provide as an ISO 8601 date time string.`,
);
}
return true;
})
Expand All @@ -66,4 +65,4 @@ export default {
describe: "Create a key for a database",
builder: buildCreateCommand,
handler: createKey,
}
};
8 changes: 2 additions & 6 deletions src/commands/key/key.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
import createCommand from "./create.mjs";

function buildKeyCommand(yargs) {
console.log("KEY COMMAND");
return yargs
.command(createCommand)
.demandCommand()
.help("help", "show help");
return yargs.command(createCommand).demandCommand().help("help", "show help");
}

export default {
command: "key <method>",
describe: "Create and manage database keys",
builder: buildKeyCommand,
handler: () => {},
handler: () => {}, // eslint-disable-line no-empty-function
};
2 changes: 0 additions & 2 deletions src/lib/auth/credentials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ export class Credentials {
* @param {*} argv
*/
export function buildCredentials(argv) {
console.log("IN CREDS");
const credentials = new Credentials(argv);
container.register({
credentials: asValue(credentials, { lifetime: Lifetime.SINGLETON }),
});
console.log("LEAVING CREDS");
}
2 changes: 1 addition & 1 deletion src/lib/fauna-account-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { container } from "../cli.mjs";
import { InvalidCredsError } from "./misc.mjs";

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

/**
* Class representing a client for interacting with the Fauna account API.
Expand Down
6 changes: 0 additions & 6 deletions src/lib/middleware.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const LOCAL_SECRET = "secret";
const DEFAULT_URL = "https://db.fauna.com";

export function logArgv(argv) {
console.log("logArgv");
const logger = container.resolve("logger");
logger.debug(JSON.stringify(argv, null, 4), "argv", argv);
logger.debug(
Expand All @@ -35,7 +34,6 @@ function captureEnvVars() {
}

export function fixPaths(argv) {
console.log("fixPaths");
if (argv.dir) {
return { ...argv, dir: fixPath(argv.dir) };
} else {
Expand All @@ -44,7 +42,6 @@ export function fixPaths(argv) {
}

export function checkForUpdates(argv) {
console.log("checkForUpdates");
// TODO: figure out upgrade path for SEA installations

Check warning on line 45 in src/lib/middleware.mjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO: figure out upgrade path for SEA...'
if (isSea()) return argv;

Expand All @@ -64,7 +61,6 @@ export function checkForUpdates(argv) {
});

notifier.notify();
console.log("checkForUpdates done");
return argv;
}

Expand All @@ -78,7 +74,6 @@ export function checkForUpdates(argv) {
* @returns {void}
*/
export function applyLocalArg(argv) {
console.log("applyLocalArg");
const logger = container.resolve("logger");
if (!argv.url) {
if (argv.local) {
Expand All @@ -105,6 +100,5 @@ export function applyLocalArg(argv) {
argv,
);
}
console.log("applyLocalArg done");
return argv;
}
10 changes: 3 additions & 7 deletions test/key/create.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import { run } from "../../src/cli.mjs";
import { setupTestContainer as setupContainer } from "../../src/config/setup-test-container.mjs";

describe.only("key create", () => {
let container,
fs,
logger;
let container, /*fs,*/ logger;

beforeEach(() => {
// reset the container before each test
container = setupContainer();
fs = container.resolve("fs");
// fs = container.resolve("fs");
logger = container.resolve("logger");
});

Expand All @@ -30,13 +28,11 @@ describe.only("key create", () => {
].forEach(({ command, expected }) => {
it("Provides clear error when invalid args are provided", async () => {
try {
console.log("running");
await run(command, container);
} catch (e) {}

expect(logger.stderr).to.have.been.calledWith(sinon.match(expected));
expect(container.resolve("parseYargs")).to.have.been.calledOnce;
});
});

});

0 comments on commit 05c286e

Please sign in to comment.