Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public IEnumerable <NamespaceAttributes> ListAllNamespaces()
        {
            Rest.Azure.IPage <NamespaceResource> response = Client.Namespaces.ListBySubscription();
            var resourceList = response.Select(resource => new NamespaceAttributes(resource));

            return(resourceList);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        public IEnumerable <PSNamespaceAttributes> ListAllNamespaces()
        {
            Rest.Azure.IPage <SBNamespace> response = Client.Namespaces.List();
            var resourceList = response.Select(resource => new PSNamespaceAttributes(resource));

            return(resourceList);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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 <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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }