Skip to content

Commit 9ac607a

Browse files
ramsessanchezdanguilliamsDan Guilliams
authored
Add generated Migrations folder (#3450)
* add migrations folder * Migrations module Autorest configuration updates for Cross Tenant Migration Jobs (#3447) * Updating mapping and command names for cross tenant migration jobs * Fixing comments for Migrations module autorest config --------- Co-authored-by: Dan Guilliams <daguilli@microsoft.com> Co-authored-by: Ramses Sanchez-Hernandez <63934382+ramsessanchez@users.noreply.github.com> --------- Co-authored-by: Daniel Guilliams <272397+danguilliams@users.noreply.github.com> Co-authored-by: Dan Guilliams <daguilli@microsoft.com>
1 parent e5474e6 commit 9ac607a

22 files changed

+1550
-1
lines changed

config/ModulesMapping.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"Identity.Partner": "^tenantRelationships.delegatedAdminRelationship$|^tenantRelationships.delegatedAdminCustomer$",
2727
"Mail": "^users.inferenceClassification$|^users.mailFolder$|^users.message$",
2828
"ManagedTenants": "^tenantRelationships.managedTenant$",
29-
"Migrations": "^solutions.migrations",
29+
"Migrations": "^solutions.migrationsRoot",
3030
"NetworkAccess": "^networkAccess\\.",
3131
"Notes": "^users.onenote$|^groups.onenote$|^sites.onenote$",
3232
"People": "^users.person$|^users.profile$|^users.officeGraphInsights$|^users.userAnalytics$",

src/Migrations/Migrations.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Migrations
2+
3+
This directory contains common [AutoREST.PowerShell](https://github.com/Azure/autorest.powershell) configurations for Migrations v1.0 and/or beta modules.
4+
5+
## AutoRest Configuration
6+
7+
> see <https://aka.ms/autorest>
8+
9+
``` yaml
10+
require:
11+
- $(this-folder)/../readme.graph.md
12+
```
13+
14+
### Directives
15+
16+
> see https://github.com/Azure/autorest/blob/master/docs/powershell/directives.md
17+
18+
``` yaml
19+
# Directives go here!
20+
21+
# Rename commands with 'SolutionMigrationCrossTenantMigrationJob<x>' to 'CrossTenantMigrationJob<x>'
22+
directive:
23+
- where:
24+
subject: (^SolutionMigrationCrossTenantMigrationJob)(.*)
25+
set:
26+
subject: CrossTenantMigrationJob$2
27+
# Remove all the 'DisplayName','SolutionMigration', and 'Count' commands, they are redundant/unsupported
28+
- where:
29+
subject: (DisplayName$|SolutionMigration$|Count$)
30+
remove: true
31+
# Remove extra 'Remove' commands, only jobs can be removed
32+
- where:
33+
verb: Remove
34+
subject: CrossTenantMigrationJob.+$
35+
remove: true
36+
# Remove New/Update-CrossTenantMigrationJobUser, they are not supported operations
37+
- where:
38+
verb: (New|Update)
39+
subject: CrossTenantMigrationJobUser$
40+
remove: true
41+
```

src/Migrations/beta/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

src/Migrations/beta/.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
bin
2+
obj
3+
.vs
4+
generated
5+
internal
6+
exports
7+
tools
8+
custom/*.psm1
9+
custom/autogen-model-cmdlets
10+
test/*-TestResults.xml
11+
/*.ps1
12+
/*.ps1xml
13+
/*.psm1
14+
/*.snk
15+
/*.csproj
16+
/*.nuspec
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
5+
namespace Microsoft.Graph.Beta.PowerShell
6+
{
7+
using System;
8+
using System.Text.RegularExpressions;
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
using Microsoft.Graph.Beta.PowerShell.Runtime;
12+
13+
public static class EventExtensions
14+
{
15+
/// <summary>
16+
/// Print event details to the provided stream
17+
/// </summary>
18+
/// <param name="getEventData">The event data to print</param>
19+
/// <param name="signal">The delegate for signaling events to the runtime</param>
20+
/// <param name="token">The cancellation token for the request</param>
21+
/// <param name="streamName">The name of the stream to print data to</param>
22+
/// <param name="eventName">The name of the event to be printed</param>
23+
public static async void Print(this Func<EventArgs> getEventData, Func<string, CancellationToken, Func<EventArgs>, Task> signal, CancellationToken token, string streamName, string eventName)
24+
{
25+
var eventDisplayName = EventFactory.SplitPascalCase(eventName).ToUpperInvariant();
26+
var data = EventDataConverter.ConvertFrom(getEventData()); // also, we manually use our TypeConverter to return an appropriate type
27+
if (data.Id != Events.Verbose && data.Id != Events.Warning && data.Id != Events.Debug && data.Id != Events.Information && data.Id != Events.Error)
28+
{
29+
await signal(streamName, token, () => EventFactory.CreateLogEvent($"{eventDisplayName} The contents are '{data?.Id}' and '{data?.Message}'"));
30+
if (data != null)
31+
{
32+
await signal(streamName, token, () => EventFactory.CreateLogEvent($"{eventDisplayName} Parameter: '{data.Parameter}'\n{eventDisplayName} RequestMessage '{data.RequestMessage}'\n{eventDisplayName} Response: '{data.ResponseMessage}'\n{eventDisplayName} Value: '{data.Value}'"));
33+
await signal(streamName, token, () => EventFactory.CreateLogEvent($"{eventDisplayName} ExtendedData Type: '{data.ExtendedData?.GetType()}'\n{eventDisplayName} ExtendedData '{data.ExtendedData}'"));
34+
}
35+
}
36+
}
37+
}
38+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
5+
using System;
6+
using System.Text.RegularExpressions;
7+
using System.Threading.Tasks;
8+
using Microsoft.Graph.Beta.PowerShell.Runtime;
9+
10+
namespace Microsoft.Graph.Beta.PowerShell
11+
{
12+
public static class EventFactory
13+
{
14+
/// <summary>
15+
/// Create a tracing event containing a string message
16+
/// </summary>
17+
/// <param name="message">The string message to include in event data</param>
18+
/// <returns>Valid EventData containing the message</returns>
19+
public static EventData CreateLogEvent(Task<string> message)
20+
{
21+
return new EventData
22+
{
23+
Id = Guid.NewGuid().ToString(),
24+
Message = message.Result
25+
};
26+
}
27+
28+
/// <summary>
29+
/// Create a new debug message event
30+
/// </summary>
31+
/// <param name="message">The message</param>
32+
/// <returns>An event containing the debug message</returns>
33+
public static EventData CreateDebugEvent(string message)
34+
{
35+
return new EventData
36+
{
37+
Id = Events.Debug,
38+
Message = message
39+
};
40+
}
41+
42+
/// <summary>
43+
/// Create a new debug message event
44+
/// </summary>
45+
/// <param name="message">The message</param>
46+
/// <returns>An event containing the debug message</returns>
47+
public static EventData CreateWarningEvent(string message)
48+
{
49+
return new EventData
50+
{
51+
Id = Events.Warning,
52+
Message = message
53+
};
54+
}
55+
public static string SplitPascalCase(string word)
56+
{
57+
var regex = new Regex("([a-z]+)([A-Z])");
58+
var output = regex.Replace(word, "$1 $2");
59+
regex = new Regex("([A-Z])([A-Z][a-z])");
60+
return regex.Replace(output, "$1 $2");
61+
}
62+
63+
public static EventArgs CreateLogEvent(string message)
64+
{
65+
return new EventData
66+
{
67+
Id = Guid.NewGuid().ToString(),
68+
Message = message
69+
};
70+
}
71+
}
72+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
namespace Microsoft.Graph.Beta.PowerShell.Cmdlets.Custom
5+
{
6+
using Microsoft.Graph.PowerShell.Authentication.Common;
7+
using System.IO;
8+
using System.Management.Automation;
9+
10+
public partial class FileUploadCmdlet : PSCmdlet
11+
{
12+
/// <summary>Backing field for <see cref="InFile" /> property.</summary>
13+
private string _inFile;
14+
15+
/// <summary>The path to the file to upload. This SHOULD include the file name and extension.</summary>
16+
[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.")]
17+
[Runtime.Info(
18+
Required = true,
19+
ReadOnly = false,
20+
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.",
21+
PossibleTypes = new[] { typeof(string) })]
22+
[ValidateNotNullOrEmpty()]
23+
[Category(ParameterCategory.Runtime)]
24+
public string InFile { get => this._inFile; set => this._inFile = value; }
25+
26+
/// <summary>
27+
/// Creates a file stream from the provided input file.
28+
/// </summary>
29+
/// <returns>A file stream.</returns>
30+
internal Stream GetFileAsStream()
31+
{
32+
if (MyInvocation.BoundParameters.ContainsKey(nameof(InFile)))
33+
{
34+
string resolvedFilePath = this.GetProviderPath(InFile, true);
35+
var fileProvider = ProtectedFileProvider.CreateFileProvider(resolvedFilePath, FileProtection.SharedRead, new DiskDataStore());
36+
return fileProvider.Stream;
37+
}
38+
else
39+
{
40+
return null;
41+
}
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)