Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly escape log URL and print it at the end for functions:log command #8211

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added Cloud Logging URL at the end of `functions:log` command (#8211)
11 changes: 7 additions & 4 deletions src/commands/functions-log.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as opn from "open";
import * as qs from "querystring";
import { URLSearchParams } from "url";

import { Command } from "../command";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import * as cloudlogging from "../gcp/cloudlogging";
import * as functionsLog from "../functions/functionslog";
import { needProjectId } from "../projectUtils";
Expand All @@ -17,26 +18,28 @@
.option("-n, --lines <num_lines>", "specify number of log lines to fetch")
.option("--open", "open logs page in web browser")
.before(requirePermissions, ["logging.logEntries.list", "logging.logs.list"])
.action(async (options: any) => {

Check warning on line 21 in src/commands/functions-log.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
try {
const projectId = needProjectId(options);

Check warning on line 23 in src/commands/functions-log.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `{ projectId?: string | undefined; project?: string | undefined; rc?: RC | undefined; }`
const apiFilter = functionsLog.getApiFilter(options.only);

Check warning on line 24 in src/commands/functions-log.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string | undefined`

Check warning on line 24 in src/commands/functions-log.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .only on an `any` value
const filterParams = new URLSearchParams(apiFilter);
const url = `https://console.developers.google.com/logs/viewer?advancedFilter=${filterParams.toString()}&project=${projectId}`;

if (options.open) {

Check warning on line 28 in src/commands/functions-log.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .open on an `any` value
const url = `https://console.developers.google.com/logs/viewer?advancedFilter=${qs.escape(
apiFilter,
)}&project=${projectId}`;
opn(url);

Check warning on line 29 in src/commands/functions-log.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
return;
}

const entries = await cloudlogging.listEntries(
projectId,
apiFilter,
options.lines || 35,

Check warning on line 36 in src/commands/functions-log.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `number`

Check warning on line 36 in src/commands/functions-log.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .lines on an `any` value
"desc",
);
functionsLog.logEntries(entries);
logger.info(`\nSee full logs at: ${url}`);
return entries;
} catch (err: any) {

Check warning on line 42 in src/commands/functions-log.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
throw new FirebaseError(`Failed to list log entries ${err.message}`, { exit: 1 });

Check warning on line 43 in src/commands/functions-log.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
}
});
Loading