From 3dab7877bc5616a8fe8ae170135cf0449b2ede0f Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Tue, 8 Jun 2021 15:30:02 +0800 Subject: [PATCH 01/12] add cmdlet open-azsurveylink --- src/Accounts/Accounts/Az.Accounts.psd1 | 3 +- src/Accounts/Accounts/ChangeLog.md | 1 + .../Accounts/Survey/OpenAzSurveyLinkCmdlet.cs | 36 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/Accounts/Accounts/Survey/OpenAzSurveyLinkCmdlet.cs diff --git a/src/Accounts/Accounts/Az.Accounts.psd1 b/src/Accounts/Accounts/Az.Accounts.psd1 index 09d540fe8c5d..a070de91a057 100644 --- a/src/Accounts/Accounts/Az.Accounts.psd1 +++ b/src/Accounts/Accounts/Az.Accounts.psd1 @@ -106,7 +106,8 @@ CmdletsToExport = 'Disable-AzDataCollection', 'Disable-AzContextAutosave', 'Disconnect-AzAccount', 'Get-AzContextAutosaveSetting', 'Set-AzDefault', 'Get-AzDefault', 'Clear-AzDefault', 'Register-AzModule', 'Enable-AzureRmAlias', 'Disable-AzureRmAlias', - 'Uninstall-AzureRm', 'Invoke-AzRestMethod', 'Get-AzAccessToken' + 'Uninstall-AzureRm', 'Invoke-AzRestMethod', 'Get-AzAccessToken' , + 'Open-AzSurveyLink' # Variables to export from this module # VariablesToExport = @() diff --git a/src/Accounts/Accounts/ChangeLog.md b/src/Accounts/Accounts/ChangeLog.md index a0168756551b..aec266bef508 100644 --- a/src/Accounts/Accounts/ChangeLog.md +++ b/src/Accounts/Accounts/ChangeLog.md @@ -19,6 +19,7 @@ --> ## Upcoming Release +* Added cmdlet `Open-AzSurveyLink` * Supported certificate file as input parameter of Connect-AzAccount ## Version 2.3.0 diff --git a/src/Accounts/Accounts/Survey/OpenAzSurveyLinkCmdlet.cs b/src/Accounts/Accounts/Survey/OpenAzSurveyLinkCmdlet.cs new file mode 100644 index 000000000000..c471ddc55f13 --- /dev/null +++ b/src/Accounts/Accounts/Survey/OpenAzSurveyLinkCmdlet.cs @@ -0,0 +1,36 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.ResourceManager.Common; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Management.Automation; +using System.Text; + +namespace Microsoft.Azure.Commands.Profile.Survey +{ + [Cmdlet(VerbsCommon.Open, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SurveyLink")] + public class OpenAzSurveyLinkCmdlet : AzureRMCmdlet + { + private const string _surveyLinkFormat = "https://aka.ms/azpssurvey?Q_CHL=INTERCEPT"; + + public override void ExecuteCmdlet() + { + base.ExecuteCmdlet(); + WriteInformation(new HostInformationMessage() { Message = $"Opening the default browser to {_surveyLinkFormat}" }, new string[] { "PSHOST" }); + Process.Start(new ProcessStartInfo() { FileName = _surveyLinkFormat, UseShellExecute = true}); + } + } +} From bcbdea850506fdca177c2d78e822c8dfd35862a8 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Tue, 8 Jun 2021 16:54:39 +0800 Subject: [PATCH 02/12] move new cmdlet under feedback folder --- .../Accounts/{Survey => Feedback}/OpenAzSurveyLinkCmdlet.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Accounts/Accounts/{Survey => Feedback}/OpenAzSurveyLinkCmdlet.cs (100%) diff --git a/src/Accounts/Accounts/Survey/OpenAzSurveyLinkCmdlet.cs b/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs similarity index 100% rename from src/Accounts/Accounts/Survey/OpenAzSurveyLinkCmdlet.cs rename to src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs From 27ef3f7a95f8757e38cb35b3ce500998a06d11f7 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Tue, 8 Jun 2021 16:56:06 +0800 Subject: [PATCH 03/12] remove white space --- src/Accounts/Accounts/Az.Accounts.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Accounts/Accounts/Az.Accounts.psd1 b/src/Accounts/Accounts/Az.Accounts.psd1 index a070de91a057..87c1e85ec54f 100644 --- a/src/Accounts/Accounts/Az.Accounts.psd1 +++ b/src/Accounts/Accounts/Az.Accounts.psd1 @@ -106,7 +106,7 @@ CmdletsToExport = 'Disable-AzDataCollection', 'Disable-AzContextAutosave', 'Disconnect-AzAccount', 'Get-AzContextAutosaveSetting', 'Set-AzDefault', 'Get-AzDefault', 'Clear-AzDefault', 'Register-AzModule', 'Enable-AzureRmAlias', 'Disable-AzureRmAlias', - 'Uninstall-AzureRm', 'Invoke-AzRestMethod', 'Get-AzAccessToken' , + 'Uninstall-AzureRm', 'Invoke-AzRestMethod', 'Get-AzAccessToken', 'Open-AzSurveyLink' # Variables to export from this module From 0b9a5a4ce99a40637a1bbfb8868a03c335ff8610 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Tue, 8 Jun 2021 17:44:28 +0800 Subject: [PATCH 04/12] add help markdown for new cmdlet --- src/Accounts/Accounts/help/Az.Accounts.md | 3 ++ .../Accounts/help/Open-AzSurveyLink.md | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/Accounts/Accounts/help/Open-AzSurveyLink.md diff --git a/src/Accounts/Accounts/help/Az.Accounts.md b/src/Accounts/Accounts/help/Az.Accounts.md index d2b4318cc2d3..c05e40b851cb 100644 --- a/src/Accounts/Accounts/help/Az.Accounts.md +++ b/src/Accounts/Accounts/help/Az.Accounts.md @@ -81,6 +81,9 @@ Loads Azure authentication information from a file. ### [Invoke-AzRestMethod](Invoke-AzRestMethod.md) Construct and perform HTTP request to Azure resource management endpoint only +### [Open-AzSurveyLink](Open-AzSurveyLink.md) +Open survey link in default browser. + ### [Register-AzModule](Register-AzModule.md) FOR INTERNAL USE ONLY - Provide Runtime Support for AutoRest Generated cmdlets diff --git a/src/Accounts/Accounts/help/Open-AzSurveyLink.md b/src/Accounts/Accounts/help/Open-AzSurveyLink.md new file mode 100644 index 000000000000..12208b3108f9 --- /dev/null +++ b/src/Accounts/Accounts/help/Open-AzSurveyLink.md @@ -0,0 +1,51 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Accounts.dll-Help.xml +Module Name: Az.Accounts +online version: https://docs.microsoft.com/powershell/module/az.accounts/open-azsurveylink +schema: 2.0.0 +--- + +# Open-AzSurveyLink + +## SYNOPSIS +Open survey link in default browser. + +## SYNTAX + +``` +Open-AzSurveyLink [-DefaultProfile ] [] +``` + +## DESCRIPTION + +## EXAMPLES + +## PARAMETERS + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +## NOTES + +## RELATED LINKS From f9713cf428dff2809a7bfa6a85627c4cb0830077 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Tue, 8 Jun 2021 22:42:01 +0800 Subject: [PATCH 05/12] update common version --- .../Feedback/OpenAzSurveyLinkCmdlet.cs | 2 +- .../Accounts/help/Open-AzSurveyLink.md | 1 + tools/Common.Netcore.Dependencies.targets | 33 ++++++++++--------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs b/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs index c471ddc55f13..b9dd26f38d43 100644 --- a/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs +++ b/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs @@ -21,7 +21,7 @@ namespace Microsoft.Azure.Commands.Profile.Survey { - [Cmdlet(VerbsCommon.Open, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SurveyLink")] + [Cmdlet(VerbsCommon.Open, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SurveyLink"), OutputType(typeof(void))] public class OpenAzSurveyLinkCmdlet : AzureRMCmdlet { private const string _surveyLinkFormat = "https://aka.ms/azpssurvey?Q_CHL=INTERCEPT"; diff --git a/src/Accounts/Accounts/help/Open-AzSurveyLink.md b/src/Accounts/Accounts/help/Open-AzSurveyLink.md index 12208b3108f9..b56c28062baf 100644 --- a/src/Accounts/Accounts/help/Open-AzSurveyLink.md +++ b/src/Accounts/Accounts/help/Open-AzSurveyLink.md @@ -17,6 +17,7 @@ Open-AzSurveyLink [-DefaultProfile ] [ ``` ## DESCRIPTION +Open survey link in default browser. ## EXAMPLES diff --git a/tools/Common.Netcore.Dependencies.targets b/tools/Common.Netcore.Dependencies.targets index 2caef4b2feee..f73df8fc6026 100644 --- a/tools/Common.Netcore.Dependencies.targets +++ b/tools/Common.Netcore.Dependencies.targets @@ -3,21 +3,22 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -35,7 +36,7 @@ - $(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.34-preview\tools\ + $(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.35-preview\tools\ From 1b4f366eabd1927d66b2a8798a69ece7c002e5c3 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Tue, 8 Jun 2021 22:49:46 +0800 Subject: [PATCH 06/12] suppress signature issue --- tools/StaticAnalysis/Exceptions/Az.Accounts/SignatureIssues.csv | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tools/StaticAnalysis/Exceptions/Az.Accounts/SignatureIssues.csv diff --git a/tools/StaticAnalysis/Exceptions/Az.Accounts/SignatureIssues.csv b/tools/StaticAnalysis/Exceptions/Az.Accounts/SignatureIssues.csv new file mode 100644 index 000000000000..1583eddd078b --- /dev/null +++ b/tools/StaticAnalysis/Exceptions/Az.Accounts/SignatureIssues.csv @@ -0,0 +1,2 @@ +"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation" +"Az.Accounts","Microsoft.Azure.Commands.Profile.Survey.OpenAzSurveyLinkCmdlet","Open-AzSurveyLink","1","8100","Open-AzSurveyLink Does not support ShouldProcess but the cmdlet verb Open indicates that it should.","Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue" \ No newline at end of file From b2459b59275736c6f1821032665cfd3bf5a87e18 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Wed, 9 Jun 2021 13:30:25 +0800 Subject: [PATCH 07/12] update parent class --- .../Feedback/OpenAzSurveyLinkCmdlet.cs | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs b/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs index b9dd26f38d43..6e5d67b2ab3f 100644 --- a/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs +++ b/src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs @@ -12,25 +12,55 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Commands.ResourceManager.Common; +using Microsoft.Azure.Commands.Common.Authentication.Abstractions; +using Microsoft.WindowsAzure.Commands.Utilities.Common; using System; -using System.Collections.Generic; using System.Diagnostics; using System.Management.Automation; -using System.Text; +using System.Runtime.InteropServices; namespace Microsoft.Azure.Commands.Profile.Survey { [Cmdlet(VerbsCommon.Open, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SurveyLink"), OutputType(typeof(void))] - public class OpenAzSurveyLinkCmdlet : AzureRMCmdlet + public class OpenAzSurveyLinkCmdlet : AzurePSCmdlet { private const string _surveyLinkFormat = "https://aka.ms/azpssurvey?Q_CHL=INTERCEPT"; + protected override IAzureContext DefaultContext => null; + + protected override string DataCollectionWarning => null; + public override void ExecuteCmdlet() { - base.ExecuteCmdlet(); WriteInformation(new HostInformationMessage() { Message = $"Opening the default browser to {_surveyLinkFormat}" }, new string[] { "PSHOST" }); - Process.Start(new ProcessStartInfo() { FileName = _surveyLinkFormat, UseShellExecute = true}); + OpenBrowser(_surveyLinkFormat); + } + + private void OpenBrowser(string url) + { + try + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + url = url.Replace("&", "^&"); + Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true }); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Process.Start("xdg-open", url); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + Process.Start("open", url); + } + else + { + throw new PlatformNotSupportedException(RuntimeInformation.OSDescription); + } + } + catch + { + } } } -} +} \ No newline at end of file From 6fb2677a0cb217cf6fb8b450bfadbf12b419cf7d Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Wed, 9 Jun 2021 13:31:17 +0800 Subject: [PATCH 08/12] update namespace for share assembly --- tools/Common.Netcore.Dependencies.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Common.Netcore.Dependencies.targets b/tools/Common.Netcore.Dependencies.targets index f73df8fc6026..4e43d251b45e 100644 --- a/tools/Common.Netcore.Dependencies.targets +++ b/tools/Common.Netcore.Dependencies.targets @@ -18,7 +18,7 @@ - + From 452ef15786fce03801b84025990f63962e5214a7 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Wed, 9 Jun 2021 13:43:31 +0800 Subject: [PATCH 09/12] upgrade common version --- tools/Common.Netcore.Dependencies.targets | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tools/Common.Netcore.Dependencies.targets b/tools/Common.Netcore.Dependencies.targets index 4e43d251b45e..2010ef8fdf8f 100644 --- a/tools/Common.Netcore.Dependencies.targets +++ b/tools/Common.Netcore.Dependencies.targets @@ -3,22 +3,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -36,7 +36,7 @@ - $(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.35-preview\tools\ + $(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.36-preview\tools\ From 2a90a50c155605e5793b8d6f025287367e00485a Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Wed, 9 Jun 2021 14:06:30 +0800 Subject: [PATCH 10/12] add example --- src/Accounts/Accounts/help/Open-AzSurveyLink.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Accounts/Accounts/help/Open-AzSurveyLink.md b/src/Accounts/Accounts/help/Open-AzSurveyLink.md index b56c28062baf..5bb7b5dd8399 100644 --- a/src/Accounts/Accounts/help/Open-AzSurveyLink.md +++ b/src/Accounts/Accounts/help/Open-AzSurveyLink.md @@ -20,6 +20,11 @@ Open-AzSurveyLink [-DefaultProfile ] [ Open survey link in default browser. ## EXAMPLES +``` +Open-AzSurveyLink + +Opening the default browser to https://aka.ms/azpssurvey?Q_CHL=INTERCEPT +``` ## PARAMETERS From 59787ceec201b16c7722dd9fe925da2bc8200e01 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Wed, 9 Jun 2021 14:32:50 +0800 Subject: [PATCH 11/12] fix help markdown --- src/Accounts/Accounts/help/Open-AzSurveyLink.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Accounts/Accounts/help/Open-AzSurveyLink.md b/src/Accounts/Accounts/help/Open-AzSurveyLink.md index 5bb7b5dd8399..d0dea213f408 100644 --- a/src/Accounts/Accounts/help/Open-AzSurveyLink.md +++ b/src/Accounts/Accounts/help/Open-AzSurveyLink.md @@ -20,9 +20,10 @@ Open-AzSurveyLink [-DefaultProfile ] [ Open survey link in default browser. ## EXAMPLES + +### Example 1 ``` Open-AzSurveyLink - Opening the default browser to https://aka.ms/azpssurvey?Q_CHL=INTERCEPT ``` From 7e46008e0115924baa74259f898a1f0d6edb01ef Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Wed, 9 Jun 2021 15:56:33 +0800 Subject: [PATCH 12/12] add required assembly --- src/Accounts/Accounts/Az.Accounts.psd1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Accounts/Accounts/Az.Accounts.psd1 b/src/Accounts/Accounts/Az.Accounts.psd1 index 87c1e85ec54f..88495d1cb67c 100644 --- a/src/Accounts/Accounts/Az.Accounts.psd1 +++ b/src/Accounts/Accounts/Az.Accounts.psd1 @@ -78,7 +78,8 @@ RequiredAssemblies = 'Microsoft.Azure.PowerShell.Authentication.Abstractions.dll 'Microsoft.WindowsAzure.Storage.dll', 'Microsoft.WindowsAzure.Storage.DataMovement.dll', 'Microsoft.Azure.PowerShell.Clients.Aks.dll', - 'Microsoft.Azure.PowerShell.Strategies.dll' + 'Microsoft.Azure.PowerShell.Strategies.dll', + 'Microsoft.Azure.PowerShell.Common.Share.dll' # Script files (.ps1) that are run in the caller's environment prior to importing this module. # ScriptsToProcess = @()