-
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 logging and local development server support
This cleans up the auth commands a little bit, integrates `pino` for logging, and adds a `--baseUrl` argument to `sindri login` which can be used for working against a local development or staging environment. Merges #13
- Loading branch information
Showing
10 changed files
with
410 additions
and
48 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pino from "pino"; | ||
import pretty from "pino-pretty"; | ||
|
||
const prettyStream = pretty({ | ||
colorize: true, | ||
destination: 2, | ||
ignore: "hostname,pid", | ||
levelFirst: false, | ||
sync: true, | ||
}); | ||
|
||
export const logger = pino(prettyStream); | ||
|
||
export const print = console.log; |
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,19 +1,20 @@ | ||
import chalk from "chalk"; | ||
import { Command } from "@commander-js/extra-typings"; | ||
|
||
import { config } from "cli/config"; | ||
import { Config } from "cli/config"; | ||
import { logger } from "cli/logging"; | ||
|
||
export const logoutCommand = new Command() | ||
.name("logout") | ||
.description("Display the currently authorized team name.") | ||
.description("Remove the current client authorization credentials.") | ||
.action(async () => { | ||
// Authorize the API client. | ||
const config = new Config(); | ||
const auth = config.auth; | ||
if (!auth) { | ||
console.error(chalk.red("You must log in first with `sindri login`.")); | ||
logger.error("You must log in first with `sindri login`."); | ||
return; | ||
} | ||
|
||
config.update({ auth: null }); | ||
console.log(chalk.green("You have successfully logged out.")); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
import axios from "axios"; | ||
import chalk from "chalk"; | ||
import process from "process"; | ||
|
||
import { Command } from "@commander-js/extra-typings"; | ||
|
||
import { config } from "cli/config"; | ||
import { Config } from "cli/config"; | ||
import { logger, print } from "cli/logging"; | ||
|
||
export const whoamiCommand = new Command() | ||
.name("whoami") | ||
.description("Display the currently authorized team name.") | ||
.action(async () => { | ||
// Authorize the API client. | ||
const config = new Config(); | ||
const auth = config.auth; | ||
if (!auth) { | ||
console.error(chalk.red("You must login first with `sindri login`.")); | ||
return; | ||
logger.warn("You must login first with `sindri login`."); | ||
return process.exit(1); | ||
} | ||
axios.defaults.headers.common = { | ||
Authorization: `Bearer ${auth.apiKey}`, | ||
}; | ||
|
||
// TODO: Use the new "team-me" endpoint to test authentication and fetch the current team. | ||
// This should be deployed soon, and we'll update this method then. For now, we just rely on | ||
// whatever the team slug was when we logged in last. | ||
console.log(auth.teamSlug); | ||
print(auth.teamSlug); | ||
}); |
Oops, something went wrong.