Skip to content

Commit cf569b5

Browse files
author
Maddie Clayton
committed
Merge branch 'preview' of https://github.com/Azure/azure-powershell into use-connect-and-disconnect-verbs
2 parents fde94d8 + 71f221e commit cf569b5

File tree

70 files changed

+8356
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+8356
-36
lines changed

TestMappings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,4 @@
184184
"src/ResourceManager/ApplicationInsights/": [
185185
".\\src\\ResourceManager\\ApplicationInsights\\Commands.ApplicationInsights.Test\\bin\\Debug\\Microsoft.Azure.Commands.ApplicationInsights.Test.dll"
186186
]
187-
}
187+
}

build.proj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@
509509
<Message Importance="high" Text="Running Dependency Analysis..." />
510510
<Exec Command="$(MSBuildProjectDirectory)\src\Package\StaticAnalysis.exe $(MSBuildProjectDirectory)\src\Package\$(Configuration) $(MSBuildProjectDirectory)\src\Package true $(SkipHelp)" Condition="'$(Latest)' == 'true'"/>
511511
<Exec Command="$(MSBuildProjectDirectory)\src\Package\StaticAnalysis.exe $(MSBuildProjectDirectory)\src\Stack\$(Configuration) $(MSBuildProjectDirectory)\src\Stack" Condition="'$(Stack)' == 'true'" ContinueOnError="True"/>
512+
<OnError ExecuteTargets="StaticAnalysisErrorMessage"/>
513+
</Target>
514+
515+
<Target Name="StaticAnalysisErrorMessage">
516+
<Error Text="StaticAnalysis has failed. Please follow the instructions on this doc: https://github.com/Azure/azure-powershell/blob/preview/documentation/Debugging-StaticAnalysis-Errors.md"/>
512517
</Target>
513518

514519
<!-- Publish all packages -->

documentation/Using-Azure-TestFramework.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ To use this option, set the following environment variable before starting Visua
144144

145145
## Record or Playback Tests
146146

147-
1. Run the test and make sure that you got a generated .json file that matches the test name in the bin folder under *SessionRecords folder
147+
1. [Run the test](https://github.com/Azure/azure-powershell/wiki/Azure-Powershell-Developer-Guide#running-tests) and make sure that you got a generated .json file that matches the test name in the bin folder under *SessionRecords folder
148148
2. Copy SessionRecords folder inside the test project and add all *.json files in Visual Studio setting "Copy to Output Directory" property to "Copy if newer"
149149
3. To assure that the records work fine, delete the connection string (default mode is Playback mode) OR change HttpRecorderMode within the connection string to "Playback"
150150

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Debugging StaticAnalysis Errors
2+
3+
Our StaticAnalysis tools help us ensure our modules follow PowerShell guidelines and prevent breaking changes from occurring outside of breaking change releases.
4+
5+
- [How to know if you have a StaticAnalysis Error](#how-to-know-if-you-have-a-staticanalysis-error)
6+
- [Where to find StaticAnalysis reports](#where-to-find-staticanalysis-reports)
7+
- [Types of StaticAnalysis Errors](#types-of-staticanalysis-errors)
8+
- [Breaking Changes](#breaking-changes)
9+
- [Signature Issues](#signature-issues)
10+
- [Help Issues](#help-issues)
11+
12+
## How to know if you have a StaticAnalysis Error
13+
If your build is failing, click on the Jenkins job inside the PR (marked as "Default" within checks). Then check the Console Output within the Jenkins job. If you have this error, then you have failed StaticAnalysis:
14+
```
15+
d:\workspace\powershell\build.proj(511,5): error MSB3073: The command "d:\workspace\powershell\src\Package\StaticAnalysis.exe d:\workspace\powershell\src\Package\Debug d:\workspace\powershell\src\Package true false" exited with code 255.
16+
```
17+
18+
## Where to find StaticAnalysis reports
19+
20+
The StaticAnalysis reports could show up in two different places in the CI build:
21+
- On the status page in Jenkins, under the Build Artifacts: the relevant files are BreakingChangeIssues.csv, SignatureIssues.csv, and/or HelpIssues.csv.
22+
- On the status page in Jenkins, click Build Artifacts then navigate to src/Package. You will see BreakingChangeIssues.csv, SignatureIssues.csv, and/or HelpIssues.csv.
23+
24+
Locally, the StaticAnalysis report will show up under Azure-PowerShell/src/Package. You will see BreakingChangeIssues.csv, SignatureIssues.csv, and/or HelpIssues.csv. You can generate these files by running
25+
```
26+
msbuild build.proj
27+
```
28+
29+
## Types of StaticAnalysis Errors
30+
The three most common Static Analysis errors are breaking changes, signature issues, and help issues. To figure out which type of error is causing the build failure, open each of the relevant .csv files (if the .csv file does not exist, there is no violation detected). Any issue marked with severity 0 or 1 must be resolved in order for the build to pass.
31+
32+
### Breaking Changes
33+
If you make a change that could cause a breaking change, it will be listed in BreakingChangeIssues.csv. Please look at each of these errors, and if they do indeed introduce a breaking change in a non-breaking change release, please revert the change that caused this violation. Sometimes the error listed in the .csv file can be a false positive (for example, if you change a parameter attribute to span all parameter sets rather than individual parameter sets). Please read the error thoroughly and examine the relevant code before deciding that an error is a false positive, and contact the Azure PowerShell team if you have questions. If you are releasing a preview module, are releasing during a breaking change release, or have determined that the error is a false positive, please follow these instructions:
34+
- Copy each of the errors you would like to suppress directly from the BreakingChangeIssues.csv file output in the Jenkins build
35+
- Paste each of these error into the [BreakingChangeIssues.csv file](https://github.com/Azure/azure-powershell/blob/preview/tools/StaticAnalysis/Exceptions/BreakingChangeIssues.csv) in our GitHub repo. Note that you will need to edit this file in a text editor rather than Excel to prevent parsing errors.
36+
- Push the changes to the .csv file and ensure the errors no longer show up in the BreakingChangeIssues.csv file output from the Jenkins build.
37+
38+
We take breaking changes very seriously, so please be mindful about the violations that you suppress in our repo.
39+
40+
### Signature Issues
41+
Signature issues occur when your cmdlets do not follow PowerShell standards. Please check [this page](https://github.com/Azure/azure-powershell/wiki/PowerShell-Cmdlet-Design-Guidelines) to ensure you are following PowerShell guidelines. Issues with severity 0 or 1 must be addressed, while issues with severity 2 are advisory. If you have an issue with severity 0 or 1 that has been approved by the Azure PowerShell team, you can suppress them following these steps:
42+
- Copy each of the errors you would like to suppress directly from the SignatureIssues.csv file output in the Jenkins build
43+
- Paste each of these error into the [SignatureIssues.csv file](https://github.com/Azure/azure-powershell/blob/preview/tools/StaticAnalysis/Exceptions/SignatureIssues.csv) in our GitHub repo. Note that you will need to edit this file in a text editor rather than Excel to prevent parsing errors.
44+
- Push the changes to the .csv file and ensure the errors no longer show up in the SignatureIssues.csv file output from the Jenkins build.
45+
46+
### Help Issues
47+
Most help issues that cause StaticAnalysis to fail occur when help has not been added for a particular cmdlet. If you have not generated help for your new cmdlets, please follow the instructions [here](https://github.com/Azure/azure-powershell/blob/preview/documentation/help-generation.md). If this is not the issue, follow the steps listed under "Remediation" for each violation listed in HelpIssues.csv.

src/Common/Commands.Common.Authentication.Abstractions/Settings/ClientFactorySettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
2323
public class ClientFactorySettings : IExtensibleSettings
2424
{
2525
/// <summary>
26-
/// The user agents in the cusrrent client factory
26+
/// The user agents in the current client factory
2727
/// </summary>
2828
public IEnumerable<UserAgentSettings> UserAgents { get; }
2929

src/ResourceManager/Billing/Commands.Billing/Common/AzureBillingCmdletBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public abstract class AzureBillingCmdletBase : AzureRMCmdlet
2929
{
3030
private IBillingManagementClient _billingManagementClient;
3131

32-
private Dictionary<string, List<string>> _defaultRequestHeaders;
33-
3432
/// <summary>
3533
/// Gets or sets the Billing management client.
3634
/// </summary>

src/ResourceManager/Consumption/Commands.Consumption/Common/AzureConsumptionCmdletBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public abstract class AzureConsumptionCmdletBase : AzureRMCmdlet
2828
{
2929
private IConsumptionManagementClient _consumptionManagementClient;
3030

31-
private Dictionary<string, List<string>> _defaultRequestHeaders;
32-
3331
/// <summary>
3432
/// Gets or sets the Consumption management client.
3533
/// </summary>

src/ResourceManager/ContainerInstance/Commands.ContainerInstance/help/New-AzureRmContainerGroup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The **New-AzureRmContainerGroup** cmdlets creates a container group.
4646

4747
### Example 1
4848
```
49-
PS C:\> New-AzureRmContainerGroup -ResourceGroupName demo -Name mycontainer -Image nginx -OsType Linux -IpAddressType Public -Ports @(8000)
49+
PS C:\> New-AzureRmContainerGroup -ResourceGroupName demo -Name mycontainer -Image nginx -OsType Linux -IpAddressType Public -Port @(8000)
5050
5151
ResourceGroupName : demo
5252
Id : /subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/demo/providers/Microsoft.ContainerInstance/containerGroups/mycontainer

src/ResourceManager/KeyVault/Commands.KeyVault.Test/Commands.KeyVault.Test.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,4 @@
362362
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
363363
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
364364
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
365-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
366-
<PropertyGroup>
367-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
368-
</PropertyGroup>
369-
<Error Condition="!Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
370-
</Target>
371365
</Project>

src/ResourceManager/KeyVault/Commands.KeyVault/Models/KeyVaultManagementCmdletBase.cs

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
#if NETSTANDARD
1516
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
17+
#else
18+
using Microsoft.Azure.ActiveDirectory.GraphClient;
19+
#endif
1620
using Microsoft.Azure.Commands.Common.Authentication;
1721
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
1822
using Microsoft.Azure.Commands.Common.Authentication.Models;
@@ -67,7 +71,13 @@ public ActiveDirectoryClient ActiveDirectoryClient
6771
if (_activeDirectoryClient == null)
6872
{
6973
_dataServiceCredential = new DataServiceCredential(AzureSession.Instance.AuthenticationFactory, DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.Graph);
74+
#if NETSTANDARD
7075
_activeDirectoryClient = new ActiveDirectoryClient(DefaultProfile.DefaultContext);
76+
#else
77+
_activeDirectoryClient = new ActiveDirectoryClient(new Uri(string.Format("{0}/{1}",
78+
DefaultProfile.DefaultContext.Environment.GetEndpoint(AzureEnvironment.Endpoint.Graph), _dataServiceCredential.TenantId)),
79+
() => Task.FromResult(_dataServiceCredential.GetToken()));
80+
#endif
7181
}
7282
return this._activeDirectoryClient;
7383
}
@@ -204,7 +214,13 @@ protected string GetCurrentUsersObjectId()
204214
string objectId = null;
205215
if (DefaultContext.Account.Type == AzureAccount.AccountType.User)
206216
{
207-
objectId = ActiveDirectoryClient.GetObjectId(new ADObjectFilterOptions()).ToString();
217+
#if NETSTANDARD
218+
objectId = ActiveDirectoryClient.GetObjectId(new ADObjectFilterOptions {UPN = DefaultContext.Account.Id}).ToString();
219+
#else
220+
var userFetcher = ActiveDirectoryClient.Me.ToUser();
221+
var user = userFetcher.ExecuteAsync().Result;
222+
objectId = user.ObjectId;
223+
#endif
208224
}
209225

210226
return objectId;
@@ -225,9 +241,20 @@ private string GetObjectIdByUpn(string upn)
225241
string objId = null;
226242
if (!string.IsNullOrWhiteSpace(upn))
227243
{
228-
var user = ActiveDirectoryClient.FilterUsers(new ADObjectFilterOptions() { SPN = upn }).SingleOrDefault();
244+
#if NETSTANDARD
245+
var user = ActiveDirectoryClient.FilterUsers(new ADObjectFilterOptions() { UPN = upn }).SingleOrDefault();
246+
#else
247+
var user = ActiveDirectoryClient.Users.Where(u => u.UserPrincipalName.Equals(upn, StringComparison.OrdinalIgnoreCase))
248+
.ExecuteAsync().ConfigureAwait(false).GetAwaiter().GetResult().CurrentPage.SingleOrDefault();
249+
#endif
229250
if (user != null)
251+
{
252+
#if NETSTANDARD
230253
objId = user.Id.ToString();
254+
#else
255+
objId = user.ObjectId;
256+
#endif
257+
}
231258
}
232259
return objId;
233260
}
@@ -237,9 +264,15 @@ private string GetObjectIdBySpn(string spn)
237264
string objId = null;
238265
if (!string.IsNullOrWhiteSpace(spn))
239266
{
267+
#if NETSTANDARD
240268
var servicePrincipal = ActiveDirectoryClient.FilterServicePrincipals(new ADObjectFilterOptions() { SPN = spn }).SingleOrDefault();
241-
if (servicePrincipal != null)
242-
objId = servicePrincipal.Id.ToString();
269+
objId = servicePrincipal?.Id.ToString();
270+
#else
271+
var servicePrincipal = ActiveDirectoryClient.ServicePrincipals.Where(s =>
272+
s.ServicePrincipalNames.Any(n => n.Equals(spn, StringComparison.OrdinalIgnoreCase)))
273+
.ExecuteAsync().GetAwaiter().GetResult().CurrentPage.SingleOrDefault();
274+
objId = servicePrincipal?.ObjectId;
275+
#endif
243276
}
244277
return objId;
245278
}
@@ -250,23 +283,44 @@ private string GetObjectIdByEmail(string email)
250283
// In ADFS, Graph cannot handle this particular combination of filters.
251284
if (!DefaultProfile.DefaultContext.Environment.OnPremise && !string.IsNullOrWhiteSpace(email))
252285
{
286+
#if NETSTANDARD
253287
var users = ActiveDirectoryClient.FilterUsers(new ADObjectFilterOptions() { Mail = email });
254288
if (users != null)
255289
{
256290
ThrowIfMultipleObjectIds(users, email);
257291
var user = users.FirstOrDefault();
258292
objId = user?.Id.ToString();
259293
}
294+
#else
295+
var users = ActiveDirectoryClient.Users.Where(FilterByEmail(email)).ExecuteAsync().GetAwaiter().GetResult().CurrentPage;
296+
if (users != null)
297+
{
298+
ThrowIfMultipleObjectIds(users, email);
299+
var user = users.FirstOrDefault();
300+
objId = user?.ObjectId;
301+
}
302+
#endif
260303
}
261304
return objId;
262305
}
263306

307+
#if !NETSTANDARD
308+
private Expression<Func<IUser, bool>> FilterByEmail(string email)
309+
{
310+
return u => u.Mail.Equals(email, StringComparison.OrdinalIgnoreCase) ||
311+
u.OtherMails.Any(m => m.Equals(email, StringComparison.OrdinalIgnoreCase));
312+
}
313+
#endif
264314
private bool ValidateObjectId(string objId)
265315
{
266316
bool isValid = false;
267317
if (!string.IsNullOrWhiteSpace(objId))
268318
{
319+
#if NETSTANDARD
269320
var objectCollection = ActiveDirectoryClient.GetObjectsByObjectId(new List<string> { objId });
321+
#else
322+
var objectCollection = ActiveDirectoryClient.GetObjectsByObjectIdsAsync(new[] { objId }, new string[] { }).GetAwaiter().GetResult();
323+
#endif
270324
if (objectCollection.Any())
271325
{
272326
isValid = true;

src/ResourceManager/KeyVault/Commands.KeyVault/Models/ModelExtensions.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
#if NETSTANDARD
1516
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
17+
#else
18+
using Microsoft.Azure.ActiveDirectory.GraphClient;
19+
#endif
1620
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1721
using System;
1822
using System.Collections.Generic;
@@ -97,6 +101,7 @@ public static string GetDisplayNameForADObject(string objectId, ActiveDirectoryC
97101

98102
try
99103
{
104+
#if NETSTANDARD
100105
var obj = adClient.GetObjectsByObjectId(new List<string> { objectId }).FirstOrDefault();
101106
if (obj != null)
102107
{
@@ -113,6 +118,25 @@ public static string GetDisplayNameForADObject(string objectId, ActiveDirectoryC
113118
upnOrSpn = servicePrincipal.ServicePrincipalNames.FirstOrDefault();
114119
}
115120
}
121+
#else
122+
var obj = adClient.GetObjectsByObjectIdsAsync(new[] { objectId }, new string[] { }).GetAwaiter().GetResult().FirstOrDefault();
123+
if (obj != null)
124+
{
125+
if (obj.ObjectType.Equals("user", StringComparison.InvariantCultureIgnoreCase))
126+
{
127+
var user = adClient.Users.GetByObjectId(objectId).ExecuteAsync().GetAwaiter().GetResult();
128+
displayName = user.DisplayName;
129+
upnOrSpn = user.UserPrincipalName;
130+
}
131+
else if (obj.ObjectType.Equals("serviceprincipal", StringComparison.InvariantCultureIgnoreCase))
132+
{
133+
var servicePrincipal = adClient.ServicePrincipals.GetByObjectId(objectId).ExecuteAsync().GetAwaiter().GetResult();
134+
displayName = servicePrincipal.AppDisplayName;
135+
upnOrSpn = servicePrincipal.ServicePrincipalNames.FirstOrDefault();
136+
}
137+
}
138+
139+
#endif
116140
}
117141
catch
118142
{

src/ResourceManager/KeyVault/Commands.KeyVault/Models/PSVault.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
#if NETSTANDARD
1516
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
17+
#else
18+
using Microsoft.Azure.ActiveDirectory.GraphClient;
19+
#endif
1620
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
1721
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
1822
using Microsoft.Azure.Management.KeyVault.Models;

src/ResourceManager/KeyVault/Commands.KeyVault/Models/PSVaultAccessPolicy.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
#if NETSTANDARD
1516
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
17+
#else
18+
using Microsoft.Azure.ActiveDirectory.GraphClient;
19+
#endif
1620
using System;
1721
using System.Collections.Generic;
1822
using KeyVaultManagement = Microsoft.Azure.Management.KeyVault;

src/ResourceManager/KeyVault/Commands.KeyVault/Models/VaultManagementClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
#if NETSTANDARD
1516
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
17+
#else
18+
using Microsoft.Azure.ActiveDirectory.GraphClient;
19+
#endif
1620
using Microsoft.Azure.Commands.Common.Authentication;
1721
using Microsoft.Azure.Commands.Common.Authentication.Models;
1822
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;

0 commit comments

Comments
 (0)