From 8b2fcf6180dfd584c81a69edc9d796d0e70b4388 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Mon, 7 Aug 2023 12:14:57 -0700 Subject: [PATCH 1/2] feat: Add SDK and API links to welcome message. --- .../Authentication/Cmdlets/ConnectMgGraph.cs | 19 ++++++++++++++++++- .../Authentication/Constants.cs | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs b/src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs index fc116139660..df3a0629837 100644 --- a/src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs +++ b/src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs @@ -99,6 +99,9 @@ public class ConnectMgGraph : PSCmdlet, IModuleAssemblyInitializer, IModuleAssem [Parameter(ParameterSetName = Constants.EnvironmentVariableParameterSet, Mandatory = false, HelpMessage = HelpMessages.EnvironmentVariable)] public SwitchParameter EnvironmentVariable { get; set; } + [Parameter(Mandatory = false, HelpMessage = HelpMessages.NoWelcome)] + public SwitchParameter NoWelcome { get; set; } + [Parameter(Mandatory = false, DontShow = true, HelpMessage = "Wait for .NET debugger to attach")] public SwitchParameter Break { get; set; } @@ -248,7 +251,9 @@ private async Task ProcessRecordAsync() await AuthenticationHelpers.LogoutAsync(); throw; } - WriteObject("Welcome To Microsoft Graph!"); + + if (!NoWelcome.IsPresent) + WriteObject(GetWelcomeMessage(authContext.ClientId, authContext.AuthType.ToString())); } } protected override void StopProcessing() @@ -257,6 +262,18 @@ protected override void StopProcessing() base.StopProcessing(); } + private static string GetWelcomeMessage(string clientId, string authType) + { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.AppendLine($"Welcome to Microsoft Graph!{System.Environment.NewLine}"); + stringBuilder.AppendLine($"Connected via {authType.ToLower()} access using {clientId}"); + stringBuilder.AppendLine($"ReadMe: {Constants.SdkReadmeLink}"); + stringBuilder.AppendLine($"SDK Docs: {Constants.SdkDocsLink}"); + stringBuilder.AppendLine($"API Docs: {Constants.ApiDocsLink}{System.Environment.NewLine}"); + stringBuilder.AppendLine($"NOTE: You can use the -NoWelcome parameter to suppress this message."); + return stringBuilder.ToString(); + } + /// /// Processes user provided scopes by removing whitespace and splitting comma separated scopes. /// diff --git a/src/Authentication/Authentication/Constants.cs b/src/Authentication/Authentication/Constants.cs index 6bc4d5ec1b3..b97b063c27c 100644 --- a/src/Authentication/Authentication/Constants.cs +++ b/src/Authentication/Authentication/Constants.cs @@ -25,6 +25,9 @@ public static class Constants internal const int DEFAULT_RETRY_DELAY = 3; internal const int DEFAULT_MAX_RETRY = 3; internal static readonly string GraphOptionsFilePath = Path.Combine(Core.Constants.GraphDirectoryPath, "mg.graphoptions.json"); + internal static readonly string SdkReadmeLink = "https://github.com/microsoftgraph/msgraph-sdk-powershell/#readme"; + internal static readonly string SdkDocsLink = "https://learn.microsoft.com/powershell/microsoftgraph"; + internal static readonly string ApiDocsLink = "https://docs.microsoft.com/graph"; public static class HelpMessages { @@ -40,6 +43,7 @@ public static class HelpMessages public const string Environment = "The name of the national cloud environment to connect to. By default global cloud is used."; public const string UseDeviceCode = "Use device code authentication instead of a browser control."; public const string ClientTimeout = "Sets the HTTP client timeout in seconds."; + public const string NoWelcome = "Hides the welcome message."; public const string Identity = "Login using a Managed Identity."; public const string EnvironmentVariable = "Allows for authentication using environment variables configured on the host machine. See https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/identity/Azure.Identity#environment-variables."; public const string ManagedIdentityClientId = "The client id to authenticate for a user assigned managed identity. For more information on user assigned managed identities see: https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview#how-a-user-assigned-managed-identity-works-with-an-azure-vmId. To use the SystemAssigned identity, leave this field blank."; From afc603ea877e436e69ffdbc36b74f6bfd38ae0e3 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Thu, 10 Aug 2023 15:27:25 -0700 Subject: [PATCH 2/2] chore: Use aka.ms links. --- src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs | 2 +- src/Authentication/Authentication/Constants.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs b/src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs index df3a0629837..c2944d8421e 100644 --- a/src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs +++ b/src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs @@ -267,7 +267,7 @@ private static string GetWelcomeMessage(string clientId, string authType) StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"Welcome to Microsoft Graph!{System.Environment.NewLine}"); stringBuilder.AppendLine($"Connected via {authType.ToLower()} access using {clientId}"); - stringBuilder.AppendLine($"ReadMe: {Constants.SdkReadmeLink}"); + stringBuilder.AppendLine($"Readme: {Constants.SdkReadmeLink}"); stringBuilder.AppendLine($"SDK Docs: {Constants.SdkDocsLink}"); stringBuilder.AppendLine($"API Docs: {Constants.ApiDocsLink}{System.Environment.NewLine}"); stringBuilder.AppendLine($"NOTE: You can use the -NoWelcome parameter to suppress this message."); diff --git a/src/Authentication/Authentication/Constants.cs b/src/Authentication/Authentication/Constants.cs index b97b063c27c..a60a0dd9ae5 100644 --- a/src/Authentication/Authentication/Constants.cs +++ b/src/Authentication/Authentication/Constants.cs @@ -25,9 +25,9 @@ public static class Constants internal const int DEFAULT_RETRY_DELAY = 3; internal const int DEFAULT_MAX_RETRY = 3; internal static readonly string GraphOptionsFilePath = Path.Combine(Core.Constants.GraphDirectoryPath, "mg.graphoptions.json"); - internal static readonly string SdkReadmeLink = "https://github.com/microsoftgraph/msgraph-sdk-powershell/#readme"; - internal static readonly string SdkDocsLink = "https://learn.microsoft.com/powershell/microsoftgraph"; - internal static readonly string ApiDocsLink = "https://docs.microsoft.com/graph"; + internal static readonly string SdkReadmeLink = "https://aka.ms/graph/sdk/powershell"; + internal static readonly string SdkDocsLink = "https://aka.ms/graph/sdk/powershell/docs"; + internal static readonly string ApiDocsLink = "https://aka.ms/graph/docs"; public static class HelpMessages {