@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
85 lines • 4.52 kB
JavaScript
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _EntraAppRoleListCommand_instances, _EntraAppRoleListCommand_initTelemetry, _EntraAppRoleListCommand_initOptions, _EntraAppRoleListCommand_initOptionSets;
import request from '../../../../request.js';
import { formatting } from '../../../../utils/formatting.js';
import { odata } from '../../../../utils/odata.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
import { cli } from '../../../../cli/cli.js';
class EntraAppRoleListCommand extends GraphCommand {
get name() {
return commands.APP_ROLE_LIST;
}
get description() {
return 'Gets Entra app registration roles';
}
constructor() {
super();
_EntraAppRoleListCommand_instances.add(this);
__classPrivateFieldGet(this, _EntraAppRoleListCommand_instances, "m", _EntraAppRoleListCommand_initTelemetry).call(this);
__classPrivateFieldGet(this, _EntraAppRoleListCommand_instances, "m", _EntraAppRoleListCommand_initOptions).call(this);
__classPrivateFieldGet(this, _EntraAppRoleListCommand_instances, "m", _EntraAppRoleListCommand_initOptionSets).call(this);
}
defaultProperties() {
return ['displayName', 'description', 'id'];
}
async commandAction(logger, args) {
try {
const objectId = await this.getAppObjectId(args, logger);
const appRoles = await odata.getAllItems(`${this.resource}/v1.0/myorganization/applications/${objectId}/appRoles`);
await logger.log(appRoles);
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
async getAppObjectId(args, logger) {
if (args.options.appObjectId) {
return args.options.appObjectId;
}
const { appId, appName } = args.options;
if (this.verbose) {
await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appId ? appId : appName}...`);
}
const filter = appId ?
`appId eq '${formatting.encodeQueryParameter(appId)}'` :
`displayName eq '${formatting.encodeQueryParameter(appName)}'`;
const requestOptions = {
url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
headers: {
accept: 'application/json;odata.metadata=none'
},
responseType: 'json'
};
const res = await request.get(requestOptions);
if (res.value.length === 1) {
return res.value[0].id;
}
if (res.value.length === 0) {
const applicationIdentifier = appId ? `ID ${appId}` : `name ${appName}`;
throw `No Microsoft Entra application registration with ${applicationIdentifier} found`;
}
const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registrations with name '${appName}' found.`, resultAsKeyValuePair);
return result.id;
}
}
_EntraAppRoleListCommand_instances = new WeakSet(), _EntraAppRoleListCommand_initTelemetry = function _EntraAppRoleListCommand_initTelemetry() {
this.telemetry.push((args) => {
Object.assign(this.telemetryProperties, {
appId: typeof args.options.appId !== 'undefined',
appObjectId: typeof args.options.appObjectId !== 'undefined',
appName: typeof args.options.appName !== 'undefined'
});
});
}, _EntraAppRoleListCommand_initOptions = function _EntraAppRoleListCommand_initOptions() {
this.options.unshift({ option: '--appId [appId]' }, { option: '--appObjectId [appObjectId]' }, { option: '--appName [appName]' });
}, _EntraAppRoleListCommand_initOptionSets = function _EntraAppRoleListCommand_initOptionSets() {
this.optionSets.push({ options: ['appId', 'appObjectId', 'appName'] });
};
export default new EntraAppRoleListCommand();
//# sourceMappingURL=app-role-list.js.map