Added more filtering options to app listing.
This commit is contained in:
@@ -32,10 +32,12 @@ or: sk-az-tools <command> --help`;
|
|||||||
}
|
}
|
||||||
|
|
||||||
function usageListApps() {
|
function usageListApps() {
|
||||||
return `Usage: sk-az-tools list-apps [--display-name|-n <name>] [global options]
|
return `Usage: sk-az-tools list-apps [--display-name|-n <name>] [--app-id|-i <appId>] [--filter|-f <glob>] [global options]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-n, --display-name <name> Filter apps by exact display name`;
|
-n, --display-name <name> Get app by name
|
||||||
|
-i, --app-id <appId> Get app by id
|
||||||
|
-f, --filter <glob> Filter by app display name glob`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function usageListAppPermissions() {
|
function usageListAppPermissions() {
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ function filterByPermissionName(rows, pattern) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterByDisplayName(rows, pattern) {
|
||||||
|
return rows.filter((item) =>
|
||||||
|
minimatch(item.displayName ?? "", pattern, { nocase: true })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function getGraphClientFromPublicConfig() {
|
async function getGraphClientFromPublicConfig() {
|
||||||
const config = await loadPublicConfig();
|
const config = await loadPublicConfig();
|
||||||
return getGraphClient({
|
return getGraphClient({
|
||||||
@@ -34,9 +40,17 @@ async function runTableCommand() {
|
|||||||
|
|
||||||
async function runListAppsCommand(values) {
|
async function runListAppsCommand(values) {
|
||||||
const { client } = await getGraphClientFromPublicConfig();
|
const { client } = await getGraphClientFromPublicConfig();
|
||||||
return listApps(client, {
|
let result = await listApps(client, {
|
||||||
displayName: values["display-name"],
|
displayName: values["display-name"],
|
||||||
|
appId: values["app-id"],
|
||||||
});
|
});
|
||||||
|
if (values["app-id"] && result.length > 1) {
|
||||||
|
throw new Error(`Expected a single app for --app-id ${values["app-id"]}, but got ${result.length}`);
|
||||||
|
}
|
||||||
|
if (values.filter) {
|
||||||
|
result = filterByDisplayName(result, values.filter);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runListAppPermissionsCommand(values) {
|
async function runListAppPermissionsCommand(values) {
|
||||||
|
|||||||
@@ -34,19 +34,28 @@ export async function deleteApp(client, appObjectId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List Azure applications, optionally filtered by display name.
|
* List Azure applications, optionally filtered by display name and/or app ID.
|
||||||
*
|
*
|
||||||
* @param { Object } client
|
* @param { Object } client
|
||||||
* @param { Object } [options]
|
* @param { Object } [options]
|
||||||
* @param { string } [options.displayName]
|
* @param { string } [options.displayName]
|
||||||
|
* @param { string } [options.appId]
|
||||||
* @returns { Promise<Array> }
|
* @returns { Promise<Array> }
|
||||||
*/
|
*/
|
||||||
export async function listApps(client, options = {}) {
|
export async function listApps(client, options = {}) {
|
||||||
const { displayName } = options;
|
const { displayName, appId } = options;
|
||||||
let request = client.api("/applications");
|
let request = client.api("/applications");
|
||||||
|
const filters = [];
|
||||||
|
|
||||||
if (displayName) {
|
if (displayName) {
|
||||||
request = request.filter(`displayName eq '${displayName}'`);
|
filters.push(`displayName eq '${displayName}'`);
|
||||||
|
}
|
||||||
|
if (appId) {
|
||||||
|
filters.push(`appId eq '${appId}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters.length > 0) {
|
||||||
|
request = request.filter(filters.join(" and "));
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await request.get();
|
const result = await request.get();
|
||||||
|
|||||||
Reference in New Issue
Block a user