Skip to content

Commit 05a871b

Browse files
authored
Merge branch 'dev' into po/directiveUpdates
2 parents 8b1f862 + 3d31022 commit 05a871b

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

src/Authentication/Authentication/Cmdlets/SelectMgProfile.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ namespace Microsoft.Graph.PowerShell.Authentication.Cmdlets
1717
[OutputType(typeof(bool))]
1818
public class SelectMgProfile: PSCmdlet
1919
{
20-
[Parameter(Mandatory = true)]
20+
[Parameter(Mandatory = true, Position = 1)]
2121
[Alias("ProfileName")]
22+
[ValidateSet("v1.0", "beta")]
2223
[ValidateNotNullOrEmpty]
2324
public string Name { get; set; }
2425

@@ -32,11 +33,15 @@ protected override void ProcessRecord()
3233
{
3334
if (this.IsParameterBound(c => c.Name))
3435
{
35-
PSModuleInfo[] modules = GetModules(InvokeCommand).Where(m => GetProfiles(m).Contains(Name)).ToArray();
36+
string profileName = Name.ToLower();
37+
// Internally treat beta profile as v1.0-beta.
38+
// This is an AutoREST limitation.
39+
profileName = profileName.ContainsValue("beta") ? "v1.0-beta" : profileName;
40+
PSModuleInfo[] modules = GetModules(InvokeCommand).Where(m => GetProfiles(m).Contains(profileName)).ToArray();
3641
string moduleList = string.Join(", ", modules.Select(m => m.Name));
37-
if (ShouldProcess($"Modules {moduleList}", $"Load modules with profile {Name}"))
42+
if (ShouldProcess($"Modules {moduleList}", $"Load modules with profile {profileName}"))
3843
{
39-
GraphSession.Instance.SelectedProfile = Name;
44+
GraphSession.Instance.SelectedProfile = profileName;
4045
ReloadModules(InvokeCommand, modules);
4146
if (PassThru.IsPresent && PassThru.ToBool())
4247
{

src/Authentication/Authentication/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class Constants
1717
internal static readonly string TokenCacheDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".graph");
1818
internal const string ProfileDescription = "A snapshot of the Microsoft Graph {0} API for {1} cloud.";
1919
internal const string TokenCacheServiceName = "com.microsoft.graph.powershell.sdkcache";
20-
internal const string DefaultProfile = "v1.0-beta";
20+
internal const string DefaultProfile = "v1.0";
2121
internal const int TokenExpirationBufferInMinutes = 5;
2222
}
2323
}

src/Authentication/Authentication/Models/PSGraphServiceProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal static PSGraphServiceProfile Create(string name)
3434
{
3535
throw new ArgumentNullException(nameof(name));
3636
}
37-
return new PSGraphServiceProfile { Name = name, Description = GetProfileDescription(name) };
37+
return new PSGraphServiceProfile { Name = GetProfileVersion(name), Description = GetProfileDescription(name) };
3838
}
3939

4040
/// <summary>

tools/Custom/Module.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public partial class Module
2424
/// <summary>
2525
/// The selected Microsoft Graph profile.
2626
/// </summary>
27-
public string ProfileName { get; set; } = "v1.0-beta";
27+
public string ProfileName { get; set; } = "v1.0";
2828
partial void BeforeCreatePipeline(System.Management.Automation.InvocationInfo invocationInfo, ref Runtime.HttpPipeline pipeline)
2929
{
3030
// Call Init to trigger any custom initialization needed after

tools/GenerateModules.ps1

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,37 @@ $ModuleMapping.Keys | ForEach-Object -Begin { $RequestCount = 0 } -End { Write-H
127127
[HashTable]$PrivateData = @{ Profiles = $Profiles }
128128
Update-ModuleManifest -Path $ModuleManifestPath -PrivateData $PrivateData
129129

130-
# Update module psm1 with Graph session profile name.
130+
# Update main module psm1.
131131
$ModulePsm1 = Join-Path $ModuleProjectDir "/$ModulePrefix.$ModuleName.psm1"
132132
(Get-Content -Path $ModulePsm1) | ForEach-Object{
133-
$_
134133
if ($_ -match '\$instance = \[Microsoft.Graph.PowerShell.Module\]::Instance') {
134+
# Update main psm1 with Graph session profile name and module name.
135+
$_
135136
' $instance.ProfileName = [Microsoft.Graph.PowerShell.Authentication.GraphSession]::Instance.SelectedProfile'
137+
} else {
138+
# Rename all Azure instances in psm1 to `Microsoft Graph`.
139+
$updatedLine = $_ -replace 'Azure', 'Microsoft Graph'
140+
# Replace all 'instance.Name' declarations with fully qualified module name.
141+
$updatedLine = $updatedLine -replace '\$\(\$instance.Name\)', "$ModulePrefix.$ModuleName"
142+
$updatedLine
136143
}
137144
} | Set-Content $ModulePsm1
138145

139-
# Address AutoREST bug where it looks for exports in the wrong directory.
146+
# Update internal module psm1.
140147
$InternalModulePsm1 = Join-Path $ModuleProjectDir "/internal/$ModulePrefix.$ModuleName.internal.psm1"
141148
(Get-Content -Path $InternalModulePsm1) | ForEach-Object{
142-
$_
149+
$updatedLine = $_
150+
# Address AutoREST bug where it looks for exports in the wrong directory.
143151
if ($_ -match '\$exportsPath = \$PSScriptRoot') {
144-
' $exportsPath = Join-Path $PSScriptRoot "../exports"'
152+
$updatedLine = ' $exportsPath = Join-Path $PSScriptRoot "../exports"'
145153
}
154+
155+
# Remove duplicate instance.Name declarations in internal.psm1
156+
# Main .psm1 already handles this.
157+
if ($_ -match '\$\(\$instance.Name\)') {
158+
$updatedLine = ""
159+
}
160+
$updatedLine
146161
} | Set-Content $InternalModulePsm1
147162

148163
if ($LASTEXITCODE) {

0 commit comments

Comments
 (0)