-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a key --------- Co-authored-by: Ashton Eby <[email protected]> Co-authored-by: Ashton Eby <[email protected]>
- Loading branch information
1 parent
4fd660a
commit a7227a3
Showing
13 changed files
with
254 additions
and
90 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { DateTime, Settings } from "luxon"; | ||
|
||
import { container } from "../../cli.mjs"; | ||
import { FaunaAccountClient } from "../../lib/fauna-account-client.mjs"; | ||
import { formatObject } from "../../lib/misc.mjs"; | ||
|
||
Settings.defaultZone = "utc"; | ||
|
||
async function createKey(argv) { | ||
if (argv.secret) { | ||
return createKeyWithSecret(argv); | ||
} | ||
return createKeyWithAccountApi(argv); | ||
} | ||
|
||
async function createKeyWithSecret(/*argv*/) { | ||
const logger = container.resolve("logger"); | ||
logger.stderr("TODO"); | ||
} | ||
|
||
async function createKeyWithAccountApi(argv) { | ||
const accountClient = new FaunaAccountClient(); | ||
const { database, keyRole, ttl, name } = argv; | ||
const databaseKey = await accountClient.createKey({ | ||
path: database, | ||
role: keyRole, | ||
ttl, | ||
name, | ||
}); | ||
const { path: db, ...rest } = databaseKey; | ||
container | ||
.resolve("logger") | ||
.stdout(formatObject({ ...rest, database: db }, argv)); | ||
} | ||
|
||
function buildCreateCommand(yargs) { | ||
return yargs | ||
.options({ | ||
name: { | ||
type: "string", | ||
required: false, | ||
description: "The name of the key", | ||
}, | ||
ttl: { | ||
type: "string", | ||
required: false, | ||
description: | ||
"The time-to-live for the key. Provide as an ISO 8601 date time string.", | ||
}, | ||
keyRole: { | ||
type: "string", | ||
required: true, | ||
description: "The role to assign to the key; e.g. admin", | ||
}, | ||
}) | ||
.check((argv) => { | ||
if (argv.ttl && !DateTime.fromISO(argv.ttl).isValid) { | ||
throw new Error( | ||
`Invalid ttl '${argv.ttl}'. Provide as an ISO 8601 date time string.`, | ||
); | ||
} | ||
if (argv.database === undefined && argv.secret === undefined) { | ||
throw new Error( | ||
"You must provide at least one of: --database, --secret, --local.", | ||
); | ||
} | ||
return true; | ||
}) | ||
.help("help", "show help"); | ||
} | ||
|
||
export default { | ||
command: "create", | ||
describe: "Create a key for a database", | ||
builder: buildCreateCommand, | ||
handler: createKey, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//@ts-check | ||
|
||
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs"; | ||
import createCommand from "./create.mjs"; | ||
|
||
function buildKeyCommand(yargs) { | ||
return yargsWithCommonQueryOptions(yargs) | ||
.command(createCommand) | ||
.demandCommand() | ||
.help("help", "show help"); | ||
} | ||
|
||
export default { | ||
command: "key <method>", | ||
describe: "Create and manage database keys", | ||
builder: buildKeyCommand, | ||
handler: () => {}, // eslint-disable-line no-empty-function | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,4 +100,5 @@ export function applyLocalArg(argv) { | |
argv, | ||
); | ||
} | ||
return argv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.