Skip to content

Commit b95dd51

Browse files
committed
Resolve review feedback, remove local .nupkg file
1 parent fb94617 commit b95dd51

File tree

6 files changed

+28
-148
lines changed

6 files changed

+28
-148
lines changed

src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/Cmdlets/ActiveDirectoryBaseCmdlet.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ namespace Microsoft.Azure.Commands.ActiveDirectory
2323
{
2424
public abstract class ActiveDirectoryBaseCmdlet : AzureRMCmdlet
2525
{
26-
private ActiveDirectoryClient activeDirectoryClient;
26+
private ActiveDirectoryClient _activeDirectoryClient;
2727

2828
public ActiveDirectoryClient ActiveDirectoryClient
2929
{
3030
get
3131
{
32-
if (activeDirectoryClient == null)
32+
if (_activeDirectoryClient == null)
3333
{
34-
activeDirectoryClient = new ActiveDirectoryClient(DefaultProfile.DefaultContext);
34+
_activeDirectoryClient = new ActiveDirectoryClient(DefaultProfile.DefaultContext);
3535
}
3636

37-
return activeDirectoryClient;
37+
return _activeDirectoryClient;
3838
}
3939

40-
set { activeDirectoryClient = value; }
40+
set { _activeDirectoryClient = value; }
4141
}
4242

4343
/// <summary>

src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/Models/ActiveDirectoryClient.cs

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@ public ActiveDirectoryClient(IAzureContext context)
3939
{
4040
GraphClient = AzureSession.Instance.ClientFactory.CreateArmClient<GraphRbacManagementClient>(
4141
context, AzureEnvironment.Endpoint.Graph);
42-
4342
GraphClient.TenantID = context.Tenant.Id.ToString();
4443
}
4544

4645
public PSADObject GetADObject(ADObjectFilterOptions options)
4746
{
4847
PSADObject result = null;
49-
5048
Debug.Assert(options != null);
51-
5249
if (IsSet(options.Mail, options.UPN, options.Id))
5350
{
5451
result = FilterUsers(options).FirstOrDefault();
@@ -115,7 +112,6 @@ public IEnumerable<PSADServicePrincipal> FilterServicePrincipals(ADObjectFilterO
115112
{
116113
List<PSADServicePrincipal> servicePrincipals = new List<PSADServicePrincipal>();
117114
ServicePrincipal servicePrincipal = null;
118-
119115
if (!string.IsNullOrEmpty(options.Id))
120116
{
121117
try
@@ -246,7 +242,6 @@ public List<PSADObject> ListUserGroups(string principal)
246242
var groupsIds = GraphClient.Users.GetMemberGroups(objectId.ToString(), new UserGetMemberGroupsParameters());
247243
var groupsResult = GraphClient.Objects.GetObjectsByObjectIds(new GetObjectsParameters { ObjectIds = groupsIds.ToList() });
248244
result.AddRange(groupsResult.Select(g => g.ToPSADGroup()));
249-
250245
return result;
251246
}
252247

@@ -305,25 +300,29 @@ public IEnumerable<PSADGroup> FilterGroups(ADObjectFilterOptions options, ulong
305300
}
306301
}
307302
catch { /* The group does not exist, ignore the exception */ }
303+
304+
return new List<PSADGroup>();
305+
}
306+
else if (options.Mail != null)
307+
{
308+
Rest.Azure.OData.ODataQuery<ADGroup> odataQuery = new Rest.Azure.OData.ODataQuery<ADGroup>(g => g.Mail == options.Mail);
309+
return new GenericPageEnumerable<ADGroup>(
310+
delegate ()
311+
{
312+
return GraphClient.Groups.List(odataQuery);
313+
}, GraphClient.Groups.ListNext, first, skip).Select(g => g.ToPSADGroup());
308314
}
309315
else
310316
{
311317
Rest.Azure.OData.ODataQuery<ADGroup> odataQuery = null;
312-
if (options.Mail != null)
318+
if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
313319
{
314-
odataQuery = new Rest.Azure.OData.ODataQuery<ADGroup>(g => g.Mail == options.Mail);
320+
options.SearchString = options.SearchString.TrimEnd('*');
321+
odataQuery = new Rest.Azure.OData.ODataQuery<ADGroup>(g => g.DisplayName.StartsWith(options.SearchString));
315322
}
316323
else
317324
{
318-
if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
319-
{
320-
options.SearchString = options.SearchString.TrimEnd('*');
321-
odataQuery = new Rest.Azure.OData.ODataQuery<ADGroup>(g => g.DisplayName.StartsWith(options.SearchString));
322-
}
323-
else
324-
{
325-
odataQuery = new Rest.Azure.OData.ODataQuery<ADGroup>(g => g.DisplayName == options.SearchString);
326-
}
325+
odataQuery = new Rest.Azure.OData.ODataQuery<ADGroup>(g => g.DisplayName == options.SearchString);
327326
}
328327

329328
return new GenericPageEnumerable<ADGroup>(
@@ -332,8 +331,6 @@ public IEnumerable<PSADGroup> FilterGroups(ADObjectFilterOptions options, ulong
332331
return GraphClient.Groups.List(odataQuery);
333332
}, GraphClient.Groups.ListNext, first, skip).Select(g => g.ToPSADGroup());
334333
}
335-
336-
return new List<PSADGroup>();
337334
}
338335

339336
public IEnumerable<PSADGroup> FilterGroups()
@@ -485,51 +482,38 @@ private void PatchAppPasswordCredentials(string appObjectId, List<PasswordCreden
485482
public PSADCredential CreateAppKeyCredential(string appObjectId, KeyCredential credential)
486483
{
487484
ValidateKeyCredential(credential);
488-
489485
var keyCredsList = GetAppKeyCredentials(appObjectId);
490-
491486
// Add new KeyCredential to existing KeyCredential list
492487
keyCredsList.Add(credential);
493-
494488
PatchAppKeyCredentials(appObjectId, keyCredsList);
495-
496489
return credential.ToPSADCredential();
497490
}
498491

499492
public PSADCredential CreateAppPasswordCredential(string appObjectId, PasswordCredential credential)
500493
{
501494
ValidatePasswordCredential(credential);
502-
503495
var passwordCredsList = GetAppPasswordCredentials(appObjectId);
504-
505496
// Add new PasswordCredential to existing KeyCredential list
506497
passwordCredsList.Add(credential);
507-
508498
PatchAppPasswordCredentials(appObjectId, passwordCredsList);
509-
510499
return credential.ToPSADCredential();
511500
}
512501

513502
public List<PSADCredential> GetAppCredentials(string appObjectId)
514503
{
515504
List<PSADCredential> CredentialList = new List<PSADCredential>();
516-
517505
var keyCredsList = GetAppKeyCredentials(appObjectId);
518506
CredentialList.AddRange(keyCredsList.Select(kc => kc.ToPSADCredential()));
519-
520507
var passwordCredsList = GetAppPasswordCredentials(appObjectId);
521508
CredentialList.AddRange(passwordCredsList.Select(pc => pc.ToPSADCredential()));
522-
523509
return CredentialList;
524510
}
525511

526512

527513
public void RemoveAppCredentialByKeyId(string appObjectId, Guid keyId)
528514
{
529515
var keyCredsList = GetAppKeyCredentials(appObjectId);
530-
531516
var toBeDeletedKeyCred = keyCredsList.Find(kc => Guid.Parse(kc.KeyId) == keyId);
532-
533517
if (toBeDeletedKeyCred != null)
534518
{
535519
keyCredsList.Remove(toBeDeletedKeyCred);
@@ -539,7 +523,6 @@ public void RemoveAppCredentialByKeyId(string appObjectId, Guid keyId)
539523
{
540524
var passwordCredsList = GetAppPasswordCredentials(appObjectId);
541525
var toBeDeletedPasswwordCred = passwordCredsList.Find(pc => Guid.Parse(pc.KeyId) == keyId);
542-
543526
if (toBeDeletedPasswwordCred != null)
544527
{
545528
passwordCredsList.Remove(toBeDeletedPasswwordCred);
@@ -634,50 +617,37 @@ private void PatchSpPasswordCredentials(string spObjectId, List<PasswordCredenti
634617
public PSADCredential CreateSpKeyCredential(string spObjectId, KeyCredential credential)
635618
{
636619
ValidateKeyCredential(credential);
637-
638620
var keyCredsList = GetSpKeyCredentials(spObjectId);
639-
640621
// Add new KeyCredential to existing KeyCredential list
641622
keyCredsList.Add(credential);
642-
643623
PatchSpKeyCredentials(spObjectId, keyCredsList);
644-
645624
return credential.ToPSADCredential();
646625
}
647626

648627
public PSADCredential CreateSpPasswordCredential(string spObjectId, PasswordCredential credential)
649628
{
650629
ValidatePasswordCredential(credential);
651-
652630
var passwordCredsList = GetSpPasswordCredentials(spObjectId);
653-
654631
// Add new PasswordCredential to existing KeyCredential list
655632
passwordCredsList.Add(credential);
656-
657633
PatchSpPasswordCredentials(spObjectId, passwordCredsList);
658-
659634
return credential.ToPSADCredential();
660635
}
661636

662637
public List<PSADCredential> GetSpCredentials(string spObjectId)
663638
{
664639
List<PSADCredential> CredentialList = new List<PSADCredential>();
665-
666640
var keyCredsList = GetSpKeyCredentials(spObjectId);
667641
CredentialList.AddRange(keyCredsList.Select(kc => kc.ToPSADCredential()));
668-
669642
var passwordCredsList = GetSpPasswordCredentials(spObjectId);
670643
CredentialList.AddRange(passwordCredsList.Select(pc => pc.ToPSADCredential()));
671-
672644
return CredentialList;
673645
}
674646

675647
public void RemoveSpCredentialByKeyId(string spObjectId, Guid keyId)
676648
{
677649
var keyCredsList = GetSpKeyCredentials(spObjectId);
678-
679650
var toBeDeletedKeyCred = keyCredsList.Find(kc => Guid.Parse(kc.KeyId) == keyId);
680-
681651
if (toBeDeletedKeyCred != null)
682652
{
683653
keyCredsList.Remove(toBeDeletedKeyCred);
@@ -687,7 +657,6 @@ public void RemoveSpCredentialByKeyId(string spObjectId, Guid keyId)
687657
{
688658
var passwordCredsList = GetSpPasswordCredentials(spObjectId);
689659
var toBeDeletedPasswwordCred = passwordCredsList.Find(pc => Guid.Parse(pc.KeyId) == keyId);
690-
691660
if (toBeDeletedPasswwordCred != null)
692661
{
693662
passwordCredsList.Remove(toBeDeletedPasswwordCred);

0 commit comments

Comments
 (0)