diff --git a/config/ModulesMapping.jsonc b/config/ModulesMapping.jsonc
index e30f63a2297..760d1a25ee3 100644
--- a/config/ModulesMapping.jsonc
+++ b/config/ModulesMapping.jsonc
@@ -13,7 +13,7 @@
"Files": "^drives\\.|^shares\\.|^users.drive$|^groups.drive$",
"Financials": "^financials\\.",
"Groups": "^groups.group$|^groups.directoryObject$|^groups.conversation$|^groups.endpoint$|^groups.extension$|^groups.resourceSpecificPermissionGrant$|^groups.profilePhoto$|^groups.conversationThread$|^groupLifecyclePolicies\\.|^users.group$|^groups.directorySetting$|^groups.Actions$|^groups.Functions$",
- "Identity.DirectoryManagement": "^administrativeUnits\\.|^contacts\\.|^devices\\.|^domains\\.|^directoryRoles\\.|^directoryRoleTemplates\\.|^directorySettingTemplates\\.|^settings\\.|^subscribedSkus\\.|^contracts\\.|^directory\\.|^users.scopedRoleMembership$|^organization.organization$|^organization.organizationalBranding$|^organization.organizationSettings $|^organization.Actions$|^organization.extension$",
+ "Identity.DirectoryManagement": "^administrativeUnits\\.|^contacts\\.|^devices\\.|^domains\\.|^directoryRoles\\.|^directoryRoleTemplates\\.|^directorySettingTemplates\\.|^settings\\.|^subscribedSkus\\.|^contracts\\.|^directory\\.|^users.scopedRoleMembership$|^organization.organization$|^organization.organizationalBranding$|^organization.organizationSettings$|^organization.Actions$|^organization.extension$",
"Identity.Governance": "^accessReviews\\.|^businessFlowTemplates\\.|^programs\\.|^programControls\\.|^programControlTypes\\.|^privilegedRoles\\.|^privilegedRoleAssignments\\.|^privilegedRoleAssignmentRequests\\.|^privilegedApproval\\.|^privilegedOperationEvents\\.|^privilegedAccess\\.|^agreements\\.|^users.agreementAcceptance$|^identityGovernance.entitlementManagement$|^identityGovernance.Functions$|^identityGovernance.Actions$",
"Identity.SignIns": "^organization.certificateBasedAuthConfiguration$|^invitations\\.|^identityProviders\\.|^oauth2PermissionGrants\\.|^riskDetections\\.|^riskyUsers\\.|^dataPolicyOperations\\.|^identity.identityUserFlow$|^trustFramework\\.|^informationProtection\\.|^policies\\.|^users.authentication$|^users.informationProtection$|^identity.conditionalAccessRoot$",
"Mail": "^users.inferenceClassification$|^users.mailFolder$|^users.message$",
@@ -26,7 +26,7 @@
"Search": "^search\\.|^external\\.",
"Security": "^Security\\.",
"Sites": "^sites.site$|^sites.itemAnalytics$|^sites.columnDefinition$|^sites.contentType$|^sites.drive$|^sites.list$|^sites.sitePage$|^users.site$|^groups.site$|^sites.Functions$|^sites.Actions$",
- "Teams": "^teams\\.|^chats\\.|^users.chat$|^appCatalogs$|^users.userTeamwork$|^teamwork\\.|^users.team$|^users.userTeamwork$|^groups.team$",
+ "Teams": "^teams\\.|^chats\\.|^users.chat$|^appCatalogs.teamsApp$|^users.userTeamwork$|^teamwork\\.|^users.team$|^groups.team$",
"Users": "^users.user$|^users.directoryObject$|^users.licenseDetails$|^users.notification$|^users.outlookUser$|^users.profilePhoto$|^users.userSettings$|^users.extension$|^users.oAuth2PermissionGrant$|^users.todo$",
"Users.Actions": "^users.Actions$",
"Users.Functions": "^users.Functions$"
diff --git a/src/Applications/Applications/readme.md b/src/Applications/Applications/readme.md
index 4f9c1720cd8..7a0ef89821f 100644
--- a/src/Applications/Applications/readme.md
+++ b/src/Applications/Applications/readme.md
@@ -38,6 +38,9 @@ subject-prefix: ''
``` yaml
directive:
+# Remove invalid paths.
+ - remove-path-by-operation: onPremisesPublishingProfiles\.(connectors\.memberOf_.*|connectors_GetMemberOf|connectorGroups\.members_.*|connectorGroups_(Get|Create|Update|Delete)Members)
+
# Remove cmdlets
- where:
verb: Test
@@ -69,6 +72,11 @@ directive:
subject: ^OnPremis(PublishingProfile.*)$
set:
subject: OnPremise$1
+# Fix cmdlet name
+ - where:
+ subject: (^OnPremisePublishingProfileConnectorMember$)
+ set:
+ subject: $1Of
```
### Versioning
diff --git a/src/Authentication/Authentication/Common/DiskDataStore.cs b/src/Authentication/Authentication/Common/DiskDataStore.cs
index 667791297e4..6331d987b51 100644
--- a/src/Authentication/Authentication/Common/DiskDataStore.cs
+++ b/src/Authentication/Authentication/Common/DiskDataStore.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Graph.PowerShell.Authentication.Common
///
/// Disk data store based on System.IO APIs.
///
- internal class DiskDataStore : IDataStore
+ public class DiskDataStore : IDataStore
{
///
/// Writes the given contents to the specified file.
diff --git a/src/Authentication/Authentication/Common/ProtectedFileProvider.cs b/src/Authentication/Authentication/Common/ProtectedFileProvider.cs
index 4bf2514e263..599e937fbcb 100644
--- a/src/Authentication/Authentication/Common/ProtectedFileProvider.cs
+++ b/src/Authentication/Authentication/Common/ProtectedFileProvider.cs
@@ -22,7 +22,7 @@ public enum FileProtection
/// The file can be accessed in ReadOnly or ReadWrite mode.
/// This class MUST be disposed by the caller.
///
- internal abstract class ProtectedFileProvider : IFileProvider, IDisposable
+ public abstract class ProtectedFileProvider : IFileProvider, IDisposable
{
protected Stream _stream;
public const int MaxTries = 30;
diff --git a/src/Files/Files/readme.md b/src/Files/Files/readme.md
index af7eb70b7a5..a0faac5c5b7 100644
--- a/src/Files/Files/readme.md
+++ b/src/Files/Files/readme.md
@@ -38,7 +38,7 @@ subject-prefix: ''
``` yaml
directive:
- - remove-path-by-operation: .*_(Create|Get|Update|Set|Delete)Activities$|.*\.activities.*$
+ - remove-path-by-operation: .*_(Create|Get|Update|Set|Delete)Activities$|.*\.activities.*$|shares\..*_createLink
```
### Versioning
diff --git a/src/readme.graph.md b/src/readme.graph.md
index ce60a66c993..413b58a76f1 100644
--- a/src/readme.graph.md
+++ b/src/readme.graph.md
@@ -6,7 +6,7 @@
azure: false
powershell: true
version: latest
-use: "@autorest/powershell@latest"
+use: "@autorest/powershell@2.1.401"
metadata:
authors: Microsoft Corporation
owners: Microsoft Corporation
@@ -555,6 +555,49 @@ directive:
return $;
}
+# Modify generated .cs file download cmdlets.
+ - from: source-file-csharp
+ where: $
+ transform: >
+ if (!$documentPath.match(/generated%2Fcmdlets%2FGet\w*\d*.cs/gm))
+ {
+ return $;
+ } else {
+ let outFileParameterRegex = /(^\s*)public\s*global::System\.String\s*OutFile\s*/gmi
+ let streamResponseRegex = /global::System\.Threading\.Tasks\.Task\s*response/gmi
+ if($.match(outFileParameterRegex) && $.match(streamResponseRegex)) {
+ // Handle file download.
+ let overrideOnOkCallRegex = /(^\s*)(overrideOnOk\(\s*responseMessage\s*,\s*response\s*,\s*ref\s*_returnNow\s*\);)/gmi
+ $ = $.replace(overrideOnOkCallRegex, '$1$2\n$1using(var stream = await response){ this.WriteToFile(responseMessage, stream, this.GetProviderPath(OutFile, false), _cancellationTokenSource.Token); _returnNow = global::System.Threading.Tasks.Task.FromResult(true);}\n$1');
+ }
+ return $;
+ }
+
+# Modify generated .cs file upload cmdlets.
+ - from: source-file-csharp
+ where: $
+ transform: >
+ if (!$documentPath.match(/generated%2Fcmdlets%2FSet\w*\d*.cs/gm))
+ {
+ return $;
+ } else {
+ let streamBodyParameterRegex = /(^\s*)public\s*global::System.IO.Stream\s*BodyParameter\s*/gmi
+ if($.match(streamBodyParameterRegex)) {
+ // Replace base class with FileUploadCmdlet.
+ let psBaseClassImplementationRegex = /(\s*:\s*)(global::System.Management.Automation.PSCmdlet)/gmi
+ $ = $.replace(psBaseClassImplementationRegex, '$1Microsoft.Graph.PowerShell.Cmdlets.Custom.FileUploadCmdlet');
+
+ // Set bodyParameter to required to false.
+ let streamBodyParameterAnnotation = /(global::System\.IO\.Stream _bodyParameter;\s*\[global::System\.Management\.Automation\.Parameter\(Mandatory\s*=\s*)(true)/gmi
+ $ = $.replace(streamBodyParameterAnnotation, '$1false');
+
+ // Handle file upload.
+ let processRecordCallRegex = /(^\s*)(asyncCommandRuntime\.Wait\(\s*ProcessRecordAsync\s*\(\))/gmi
+ $ = $.replace(processRecordCallRegex, '$1if (!MyInvocation.BoundParameters.ContainsKey(nameof(BodyParameter))){BodyParameter = GetFileAsStream() ?? BodyParameter;}\n$1$2');
+ }
+ return $;
+ }
+
# Modify generated runtime TypeConverterExtensions class.
- from: source-file-csharp
where: $
diff --git a/tools/Custom/FileUploadCmdlet.cs b/tools/Custom/FileUploadCmdlet.cs
new file mode 100644
index 00000000000..fbb11252aae
--- /dev/null
+++ b/tools/Custom/FileUploadCmdlet.cs
@@ -0,0 +1,44 @@
+// ------------------------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
+// ------------------------------------------------------------------------------
+namespace Microsoft.Graph.PowerShell.Cmdlets.Custom
+{
+ using Microsoft.Graph.PowerShell.Authentication.Common;
+ using System.IO;
+ using System.Management.Automation;
+
+ public partial class FileUploadCmdlet : PSCmdlet
+ {
+ /// Backing field for property.
+ private string _inFile;
+
+ /// The path to the file to upload. This SHOULD include the file name and extension.
+ [Parameter(Mandatory = true, HelpMessage = "The path to the file to upload. This should include a path and file name. If you omit the path, the current location will be used.")]
+ [Runtime.Info(
+ Required = true,
+ ReadOnly = false,
+ Description = @"The path to the file to upload. This should include a path and file name. If you omit the path, the current location will be used.",
+ PossibleTypes = new[] { typeof(string) })]
+ [ValidateNotNullOrEmpty()]
+ [Category(ParameterCategory.Runtime)]
+ public string InFile { get => this._inFile; set => this._inFile = value; }
+
+ ///
+ /// Creates a file stream from the provided input file.
+ ///
+ /// A file stream.
+ internal Stream GetFileAsStream()
+ {
+ if (MyInvocation.BoundParameters.ContainsKey(nameof(InFile)))
+ {
+ string resolvedFilePath = this.GetProviderPath(InFile, true);
+ var fileProvider = ProtectedFileProvider.CreateFileProvider(resolvedFilePath, FileProtection.SharedRead, new DiskDataStore());
+ return fileProvider.Stream;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tools/Custom/PSCmdletExtensions.cs b/tools/Custom/PSCmdletExtensions.cs
new file mode 100644
index 00000000000..9139c80e901
--- /dev/null
+++ b/tools/Custom/PSCmdletExtensions.cs
@@ -0,0 +1,121 @@
+// ------------------------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
+// ------------------------------------------------------------------------------
+namespace Microsoft.Graph.PowerShell
+{
+ using Microsoft.Graph.PowerShell.Authentication.Common;
+ using System;
+ using System.Collections.ObjectModel;
+ using System.IO;
+ using System.Management.Automation;
+ using System.Net.Http;
+ using System.Threading;
+ using System.Threading.Tasks;
+
+ internal static class PSCmdletExtensions
+ {
+ ///
+ /// Gets a resolved or unresolved path from PSPath.
+ ///
+ /// The calling .
+ /// The file path to get a provider path for.
+ /// Determines whether get a resolved or unresolved provider path.
+ /// The provider path from PSPath.
+ internal static string GetProviderPath(this PSCmdlet cmdlet, string filePath, bool isResolvedPath)
+ {
+ string providerPath = null;
+ ProviderInfo provider;
+ try
+ {
+ var paths = new Collection();
+ if (isResolvedPath)
+ {
+ paths = cmdlet.SessionState.Path.GetResolvedProviderPathFromPSPath(filePath, out provider);
+ }
+ else
+ {
+ paths.Add(cmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(filePath, out provider, out _));
+ }
+
+ if (provider.Name != "FileSystem" || paths.Count == 0)
+ {
+ cmdlet.ThrowTerminatingError(new ErrorRecord(new Exception("Invalid path."), string.Empty, ErrorCategory.InvalidArgument, filePath));
+ }
+ if (paths.Count > 1)
+ {
+ cmdlet.ThrowTerminatingError(new ErrorRecord(new Exception("Multiple paths not allowed."), string.Empty, ErrorCategory.InvalidArgument, filePath));
+ }
+ providerPath = paths[0];
+ }
+ catch (Exception)
+ {
+ providerPath = filePath;
+ }
+
+ return providerPath;
+ }
+
+ ///
+ /// Saves a stream to a file on disk.
+ ///
+ /// The calling .
+ /// The HTTP response from the service.
+ /// The stream to write to file.
+ /// The path to write the file to. This should include the file name and extension.
+ /// A cancellation token that will be used to cancel the operation by the user.
+ internal static void WriteToFile(this PSCmdlet cmdlet, HttpResponseMessage response, Stream inputStream, string filePath, CancellationToken cancellationToken)
+ {
+ using (var fileProvider = ProtectedFileProvider.CreateFileProvider(filePath, FileProtection.ExclusiveWrite, new DiskDataStore()))
+ {
+ string downloadUrl = response?.RequestMessage?.RequestUri.ToString();
+ cmdlet.WriteToStream(inputStream, fileProvider.Stream, downloadUrl, cancellationToken);
+ }
+ }
+
+ ///
+ /// Writes an input stream to an output stream.
+ ///
+ /// The calling .
+ /// The stream to write to an output stream.
+ /// The stream to write the input stream to.
+ /// A cancellation token that will be used to cancel the operation by the user.
+ private static void WriteToStream(this PSCmdlet cmdlet, Stream inputStream, Stream outputStream, string downloadUrl, CancellationToken cancellationToken)
+ {
+ Task copyTask = inputStream.CopyToAsync(outputStream);
+ ProgressRecord record = new ProgressRecord(
+ activityId: 0,
+ activity: $"Downloading {downloadUrl ?? "file"}",
+ statusDescription: $"{outputStream.Position} of {outputStream.Length} bytes downloaded.");
+ try
+ {
+ do
+ {
+ cmdlet.WriteProgress(GetProgress(record, outputStream));
+
+ Task.Delay(1000, cancellationToken).Wait(cancellationToken);
+ } while (!copyTask.IsCompleted && !cancellationToken.IsCancellationRequested);
+
+ if (copyTask.IsCompleted)
+ {
+ cmdlet.WriteProgress(GetProgress(record, outputStream));
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ }
+ }
+
+ ///
+ /// Calculates and updates the progress record of the provided stream.
+ ///
+ /// The to update.
+ /// The stream to calculate its progress.
+ /// An updated .
+ private static ProgressRecord GetProgress(ProgressRecord currentProgressRecord, Stream stream)
+ {
+ currentProgressRecord.StatusDescription = $"{stream.Position} of {stream.Length} bytes downloaded.";
+ currentProgressRecord.PercentComplete = (int)Math.Round((double)(100 * stream.Position) / stream.Length);
+ return currentProgressRecord;
+ }
+ }
+}