mirror of
https://github.com/github/codeql-action.git
synced 2026-10-30 01:27:22 +00:00
Address review comments
This commit is contained in:
@@ -12,6 +12,7 @@ import { scanArtifactsForTokens } from "./artifact-scanner";
|
||||
import { type CodeQL } from "./codeql";
|
||||
import { Config } from "./config-utils";
|
||||
import { EnvVar } from "./environment";
|
||||
import * as json from "./json";
|
||||
import { Language } from "./languages";
|
||||
import { Logger, withGroup } from "./logging";
|
||||
import {
|
||||
@@ -261,7 +262,7 @@ export function getArtifactSuffix(matrix: string | undefined): string {
|
||||
if (matrix) {
|
||||
try {
|
||||
const matrixObject = JSON.parse(matrix);
|
||||
if (matrixObject !== null && typeof matrixObject === "object") {
|
||||
if (json.isObject(matrixObject)) {
|
||||
for (const matrixKey of Object.keys(matrixObject as object).sort())
|
||||
suffix += `-${matrixObject[matrixKey]}`;
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@ import path from "path";
|
||||
import Long from "long";
|
||||
|
||||
import { DocUrl } from "./doc-url";
|
||||
import * as json from "./json";
|
||||
import { Logger } from "./logging";
|
||||
import type * as sarif from "./sarif";
|
||||
|
||||
@@ -189,7 +190,7 @@ export function resolveUriToFile(
|
||||
typeof location.index !== "number" ||
|
||||
location.index < 0 ||
|
||||
location.index >= artifacts.length ||
|
||||
typeof artifacts[location.index].location !== "object"
|
||||
!json.isObject(artifacts[location.index].location)
|
||||
) {
|
||||
logger.debug(`Ignoring location as index "${location.index}" is invalid`);
|
||||
return undefined;
|
||||
|
||||
@@ -17,7 +17,7 @@ export function parseString(data: string): unknown {
|
||||
|
||||
/** Asserts that `value` is an object, which is not yet validated, but expected to be of type `T`. */
|
||||
export function isObject<T>(value: unknown): value is UnvalidatedObject<T> {
|
||||
return typeof value === "object";
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
/** Asserts that `value` is an array, which is not yet validated. */
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
getWorkflowRunID,
|
||||
} from "../actions-util";
|
||||
import { type CodeQL } from "../codeql";
|
||||
import * as json from "../json";
|
||||
import { Logger } from "../logging";
|
||||
import {
|
||||
DiskUsage,
|
||||
@@ -149,8 +150,7 @@ export async function getOverlayStatus(
|
||||
const contents = await fs.promises.readFile(statusFile, "utf-8");
|
||||
const parsed: unknown = JSON.parse(contents);
|
||||
if (
|
||||
typeof parsed !== "object" ||
|
||||
parsed === null ||
|
||||
!json.isObject<OverlayStatus>(parsed) ||
|
||||
typeof parsed["attemptedToBuildOverlayBaseDatabase"] !== "boolean" ||
|
||||
typeof parsed["builtOverlayBaseDatabase"] !== "boolean"
|
||||
) {
|
||||
|
||||
@@ -323,7 +323,7 @@ export function getAuthConfig(
|
||||
// There are three scenarios for non-OIDC authentication based on the registry type:
|
||||
//
|
||||
// 1. `username`+`token`
|
||||
// 2. A `token` that combines the username and actual token, seperated by ':'.
|
||||
// 2. A `token` that combines the username and actual token, separated by ':'.
|
||||
// 3. `username`+`password`
|
||||
//
|
||||
// In all three cases, all fields are optional. If the `token` field is present,
|
||||
|
||||
@@ -49,6 +49,12 @@ export type Token = {
|
||||
export function isToken(
|
||||
config: UnvalidatedObject<AuthConfig>,
|
||||
): config is Token {
|
||||
// The "username" field is optional, but should be a string if present.
|
||||
if ("username" in config && !json.isStringOrUndefined(config.username)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The "token" field is required, and must be a string or undefined.
|
||||
return "token" in config && json.isStringOrUndefined(config.token);
|
||||
}
|
||||
|
||||
@@ -121,7 +127,7 @@ export type JFrogConfig = {
|
||||
export function isJFrogConfig(
|
||||
config: UnvalidatedObject<AuthConfig>,
|
||||
): config is JFrogConfig {
|
||||
// The "audience" and "identity_mapping_name" fields is optional, but should be strings if present.
|
||||
// The "audience" and "identity_mapping_name" fields are optional, but should be strings if present.
|
||||
if ("audience" in config && !json.isStringOrUndefined(config.audience)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
11
src/util.ts
11
src/util.ts
@@ -14,6 +14,7 @@ import type { CodeQL, VersionInfo } from "./codeql";
|
||||
import type { Pack } from "./config/db-config";
|
||||
import type { Config } from "./config-utils";
|
||||
import { EnvVar } from "./environment";
|
||||
import * as json from "./json";
|
||||
import { Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
|
||||
@@ -603,19 +604,15 @@ export class HTTPError extends Error {
|
||||
export class ConfigurationError extends Error {}
|
||||
|
||||
export function asHTTPError(arg: any): HTTPError | undefined {
|
||||
if (
|
||||
typeof arg !== "object" ||
|
||||
arg === null ||
|
||||
typeof arg.message !== "string"
|
||||
) {
|
||||
if (!json.isObject<any>(arg) || !json.isString(arg.message)) {
|
||||
return undefined;
|
||||
}
|
||||
if (Number.isInteger(arg.status)) {
|
||||
return new HTTPError(arg.message as string, arg.status as number);
|
||||
return new HTTPError(arg.message, arg.status as number);
|
||||
}
|
||||
// See https://github.com/actions/toolkit/blob/acb230b99a46ed33a3f04a758cd68b47b9a82908/packages/tool-cache/src/tool-cache.ts#L19
|
||||
if (Number.isInteger(arg.httpStatusCode)) {
|
||||
return new HTTPError(arg.message as string, arg.httpStatusCode as number);
|
||||
return new HTTPError(arg.message, arg.httpStatusCode as number);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user