@pnp/cli-microsoft365 4.2.0-beta.b126b71 → 4.3.0-beta.014ebf5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/Dockerfile +1 -1
- package/.eslintrc.js +1 -0
- package/dist/appInsights.js +2 -0
- package/dist/cli/Cli.js +4 -1
- package/dist/m365/aad/commands/app/app-add.js +58 -5
- package/dist/m365/aad/commands/app/app-get.js +97 -0
- package/dist/m365/aad/commands/o365group/o365group-add.js +56 -50
- package/dist/m365/aad/commands/sp/sp-add.js +107 -0
- package/dist/m365/aad/commands.js +2 -0
- package/dist/m365/base/M365RcJson.js +3 -0
- package/dist/m365/file/commands/file-list.js +181 -0
- package/dist/m365/file/commands.js +2 -1
- package/dist/m365/search/commands/externalconnection/externalconnection-add.js +99 -0
- package/dist/m365/search/commands.js +7 -0
- package/dist/m365/spfx/commands/project/project-upgrade/upgrade-1.13.1.js +53 -0
- package/dist/m365/spfx/commands/project/project-upgrade.js +2 -1
- package/dist/m365/spfx/commands/spfx-doctor.js +176 -62
- package/dist/m365/spo/commands/contenttype/contenttype-list.js +52 -0
- package/dist/m365/spo/commands/list/list-get.js +6 -2
- package/dist/m365/spo/commands/page/Page.js +3 -1
- package/dist/m365/spo/commands/page/page-add.js +7 -10
- package/dist/m365/spo/commands/page/page-set.js +7 -10
- package/dist/m365/spo/commands/site/site-remove.js +98 -30
- package/dist/m365/spo/commands/web/web-installedlanguage-list.js +48 -0
- package/dist/m365/spo/commands.js +3 -1
- package/dist/m365/teams/commands/report/report-directroutingcalls.js +1 -1
- package/docs/docs/cmd/aad/app/app-add.md +11 -0
- package/docs/docs/cmd/aad/app/app-get.md +48 -0
- package/docs/docs/cmd/aad/o365group/o365group-add.md +1 -0
- package/docs/docs/cmd/aad/sp/sp-add.md +53 -0
- package/docs/docs/cmd/file/file-list.md +46 -0
- package/docs/docs/cmd/search/externalconnection/externalconnection-add.md +43 -0
- package/docs/docs/cmd/spfx/project/project-upgrade.md +1 -1
- package/docs/docs/cmd/spo/contenttype/contenttype-list.md +33 -0
- package/docs/docs/cmd/spo/list/list-get.md +9 -0
- package/docs/docs/cmd/spo/page/page-add.md +2 -2
- package/docs/docs/cmd/spo/page/page-set.md +3 -3
- package/docs/docs/cmd/spo/site/site-remove.md +3 -1
- package/docs/docs/cmd/spo/web/web-installedlanguage-list.md +24 -0
- package/docs/docs/cmd/teams/report/report-directroutingcalls.md +0 -3
- package/npm-shrinkwrap.json +510 -888
- package/package.json +19 -17
package/.devcontainer/Dockerfile
CHANGED
|
@@ -23,7 +23,7 @@ RUN apt-get update && apt-get install -y \
|
|
|
23
23
|
vim \
|
|
24
24
|
python3.8 \
|
|
25
25
|
python3-pip \
|
|
26
|
-
&& curl -sL https://deb.nodesource.com/
|
|
26
|
+
&& curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - \
|
|
27
27
|
&& apt-get install nodejs -y \
|
|
28
28
|
&& rm -rf /var/lib/apt/lists/*
|
|
29
29
|
|
package/.eslintrc.js
CHANGED
package/dist/appInsights.js
CHANGED
|
@@ -4,6 +4,8 @@ const packageJSON = require('../package.json');
|
|
|
4
4
|
// disable automatic third-party instrumentation for Application Insights
|
|
5
5
|
// speeds up execution by preventing loading unnecessary dependencies
|
|
6
6
|
process.env.APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL = 'none';
|
|
7
|
+
// prevents tests from hanging
|
|
8
|
+
process.env.APPLICATION_INSIGHTS_NO_STATSBEAT = 'true';
|
|
7
9
|
const appInsights = require("applicationinsights");
|
|
8
10
|
const crypto = require("crypto");
|
|
9
11
|
const fs = require("fs");
|
package/dist/cli/Cli.js
CHANGED
|
@@ -386,7 +386,10 @@ class Cli {
|
|
|
386
386
|
logStatementType = typeof logStatement;
|
|
387
387
|
}
|
|
388
388
|
if (!options.output || options.output === 'json') {
|
|
389
|
-
return JSON
|
|
389
|
+
return JSON
|
|
390
|
+
.stringify(logStatement, null, 2)
|
|
391
|
+
// replace unescaped newlines with escaped newlines #2807
|
|
392
|
+
.replace(/([^\\])\\n/g, '$1\\\\\\n');
|
|
390
393
|
}
|
|
391
394
|
if (logStatement instanceof Command_1.CommandError) {
|
|
392
395
|
const chalk = require('chalk');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs");
|
|
3
4
|
const uuid_1 = require("uuid");
|
|
4
5
|
const Auth_1 = require("../../../../Auth");
|
|
5
6
|
const request_1 = require("../../../../request");
|
|
@@ -7,6 +8,10 @@ const Utils_1 = require("../../../../Utils");
|
|
|
7
8
|
const GraphItemsListCommand_1 = require("../../../base/GraphItemsListCommand");
|
|
8
9
|
const commands_1 = require("../../commands");
|
|
9
10
|
class AadAppAddCommand extends GraphItemsListCommand_1.GraphItemsListCommand {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.appName = '';
|
|
14
|
+
}
|
|
10
15
|
get name() {
|
|
11
16
|
return commands_1.default.APP_ADD;
|
|
12
17
|
}
|
|
@@ -32,18 +37,23 @@ class AadAppAddCommand extends GraphItemsListCommand_1.GraphItemsListCommand {
|
|
|
32
37
|
this
|
|
33
38
|
.resolveApis(args, logger)
|
|
34
39
|
.then(apis => this.createAppRegistration(args, apis, logger))
|
|
40
|
+
.then(appInfo => {
|
|
41
|
+
// based on the assumption that we're adding AAD app to the current
|
|
42
|
+
// directory. If we in the future extend the command with allowing
|
|
43
|
+
// users to create AAD app in a different directory, we'll need to
|
|
44
|
+
// adjust this
|
|
45
|
+
appInfo.tenantId = Utils_1.default.getTenantIdFromAccessToken(Auth_1.default.service.accessTokens[Auth_1.default.defaultResource].accessToken);
|
|
46
|
+
return Promise.resolve(appInfo);
|
|
47
|
+
})
|
|
35
48
|
.then(appInfo => this.updateAppFromManifest(args, appInfo))
|
|
36
49
|
.then(appInfo => this.configureUri(args, appInfo, logger))
|
|
37
50
|
.then(appInfo => this.configureSecret(args, appInfo, logger))
|
|
51
|
+
.then(appInfo => this.saveAppInfo(args, appInfo, logger))
|
|
38
52
|
.then((_appInfo) => {
|
|
39
53
|
const appInfo = {
|
|
40
54
|
appId: _appInfo.appId,
|
|
41
55
|
objectId: _appInfo.id,
|
|
42
|
-
|
|
43
|
-
// directory. If we in the future extend the command with allowing
|
|
44
|
-
// users to create AAD app in a different directory, we'll need to
|
|
45
|
-
// adjust this
|
|
46
|
-
tenantId: Utils_1.default.getTenantIdFromAccessToken(Auth_1.default.service.accessTokens[Auth_1.default.defaultResource].accessToken)
|
|
56
|
+
tenantId: _appInfo.tenantId
|
|
47
57
|
};
|
|
48
58
|
if (_appInfo.secret) {
|
|
49
59
|
appInfo.secret = _appInfo.secret;
|
|
@@ -60,6 +70,7 @@ class AadAppAddCommand extends GraphItemsListCommand_1.GraphItemsListCommand {
|
|
|
60
70
|
if (!applicationInfo.displayName && this.manifest) {
|
|
61
71
|
applicationInfo.displayName = this.manifest.name;
|
|
62
72
|
}
|
|
73
|
+
this.appName = applicationInfo.displayName;
|
|
63
74
|
if (apis.length > 0) {
|
|
64
75
|
applicationInfo.requiredResourceAccess = apis;
|
|
65
76
|
}
|
|
@@ -332,6 +343,45 @@ class AadAppAddCommand extends GraphItemsListCommand_1.GraphItemsListCommand {
|
|
|
332
343
|
return Promise.resolve(appInfo);
|
|
333
344
|
});
|
|
334
345
|
}
|
|
346
|
+
saveAppInfo(args, appInfo, logger) {
|
|
347
|
+
if (!args.options.save) {
|
|
348
|
+
return Promise.resolve(appInfo);
|
|
349
|
+
}
|
|
350
|
+
const filePath = '.m365rc.json';
|
|
351
|
+
if (this.verbose) {
|
|
352
|
+
logger.logToStderr(`Saving Azure AD app registration information to the ${filePath} file...`);
|
|
353
|
+
}
|
|
354
|
+
let m365rc = {};
|
|
355
|
+
if (fs.existsSync(filePath)) {
|
|
356
|
+
if (this.debug) {
|
|
357
|
+
logger.logToStderr(`Reading existing ${filePath}...`);
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
const fileContents = fs.readFileSync(filePath, 'utf8');
|
|
361
|
+
if (fileContents) {
|
|
362
|
+
m365rc = JSON.parse(fileContents);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
catch (e) {
|
|
366
|
+
logger.logToStderr(`Error reading ${filePath}: ${e}. Please add app info to ${filePath} manually.`);
|
|
367
|
+
return Promise.resolve(appInfo);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (!m365rc.apps) {
|
|
371
|
+
m365rc.apps = [];
|
|
372
|
+
}
|
|
373
|
+
m365rc.apps.push({
|
|
374
|
+
appId: appInfo.appId,
|
|
375
|
+
name: this.appName
|
|
376
|
+
});
|
|
377
|
+
try {
|
|
378
|
+
fs.writeFileSync(filePath, JSON.stringify(m365rc, null, 2));
|
|
379
|
+
}
|
|
380
|
+
catch (e) {
|
|
381
|
+
logger.logToStderr(`Error writing ${filePath}: ${e}. Please add app info to ${filePath} manually.`);
|
|
382
|
+
}
|
|
383
|
+
return Promise.resolve(appInfo);
|
|
384
|
+
}
|
|
335
385
|
options() {
|
|
336
386
|
const options = [
|
|
337
387
|
{
|
|
@@ -377,6 +427,9 @@ class AadAppAddCommand extends GraphItemsListCommand_1.GraphItemsListCommand {
|
|
|
377
427
|
},
|
|
378
428
|
{
|
|
379
429
|
option: '--manifest [manifest]'
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
option: '--save'
|
|
380
433
|
}
|
|
381
434
|
];
|
|
382
435
|
const parentOptions = super.options();
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const request_1 = require("../../../../request");
|
|
4
|
+
const Utils_1 = require("../../../../Utils");
|
|
5
|
+
const GraphCommand_1 = require("../../../base/GraphCommand");
|
|
6
|
+
const commands_1 = require("../../commands");
|
|
7
|
+
class AadAppGetCommand extends GraphCommand_1.default {
|
|
8
|
+
get name() {
|
|
9
|
+
return commands_1.default.APP_GET;
|
|
10
|
+
}
|
|
11
|
+
get description() {
|
|
12
|
+
return 'Gets an Azure AD app registration';
|
|
13
|
+
}
|
|
14
|
+
getTelemetryProperties(args) {
|
|
15
|
+
const telemetryProps = super.getTelemetryProperties(args);
|
|
16
|
+
telemetryProps.appId = typeof args.options.appId !== 'undefined';
|
|
17
|
+
telemetryProps.objectId = typeof args.options.objectId !== 'undefined';
|
|
18
|
+
telemetryProps.name = typeof args.options.name !== 'undefined';
|
|
19
|
+
return telemetryProps;
|
|
20
|
+
}
|
|
21
|
+
commandAction(logger, args, cb) {
|
|
22
|
+
this
|
|
23
|
+
.getAppObjectId(args)
|
|
24
|
+
.then((appObjectId) => {
|
|
25
|
+
const requestOptions = {
|
|
26
|
+
url: `${this.resource}/v1.0/myorganization/applications/${appObjectId}`,
|
|
27
|
+
headers: {
|
|
28
|
+
accept: 'application/json;odata.metadata=none'
|
|
29
|
+
},
|
|
30
|
+
responseType: 'json'
|
|
31
|
+
};
|
|
32
|
+
return request_1.default.get(requestOptions);
|
|
33
|
+
})
|
|
34
|
+
.then((res) => {
|
|
35
|
+
logger.log(res);
|
|
36
|
+
cb();
|
|
37
|
+
}, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
|
|
38
|
+
}
|
|
39
|
+
getAppObjectId(args) {
|
|
40
|
+
if (args.options.objectId) {
|
|
41
|
+
return Promise.resolve(args.options.objectId);
|
|
42
|
+
}
|
|
43
|
+
const { appId, name } = args.options;
|
|
44
|
+
const filter = appId ?
|
|
45
|
+
`appId eq '${encodeURIComponent(appId)}'` :
|
|
46
|
+
`displayName eq '${encodeURIComponent(name)}'`;
|
|
47
|
+
const requestOptions = {
|
|
48
|
+
url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
|
|
49
|
+
headers: {
|
|
50
|
+
accept: 'application/json;odata.metadata=none'
|
|
51
|
+
},
|
|
52
|
+
responseType: 'json'
|
|
53
|
+
};
|
|
54
|
+
return request_1.default
|
|
55
|
+
.get(requestOptions)
|
|
56
|
+
.then((res) => {
|
|
57
|
+
if (res.value.length === 1) {
|
|
58
|
+
return Promise.resolve(res.value[0].id);
|
|
59
|
+
}
|
|
60
|
+
if (res.value.length === 0) {
|
|
61
|
+
const applicationIdentifier = appId ? `ID ${appId}` : `name ${name}`;
|
|
62
|
+
return Promise.reject(`No Azure AD application registration with ${applicationIdentifier} found`);
|
|
63
|
+
}
|
|
64
|
+
return Promise.reject(`Multiple Azure AD application registration with name ${name} found. Please disambiguate (app object IDs): ${res.value.map(a => a.id).join(', ')}`);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
options() {
|
|
68
|
+
const options = [
|
|
69
|
+
{ option: '--appId [appId]' },
|
|
70
|
+
{ option: '--objectId [objectId]' },
|
|
71
|
+
{ option: '--name [name]' }
|
|
72
|
+
];
|
|
73
|
+
const parentOptions = super.options();
|
|
74
|
+
return options.concat(parentOptions);
|
|
75
|
+
}
|
|
76
|
+
validate(args) {
|
|
77
|
+
if (!args.options.appId &&
|
|
78
|
+
!args.options.objectId &&
|
|
79
|
+
!args.options.name) {
|
|
80
|
+
return 'Specify either appId, objectId, or name';
|
|
81
|
+
}
|
|
82
|
+
if ((args.options.appId && args.options.objectId) ||
|
|
83
|
+
(args.options.appId && args.options.name) ||
|
|
84
|
+
(args.options.objectId && args.options.name)) {
|
|
85
|
+
return 'Specify either appId, objectId, or name but not both';
|
|
86
|
+
}
|
|
87
|
+
if (args.options.appId && !Utils_1.default.isValidGuid(args.options.appId)) {
|
|
88
|
+
return `${args.options.appId} is not a valid GUID`;
|
|
89
|
+
}
|
|
90
|
+
if (args.options.objectId && !Utils_1.default.isValidGuid(args.options.objectId)) {
|
|
91
|
+
return `${args.options.objectId} is not a valid GUID`;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
module.exports = new AadAppGetCommand();
|
|
97
|
+
//# sourceMappingURL=app-get.js.map
|
|
@@ -5,6 +5,7 @@ const path = require("path");
|
|
|
5
5
|
const request_1 = require("../../../../request");
|
|
6
6
|
const GraphCommand_1 = require("../../../base/GraphCommand");
|
|
7
7
|
const commands_1 = require("../../commands");
|
|
8
|
+
const Utils_1 = require("../../../../Utils");
|
|
8
9
|
class AadO365GroupAddCommand extends GraphCommand_1.default {
|
|
9
10
|
get name() {
|
|
10
11
|
return commands_1.default.O365GROUP_ADD;
|
|
@@ -14,6 +15,8 @@ class AadO365GroupAddCommand extends GraphCommand_1.default {
|
|
|
14
15
|
}
|
|
15
16
|
commandAction(logger, args, cb) {
|
|
16
17
|
let group;
|
|
18
|
+
let ownerIds = [];
|
|
19
|
+
let memberIds = [];
|
|
17
20
|
if (this.verbose) {
|
|
18
21
|
logger.logToStderr(`Creating Microsoft 365 Group...`);
|
|
19
22
|
}
|
|
@@ -35,8 +38,16 @@ class AadO365GroupAddCommand extends GraphCommand_1.default {
|
|
|
35
38
|
visibility: args.options.isPrivate === 'true' ? 'Private' : 'Public'
|
|
36
39
|
}
|
|
37
40
|
};
|
|
38
|
-
|
|
39
|
-
.
|
|
41
|
+
this
|
|
42
|
+
.getUserIds(logger, args.options.owners)
|
|
43
|
+
.then((ownerIdsRes) => {
|
|
44
|
+
ownerIds = ownerIdsRes;
|
|
45
|
+
return this.getUserIds(logger, args.options.members);
|
|
46
|
+
})
|
|
47
|
+
.then((memberIdsRes) => {
|
|
48
|
+
memberIds = memberIdsRes;
|
|
49
|
+
return request_1.default.post(requestOptions);
|
|
50
|
+
})
|
|
40
51
|
.then((res) => {
|
|
41
52
|
group = res;
|
|
42
53
|
if (!args.options.logoPath) {
|
|
@@ -61,72 +72,32 @@ class AadO365GroupAddCommand extends GraphCommand_1.default {
|
|
|
61
72
|
});
|
|
62
73
|
})
|
|
63
74
|
.then(() => {
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
logger.logToStderr('Owners not set. Skipping');
|
|
67
|
-
}
|
|
68
|
-
return Promise.resolve(undefined);
|
|
69
|
-
}
|
|
70
|
-
const owners = args.options.owners.split(',').map(o => o.trim());
|
|
71
|
-
if (this.verbose) {
|
|
72
|
-
logger.logToStderr('Retrieving user information to set group owners...');
|
|
73
|
-
}
|
|
74
|
-
const requestOptions = {
|
|
75
|
-
url: `${this.resource}/v1.0/users?$filter=${owners.map(o => `userPrincipalName eq '${o}'`).join(' or ')}&$select=id`,
|
|
76
|
-
headers: {
|
|
77
|
-
'content-type': 'application/json'
|
|
78
|
-
},
|
|
79
|
-
responseType: 'json'
|
|
80
|
-
};
|
|
81
|
-
return request_1.default.get(requestOptions);
|
|
82
|
-
})
|
|
83
|
-
.then((res) => {
|
|
84
|
-
if (!res) {
|
|
85
|
-
return Promise.resolve();
|
|
75
|
+
if (ownerIds.length === 0) {
|
|
76
|
+
return Promise.resolve([]);
|
|
86
77
|
}
|
|
87
|
-
return Promise.all(
|
|
78
|
+
return Promise.all(ownerIds.map(ownerId => request_1.default.post({
|
|
88
79
|
url: `${this.resource}/v1.0/groups/${group.id}/owners/$ref`,
|
|
89
80
|
headers: {
|
|
90
81
|
'content-type': 'application/json'
|
|
91
82
|
},
|
|
92
83
|
responseType: 'json',
|
|
93
84
|
data: {
|
|
94
|
-
"@odata.id": `https://graph.microsoft.com/v1.0/users/${
|
|
85
|
+
"@odata.id": `https://graph.microsoft.com/v1.0/users/${ownerId}`
|
|
95
86
|
}
|
|
96
87
|
})));
|
|
97
88
|
})
|
|
98
89
|
.then(() => {
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
logger.logToStderr('Members not set. Skipping');
|
|
102
|
-
}
|
|
103
|
-
return Promise.resolve(undefined);
|
|
104
|
-
}
|
|
105
|
-
const members = args.options.members.split(',').map(o => o.trim());
|
|
106
|
-
if (this.verbose) {
|
|
107
|
-
logger.logToStderr('Retrieving user information to set group members...');
|
|
108
|
-
}
|
|
109
|
-
const requestOptions = {
|
|
110
|
-
url: `${this.resource}/v1.0/users?$filter=${members.map(o => `userPrincipalName eq '${o}'`).join(' or ')}&$select=id`,
|
|
111
|
-
headers: {
|
|
112
|
-
'content-type': 'application/json'
|
|
113
|
-
},
|
|
114
|
-
responseType: 'json'
|
|
115
|
-
};
|
|
116
|
-
return request_1.default.get(requestOptions);
|
|
117
|
-
})
|
|
118
|
-
.then((res) => {
|
|
119
|
-
if (!res) {
|
|
120
|
-
return Promise.resolve();
|
|
90
|
+
if (memberIds.length === 0) {
|
|
91
|
+
return Promise.resolve([]);
|
|
121
92
|
}
|
|
122
|
-
return Promise.all(
|
|
93
|
+
return Promise.all(memberIds.map(memberId => request_1.default.post({
|
|
123
94
|
url: `${this.resource}/v1.0/groups/${group.id}/members/$ref`,
|
|
124
95
|
headers: {
|
|
125
96
|
'content-type': 'application/json'
|
|
126
97
|
},
|
|
127
98
|
responseType: 'json',
|
|
128
99
|
data: {
|
|
129
|
-
"@odata.id": `https://graph.microsoft.com/v1.0/users/${
|
|
100
|
+
"@odata.id": `https://graph.microsoft.com/v1.0/users/${memberId}`
|
|
130
101
|
}
|
|
131
102
|
})));
|
|
132
103
|
})
|
|
@@ -135,6 +106,41 @@ class AadO365GroupAddCommand extends GraphCommand_1.default {
|
|
|
135
106
|
cb();
|
|
136
107
|
}, (rawRes) => this.handleRejectedODataJsonPromise(rawRes, logger, cb));
|
|
137
108
|
}
|
|
109
|
+
getUserIds(logger, users) {
|
|
110
|
+
if (!users) {
|
|
111
|
+
if (this.debug) {
|
|
112
|
+
logger.logToStderr('No users to validate, skipping.');
|
|
113
|
+
}
|
|
114
|
+
return Promise.resolve([]);
|
|
115
|
+
}
|
|
116
|
+
if (this.verbose) {
|
|
117
|
+
logger.logToStderr('Retrieving user information.');
|
|
118
|
+
}
|
|
119
|
+
const userArr = users.split(',').map(o => o.trim());
|
|
120
|
+
let promises = [];
|
|
121
|
+
let userIds = [];
|
|
122
|
+
promises = userArr.map(user => {
|
|
123
|
+
const requestOptions = {
|
|
124
|
+
url: `${this.resource}/v1.0/users?$filter=userPrincipalName eq '${Utils_1.default.encodeQueryParameter(user)}'&$select=id,userPrincipalName`,
|
|
125
|
+
headers: {
|
|
126
|
+
'content-type': 'application/json'
|
|
127
|
+
},
|
|
128
|
+
responseType: 'json'
|
|
129
|
+
};
|
|
130
|
+
return request_1.default.get(requestOptions);
|
|
131
|
+
});
|
|
132
|
+
return Promise.all(promises).then((usersRes) => {
|
|
133
|
+
let userUpns = [];
|
|
134
|
+
userUpns = usersRes.map(res => { var _a; return (_a = res.value[0]) === null || _a === void 0 ? void 0 : _a.userPrincipalName; });
|
|
135
|
+
userIds = usersRes.map(res => { var _a; return (_a = res.value[0]) === null || _a === void 0 ? void 0 : _a.id; });
|
|
136
|
+
// Find the members where no graph response was found
|
|
137
|
+
const invalidUsers = userArr.filter(user => !userUpns.some((upn) => (upn === null || upn === void 0 ? void 0 : upn.toLowerCase()) === user.toLowerCase()));
|
|
138
|
+
if (invalidUsers && invalidUsers.length > 0) {
|
|
139
|
+
return Promise.reject(`Cannot proceed with group creation. The following users provided are invalid : ${invalidUsers.join(',')}`);
|
|
140
|
+
}
|
|
141
|
+
return Promise.resolve(userIds);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
138
144
|
setGroupLogo(requestOptions, retryLeft, resolve, reject, logger) {
|
|
139
145
|
request_1.default
|
|
140
146
|
.put(requestOptions)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const request_1 = require("../../../../request");
|
|
4
|
+
const Utils_1 = require("../../../../Utils");
|
|
5
|
+
const GraphCommand_1 = require("../../../base/GraphCommand");
|
|
6
|
+
const commands_1 = require("../../commands");
|
|
7
|
+
class AadSpAddCommand extends GraphCommand_1.default {
|
|
8
|
+
get name() {
|
|
9
|
+
return commands_1.default.SP_ADD;
|
|
10
|
+
}
|
|
11
|
+
get description() {
|
|
12
|
+
return 'Adds a service principal to a registered Azure AD app';
|
|
13
|
+
}
|
|
14
|
+
getTelemetryProperties(args) {
|
|
15
|
+
const telemetryProps = super.getTelemetryProperties(args);
|
|
16
|
+
telemetryProps.appId = (!(!args.options.appId)).toString();
|
|
17
|
+
telemetryProps.appName = (!(!args.options.appName)).toString();
|
|
18
|
+
telemetryProps.objectId = (!(!args.options.objectId)).toString();
|
|
19
|
+
return telemetryProps;
|
|
20
|
+
}
|
|
21
|
+
getAppId(args) {
|
|
22
|
+
if (args.options.appId) {
|
|
23
|
+
return Promise.resolve(args.options.appId);
|
|
24
|
+
}
|
|
25
|
+
let spMatchQuery = '';
|
|
26
|
+
if (args.options.appName) {
|
|
27
|
+
spMatchQuery = `displayName eq '${encodeURIComponent(args.options.appName)}'`;
|
|
28
|
+
}
|
|
29
|
+
else if (args.options.objectId) {
|
|
30
|
+
spMatchQuery = `id eq '${encodeURIComponent(args.options.objectId)}'`;
|
|
31
|
+
}
|
|
32
|
+
const appIdRequestOptions = {
|
|
33
|
+
url: `${this.resource}/v1.0/applications?$filter=${spMatchQuery}`,
|
|
34
|
+
headers: {
|
|
35
|
+
accept: 'application/json;odata.metadata=none'
|
|
36
|
+
},
|
|
37
|
+
responseType: 'json'
|
|
38
|
+
};
|
|
39
|
+
return request_1.default
|
|
40
|
+
.get(appIdRequestOptions)
|
|
41
|
+
.then(response => {
|
|
42
|
+
const spItem = response.value[0];
|
|
43
|
+
if (!spItem) {
|
|
44
|
+
return Promise.reject(`The specified Azure AD app doesn't exist`);
|
|
45
|
+
}
|
|
46
|
+
if (response.value.length > 1) {
|
|
47
|
+
return Promise.reject(`Multiple Azure AD apps with name ${args.options.appName} found: ${response.value.map(x => x.appId)}`);
|
|
48
|
+
}
|
|
49
|
+
return Promise.resolve(spItem.appId);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
commandAction(logger, args, cb) {
|
|
53
|
+
this
|
|
54
|
+
.getAppId(args)
|
|
55
|
+
.then((appId) => {
|
|
56
|
+
const requestOptions = {
|
|
57
|
+
url: `${this.resource}/v1.0/servicePrincipals`,
|
|
58
|
+
headers: {
|
|
59
|
+
accept: 'application/json;odata.metadata=none',
|
|
60
|
+
'content-type': 'application/json;odata=nometadata'
|
|
61
|
+
},
|
|
62
|
+
data: {
|
|
63
|
+
appId: appId
|
|
64
|
+
},
|
|
65
|
+
responseType: 'json'
|
|
66
|
+
};
|
|
67
|
+
return request_1.default.post(requestOptions);
|
|
68
|
+
})
|
|
69
|
+
.then((res) => {
|
|
70
|
+
logger.log(res);
|
|
71
|
+
cb();
|
|
72
|
+
}, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
|
|
73
|
+
}
|
|
74
|
+
options() {
|
|
75
|
+
const options = [
|
|
76
|
+
{
|
|
77
|
+
option: '--appId [appId]'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
option: '--appName [appName]'
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
option: '--objectId [objectId]'
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
const parentOptions = super.options();
|
|
87
|
+
return options.concat(parentOptions);
|
|
88
|
+
}
|
|
89
|
+
validate(args) {
|
|
90
|
+
let optionsSpecified = 0;
|
|
91
|
+
optionsSpecified += args.options.appId ? 1 : 0;
|
|
92
|
+
optionsSpecified += args.options.appName ? 1 : 0;
|
|
93
|
+
optionsSpecified += args.options.objectId ? 1 : 0;
|
|
94
|
+
if (optionsSpecified !== 1) {
|
|
95
|
+
return 'Specify either appId, appName, or objectId';
|
|
96
|
+
}
|
|
97
|
+
if (args.options.appId && !Utils_1.default.isValidGuid(args.options.appId)) {
|
|
98
|
+
return `${args.options.appId} is not a valid appId GUID`;
|
|
99
|
+
}
|
|
100
|
+
if (args.options.objectId && !Utils_1.default.isValidGuid(args.options.objectId)) {
|
|
101
|
+
return `${args.options.objectId} is not a valid objectId GUID`;
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
module.exports = new AadSpAddCommand();
|
|
107
|
+
//# sourceMappingURL=sp-add.js.map
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const prefix = 'aad';
|
|
4
4
|
exports.default = {
|
|
5
5
|
APP_ADD: `${prefix} app add`,
|
|
6
|
+
APP_GET: `${prefix} app get`,
|
|
6
7
|
APP_SET: `${prefix} app set`,
|
|
7
8
|
APP_ROLE_ADD: `${prefix} app role add`,
|
|
8
9
|
APP_ROLE_LIST: `${prefix} app role list`,
|
|
@@ -46,6 +47,7 @@ exports.default = {
|
|
|
46
47
|
SITECLASSIFICATION_ENABLE: `${prefix} siteclassification enable`,
|
|
47
48
|
SITECLASSIFICATION_GET: `${prefix} siteclassification get`,
|
|
48
49
|
SITECLASSIFICATION_SET: `${prefix} siteclassification set`,
|
|
50
|
+
SP_ADD: `${prefix} sp add`,
|
|
49
51
|
SP_GET: `${prefix} sp get`,
|
|
50
52
|
USER_GET: `${prefix} user get`,
|
|
51
53
|
USER_LIST: `${prefix} user list`,
|