Skip to content

Commit 8110e97

Browse files
KoenZomersgautamdshetherwinvanhunenPaoloPiamarkgort86
authored
Adding in depth verbose logging to Graph based cmdlets (#4023)
* Adding additional information, removing alias as it works inversed from the original cmdlet name, only kept the Graph name and ditched the Exchange Online name * Added code to distinguish the type of token being used (Delegate vs AppOnly) and using it to show a warning if properties are being set with the wrong token type * Renaming method as this makes more sense * Changed code to pass along the cmdlet instance so logging can take place in deeper levels * Rewrote async functionality to become sync as PowerShell doesn't support async handling anyway * Optimized logging * Further fixes and optimization * Removing logging oauth token to verbose output * Add verbose logging of HTTP body * Removed async from method as it was no longer async anyway * Fixing Sync HttpClient Sends to support HTTP/2 * Further testing and optimization. Now also writing verbose if the permissions set through the attribute above the cmdlet are present in the current access token. * Added code to distinguish the type of token being used (Delegate vs AppOnly) and using it to show a warning if properties are being set with the wrong token type * Renaming method as this makes more sense * Removing logging oauth token to verbose output * Add verbose logging of HTTP body * Removed async from method as it was no longer async anyway * Nightly publish to PowerShell Gallery * Nightly publish to PowerShell Gallery * Updated documentation for Set-PnPFolderPermission (#4025) Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com> * Update Set-PnPList.md (#4020) See #3783 where an issue is described when this feature is not activated. So maybe this PR makes the documentation more clear. Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com> * New cmdlet for Get-PnPTenantRestrictedSearchAllowedList (#3997) * new cmdlet * correct space * add documentation --------- Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com> * Update CHANGELOG.md * Feature #4028 : return EnableAIPIntegation in Get-PnPTenant cmdlet (#4030) Co-authored-by: Gautam Sheth <gautam.sheth@staffbase.com> * Fix #3908: improve connection validation in ConnectOnline.cs (#4031) Co-authored-by: Gautam Sheth <gautam.sheth@staffbase.com> * Adding `-IsSharePointAddInsDisabled` to `Set-PnPTenant` (#4032) * Added -IsSharePointAddInsDisabled to Set-PnPTenant * Added PR reference * Nightly publish to PowerShell Gallery * Nightly publish to PowerShell Gallery * Fix error handling in Remove-PnPTeamsChannel (#4036) Fix Remove-PnPTeamsChannel error handling mismatch between "Team not found", "Channel not found" and no error. * Update CHANGELOG.md * More settings related to version trim ,ReadOnlyForUnmanagedDevices and RestrictContentOrgWideSearch (#4024) * More settings related to version trim ,ReadOnlyForUnmanagedDevices and RestrictContentOrgWideSearch * remove reference to forms * remove version trim settings --------- Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com> * Update CHANGELOG.md * Fixing Sync HttpClient Sends to support HTTP/2 * Further testing and optimization. Now also writing verbose if the permissions set through the attribute above the cmdlet are present in the current access token. * Rebasing to close the gap with dev * Added changelog entry * Optimizations * Code cleanup and simplification * Fixing typo * Moving changelog entry to nightly --------- Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com> Co-authored-by: erwinvanhunen <erwinvanhunen@users.noreply.github.com> Co-authored-by: Paolo Pialorsi <paolo@pialorsi.com> Co-authored-by: Mark Gort <52573368+markgort86@users.noreply.github.com> Co-authored-by: Reshmee Auckloo <reshmee011@gmail.com> Co-authored-by: Gautam Sheth <gautam.sheth@staffbase.com> Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
1 parent f4820d5 commit 8110e97

File tree

202 files changed

+1279
-1209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+1279
-1209
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
99
## [Current Nightly]
1010

1111
### Added
12-
12+
- Added in depth verbose logging to all cmdlets which is revealed by adding `-Verbose` to the cmdlet execution [#4023](https://github.com/pnp/powershell/pull/4023)
13+
1314
### Fixed
1415

1516
### Changed
@@ -18,6 +19,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1819

1920
### Contributors
2021

22+
- Koen Zomers [koenzomers]
23+
2124
## [2.5.0]
2225

2326
### Added

src/Commands/Admin/GetTenantInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected override void ExecuteCmdlet()
3535
var requestUrl = BuildRequestUrl();
3636

3737
WriteVerbose($"Making call to {requestUrl} to request tenant information");
38-
var results = RestHelper.GetAsync<Model.TenantInfo>(Connection.HttpClient, requestUrl, graphAccessToken).GetAwaiter().GetResult();
38+
var results = RestHelper.Get<Model.TenantInfo>(Connection.HttpClient, requestUrl, graphAccessToken);
3939
WriteObject(results, true);
4040
}
4141

src/Commands/Admin/PublishCompanyApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected override void ExecuteCmdlet()
185185
if (!NoUpload)
186186
{
187187
var bytes = System.IO.File.ReadAllBytes(System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, $"{AppName}.zip"));
188-
TeamsUtility.AddAppAsync(Connection, GraphAccessToken, bytes).GetAwaiter().GetResult();
188+
TeamsUtility.AddApp(this, Connection, GraphAccessToken, bytes);
189189
WriteObject($"Teams app uploaded to teams app Store.");
190190
}
191191
}

src/Commands/Admin/RenameTenantSite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected override void ExecuteCmdlet()
6868
OperationId = Guid.Empty
6969
};
7070

71-
var results = Utilities.REST.RestHelper.PostAsync<SPOSiteRenameJob>(HttpClient, $"{AdminContext.Url.TrimEnd('/')}/_api/SiteRenameJobs?api-version=1.4.7", AdminContext, body, false).GetAwaiter().GetResult();
71+
var results = Utilities.REST.RestHelper.Post<SPOSiteRenameJob>(HttpClient, $"{AdminContext.Url.TrimEnd('/')}/_api/SiteRenameJobs?api-version=1.4.7", AdminContext, body, false);
7272
if (!Wait.IsPresent)
7373
{
7474
if (results != null)

src/Commands/Apps/AddAzureADServicePrincipalAppRole.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class AddAzureADServicePrincipalAppRole : PnPGraphCmdlet
3434

3535
protected override void ExecuteCmdlet()
3636
{
37-
var principal = Principal.GetServicePrincipal(Connection, AccessToken);
37+
var principal = Principal.GetServicePrincipal(this, Connection, AccessToken);
3838

3939
if(principal == null)
4040
{
@@ -47,7 +47,7 @@ protected override void ExecuteCmdlet()
4747

4848
if (AppRole.AppRole == null)
4949
{
50-
var resource = ParameterSetName == ParameterSet_BYBUILTINTYPE ? ServicePrincipalUtility.GetServicePrincipalByBuiltInType(Connection, AccessToken, BuiltInType) : Resource.GetServicePrincipal(Connection, AccessToken);
50+
var resource = ParameterSetName == ParameterSet_BYBUILTINTYPE ? ServicePrincipalUtility.GetServicePrincipalByBuiltInType(this, Connection, AccessToken, BuiltInType) : Resource.GetServicePrincipal(this, Connection, AccessToken);
5151

5252
if (resource == null)
5353
{
@@ -67,7 +67,7 @@ protected override void ExecuteCmdlet()
6767

6868
WriteVerbose($"Adding app role {appRole.Value}: {appRole.DisplayName}");
6969

70-
var response = ServicePrincipalUtility.AddServicePrincipalRoleAssignment(Connection, AccessToken, principal, appRole);
70+
var response = ServicePrincipalUtility.AddServicePrincipalRoleAssignment(this, Connection, AccessToken, principal, appRole);
7171
WriteObject(response, false);
7272
}
7373
}

src/Commands/Apps/GetAzureADAppSitePermission.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ protected override void ExecuteCmdlet()
5252
var accessToken = AccessToken;
5353

5454
// All permissions, first fetch just the Ids as the API works in a weird way that requesting all permissions does not reveal their roles, so we will request all permissions and then request each permission individually so we will also have the roles
55-
var permissions = GraphHelper.GetResultCollectionAsync<AzureADAppPermissionInternal>(Connection, $"https://{Connection.GraphEndPoint}/v1.0/sites/{siteId}/permissions?$select=Id", accessToken).GetAwaiter().GetResult();
55+
var permissions = GraphHelper.GetResultCollection<AzureADAppPermissionInternal>(this, Connection, $"https://{Connection.GraphEndPoint}/v1.0/sites/{siteId}/permissions?$select=Id", accessToken);
5656
if (permissions.Any())
5757
{
5858
var results = new List<AzureADAppPermission>();
5959
foreach (var permission in permissions)
6060
{
6161
// Request the permission individually so it will include the roles
62-
var detailedApp = GraphHelper.GetAsync<AzureADAppPermissionInternal>(Connection, $"https://{Connection.GraphEndPoint}/v1.0/sites/{siteId}/permissions/{permission.Id}", accessToken).GetAwaiter().GetResult();
62+
var detailedApp = GraphHelper.Get<AzureADAppPermissionInternal>(this, Connection, $"https://{Connection.GraphEndPoint}/v1.0/sites/{siteId}/permissions/{permission.Id}", accessToken);
6363
results.Add(detailedApp.Convert());
6464
}
6565

@@ -76,7 +76,7 @@ protected override void ExecuteCmdlet()
7676
}
7777
else
7878
{
79-
var results = GraphHelper.GetAsync<AzureADAppPermissionInternal>(Connection, $"https://{Connection.GraphEndPoint}/v1.0/sites/{siteId}/permissions/{PermissionId}", AccessToken).GetAwaiter().GetResult();
79+
var results = GraphHelper.Get<AzureADAppPermissionInternal>(this, Connection, $"https://{Connection.GraphEndPoint}/v1.0/sites/{siteId}/permissions/{PermissionId}", AccessToken);
8080
WriteObject(results.Convert());
8181
}
8282
}

src/Commands/Apps/GetAzureADServicePrincipal.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ protected override void ExecuteCmdlet()
4242
switch (ParameterSetName)
4343
{
4444
case ParameterSet_BYAPPID:
45-
servicePrincipal = ServicePrincipalUtility.GetServicePrincipalByAppId(Connection, AccessToken, AppId);
45+
servicePrincipal = ServicePrincipalUtility.GetServicePrincipalByAppId(this, Connection, AccessToken, AppId);
4646
break;
4747
case ParameterSet_BYOBJECTID:
48-
servicePrincipal = ServicePrincipalUtility.GetServicePrincipalByObjectId(Connection, AccessToken, ObjectId);
48+
servicePrincipal = ServicePrincipalUtility.GetServicePrincipalByObjectId(this, Connection, AccessToken, ObjectId);
4949
break;
5050
case ParameterSet_BYAPPNAME:
51-
servicePrincipal = ServicePrincipalUtility.GetServicePrincipalByAppName(Connection, AccessToken, AppName);
51+
servicePrincipal = ServicePrincipalUtility.GetServicePrincipalByAppName(this, Connection, AccessToken, AppName);
5252
break;
5353
case ParameterSet_BYBUILTINTYPE:
54-
servicePrincipal = ServicePrincipalUtility.GetServicePrincipalByBuiltInType(Connection, AccessToken, BuiltInType);
54+
servicePrincipal = ServicePrincipalUtility.GetServicePrincipalByBuiltInType(this, Connection, AccessToken, BuiltInType);
5555
break;
5656
case ParameterSet_ALL:
57-
var servicePrincipals = ServicePrincipalUtility.GetServicePrincipals(Connection, AccessToken, Filter);
57+
var servicePrincipals = ServicePrincipalUtility.GetServicePrincipals(this, Connection, AccessToken, Filter);
5858
WriteObject(servicePrincipals, true);
5959
return;
6060
}

src/Commands/Apps/GetAzureADServicePrincipalAssignedAppRole.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class GetAzureADServicePrincipalAssignedAppRole : PnPGraphCmdlet
2222

2323
protected override void ExecuteCmdlet()
2424
{
25-
var principal = Principal.GetServicePrincipal(Connection, AccessToken);
25+
var principal = Principal.GetServicePrincipal(this, Connection, AccessToken);
2626

2727
if(principal == null)
2828
{
@@ -31,7 +31,7 @@ protected override void ExecuteCmdlet()
3131

3232
WriteVerbose($"Requesting currently assigned app roles to service principal {principal.DisplayName}");
3333

34-
var appRoleAssignments = ServicePrincipalUtility.GetServicePrincipalAppRoleAssignmentsByServicePrincipalObjectId(Connection, AccessToken, principal.Id);
34+
var appRoleAssignments = ServicePrincipalUtility.GetServicePrincipalAppRoleAssignmentsByServicePrincipalObjectId(this, Connection, AccessToken, principal.Id);
3535
if(ParameterSpecified(nameof(Identity)))
3636
{
3737
var appRole = Identity.GetAvailableAppRole(Connection, AccessToken, principal);

src/Commands/Apps/GetAzureADServicePrincipalAvailableAppRole.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class GetAzureADServicePrincipalAvailableAppRole : PnPGraphCmdlet
2121

2222
protected override void ExecuteCmdlet()
2323
{
24-
var principal = Principal.GetServicePrincipal(Connection, AccessToken);
24+
var principal = Principal.GetServicePrincipal(this, Connection, AccessToken);
2525

2626
if(principal == null)
2727
{

src/Commands/Apps/GrantAzureADAppSitePermission.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected override void ExecuteCmdlet()
5656

5757
// Adding a fix for multi-geo issue
5858
// https://github.com/pnp/powershell/issues/2801
59-
var multiGeoFix = Utilities.REST.RestHelper.GetAsync(Connection.HttpClient, $"https://{Connection.GraphEndPoint}/v1.0/sites/{siteId}", AccessToken).GetAwaiter().GetResult();
59+
var multiGeoFix = Utilities.REST.RestHelper.Get(Connection.HttpClient, $"https://{Connection.GraphEndPoint}/v1.0/sites/{siteId}", AccessToken);
6060

6161
// Construct the payload of the Graph request
6262
var payload = new
@@ -83,7 +83,7 @@ protected override void ExecuteCmdlet()
8383
WriteVerbose($"Granting App with Id {AppId} the permission{(payload.roles.Length != 1 ? "s" : "")} {string.Join(',', payload.roles)}");
8484

8585
// Make the Graph Grant request
86-
var result = Utilities.REST.RestHelper.PostAsync<AzureADAppPermissionInternal>(Connection.HttpClient, $"https://{Connection.GraphEndPoint}/v1.0/sites/{siteId}/permissions", AccessToken, payload).GetAwaiter().GetResult();
86+
var result = Utilities.REST.RestHelper.Post<AzureADAppPermissionInternal>(Connection.HttpClient, $"https://{Connection.GraphEndPoint}/v1.0/sites/{siteId}/permissions", AccessToken, payload);
8787
WriteObject(result.Convert());
8888
}
8989
}

0 commit comments

Comments
 (0)