-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a config subcommand, revoke API keys on logout, check authentication
This generally increases the level of detail in debug logging, bases off of our currently unreleased backend to do things like verify credentials and revoke API keys, and adds a `sindri config list` command to facilitate debugging. Merges #14
- Loading branch information
Showing
22 changed files
with
198 additions
and
151 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
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 |
---|---|---|
@@ -1,20 +1,44 @@ | ||
import { Command } from "@commander-js/extra-typings"; | ||
import { confirm } from "@inquirer/prompts"; | ||
|
||
import { Config } from "cli/config"; | ||
import { logger } from "cli/logging"; | ||
import { AuthorizationService } from "lib/api"; | ||
|
||
export const logoutCommand = new Command() | ||
.name("logout") | ||
.description("Remove the current client authorization credentials.") | ||
.action(async () => { | ||
// Authorize the API client. | ||
// Check whether we're currently authenticated. | ||
const config = new Config(); | ||
const auth = config.auth; | ||
if (!auth) { | ||
logger.error("You must log in first with `sindri login`."); | ||
return; | ||
} | ||
|
||
// Optionally revoke the current key. | ||
const revokeKey = await confirm({ | ||
message: `Would you like to also revoke the "${auth.apiKeyName}" API key? (recommended)`, | ||
default: true, | ||
}); | ||
if (revokeKey) { | ||
try { | ||
const response = await AuthorizationService.apikeyDelete(auth.apiKeyId); | ||
logger.info(`Successfully revoked "${auth.apiKeyName}" key.`); | ||
logger.debug(`/api/v1/apikey/${auth.apiKeyId}/delete/ response:`); | ||
logger.debug(response); | ||
} catch (error) { | ||
logger.warn( | ||
`Error revoking "${auth.apiKeyName}" key, proceeding to clear credentials anyway.`, | ||
); | ||
logger.error(error); | ||
} | ||
} else { | ||
logger.warn("Skipping revocation of existing key."); | ||
} | ||
|
||
// Clear the existing credentials. | ||
config.update({ auth: null }); | ||
logger.info("You have successfully logged out."); | ||
}); |
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 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
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.