35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
// SPDX-License-Identifier: MIT
|
|
|
|
import { listResourcePermissions } from "../../graph/app.ts";
|
|
|
|
import { filterByPermissionName, getGraphClientFromPublicConfig } from "./shared.ts";
|
|
import type { CommandValues } from "./types.ts";
|
|
|
|
export function usageListResourcePermissions(): string {
|
|
return `Usage: sk-az-tools list-resource-permissions [--app-id|-i <appId> | --display-name|-n <name>] [--filter|-f <glob>] [global options]
|
|
|
|
Options:
|
|
-i, --app-id <appId> Resource app ID
|
|
-n, --display-name <name> Resource app display name
|
|
-f, --filter <glob> Filter by permission name glob`;
|
|
}
|
|
|
|
export async function runListResourcePermissionsCommand(values: CommandValues): Promise<unknown> {
|
|
if (!values["app-id"] && !values["display-name"]) {
|
|
throw new Error("--app-id or --display-name is required for list-resource-permissions");
|
|
}
|
|
if (values["app-id"] && values["display-name"]) {
|
|
throw new Error("Use either --app-id or --display-name for list-resource-permissions, not both");
|
|
}
|
|
|
|
const { client } = await getGraphClientFromPublicConfig();
|
|
let result = await listResourcePermissions(client, {
|
|
appId: values["app-id"],
|
|
displayName: values["display-name"],
|
|
});
|
|
if (values.filter) {
|
|
result = filterByPermissionName(result, values.filter);
|
|
}
|
|
return result;
|
|
}
|