update: adopted new output options. Various optimizations.
Some checks failed
build / build (push) Failing after 15s
Some checks failed
build / build (push) Failing after 15s
This commit is contained in:
@@ -5,6 +5,23 @@ import { listAppPermissions, listAppPermissionsResolved } from "../../graph/app.
|
||||
import { filterByPermissionName, getGraphClientFromPublicConfig } from "./shared.ts";
|
||||
import type { CommandValues } from "./types.ts";
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return value !== null && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function omitColumns(input: unknown, names: string[]): unknown {
|
||||
if (!Array.isArray(input) || !input.every(isRecord)) {
|
||||
return input;
|
||||
}
|
||||
|
||||
const namesSet = new Set(names);
|
||||
return input.map((record) =>
|
||||
Object.fromEntries(
|
||||
Object.entries(record).filter(([key]) => !namesSet.has(key)),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function usageListAppPermissions(): string {
|
||||
return `Usage: sk-az-tools list-app-permissions --app-id|-i <appId> [--resolve|-r] [--short|-s] [--filter|-f <glob>] [global options]
|
||||
|
||||
@@ -21,11 +38,14 @@ export async function runListAppPermissionsCommand(values: CommandValues): Promi
|
||||
}
|
||||
|
||||
const { client } = await getGraphClientFromPublicConfig();
|
||||
let result = values.resolve || values.filter
|
||||
let result: unknown = values.resolve || values.filter
|
||||
? await listAppPermissionsResolved(client, values["app-id"])
|
||||
: await listAppPermissions(client, values["app-id"]);
|
||||
if (values.short) {
|
||||
result = omitColumns(result, ["resourceAppId", "permissionId"]);
|
||||
}
|
||||
if (values.filter) {
|
||||
result = filterByPermissionName(result, values.filter);
|
||||
result = filterByPermissionName(result as Array<Record<string, unknown>>, values.filter);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user