-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from CodeGrade/feat/list-and-delete-keys
List and Delete API Keys from Command Line
- Loading branch information
Showing
7 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { parseArgs } from "util"; | ||
import prismaInstance from "../prisma-instance"; | ||
|
||
const main = async () => { | ||
const { values } = parseArgs( | ||
{ | ||
options: | ||
{ | ||
hostname: { type: "string", short: "h" }, | ||
key: { type: "string", short: "k" } | ||
}, | ||
} | ||
); | ||
const missing = Object.entries(values).filter(([_, v]) => v === undefined).map(([k, _]) => k); | ||
if (missing.length) { | ||
process.stderr.write(`Missing the following options: ${missing.join(', ')}`); | ||
process.exit(1); | ||
} | ||
const { hostname, key } = values; | ||
const deletedResult = await prismaInstance.$transaction(async (tx) => await tx.apiKey.deleteMany( | ||
{ where: { hostname, value: key } } | ||
)); | ||
const { count } = deletedResult; | ||
if (!count) { | ||
process.stderr.write("The given key does not exist under the given host name."); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
main(); |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { parseArgs } from "util"; | ||
import prismaInstance from "../prisma-instance"; | ||
|
||
const main = async () => { | ||
const { values } = parseArgs({ options: { hostname: { type: "string", short: "h" } } }); | ||
const { hostname } = values; | ||
if (!hostname) { | ||
process.stderr.write("Must provide hostname option."); | ||
process.exit(1); | ||
} | ||
const keys = await prismaInstance.apiKey.findMany({ where: { hostname } }).then((vals) => vals.map((v) => v.value)); | ||
if (!keys.length) { | ||
process.stderr.write("No keys found under given host name."); | ||
process.exit(0); | ||
} | ||
process.stdout.write(keys.join("\n") + "\n"); | ||
}; | ||
|
||
main(); |