public IEnumerable <PSNamespaceAttributes> ListAllNamespaces() { Rest.Azure.IPage <SBNamespace> response = Client.Namespaces.List(); var resourceList = response.Select(resource => new PSNamespaceAttributes(resource)); return(resourceList); }
public IEnumerable <PSRulesAttributes> ListRules(string resourceGroupName, string namespaceName, string topicName, string subscriptionName) { Rest.Azure.IPage <Rule> response = Client.Rules.ListBySubscriptions(resourceGroupName, namespaceName, topicName, subscriptionName); IEnumerable <PSRulesAttributes> resourceList = response.Select(resource => new PSRulesAttributes(resource)); return(resourceList); }
public IEnumerable <PSSharedAccessAuthorizationRuleAttributes> ListServiceBusQueueAuthorizationRules(string resourceGroupName, string namespaceName, string queueName) { Rest.Azure.IPage <SBAuthorizationRule> response = Client.Queues.ListAuthorizationRules(resourceGroupName, namespaceName, queueName); IEnumerable <PSSharedAccessAuthorizationRuleAttributes> resourceList = response.Select(resource => new PSSharedAccessAuthorizationRuleAttributes(resource)); return(resourceList); }
public IEnumerable <PSRulesAttributes> ListRules(string resourceGroupName, string namespaceName, string topicName, string subscriptionName, int?maxCount = null) { IEnumerable <PSRulesAttributes> resourceList = Enumerable.Empty <PSRulesAttributes>(); int?skip = 0; switch (ReturnmaxCountvalueForSwtich(maxCount)) { case 0: Rest.Azure.IPage <Rule> response = Client.Rules.ListBySubscriptions(resourceGroupName, namespaceName, topicName, subscriptionName, skip: 0, top: maxCount); resourceList = response.Select(resource => new PSRulesAttributes(resource)); break; case 1: while (maxCount > 0) { Rest.Azure.IPage <Rule> response1 = Client.Rules.ListBySubscriptions(resourceGroupName, namespaceName, topicName, subscriptionName, skip: skip, top: maxCount); resourceList = resourceList.Concat <PSRulesAttributes>(response1.Select(resource => new PSRulesAttributes(resource))); skip += maxCount > 100 ? 100 : maxCount; maxCount = maxCount - 100; } break; default: Rest.Azure.IPage <Rule> response2 = Client.Rules.ListBySubscriptions(resourceGroupName, namespaceName, topicName, subscriptionName); resourceList = response2.Select(resource => new PSRulesAttributes(resource)); break; } return(resourceList); }
public IEnumerable <SharedAccessAuthorizationRuleAttributes> ListServiceBusTopicAuthorizationRules(string resourceGroupName, string namespaceName, string topicName) { Rest.Azure.IPage <SharedAccessAuthorizationRuleResource> response = Client.Topics.ListAuthorizationRules(resourceGroupName, namespaceName, topicName); IEnumerable <SharedAccessAuthorizationRuleAttributes> resourceList = response.Select(resource => new SharedAccessAuthorizationRuleAttributes(resource)); return(resourceList); }
public IEnumerable <TopicAttributes> ListTopics(string resourceGroupName, string namespaceName) { Rest.Azure.IPage <TopicResource> response = Client.Topics.ListAll(resourceGroupName, namespaceName); IEnumerable <TopicAttributes> resourceList = response.Select(resource => new TopicAttributes(resource)); return(resourceList); }
public List <PSADObject> GetGroupMembers(ADObjectFilterOptions options) { List <PSADObject> members = new List <PSADObject>(); Rest.Azure.IPage <AADObject> result = null; if (options.Paging) { if (string.IsNullOrEmpty(options.NextLink)) { result = GraphClient.Groups.GetGroupMembers(options.Id); } else { result = GraphClient.Groups.GetGroupMembersNext(options.NextLink); } members.AddRange(result.Select(u => u.ToPSADObject())); options.NextLink = result.NextPageLink; } else { result = GraphClient.Groups.GetGroupMembers(options.Id); members.AddRange(result.Select(u => u.ToPSADObject())); while (!string.IsNullOrEmpty(result.NextPageLink)) { result = GraphClient.Groups.GetGroupMembersNext(result.NextPageLink); members.AddRange(result.Select(u => u.ToPSADObject())); } } return(members); }
public IEnumerable <SubscriptionAttributes> ListSubscriptions(string resourceGroupName, string namespaceName, string topicName) { Rest.Azure.IPage <SubscriptionResource> response = Client.Subscriptions.ListAll(resourceGroupName, namespaceName, topicName); IEnumerable <SubscriptionAttributes> resourceList = response.Select(resource => new SubscriptionAttributes(resource)); return(resourceList); }
public IEnumerable <NamespaceAttributes> ListNamespaces(string resourceGroupName) { Rest.Azure.IPage <NamespaceResource> response = Client.Namespaces.ListByResourceGroup(resourceGroupName); IEnumerable <NamespaceAttributes> resourceList = response.Select(resource => new NamespaceAttributes(resource)); return(resourceList); }
public IEnumerable <PSQueueAttributes> ListQueues(string resourceGroupName, string namespaceName) { Rest.Azure.IPage <SBQueue> response = Client.Queues.ListByNamespace(resourceGroupName, namespaceName); IEnumerable <PSQueueAttributes> resourceList = response.Select(resource => new PSQueueAttributes(resource)); return(resourceList); }
public IEnumerable <NamespaceAttributes> ListAllNamespaces() { Rest.Azure.IPage <NamespaceResource> response = Client.Namespaces.ListBySubscription(); var resourceList = response.Select(resource => new NamespaceAttributes(resource)); return(resourceList); }
public IEnumerable <QueueAttributes> ListQueues(string resourceGroupName, string namespaceName) { Rest.Azure.IPage <QueueResource> response = Client.Queues.ListAll(resourceGroupName, namespaceName); //IEnumerable<NamespaceAttributes> resourceList = response.Select(resource => new NamespaceAttributes(resourceGroupName, resource)); IEnumerable <QueueAttributes> resourceList = response.Select(resource => new QueueAttributes(resource)); return(resourceList); }
public static List <GenericResource> FilterResources(this IResourceManagementClient client, FilterResourcesOptions options) { List <GenericResource> resources = new List <GenericResource>(); if (!string.IsNullOrEmpty(options.ResourceGroup) && !string.IsNullOrEmpty(options.Name)) { resources.Add(client.Resources.Get(options.ResourceGroup, null, null, null, options.Name, null)); } else { if (!string.IsNullOrEmpty(options.ResourceGroup)) { Rest.Azure.IPage <GenericResource> result = client.ResourceGroups.ListResources(options.ResourceGroup, new Rest.Azure.OData.ODataQuery <GenericResourceFilter>(r => r.ResourceType == options.ResourceType)); resources.AddRange(result); while (!string.IsNullOrEmpty(result.NextPageLink)) { result = client.ResourceGroups.ListResourcesNext(result.NextPageLink); resources.AddRange(result); } } else { Rest.Azure.IPage <GenericResource> result = client.Resources.List( new Rest.Azure.OData.ODataQuery <GenericResourceFilter>(r => r.ResourceType == options.ResourceType)); resources.AddRange(result); while (!string.IsNullOrEmpty(result.NextPageLink)) { result = client.Resources.ListNext(result.NextPageLink); resources.AddRange(result); } } } foreach (var resource in resources) { var identifier = new ResourceIdentifier(resource.Id); resource.ResourceGroupName = identifier.ResourceGroupName; } return(resources); }
private void SkipNObjects(out Rest.Azure.IPage <CommunicationDetails> supportTicketCommunicationPage, out IEnumerable <CommunicationDetails> supportTicketCommunications) { var remainingSkip = this.MyInvocation.BoundParameters.ContainsKey("Skip") ? this.PagingParameters.Skip : 0; supportTicketCommunicationPage = this.SupportClient.Communications.List(this.SupportTicketName, filter: this.Filter); var actualSkipCount = Math.Min(remainingSkip, (uint)supportTicketCommunicationPage.Count()); supportTicketCommunications = supportTicketCommunicationPage.Skip((int)actualSkipCount); remainingSkip -= actualSkipCount; // Skip more while (remainingSkip > 0 && supportTicketCommunicationPage != null && !string.IsNullOrWhiteSpace(supportTicketCommunicationPage.NextPageLink)) { supportTicketCommunicationPage = this.SupportClient.Communications.ListNext(supportTicketCommunicationPage.NextPageLink); actualSkipCount = Math.Min(remainingSkip, (uint)supportTicketCommunicationPage.Count()); supportTicketCommunications = supportTicketCommunicationPage.Skip((int)actualSkipCount); remainingSkip -= actualSkipCount; } }
private string GetStorageResourceGroup( ResourceManagementClient resourcesClient, string storageAccountName, string resourceType) { var query = new Rest.Azure.OData.ODataQuery <GenericResourceFilter>(r => r.ResourceType == resourceType); Rest.Azure.IPage <GenericResource> res = resourcesClient.Resources.List(query); var allResources = new List <GenericResource>(res); GenericResource account = allResources.Find(r => r.Name == storageAccountName); if (account != null) { string resId = account.Id; string[] segments = resId.Split('/'); int indexOfResoureGroup = new List <string>(segments).IndexOf("resourceGroups") + 1; return(segments[indexOfResoureGroup]); } else { return(null); } }
/// <summary> /// Creates a trust list with all certs and crls in issuer and trusted list. /// i) First load all certs and crls tagged with id==Issuer or id==Trusted. /// ii) Then walk all CA cert versions and load all certs tagged with id==Issuer or id==Trusted. /// Crl is loaded too if CA cert is tagged. /// </summary> public async Task <Models.KeyVaultTrustListModel> GetTrustListAsync(string id, int?maxResults, string nextPageLink, CancellationToken ct = default) { var trustList = new Models.KeyVaultTrustListModel(id); if (maxResults == null) { maxResults = MaxResults; } Rest.Azure.IPage <SecretItem> secretItems = null; if (nextPageLink != null) { if (nextPageLink.Contains("/secrets")) { secretItems = await _keyVaultClient.GetSecretsNextAsync(nextPageLink, ct).ConfigureAwait(false); } } else { secretItems = await _keyVaultClient.GetSecretsAsync(_vaultBaseUrl, maxResults, ct).ConfigureAwait(false); } int results = 0; while (secretItems != null) { foreach (var secretItem in secretItems.Where(s => s.Tags != null)) { string tag = secretItem.Tags.FirstOrDefault(x => String.Equals(x.Key, id, StringComparison.OrdinalIgnoreCase)).Value; bool issuer = tag == TagIssuerList; bool trusted = tag == TagTrustedList; bool certType = secretItem.ContentType == ContentTypeCert; bool crlType = secretItem.ContentType == ContentTypeCrl; if (issuer || trusted && (certType || crlType)) { X509CRL crl = null; X509Certificate2 cert = null; if (certType) { var certCollection = issuer ? trustList.IssuerCertificates : trustList.TrustedCertificates; cert = await LoadCertSecret(secretItem.Identifier.Name, ct).ConfigureAwait(false); certCollection.Add(cert); } else { var crlCollection = issuer ? trustList.IssuerCrls : trustList.TrustedCrls; crl = await LoadCrlSecret(secretItem.Identifier.Name, ct).ConfigureAwait(false); crlCollection.Add(crl); } results++; } } if (secretItems.NextPageLink != null) { if (results >= maxResults) { trustList.NextPageLink = secretItems.NextPageLink; return(trustList); } else { secretItems = await _keyVaultClient.GetSecretsNextAsync(secretItems.NextPageLink, ct).ConfigureAwait(false); } } else { secretItems = null; } } Rest.Azure.IPage <CertificateItem> certItems = null; if (nextPageLink != null) { certItems = await _keyVaultClient.GetCertificateVersionsNextAsync(nextPageLink, ct).ConfigureAwait(false); } else { certItems = await _keyVaultClient.GetCertificateVersionsAsync(_vaultBaseUrl, id, maxResults, ct).ConfigureAwait(false); } while (certItems != null) { foreach (var certItem in certItems.Where(c => c.Tags != null)) { string tag = certItem.Tags.FirstOrDefault(x => String.Equals(x.Key, id, StringComparison.OrdinalIgnoreCase)).Value; bool issuer = tag == TagIssuerList; bool trusted = tag == TagTrustedList; if (issuer || trusted) { var certBundle = await _keyVaultClient.GetCertificateAsync(certItem.Id, ct).ConfigureAwait(false); var cert = new X509Certificate2(certBundle.Cer); var crl = await LoadIssuerCACrl(id, cert, ct); if (issuer) { trustList.IssuerCertificates.Add(cert); trustList.IssuerCrls.Add(crl); } else { trustList.TrustedCertificates.Add(cert); trustList.TrustedCrls.Add(crl); } results++; } } if (certItems.NextPageLink != null) { if (results >= maxResults) { trustList.NextPageLink = certItems.NextPageLink; return(trustList); } else { certItems = await _keyVaultClient.GetCertificateVersionsNextAsync(certItems.NextPageLink, ct).ConfigureAwait(false); } } else { certItems = null; } } return(trustList); }
public List <PSADUser> FilterUsers(ADObjectFilterOptions options) { List <PSADUser> users = new List <PSADUser>(); Rest.Azure.IPage <User> result = null; User user = null; if (!string.IsNullOrEmpty(options.Id)) { try { user = GraphClient.Users.Get(Normalize(options.Id)); } catch { /* The user does not exist, ignore the exception. */ } if (user != null) { users.Add(user.ToPSADUser()); } } else if (!string.IsNullOrEmpty(options.UPN) || !string.IsNullOrEmpty(options.Mail)) { try { string upnOrMail = Normalize(options.UPN) ?? Normalize(options.Mail); result = GraphClient.Users.List(new Rest.Azure.OData.ODataQuery <User>(u => u.UserPrincipalName == upnOrMail)); } catch { /* The user does not exist, ignore the exception. */ } if (result != null) { users.AddRange(result.Select(u => u.ToPSADUser())); } } else { if (options.Paging) { if (string.IsNullOrEmpty(options.NextLink)) { result = GraphClient.Users.List(new Rest.Azure.OData.ODataQuery <User>(u => u.DisplayName.StartsWith(options.SearchString))); } else { result = GraphClient.Users.ListNext(options.NextLink); } users.AddRange(result.Select(u => u.ToPSADUser())); options.NextLink = result.NextPageLink; } else { result = GraphClient.Users.List(new Rest.Azure.OData.ODataQuery <User>(u => u.DisplayName.StartsWith(options.SearchString))); users.AddRange(result.Select(u => u.ToPSADUser())); while (!string.IsNullOrEmpty(result.NextPageLink)) { result = GraphClient.Users.ListNext(result.NextPageLink); users.AddRange(result.Select(u => u.ToPSADUser())); } } } return(users); }
public List <PSADGroup> FilterGroups(ADObjectFilterOptions options) { List <PSADGroup> groups = new List <PSADGroup>(); if (!string.IsNullOrEmpty(options.Id)) { try { // use GetObjectsByObjectId to handle Redirects in the CSP scenario PSADGroup group = this.GetObjectsByObjectId(new List <string> { options.Id }).FirstOrDefault() as PSADGroup; if (group != null) { groups.Add(group); } } catch { /* The group does not exist, ignore the exception */ } } else { Rest.Azure.IPage <ADGroup> result = null; Rest.Azure.OData.ODataQuery <ADGroup> odataQuery = null; if (options.Paging) { if (string.IsNullOrEmpty(options.NextLink)) { if (options.Mail != null) { odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.Mail == options.Mail); } else { odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.DisplayName.StartsWith(options.SearchString)); } result = GraphClient.Groups.List(odataQuery); } else { result = GraphClient.Groups.ListNext(options.NextLink); } groups.AddRange(result.Select(g => g.ToPSADGroup())); options.NextLink = result.NextPageLink; } else { if (options.Mail != null) { odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.Mail == options.Mail); } else { odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.DisplayName.StartsWith(options.SearchString)); } result = GraphClient.Groups.List(odataQuery); groups.AddRange(result.Select(g => g.ToPSADGroup())); while (!string.IsNullOrEmpty(result.NextPageLink)) { result = GraphClient.Groups.ListNext(result.NextPageLink); groups.AddRange(result.Select(g => g.ToPSADGroup())); } } } return(groups); }
public List <PSADServicePrincipal> FilterServicePrincipals(ADObjectFilterOptions options) { List <PSADServicePrincipal> servicePrincipals = new List <PSADServicePrincipal>(); Rest.Azure.IPage <ServicePrincipal> result = null; ServicePrincipal servicePrincipal = null; if (!string.IsNullOrEmpty(options.Id)) { try { servicePrincipal = GraphClient.ServicePrincipals.Get(options.Id); } catch { /* The user does not exist, ignore the exception. */ } if (servicePrincipal != null) { servicePrincipals.Add(servicePrincipal.ToPSADServicePrincipal()); } } else if (!string.IsNullOrEmpty(options.SPN)) { try { servicePrincipal = GraphClient.ServicePrincipals.List(new Rest.Azure.OData.ODataQuery <ServicePrincipal>(s => s.ServicePrincipalNames.Contains(options.SPN))).FirstOrDefault(); } catch { /* The user does not exist, ignore the exception. */ } if (servicePrincipal != null) { servicePrincipals.Add(servicePrincipal.ToPSADServicePrincipal()); } } else { if (options.Paging) { if (string.IsNullOrEmpty(options.NextLink)) { result = GraphClient.ServicePrincipals.List(new Rest.Azure.OData.ODataQuery <ServicePrincipal>(s => s.DisplayName.StartsWith(options.SearchString))); } else { result = GraphClient.ServicePrincipals.ListNext(options.NextLink); } servicePrincipals.AddRange(result.Select(u => u.ToPSADServicePrincipal())); options.NextLink = result.NextPageLink; } else { result = GraphClient.ServicePrincipals.List(new Rest.Azure.OData.ODataQuery <ServicePrincipal>(s => s.DisplayName.StartsWith(options.SearchString))); servicePrincipals.AddRange(result.Select(u => u.ToPSADServicePrincipal())); while (!string.IsNullOrEmpty(result.NextPageLink)) { result = GraphClient.ServicePrincipals.ListNext(result.NextPageLink); servicePrincipals.AddRange(result.Select(u => u.ToPSADServicePrincipal())); } } } return(servicePrincipals); }
public static IEnumerable <DeploymentOperation> Operations(this Rest.Azure.IPage <DeploymentOperation> operations) { return(operations); }
public static string NextLink(this Rest.Azure.IPage <DeploymentOperation> operations) { return(operations.NextPageLink); }
/// <summary> /// Filters role assignments based on the passed options. /// </summary> /// <param name="options">The filtering options</param> /// <param name="currentSubscription">The current subscription</param> /// <returns>The filtered role assignments</returns> public List <PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions options, string currentSubscription) { List <PSRoleAssignment> result = new List <PSRoleAssignment>(); string principalId = null; PSADObject adObject = null; if (options.ADObjectFilter.HasFilter) { if (string.IsNullOrEmpty(options.ADObjectFilter.Id) || options.ExpandPrincipalGroups || options.IncludeClassicAdministrators) { adObject = ActiveDirectoryClient.GetADObject(options.ADObjectFilter); if (adObject == null) { throw new KeyNotFoundException(ProjectResources.PrincipalNotFound); } } // Filter first by principal if (options.ExpandPrincipalGroups) { if (!(adObject is PSADUser)) { throw new InvalidOperationException(ProjectResources.ExpandGroupsNotSupported); } principalId = adObject.Id.ToString(); } else { principalId = string.IsNullOrEmpty(options.ADObjectFilter.Id) ? adObject.Id.ToString() : options.ADObjectFilter.Id; } Rest.Azure.IPage <RoleAssignment> tempResult = null; if (!string.IsNullOrEmpty(options.Scope)) { tempResult = AuthorizationManagementClient.RoleAssignments.ListForScope(options.Scope, new Rest.Azure.OData.ODataQuery <RoleAssignmentFilter>(f => f.PrincipalId == principalId)); result.AddRange(tempResult.FilterRoleAssignmentsOnRoleId(AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromSubscriptionAndIdAsGuid(currentSubscription, options.RoleDefinitionId)) .ToPSRoleAssignments(this, ActiveDirectoryClient, options.Scope, options.ExcludeAssignmentsForDeletedPrincipals)); } else { tempResult = AuthorizationManagementClient.RoleAssignments.List( new Rest.Azure.OData.ODataQuery <RoleAssignmentFilter>(f => f.PrincipalId == principalId)); result.AddRange(tempResult.FilterRoleAssignmentsOnRoleId(AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromSubscriptionAndIdAsGuid(currentSubscription, options.RoleDefinitionId)) .ToPSRoleAssignments(this, ActiveDirectoryClient, AuthorizationHelper.GetSubscriptionScope(currentSubscription), options.ExcludeAssignmentsForDeletedPrincipals)); } while (!string.IsNullOrWhiteSpace(tempResult.NextPageLink)) { tempResult = AuthorizationManagementClient.RoleAssignments.ListNext(tempResult.NextPageLink); result.AddRange(tempResult.FilterRoleAssignmentsOnRoleId(AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromSubscriptionAndIdAsGuid(currentSubscription, options.RoleDefinitionId)) .ToPSRoleAssignments(this, ActiveDirectoryClient, options.Scope, options.ExcludeAssignmentsForDeletedPrincipals)); } // Filter out by scope if (!string.IsNullOrEmpty(options.Scope)) { result.RemoveAll(r => !options.Scope.StartsWith(r.Scope, StringComparison.OrdinalIgnoreCase)); } } else if (!string.IsNullOrEmpty(options.Scope)) { // Filter by scope and above directly var tempResult = AuthorizationManagementClient.RoleAssignments.ListForScope( options.Scope, new Rest.Azure.OData.ODataQuery <RoleAssignmentFilter>( f => f.PrincipalId == principalId)); result.AddRange(tempResult.FilterRoleAssignmentsOnRoleId(AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromSubscriptionAndIdAsGuid(currentSubscription, options.RoleDefinitionId)) .ToPSRoleAssignments(this, ActiveDirectoryClient, options.Scope, options.ExcludeAssignmentsForDeletedPrincipals)); while (!string.IsNullOrWhiteSpace(tempResult.NextPageLink)) { tempResult = AuthorizationManagementClient.RoleAssignments.ListForScopeNext(tempResult.NextPageLink); result.AddRange(tempResult.FilterRoleAssignmentsOnRoleId(AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromSubscriptionAndIdAsGuid(currentSubscription, options.RoleDefinitionId)) .ToPSRoleAssignments(this, ActiveDirectoryClient, options.Scope, options.ExcludeAssignmentsForDeletedPrincipals)); } } else { var tempResult = AuthorizationManagementClient.RoleAssignments.List( new Rest.Azure.OData.ODataQuery <RoleAssignmentFilter>(f => f.PrincipalId == principalId)); result.AddRange(tempResult .FilterRoleAssignmentsOnRoleId(AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromSubscriptionAndIdAsGuid(currentSubscription, options.RoleDefinitionId)) .ToPSRoleAssignments(this, ActiveDirectoryClient, AuthorizationHelper.GetSubscriptionScope(currentSubscription), options.ExcludeAssignmentsForDeletedPrincipals)); while (!string.IsNullOrWhiteSpace(tempResult.NextPageLink)) { tempResult = AuthorizationManagementClient.RoleAssignments.ListNext(tempResult.NextPageLink); result.AddRange(tempResult.FilterRoleAssignmentsOnRoleId(AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromSubscriptionAndIdAsGuid(currentSubscription, options.RoleDefinitionId)) .ToPSRoleAssignments(this, ActiveDirectoryClient, AuthorizationHelper.GetSubscriptionScope(currentSubscription), options.ExcludeAssignmentsForDeletedPrincipals)); } } if (!string.IsNullOrEmpty(options.RoleDefinitionName)) { result = result.Where(r => r.RoleDefinitionName.Equals(options.RoleDefinitionName, StringComparison.OrdinalIgnoreCase)).ToList(); } if (options.IncludeClassicAdministrators) { // Get classic administrator access assignments List <ClassicAdministrator> classicAdministrators = AuthorizationManagementClient.ClassicAdministrators .List().ToList(); List <PSRoleAssignment> classicAdministratorsAssignments = classicAdministrators.Select(a => a.ToPSRoleAssignment(currentSubscription)).ToList(); // Filter by principal if provided if (options.ADObjectFilter.HasFilter) { if (!(adObject is PSADUser)) { throw new InvalidOperationException(ProjectResources.IncludeClassicAdminsNotSupported); } var userObject = adObject as PSADUser; classicAdministratorsAssignments = classicAdministratorsAssignments.Where(c => c.DisplayName.Equals(userObject.UserPrincipalName, StringComparison.OrdinalIgnoreCase)).ToList(); } result.AddRange(classicAdministratorsAssignments); } return(result); }
private List <DeploymentOperation> GetNewOperations(List <DeploymentOperation> old, Rest.Azure.IPage <DeploymentOperation> current) { List <DeploymentOperation> newOperations = new List <DeploymentOperation>(); foreach (DeploymentOperation operation in current) { DeploymentOperation operationWithSameIdAndProvisioningState = old.Find(o => o.OperationId.Equals(operation.OperationId) && o.Properties.ProvisioningState.Equals(operation.Properties.ProvisioningState)); if (operationWithSameIdAndProvisioningState == null) { newOperations.Add(operation); } //If nested deployment, get the operations under those deployments as well. Check if the deployment exists before calling list operations on it if (operation.Properties.TargetResource != null && operation.Properties.TargetResource.ResourceType.Equals("Microsoft.Resources/deployments", StringComparison.OrdinalIgnoreCase) && ResourceManagementClient.Deployments.CheckExistence( resourceGroupName: GetResourceGroupName(operation.Properties.TargetResource.Id), deploymentName: operation.Properties.TargetResource.ResourceName)) { HttpStatusCode statusCode; Enum.TryParse <HttpStatusCode>(operation.Properties.StatusCode, out statusCode); if (!IsClientFailureRequest((int)statusCode)) { List <DeploymentOperation> newNestedOperations = new List <DeploymentOperation>(); Rest.Azure.IPage <DeploymentOperation> result; result = ResourceManagementClient.DeploymentOperations.List( resourceGroupName: GetResourceGroupName(operation.Properties.TargetResource.Id), deploymentName: operation.Properties.TargetResource.ResourceName); newNestedOperations = GetNewOperations(operations, result); foreach (DeploymentOperation op in newNestedOperations) { DeploymentOperation nestedOperationWithSameIdAndProvisioningState = newOperations.Find(o => o.OperationId.Equals(op.OperationId) && o.Properties.ProvisioningState.Equals(op.Properties.ProvisioningState)); if (nestedOperationWithSameIdAndProvisioningState == null) { newOperations.Add(op); } } } } } return(newOperations); }
public List <PSADGroup> FilterGroups(ADObjectFilterOptions options) { List <PSADGroup> groups = new List <PSADGroup>(); ADGroup group = null; if (!string.IsNullOrEmpty(options.Id)) { try { group = GraphClient.Groups.Get(options.Id); } catch { /* The group does not exist, ignore the exception */ } if (group != null) { groups.Add(group.ToPSADGroup()); } } else { Rest.Azure.IPage <ADGroup> result = null; Rest.Azure.OData.ODataQuery <ADGroup> odataQuery = null; if (options.Paging) { if (string.IsNullOrEmpty(options.NextLink)) { if (options.Mail != null) { odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.Mail == options.Mail); } else { odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.DisplayName.StartsWith(options.SearchString)); } result = GraphClient.Groups.List(odataQuery); } else { result = GraphClient.Groups.ListNext(options.NextLink); } groups.AddRange(result.Select(g => g.ToPSADGroup())); options.NextLink = result.NextPageLink; } else { if (options.Mail != null) { odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.Mail == options.Mail); } else { odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.DisplayName.StartsWith(options.SearchString)); } result = GraphClient.Groups.List(odataQuery); groups.AddRange(result.Select(g => g.ToPSADGroup())); while (!string.IsNullOrEmpty(result.NextPageLink)) { result = GraphClient.Groups.ListNext(result.NextPageLink); groups.AddRange(result.Select(g => g.ToPSADGroup())); } } } return(groups); }