|
12 | 12 | // limitations under the License. |
13 | 13 | // ---------------------------------------------------------------------------------- |
14 | 14 |
|
15 | | -// TODO: Remove IfDef |
16 | | -#if NETSTANDARD |
17 | | -using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory; |
18 | | -#else |
19 | | -using Microsoft.Azure.ActiveDirectory.GraphClient; |
20 | | -#endif |
21 | | -using System; |
22 | | -using System.Collections; |
23 | | -using System.Collections.Generic; |
24 | | -using System.Linq; |
25 | | -using System.Linq.Expressions; |
26 | | -using System.Threading.Tasks; |
27 | 15 | using Microsoft.Azure.Commands.Common.Authentication; |
28 | 16 | using Microsoft.Azure.Commands.Common.Authentication.Abstractions; |
29 | 17 | using Microsoft.Azure.Commands.KeyVault.Models; |
| 18 | +using Microsoft.Azure.Commands.KeyVault.Properties; |
30 | 19 | using Microsoft.Azure.Commands.ResourceManager.Common; |
| 20 | +using Microsoft.Azure.Commands.ResourceManager.Common.Paging; |
31 | 21 | using Microsoft.Azure.Commands.ResourceManager.Common.Tags; |
| 22 | +using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory; |
32 | 23 | using Microsoft.Azure.Management.Internal.Resources; |
33 | 24 | using Microsoft.Azure.Management.Internal.Resources.Models; |
34 | 25 | using Microsoft.Azure.Management.Internal.Resources.Utilities; |
35 | 26 | using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; |
36 | | -using PSKeyVaultModels = Microsoft.Azure.Commands.KeyVault.Models; |
37 | | -using PSKeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties; |
38 | | -using Microsoft.Rest.Azure; |
| 27 | +using System; |
| 28 | +using System.Collections; |
| 29 | +using System.Collections.Generic; |
| 30 | +using System.Linq; |
| 31 | +using CertPerms = Microsoft.Azure.Management.KeyVault.Models.CertificatePermissions; |
39 | 32 | using KeyPerms = Microsoft.Azure.Management.KeyVault.Models.KeyPermissions; |
| 33 | +using PSKeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties; |
40 | 34 | using SecretPerms = Microsoft.Azure.Management.KeyVault.Models.SecretPermissions; |
41 | | -using CertPerms = Microsoft.Azure.Management.KeyVault.Models.CertificatePermissions; |
42 | 35 | using StoragePerms = Microsoft.Azure.Management.KeyVault.Models.StoragePermissions; |
43 | | -using Microsoft.Azure.Management.KeyVault.Models; |
44 | | -using Microsoft.Azure.Commands.ResourceManager.Common.Paging; |
45 | 36 |
|
46 | 37 | namespace Microsoft.Azure.Commands.KeyVault |
47 | 38 | { |
@@ -128,7 +119,7 @@ protected List<PSKeyVaultIdentityItem> FilterByTag(List<PSKeyVaultIdentityItem> |
128 | 119 |
|
129 | 120 | protected PSKeyVault FilterByTag(PSKeyVault keyVault, Hashtable tag) |
130 | 121 | { |
131 | | - return (PSKeyVault) FilterByTag(new List<PSKeyVaultIdentityItem> { keyVault }, tag).FirstOrDefault(); |
| 122 | + return (PSKeyVault)FilterByTag(new List<PSKeyVaultIdentityItem> { keyVault }, tag).FirstOrDefault(); |
132 | 123 | } |
133 | 124 |
|
134 | 125 | protected List<PSKeyVaultIdentityItem> ListVaults(string resourceGroupName, Hashtable tag) |
@@ -235,7 +226,7 @@ protected string GetCurrentUsersObjectId() |
235 | 226 | { |
236 | 227 | // TODO: Remove IfDef |
237 | 228 | #if NETSTANDARD |
238 | | - objectId = ActiveDirectoryClient.GetObjectId(new ADObjectFilterOptions {UPN = DefaultContext.Account.Id}).ToString(); |
| 229 | + objectId = ActiveDirectoryClient.GetObjectId(new ADObjectFilterOptions { UPN = DefaultContext.Account.Id }).ToString(); |
239 | 230 | #else |
240 | 231 | var userFetcher = ActiveDirectoryClient.Me.ToUser(); |
241 | 232 | var user = userFetcher.ExecuteAsync().Result; |
@@ -335,13 +326,16 @@ private Expression<Func<IUser, bool>> FilterByEmail(string email) |
335 | 326 | private bool ValidateObjectId(string objId) |
336 | 327 | { |
337 | 328 | if (string.IsNullOrWhiteSpace(objId)) return false; |
338 | | -// TODO: Remove IfDef |
339 | | -#if NETSTANDARD |
340 | | - var objectCollection = ActiveDirectoryClient.GetObjectsByObjectId(new List<string> { objId }); |
341 | | -#else |
342 | | - var objectCollection = ActiveDirectoryClient.GetObjectsByObjectIdsAsync(new[] { objId }, new string[] { }).GetAwaiter().GetResult(); |
343 | | -#endif |
344 | | - return objectCollection.Any(); |
| 329 | + try |
| 330 | + { |
| 331 | + var objectCollection = ActiveDirectoryClient.GetObjectsByObjectId(new List<string> { objId }); |
| 332 | + return objectCollection.Any(); |
| 333 | + } |
| 334 | + catch (Exception ex) |
| 335 | + { |
| 336 | + WriteWarning(Resources.ADGraphPermissionWarning); |
| 337 | + throw ex; |
| 338 | + } |
345 | 339 | } |
346 | 340 |
|
347 | 341 | protected string GetObjectId(string objectId, string upn, string email, string spn) |
@@ -410,7 +404,7 @@ protected bool IsValidObjectIdSyntax(string objectId) |
410 | 404 | KeyPerms.Recover |
411 | 405 | }; |
412 | 406 |
|
413 | | - protected readonly string[] DefaultPermissionsToSecrets = |
| 407 | + protected readonly string[] DefaultPermissionsToSecrets = |
414 | 408 | { |
415 | 409 | SecretPerms.Get, |
416 | 410 | SecretPerms.List, |
@@ -440,7 +434,7 @@ protected bool IsValidObjectIdSyntax(string objectId) |
440 | 434 | CertPerms.Restore |
441 | 435 | }; |
442 | 436 |
|
443 | | - protected readonly string[] DefaultPermissionsToStorage = |
| 437 | + protected readonly string[] DefaultPermissionsToStorage = |
444 | 438 | { |
445 | 439 | StoragePerms.Delete, |
446 | 440 | StoragePerms.Deletesas, |
|
0 commit comments