Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add GCC support for some cmdlets #3484

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added option to create a Microsoft 365 Group with dynamic membership by passing in `-DynamicMembershipRule` [#3426](https://github.com/pnp/powershell/pull/3426)
- Added `RestrictedAccessControl`, `ClearRestrictedAccessControl`, `RemoveRestrictedAccessControlGroups`, `AddRestrictedAccessControlGroups` and `RestrictedAccessControlGroups` parameters to `Set-PnPTenantSite` cmdlet to handle restricted access control. [#3463](https://github.com/pnp/powershell/pull/3463)
- Added `Get-PnPRetentionLabel` cmdlet to retrieve Purview retention labels. [#3459](https://github.com/pnp/powershell/pull/3459)
- Added GCC support for `Get-PnPAzureADUser` , `Add-PnPFlowOwner` , `Remove-PnPFlowOwner`, `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory`, `New-PnPAzureADUserTemporaryAccessPass` and `Get-PnPAvailableSensitivityLabel` cmdlets. [#3484](https://github.com/pnp/powershell/pull/3484)

### Fixed

Expand Down
8 changes: 4 additions & 4 deletions src/Commands/AzureAD/GetAzureADUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ protected override void ExecuteCmdlet()
PnP.PowerShell.Commands.Model.AzureAD.User user;
if (Guid.TryParse(Identity, out Guid identityGuid))
{
user = PnP.PowerShell.Commands.Utilities.AzureAdUtility.GetUser(AccessToken, identityGuid, ignoreDefaultProperties: IgnoreDefaultProperties, useBetaEndPoint: UseBeta.IsPresent);
user = PnP.PowerShell.Commands.Utilities.AzureAdUtility.GetUser(AccessToken, identityGuid, ignoreDefaultProperties: IgnoreDefaultProperties, useBetaEndPoint: UseBeta.IsPresent, azureEnvironment: Connection.AzureEnvironment);
}
else
{
user = PnP.PowerShell.Commands.Utilities.AzureAdUtility.GetUser(AccessToken, WebUtility.UrlEncode(Identity), Select, ignoreDefaultProperties: IgnoreDefaultProperties, useBetaEndPoint: UseBeta.IsPresent);
user = PnP.PowerShell.Commands.Utilities.AzureAdUtility.GetUser(AccessToken, WebUtility.UrlEncode(Identity), Select, ignoreDefaultProperties: IgnoreDefaultProperties, useBetaEndPoint: UseBeta.IsPresent, azureEnvironment: Connection.AzureEnvironment);
}
WriteObject(user);
}
else if (ParameterSpecified(nameof(Delta)))
{
var userDelta = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUserDelta(AccessToken, DeltaToken, Filter, OrderBy, Select, StartIndex, EndIndex, useBetaEndPoint: UseBeta.IsPresent);
var userDelta = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUserDelta(AccessToken, DeltaToken, Filter, OrderBy, Select, StartIndex, EndIndex, useBetaEndPoint: UseBeta.IsPresent, azureEnvironment: Connection.AzureEnvironment);
WriteObject(userDelta);
}
else
{
var users = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUsers(AccessToken, Filter, OrderBy, Select, ignoreDefaultProperties: IgnoreDefaultProperties, StartIndex, EndIndex, useBetaEndPoint: UseBeta.IsPresent);
var users = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUsers(AccessToken, Filter, OrderBy, Select, ignoreDefaultProperties: IgnoreDefaultProperties, StartIndex, EndIndex, useBetaEndPoint: UseBeta.IsPresent, azureEnvironment: Connection.AzureEnvironment);
WriteObject(users, true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/AzureAD/NewAzureADUserTemporaryAccessPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override void ExecuteCmdlet()
userId: Identity.User?.Id?.ToString() ?? Identity.Upn ?? Identity.UserId,
startDateTime: StartDateTime,
lifeTimeInMinutes: LifeTimeInMinutes,
isUsableOnce: IsUsableOnce);
isUsableOnce: IsUsableOnce, azureEnvironment: Connection.AzureEnvironment);

WriteObject(accessPass);
}
Expand Down
10 changes: 6 additions & 4 deletions src/Commands/Base/PipeBinds/AzureADUserPipeBind.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PnP.PowerShell.Commands.Model.AzureAD;
using PnP.Framework;
using PnP.PowerShell.Commands.Model.AzureAD;
using System;
using System.Net;

Expand Down Expand Up @@ -54,20 +55,21 @@ public AzureADUserPipeBind(string input)
/// Tries to return the User instace based on the information this pipe has available
/// </summary>
/// <param name="accessToken">Access Token for Microsoft Graph that can be used to fetch User data</param>
/// <param name="azureEnvironment">Azure environment cloud</param>
/// <returns>User instance or NULL if unable to define user instance based on the available information</returns>
public User GetUser(string accessToken)
public User GetUser(string accessToken, AzureEnvironment azureEnvironment = AzureEnvironment.Production)
{
if (_user != null)
{
return _user;
}
if (_userId != null)
{
return User.CreateFrom(PnP.Framework.Graph.UsersUtility.GetUser(accessToken, _userId));
return User.CreateFrom(PnP.Framework.Graph.UsersUtility.GetUser(accessToken, _userId, azureEnvironment: azureEnvironment));
}
if (_upn != null)
{
return User.CreateFrom(PnP.Framework.Graph.UsersUtility.GetUser(accessToken, WebUtility.UrlEncode(_upn)));
return User.CreateFrom(PnP.Framework.Graph.UsersUtility.GetUser(accessToken, WebUtility.UrlEncode(_upn), azureEnvironment: azureEnvironment));
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ protected override void ExecuteCmdlet()
if (Guid.TryParse(User, out Guid identityGuid))
{
WriteVerbose("Looking up user through Microsoft Graph by user id {identityGuid}");
user = Utilities.AzureAdUtility.GetUser(graphAccessToken, identityGuid);
user = Utilities.AzureAdUtility.GetUser(graphAccessToken, identityGuid, azureEnvironment: Connection.AzureEnvironment);
}
else
{
WriteVerbose($"Looking up user through Microsoft Graph by user principal name {User}");
user = Utilities.AzureAdUtility.GetUser(graphAccessToken, WebUtility.UrlEncode(User));
user = Utilities.AzureAdUtility.GetUser(graphAccessToken, WebUtility.UrlEncode(User), azureEnvironment: Connection.AzureEnvironment);
}

if (user == null)
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ protected override void ExecuteCmdlet()
if (Guid.TryParse(User, out Guid identityGuid))
{
WriteVerbose("Looking up user through Microsoft Graph by user id {identityGuid}");
user = Utilities.AzureAdUtility.GetUser(graphAccessToken, identityGuid);
user = Utilities.AzureAdUtility.GetUser(graphAccessToken, identityGuid, azureEnvironment: Connection.AzureEnvironment);
}
else
{
WriteVerbose($"Looking up user through Microsoft Graph by user principal name {User}");
user = Utilities.AzureAdUtility.GetUser(graphAccessToken, WebUtility.UrlEncode(User));
user = Utilities.AzureAdUtility.GetUser(graphAccessToken, WebUtility.UrlEncode(User), azureEnvironment: Connection.AzureEnvironment);
}

if (user == null)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Purview/GetAvailableSensitivityLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override void ExecuteCmdlet()
string url;
if (ParameterSpecified(nameof(User)))
{
var user = User.GetUser(AccessToken);
var user = User.GetUser(AccessToken, Connection.AzureEnvironment);

if (user == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override void ExecuteCmdlet()
WriteVerbose("Retrieving users from Azure Active Directory");

// Retrieve all the users from Azure Active Directory
aadUsers = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUsers(GraphAccessToken, null, null, allAadPropertiesList.ToArray(), endIndex: null);
aadUsers = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUsers(GraphAccessToken, null, null, allAadPropertiesList.ToArray(), endIndex: null, azureEnvironment: Connection.AzureEnvironment);

WriteVerbose($"{aadUsers.Count} user{(aadUsers.Count != 1 ? "s have" : " has")} been retrieved from Azure Active Directory");

Expand Down
17 changes: 9 additions & 8 deletions src/Commands/Utilities/AzureAdUtility.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using PnP.Framework;
using PnP.PowerShell.Commands.Model.AzureAD;

namespace PnP.PowerShell.Commands.Utilities
Expand All @@ -24,9 +25,9 @@ internal static class AzureAdUtility
/// <param name="endIndex">Optional end index indicating up to which result to return users. By default all users will be returned.</param>
/// <param name="useBetaEndPoint">Indicates if the v1.0 (false) or beta (true) endpoint should be used at Microsoft Graph to query for the data</param>
/// <returns>UserDelta instance</returns>
public static UserDelta ListUserDelta(string accessToken, string deltaToken, string filter, string orderby, string[] selectProperties = null, int startIndex = 0, int? endIndex = null, bool useBetaEndPoint = false)
public static UserDelta ListUserDelta(string accessToken, string deltaToken, string filter, string orderby, string[] selectProperties = null, int startIndex = 0, int? endIndex = null, bool useBetaEndPoint = false, AzureEnvironment azureEnvironment = AzureEnvironment.Production)
{
var userDelta = PnP.Framework.Graph.UsersUtility.ListUserDelta(accessToken, deltaToken, filter, orderby, selectProperties, startIndex, endIndex, useBetaEndPoint: useBetaEndPoint);
var userDelta = PnP.Framework.Graph.UsersUtility.ListUserDelta(accessToken, deltaToken, filter, orderby, selectProperties, startIndex, endIndex, useBetaEndPoint: useBetaEndPoint, azureEnvironment: azureEnvironment);

var result = new UserDelta
{
Expand All @@ -48,9 +49,9 @@ public static UserDelta ListUserDelta(string accessToken, string deltaToken, str
/// <param name="endIndex">Last item in the results returned by Microsoft Graph to return. Provide NULL to return all results that exist.</param>
/// <param name="useBetaEndPoint">Indicates if the v1.0 (false) or beta (true) endpoint should be used at Microsoft Graph to query for the data</param>
/// <returns>List with User objects</returns>
public static List<User> ListUsers(string accessToken, string filter, string orderby, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false)
public static List<User> ListUsers(string accessToken, string filter, string orderby, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false, AzureEnvironment azureEnvironment = AzureEnvironment.Production)
{
return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, filter, orderby, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint).Select(User.CreateFrom).ToList();
return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, filter, orderby, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint, azureEnvironment: azureEnvironment).Select(User.CreateFrom).ToList();
}

/// <summary>
Expand All @@ -64,9 +65,9 @@ public static List<User> ListUsers(string accessToken, string filter, string ord
/// <param name="endIndex">Last item in the results returned by Microsoft Graph to return. Provide NULL to return all results that exist.</param>
/// <param name="useBetaEndPoint">Indicates if the v1.0 (false) or beta (true) endpoint should be used at Microsoft Graph to query for the data</param>
/// <returns>List with User objects</returns>
public static User GetUser(string accessToken, Guid userId, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false)
public static User GetUser(string accessToken, Guid userId, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false, AzureEnvironment azureEnvironment = AzureEnvironment.Production)
{
return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, $"id eq '{userId}'", null, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint).Select(User.CreateFrom).FirstOrDefault();
return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, $"id eq '{userId}'", null, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint, azureEnvironment: azureEnvironment).Select(User.CreateFrom).FirstOrDefault();
}

/// <summary>
Expand All @@ -80,9 +81,9 @@ public static User GetUser(string accessToken, Guid userId, string[] selectPrope
/// <param name="endIndex">Last item in the results returned by Microsoft Graph to return. Provide NULL to return all results that exist.</param>
/// <param name="useBetaEndPoint">Indicates if the v1.0 (false) or beta (true) endpoint should be used at Microsoft Graph to query for the data</param>
/// <returns>User object</returns>
public static User GetUser(string accessToken, string userPrincipalName, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false)
public static User GetUser(string accessToken, string userPrincipalName, string[] selectProperties = null, bool ignoreDefaultProperties = false, int startIndex = 0, int? endIndex = 999, bool useBetaEndPoint = false, AzureEnvironment azureEnvironment = AzureEnvironment.Production)
{
return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, $"userPrincipalName eq '{userPrincipalName}'", null, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint).Select(User.CreateFrom).FirstOrDefault();
return PnP.Framework.Graph.UsersUtility.ListUsers(accessToken, $"userPrincipalName eq '{userPrincipalName}'", null, selectProperties, startIndex, endIndex, ignoreDefaultProperties: ignoreDefaultProperties, useBetaEndPoint: useBetaEndPoint, azureEnvironment: azureEnvironment).Select(User.CreateFrom).FirstOrDefault();
}

#endregion
Expand Down