Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test common #19367

Closed
wants to merge 14 commits into from
3 changes: 2 additions & 1 deletion src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using Microsoft.WindowsAzure.Commands.Common.Utilities;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.PowerShell.Common.Share.Survey;

namespace Microsoft.Azure.Commands.Profile
{
Expand Down Expand Up @@ -680,7 +681,7 @@ public void OnImport()
#if DEBUG
}
#endif

SurveyHelper.GetInstance().updateSurveyHelper(AzureSession.Instance.ExtendedProperties["InstallationId"]);
var autoSaveEnabled = AzureSession.Instance.ARMContextSaveMode == ContextSaveMode.CurrentUser;
var autosaveVariable = System.Environment.GetEnvironmentVariable(AzureProfileConstants.AzureAutosaveVariable);

Expand Down
23 changes: 19 additions & 4 deletions src/Accounts/Accounts/Feedback/OpenAzSurveyLinkCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,44 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.PowerShell.Common.Share.Survey;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Diagnostics;
using System.Management.Automation;
using System.Runtime.InteropServices;
using System.IO;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Profile.Survey
{
[Cmdlet(VerbsCommon.Open, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SurveyLink"), OutputType(typeof(void))]
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()
{
WriteInformation(new HostInformationMessage() { Message = $"Opening the default browser to {_surveyLinkFormat}" }, new string[] { "PSHOST" });
OpenBrowser(_surveyLinkFormat);
DateTime today = DateTime.UtcNow;
AzureSession.Instance.ExtendedProperties.TryGetValue("InstallationId", out string InstallationId);
String version= AzurePSCmdlet.AzVersion;
int gapDays = -1;

ScheduleInfo scheduleInfo = SurveyHelper.GetInstance().GetScheduleInfo();
DateTime LastPromptDate = Convert.ToDateTime(scheduleInfo?.LastPromptDate);
if (LastPromptDate != DateTime.MinValue){
TimeSpan ts = today.Subtract(LastPromptDate);
gapDays = (int) ts.TotalDays;
}
String svLink = $"https://go.microsoft.com/fwlink/?linkid=2201766&ID={InstallationId}&v={version}&d={gapDays}";
WriteInformation(new HostInformationMessage() { Message = $"Opening the default browser to {svLink}" }, new string[] { "PSHOST" });
OpenBrowser(svLink);
}


private void OpenBrowser(string url)
{
try
Expand Down
17 changes: 16 additions & 1 deletion src/Accounts/Accounts/help/Clear-AzConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Clear-AzConfig [-Force] [-PassThru] [-AppliesTo <String>] [-Scope <ConfigScope>]
```
Clear-AzConfig [-PassThru] [-AppliesTo <String>] [-Scope <ConfigScope>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-DefaultSubscriptionForLogin]
[-DisplayBreakingChangeWarning] [-EnableDataCollection] [<CommonParameters>]
[-DisplayBreakingChangeWarning] [-DisplaySurveyMessage] [-EnableDataCollection] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -114,6 +114,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -DisplaySurveyMessage
When enabled, you are prompted infrequently to participate in user experience surveys for Azure PowerShell.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: ClearByKey
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -EnableDataCollection
When enabled, Azure PowerShell cmdlets send telemetry data to Microsoft to improve the customer experience.
For more information, see our privacy statement: https://aka.ms/privacy
Expand Down
18 changes: 17 additions & 1 deletion src/Accounts/Accounts/help/Get-AzConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Gets the configs of Azure PowerShell.

```
Get-AzConfig [-AppliesTo <String>] [-Scope <ConfigScope>] [-DefaultProfile <IAzureContextContainer>]
[-DefaultSubscriptionForLogin] [-DisplayBreakingChangeWarning] [-EnableDataCollection] [<CommonParameters>]
[-DefaultSubscriptionForLogin] [-DisplayBreakingChangeWarning] [-DisplaySurveyMessage] [-EnableDataCollection]
[<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -125,6 +126,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -DisplaySurveyMessage
When enabled, you are prompted infrequently to participate in user experience surveys for Azure PowerShell.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -EnableDataCollection
When enabled, Azure PowerShell cmdlets send telemetry data to Microsoft to improve the customer experience.
For more information, see our privacy statement: https://aka.ms/privacy
Expand Down
17 changes: 16 additions & 1 deletion src/Accounts/Accounts/help/Update-AzConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Updates the configs of Azure PowerShell.
```
Update-AzConfig [-AppliesTo <String>] [-Scope <ConfigScope>] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [-DefaultSubscriptionForLogin <String>] [-DisplayBreakingChangeWarning <Boolean>]
[-EnableDataCollection <Boolean>] [<CommonParameters>]
[-DisplaySurveyMessage <Boolean>] [-EnableDataCollection <Boolean>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -137,6 +137,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -DisplaySurveyMessage
When enabled, you are prompted infrequently to participate in user experience surveys for Azure PowerShell.

```yaml
Type: System.Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -EnableDataCollection
When enabled, Azure PowerShell cmdlets send telemetry data to Microsoft to improve the customer experience.
For more information, see our privacy statement: https://aka.ms/privacy
Expand Down
34 changes: 32 additions & 2 deletions src/Accounts/Authentication/AzureSessionInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
using Microsoft.Azure.Commands.Common.Authentication.Properties;
using Microsoft.Azure.Commands.Common.Authentication.Config;
using Newtonsoft.Json;
using Microsoft.Azure.Commands.Common.Authentication.Models;


using TraceLevel = System.Diagnostics.TraceLevel;
using System.Collections.Generic;
Expand All @@ -39,6 +41,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication
public static class AzureSessionInitializer
{
private const string ContextAutosaveSettingFileName = ContextAutosaveSettings.AutoSaveSettingsFile;

private const string DataCollectionFileName = AzurePSDataCollectionProfile.DefaultFileName;

/// <summary>
Expand Down Expand Up @@ -173,7 +176,14 @@ static ContextAutosaveSettings InitializeSessionSettings(IDataStore store, strin
result.ContextDirectory = migrated ? profileDirectory : settings.ContextDirectory ?? result.ContextDirectory;
result.Mode = settings.Mode;
result.ContextFile = settings.ContextFile ?? result.ContextFile;
if (migrated)
result.Settings = settings.Settings;
bool updateSettings = false;
if (!settings.Settings.ContainsKey("InstallationId"))
{
result.Settings.Add("InstallationId", GetAzureCLIInstallationId(store) ?? Guid.NewGuid().ToString());
updateSettings = true;
}
if (migrated || updateSettings)
{
string autoSavePath = Path.Combine(profileDirectory, settingsFile);
store.WriteFile(autoSavePath, JsonConvert.SerializeObject(result));
Expand All @@ -188,6 +198,7 @@ static ContextAutosaveSettings InitializeSessionSettings(IDataStore store, strin
}
string autoSavePath = Path.Combine(profileDirectory, settingsFile);
result.Mode = ContextSaveMode.CurrentUser;
result.Settings.Add("InstallationId", GetAzureCLIInstallationId(store) ?? Guid.NewGuid().ToString());
store.WriteFile(autoSavePath, JsonConvert.SerializeObject(result));
}
}
Expand All @@ -202,6 +213,24 @@ static ContextAutosaveSettings InitializeSessionSettings(IDataStore store, strin
return result;
}

private static String GetAzureCLIInstallationId(IDataStore store){
if (store.FileExists(AzCLIProfileInfo.AzCLIProfileFile))
{
try
{
AzCLIProfileInfo azInfo = JsonConvert.DeserializeObject<AzCLIProfileInfo>(store.ReadFileAsText(AzCLIProfileInfo.AzCLIProfileFile));
if (!string.IsNullOrEmpty(azInfo?.installationId))
{
return azInfo.installationId;
}
}
catch (Exception)
{
TracingAdapter.Information($"[AzureSessionInitializer]: Cannot read Azure CLI profile from {AzCLIProfileInfo.AzCLIProfileFile}");
}
}
return null;
}
static void InitializeDataCollection(IAzureSession session)
{
session.RegisterComponent(DataCollectionController.RegistryKey, () => DataCollectionController.Create(session));
Expand Down Expand Up @@ -239,7 +268,8 @@ static IAzureSession CreateInstance(IDataStore dataStore = null, Action<string>
session.ARMProfileFile = autoSave.ContextFile;
session.TokenCacheDirectory = autoSave.CacheDirectory;
session.TokenCacheFile = autoSave.CacheFile;

autoSave.Settings.TryGetValue("InstallationId", out string installationId);
session.ExtendedProperties.Add("InstallationId", installationId);
InitializeConfigs(session, profilePath, writeWarning);
InitializeDataCollection(session);
session.RegisterComponent(HttpClientOperationsFactory.Name, () => HttpClientOperationsFactory.Create());
Expand Down
3 changes: 1 addition & 2 deletions src/Accounts/Authentication/Config/ConfigInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ private void RegisterConfigs(IConfigManager configManager)
AzurePSDataCollectionProfile.EnvironmentVariableName,
new[] { AppliesTo.Az }));

// configs with their own types
// configManager.RegisterConfig(new EnableInterceptSurveyConfig()); // todo: uncomment after improvements are made to survey
configManager.RegisterConfig(new EnableInterceptSurveyConfig());
configManager.RegisterConfig(new DisplayBreakingChangeWarningsConfig());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ internal class EnableInterceptSurveyConfig : TypedConfig<bool>

public override string ParseFromEnvironmentVariables(IReadOnlyDictionary<string, string> environmentVariables)
{
if (environmentVariables.TryGetValue("Azure_PS_Intercept_Survey", out string configString))
environmentVariables.TryGetValue("Azure_PS_Intercept_Survey", out string oldConfigString);
environmentVariables.TryGetValue("AzSurveyMessage", out string configString);

if (string.Equals(Boolean.FalseString, oldConfigString, StringComparison.OrdinalIgnoreCase) || string.Equals(Boolean.FalseString, configString, StringComparison.OrdinalIgnoreCase))
{
if ("Disabled".Equals(configString, StringComparison.OrdinalIgnoreCase)
|| "False".Equals(configString, StringComparison.OrdinalIgnoreCase))
{
return false.ToString();
}
return Boolean.FalseString;
}
return null;
return string.Empty;
}
}
}
34 changes: 34 additions & 0 deletions src/Accounts/Authentication/Models/AzCLIProfileInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ----------------------------------------------------------------------------------
//
// 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 Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;

namespace Microsoft.Azure.Commands.Common.Authentication.Models
{
/// <summary>
/// this class defines installation id field in Azure CLI context. This information is shared between Azure CLI and Azure PowerShell
///
/// </summary>
internal class AzCLIProfileInfo
{
[JsonProperty(PropertyName = "installationId")]
internal string installationId { get; set; }


public static readonly string AzCLIProfileFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".Azure", "AzureProfile.json");
}
}
2 changes: 1 addition & 1 deletion src/shared/ConfigKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.Shared.Config
/// </remarks>
internal static class ConfigKeys
{
public const string EnableInterceptSurvey = "EnableInterceptSurvey";
public const string EnableInterceptSurvey = "DisplaySurveyMessage";
public const string DisplayBreakingChangeWarning = "DisplayBreakingChangeWarning";
public const string DefaultSubscriptionForLogin = "DefaultSubscriptionForLogin";
public const string EnableDataCollection = "EnableDataCollection";
Expand Down
34 changes: 17 additions & 17 deletions tools/Common.Netcore.Dependencies.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
<ItemGroup>
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.24"/>
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.19"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.59-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.60-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.60-preview"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.24.0"/>
Expand All @@ -36,7 +36,7 @@
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup>
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.59-preview\tools\</StorageToolsPath>
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.60-preview\tools\</StorageToolsPath>
</PropertyGroup>
<ItemGroup Condition="'$(OmitJsonPackage)' != 'true'">
<PackageReference Include="Newtonsoft.Json" Version="10.0.3"/>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.