@pnp/cli-microsoft365 4.2.0-beta.eca91f0 → 4.2.0
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 +2 -2
- 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/o365group/o365group-add.js +56 -50
- package/dist/m365/aad/commands/oauth2grant/oauth2grant-add.js +5 -8
- package/dist/m365/aad/commands/oauth2grant/oauth2grant-set.js +3 -3
- package/dist/m365/aad/commands/sp/sp-add.js +107 -0
- package/dist/m365/aad/commands.js +1 -0
- package/dist/m365/base/M365RcJson.js +3 -0
- package/dist/m365/file/commands/file-add.js +32 -13
- package/dist/m365/file/commands/file-list.js +181 -0
- package/dist/m365/file/commands.js +2 -1
- 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/listitem/listitem-attachment-list.js +90 -0
- 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.js +3 -1
- package/dist/m365/teams/commands/report/report-directroutingcalls.js +1 -1
- package/dist/m365/teams/commands/report/report-pstncalls.js +1 -1
- package/docs/docs/cmd/aad/app/app-add.md +11 -0
- package/docs/docs/cmd/aad/o365group/o365group-add.md +1 -0
- package/docs/docs/cmd/aad/oauth2grant/oauth2grant-set.md +3 -2
- package/docs/docs/cmd/aad/sp/sp-add.md +53 -0
- package/docs/docs/cmd/file/file-add.md +11 -0
- package/docs/docs/cmd/file/file-list.md +46 -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/listitem/listitem-attachment-list.md +39 -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/teams/report/report-directroutingcalls.md +0 -3
- package/docs/docs/cmd/teams/report/report-pstncalls.md +4 -3
- package/npm-shrinkwrap.json +508 -886
- package/package.json +19 -18
package/.devcontainer/Dockerfile
CHANGED
|
@@ -23,11 +23,11 @@ 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
|
|
|
30
|
-
RUN pip3 install mkdocs-material==
|
|
30
|
+
RUN pip3 install mkdocs-material==7.1.7 pymdown-extensions==9.0
|
|
31
31
|
|
|
32
32
|
RUN useradd \
|
|
33
33
|
--user-group \
|
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();
|
|
@@ -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)
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const request_1 = require("../../../../request");
|
|
4
4
|
const Utils_1 = require("../../../../Utils");
|
|
5
|
-
const
|
|
5
|
+
const GraphCommand_1 = require("../../../base/GraphCommand");
|
|
6
6
|
const commands_1 = require("../../commands");
|
|
7
|
-
class AadOAuth2GrantAddCommand extends
|
|
7
|
+
class AadOAuth2GrantAddCommand extends GraphCommand_1.default {
|
|
8
8
|
get name() {
|
|
9
9
|
return commands_1.default.OAUTH2GRANT_ADD;
|
|
10
10
|
}
|
|
@@ -16,20 +16,17 @@ class AadOAuth2GrantAddCommand extends AadCommand_1.default {
|
|
|
16
16
|
logger.logToStderr(`Granting the service principal specified permissions...`);
|
|
17
17
|
}
|
|
18
18
|
const requestOptions = {
|
|
19
|
-
url: `${this.resource}/
|
|
19
|
+
url: `${this.resource}/v1.0/oauth2PermissionGrants`,
|
|
20
20
|
headers: {
|
|
21
|
-
'content-type': 'application/json'
|
|
21
|
+
'content-type': 'application/json;odata.metadata=none'
|
|
22
22
|
},
|
|
23
23
|
responseType: 'json',
|
|
24
24
|
data: {
|
|
25
|
-
"odata.type": "Microsoft.DirectoryServices.OAuth2PermissionGrant",
|
|
26
25
|
"clientId": args.options.clientId,
|
|
27
26
|
"consentType": "AllPrincipals",
|
|
28
27
|
"principalId": null,
|
|
29
28
|
"resourceId": args.options.resourceId,
|
|
30
|
-
"scope": args.options.scope
|
|
31
|
-
"startTime": "0001-01-01T00:00:00",
|
|
32
|
-
"expiryTime": "9000-01-01T00:00:00"
|
|
29
|
+
"scope": args.options.scope
|
|
33
30
|
}
|
|
34
31
|
};
|
|
35
32
|
request_1.default
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const request_1 = require("../../../../request");
|
|
4
|
-
const
|
|
4
|
+
const GraphCommand_1 = require("../../../base/GraphCommand");
|
|
5
5
|
const commands_1 = require("../../commands");
|
|
6
|
-
class AadOAuth2GrantSetCommand extends
|
|
6
|
+
class AadOAuth2GrantSetCommand extends GraphCommand_1.default {
|
|
7
7
|
get name() {
|
|
8
8
|
return commands_1.default.OAUTH2GRANT_SET;
|
|
9
9
|
}
|
|
@@ -15,7 +15,7 @@ class AadOAuth2GrantSetCommand extends AadCommand_1.default {
|
|
|
15
15
|
logger.logToStderr(`Updating OAuth2 permissions...`);
|
|
16
16
|
}
|
|
17
17
|
const requestOptions = {
|
|
18
|
-
url: `${this.resource}/
|
|
18
|
+
url: `${this.resource}/v1.0/oauth2PermissionGrants/${encodeURIComponent(args.options.grantId)}`,
|
|
19
19
|
headers: {
|
|
20
20
|
'content-type': 'application/json'
|
|
21
21
|
},
|
|
@@ -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
|
|
@@ -46,6 +46,7 @@ exports.default = {
|
|
|
46
46
|
SITECLASSIFICATION_ENABLE: `${prefix} siteclassification enable`,
|
|
47
47
|
SITECLASSIFICATION_GET: `${prefix} siteclassification get`,
|
|
48
48
|
SITECLASSIFICATION_SET: `${prefix} siteclassification set`,
|
|
49
|
+
SP_ADD: `${prefix} sp add`,
|
|
49
50
|
SP_GET: `${prefix} sp get`,
|
|
50
51
|
USER_GET: `${prefix} user get`,
|
|
51
52
|
USER_LIST: `${prefix} user list`,
|
|
@@ -20,7 +20,7 @@ class FileAddCommand extends GraphCommand_1.default {
|
|
|
20
20
|
folderUrlWithoutTrailingSlash = folderUrlWithoutTrailingSlash.substr(0, folderUrlWithoutTrailingSlash.length - 1);
|
|
21
21
|
}
|
|
22
22
|
this
|
|
23
|
-
.getGraphFileUrl(logger, `${folderUrlWithoutTrailingSlash}/${path.basename(args.options.filePath)}
|
|
23
|
+
.getGraphFileUrl(logger, `${folderUrlWithoutTrailingSlash}/${path.basename(args.options.filePath)}`, args.options.siteUrl)
|
|
24
24
|
.then(graphFileUrl => this.uploadFile(args.options.filePath, graphFileUrl))
|
|
25
25
|
.then(_ => cb(), rawRes => this.handleRejectedODataJsonPromise(rawRes, logger, cb));
|
|
26
26
|
}
|
|
@@ -80,20 +80,23 @@ class FileAddCommand extends GraphCommand_1.default {
|
|
|
80
80
|
*
|
|
81
81
|
* @param logger Logger instance
|
|
82
82
|
* @param fileWebUrl Web URL of the file for which to get drive item URL
|
|
83
|
+
* @param siteUrl URL of the site to which upload the file. Optional. Specify to suppress lookup.
|
|
83
84
|
* @returns Graph's drive item URL for the specified file
|
|
84
85
|
*/
|
|
85
|
-
getGraphFileUrl(logger, fileWebUrl) {
|
|
86
|
+
getGraphFileUrl(logger, fileWebUrl, siteUrl) {
|
|
86
87
|
if (this.debug) {
|
|
87
88
|
logger.logToStderr(`Resolving Graph drive item URL for ${fileWebUrl}`);
|
|
88
89
|
}
|
|
89
|
-
const
|
|
90
|
+
const _fileWebUrl = url.parse(fileWebUrl);
|
|
91
|
+
const _siteUrl = url.parse(siteUrl || fileWebUrl);
|
|
92
|
+
const isSiteUrl = typeof siteUrl !== 'undefined';
|
|
90
93
|
let siteId = '';
|
|
91
94
|
let driveRelativeFileUrl = '';
|
|
92
95
|
return this
|
|
93
|
-
.getGraphSiteInfoFromFullUrl(
|
|
96
|
+
.getGraphSiteInfoFromFullUrl(_siteUrl.host, _siteUrl.path, isSiteUrl)
|
|
94
97
|
.then(siteInfo => {
|
|
95
98
|
siteId = siteInfo.id;
|
|
96
|
-
let siteRelativeFileUrl =
|
|
99
|
+
let siteRelativeFileUrl = _fileWebUrl.path.replace(siteInfo.serverRelativeUrl, '');
|
|
97
100
|
// normalize site-relative URLs for root site collections and root sites
|
|
98
101
|
if (!siteRelativeFileUrl.startsWith('/')) {
|
|
99
102
|
siteRelativeFileUrl = '/' + siteRelativeFileUrl;
|
|
@@ -116,13 +119,14 @@ class FileAddCommand extends GraphCommand_1.default {
|
|
|
116
119
|
* Automatically detects which path chunks correspond to (sub)site.
|
|
117
120
|
* @param hostName SharePoint host name, eg. contoso.sharepoint.com
|
|
118
121
|
* @param urlPath Server-relative file URL, eg. /sites/site/docs/file1.aspx
|
|
122
|
+
* @param isSiteUrl Set to true to indicate that the specified URL is a site URL
|
|
119
123
|
* @returns ID and server-relative URL of the site denoted by urlPath
|
|
120
124
|
*/
|
|
121
|
-
getGraphSiteInfoFromFullUrl(hostName, urlPath) {
|
|
125
|
+
getGraphSiteInfoFromFullUrl(hostName, urlPath, isSiteUrl) {
|
|
122
126
|
const siteId = '';
|
|
123
127
|
const urlChunks = urlPath.split('/');
|
|
124
128
|
return new Promise((resolve, reject) => {
|
|
125
|
-
this.getGraphSiteInfo(hostName, urlChunks, 0, siteId, resolve, reject);
|
|
129
|
+
this.getGraphSiteInfo(hostName, urlChunks, isSiteUrl ? urlChunks.length - 1 : 0, siteId, resolve, reject);
|
|
126
130
|
});
|
|
127
131
|
}
|
|
128
132
|
/**
|
|
@@ -156,20 +160,28 @@ class FileAddCommand extends GraphCommand_1.default {
|
|
|
156
160
|
},
|
|
157
161
|
responseType: 'json'
|
|
158
162
|
};
|
|
163
|
+
const getResult = (id, serverRelativeUrl) => {
|
|
164
|
+
return {
|
|
165
|
+
id,
|
|
166
|
+
serverRelativeUrl
|
|
167
|
+
};
|
|
168
|
+
};
|
|
159
169
|
request_1.default
|
|
160
170
|
.get(requestOptions)
|
|
161
171
|
.then((res) => {
|
|
162
|
-
|
|
172
|
+
if (currentChunk === urlChunks.length - 1) {
|
|
173
|
+
resolve(getResult(res.id, currentPath));
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this.getGraphSiteInfo(hostName, urlChunks, ++currentChunk, res.id, resolve, reject);
|
|
177
|
+
}
|
|
163
178
|
}, err => {
|
|
164
179
|
if (lastSiteId) {
|
|
165
180
|
let serverRelativeUrl = `${urlChunks.slice(0, currentChunk).join('/')}`;
|
|
166
181
|
if (!serverRelativeUrl.startsWith('/')) {
|
|
167
182
|
serverRelativeUrl = '/' + serverRelativeUrl;
|
|
168
183
|
}
|
|
169
|
-
resolve(
|
|
170
|
-
id: lastSiteId,
|
|
171
|
-
serverRelativeUrl: serverRelativeUrl
|
|
172
|
-
});
|
|
184
|
+
resolve(getResult(lastSiteId, serverRelativeUrl));
|
|
173
185
|
}
|
|
174
186
|
else {
|
|
175
187
|
reject(err);
|
|
@@ -206,7 +218,8 @@ class FileAddCommand extends GraphCommand_1.default {
|
|
|
206
218
|
options() {
|
|
207
219
|
const options = [
|
|
208
220
|
{ option: '-u, --folderUrl <folderUrl>' },
|
|
209
|
-
{ option: '-p, --filePath <filePath>' }
|
|
221
|
+
{ option: '-p, --filePath <filePath>' },
|
|
222
|
+
{ option: '--siteUrl [siteUrl]' }
|
|
210
223
|
];
|
|
211
224
|
const parentOptions = super.options();
|
|
212
225
|
return options.concat(parentOptions);
|
|
@@ -215,6 +228,12 @@ class FileAddCommand extends GraphCommand_1.default {
|
|
|
215
228
|
if (!fs.existsSync(args.options.filePath)) {
|
|
216
229
|
return `Specified source file ${args.options.sourceFile} doesn't exist`;
|
|
217
230
|
}
|
|
231
|
+
if (args.options.siteUrl) {
|
|
232
|
+
const isValidSiteUrl = SpoCommand_1.default.isValidSharePointUrl(args.options.siteUrl);
|
|
233
|
+
if (isValidSiteUrl !== true) {
|
|
234
|
+
return isValidSiteUrl;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
218
237
|
return SpoCommand_1.default.isValidSharePointUrl(args.options.folderUrl);
|
|
219
238
|
}
|
|
220
239
|
}
|