@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
100 lines • 4.78 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 _EntraPolicyListCommand_instances, _a, _EntraPolicyListCommand_initTelemetry, _EntraPolicyListCommand_initOptions, _EntraPolicyListCommand_initValidators;
import request from '../../../../request.js';
import GraphCommand from '../../../base/GraphCommand.js';
import commands from '../../commands.js';
const policyEndPoints = {
activitybasedtimeout: "activityBasedTimeoutPolicies",
authorization: "authorizationPolicy",
claimsmapping: "claimsMappingPolicies",
homerealmdiscovery: "homeRealmDiscoveryPolicies",
identitysecuritydefaultsenforcement: "identitySecurityDefaultsEnforcementPolicy",
tokenissuance: "tokenIssuancePolicies",
tokenlifetime: "tokenLifetimePolicies"
};
class EntraPolicyListCommand extends GraphCommand {
get name() {
return commands.POLICY_LIST;
}
get description() {
return 'Returns policies from Entra ID';
}
constructor() {
super();
_EntraPolicyListCommand_instances.add(this);
__classPrivateFieldGet(this, _EntraPolicyListCommand_instances, "m", _EntraPolicyListCommand_initTelemetry).call(this);
__classPrivateFieldGet(this, _EntraPolicyListCommand_instances, "m", _EntraPolicyListCommand_initOptions).call(this);
__classPrivateFieldGet(this, _EntraPolicyListCommand_instances, "m", _EntraPolicyListCommand_initValidators).call(this);
}
defaultProperties() {
return ['id', 'displayName', 'isOrganizationDefault'];
}
async commandAction(logger, args) {
const policyType = args.options.type ? args.options.type.toLowerCase() : 'all';
try {
if (policyType && policyType !== "all") {
const policies = await this.getPolicies(policyType);
await logger.log(policies);
}
else {
const policyTypes = Object.keys(policyEndPoints);
const results = await Promise.all(policyTypes.map(policyType => this.getPolicies(policyType)));
let allPolicies = [];
results.forEach((policies) => {
allPolicies = allPolicies.concat(policies);
});
await logger.log(allPolicies);
}
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
async getPolicies(policyType) {
const endpoint = policyEndPoints[policyType];
const requestOptions = {
url: `${this.resource}/v1.0/policies/${endpoint}`,
headers: {
accept: 'application/json;odata.metadata=none'
},
responseType: 'json'
};
const response = await request.get(requestOptions);
if (endpoint === policyEndPoints.authorization ||
endpoint === policyEndPoints.identitysecuritydefaultsenforcement) {
return response;
}
else {
return response.value;
}
}
}
_a = EntraPolicyListCommand, _EntraPolicyListCommand_instances = new WeakSet(), _EntraPolicyListCommand_initTelemetry = function _EntraPolicyListCommand_initTelemetry() {
this.telemetry.push((args) => {
Object.assign(this.telemetryProperties, {
policyType: args.options.type || 'all'
});
});
}, _EntraPolicyListCommand_initOptions = function _EntraPolicyListCommand_initOptions() {
this.options.unshift({
option: '-t, --type [type]',
autocomplete: _a.supportedPolicyTypes
});
}, _EntraPolicyListCommand_initValidators = function _EntraPolicyListCommand_initValidators() {
this.validators.push(async (args) => {
if (args.options.type) {
const policyType = args.options.type.toLowerCase();
if (!_a.supportedPolicyTypes.find(p => p.toLowerCase() === policyType)) {
return `${args.options.type} is not a valid type. Allowed values are ${_a.supportedPolicyTypes.join(', ')}`;
}
}
return true;
});
};
EntraPolicyListCommand.supportedPolicyTypes = ['activityBasedTimeout', 'authorization', 'claimsMapping', 'homeRealmDiscovery', 'identitySecurityDefaultsEnforcement', 'tokenIssuance', 'tokenLifetime'];
export default new EntraPolicyListCommand();
//# sourceMappingURL=policy-list.js.map