示例#1
0
        public override void ExecuteCmdlet()
        {
            Dictionary <string, string> tagDictionary = TagsConversionHelper.CreateTagDictionary(this.Tag, true);
            string resourceGroupName = string.Empty;
            string topicName         = string.Empty;

            if (!string.IsNullOrEmpty(this.ResourceId))
            {
                EventGridUtils.GetResourceGroupNameAndTopicName(this.ResourceId, out resourceGroupName, out topicName);
            }
            else if (!string.IsNullOrEmpty(this.Name))
            {
                resourceGroupName = this.ResourceGroupName;
                topicName         = this.Name;
            }
            else if (this.InputObject != null)
            {
                resourceGroupName = this.InputObject.ResourceGroupName;
                topicName         = this.InputObject.TopicName;
            }

            if (this.ShouldProcess(topicName, $"Set topic {topicName} in Resource Group {resourceGroupName}"))
            {
                Topic existingTopic = this.Client.GetTopic(resourceGroupName, topicName);
                if (existingTopic == null)
                {
                    throw new Exception($"Cannot find an existing topic {topicName} in resource group {resourceGroupName}");
                }

                Topic   topic   = this.Client.ReplaceTopic(resourceGroupName, topicName, existingTopic.Location, tagDictionary);
                PSTopic psTopic = new PSTopic(topic);
                this.WriteObject(psTopic);
            }
        }
示例#2
0
        public override void ExecuteCmdlet()
        {
            // Create a new Event Grid Topic
            Dictionary <string, string> tagDictionary = TagsConversionHelper.CreateTagDictionary(this.Tag, true);
            Dictionary <string, string> inputMappingFieldsDictionary        = TagsConversionHelper.CreateTagDictionary(this.InputMappingField, true);
            Dictionary <string, string> inputMappingDefaultValuesDictionary = TagsConversionHelper.CreateTagDictionary(this.InputMappingDefaultValue, true);
            Dictionary <string, string> inboundIpRuleDictionary             = TagsConversionHelper.CreateTagDictionary(this.InboundIpRule, true);

            EventGridUtils.ValidateInputMappingInfo(this.InputSchema, inputMappingFieldsDictionary, inputMappingDefaultValuesDictionary);

            if (this.ShouldProcess(this.Name, $"Create a new EventGrid topic {this.Name} in Resource Group {this.ResourceGroupName}"))
            {
                Topic topic = this.Client.CreateTopic(
                    this.ResourceGroupName,
                    this.Name,
                    this.Location,
                    tagDictionary,
                    InputSchema,
                    inputMappingFieldsDictionary,
                    inputMappingDefaultValuesDictionary,
                    inboundIpRuleDictionary,
                    this.PublicNetworkAccess);

                PSTopic psTopic = new PSTopic(topic);
                this.WriteObject(psTopic);
            }
        }
示例#3
0
        public override void ExecuteCmdlet()
        {
            Dictionary <string, string> tagDictionary           = TagsConversionHelper.CreateTagDictionary(this.Tag, true);
            Dictionary <string, string> inboundIpRuleDictionary = TagsConversionHelper.CreateTagDictionary(this.InboundIpRule, true);
            string resourceGroupName = string.Empty;
            string topicName         = string.Empty;

            Dictionary <string, UserIdentityProperties> userAssignedIdentities = null;

            if (IdentityId != null && IdentityId.Length > 0)
            {
                userAssignedIdentities = new Dictionary <string, UserIdentityProperties>();
                foreach (string identityId in IdentityId)
                {
                    userAssignedIdentities.Add(identityId, new UserIdentityProperties());
                }
            }

            if (!string.IsNullOrEmpty(this.ResourceId))
            {
                EventGridUtils.GetResourceGroupNameAndTopicName(this.ResourceId, out resourceGroupName, out topicName);
            }
            else if (!string.IsNullOrEmpty(this.Name))
            {
                resourceGroupName = this.ResourceGroupName;
                topicName         = this.Name;
            }
            else if (this.InputObject != null)
            {
                resourceGroupName = this.InputObject.ResourceGroupName;
                topicName         = this.InputObject.TopicName;
            }

            if (this.ShouldProcess(topicName, $"Set topic {topicName} in Resource Group {resourceGroupName}"))
            {
                Topic existingTopic = this.Client.GetTopic(resourceGroupName, topicName);
                if (existingTopic == null)
                {
                    throw new Exception($"Cannot find an existing topic {topicName} in resource group {resourceGroupName}");
                }

                Topic topic = this.Client.ReplaceTopic(
                    resourceGroupName,
                    topicName,
                    existingTopic.Location,
                    tagDictionary,
                    inboundIpRuleDictionary,
                    this.PublicNetworkAccess,
                    this.IdentityType,
                    userAssignedIdentities);

                PSTopic psTopic = new PSTopic(topic);
                this.WriteObject(psTopic);
            }
        }
示例#4
0
        public override void ExecuteCmdlet()
        {
            string resourceGroupName = string.Empty;
            string topicName         = string.Empty;

            if (!string.IsNullOrEmpty(this.ResourceId))
            {
                EventGridUtils.GetResourceGroupNameAndTopicName(this.ResourceId, out resourceGroupName, out topicName);
            }
            else if (!string.IsNullOrEmpty(this.Name))
            {
                // If Name is provided, ResourceGroup should be non-empty as well
                resourceGroupName = this.ResourceGroupName;
                topicName         = this.Name;
            }
            else if (!string.IsNullOrEmpty(this.ResourceGroupName))
            {
                resourceGroupName = this.ResourceGroupName;
            }

            if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(topicName))
            {
                // Get details of the Event Grid topic
                Topic   topic   = this.Client.GetTopic(resourceGroupName, topicName);
                PSTopic psTopic = new PSTopic(topic);
                this.WriteObject(psTopic);
            }
            else if (!string.IsNullOrEmpty(resourceGroupName) && string.IsNullOrEmpty(topicName))
            {
                // List all Event Grid topics in the given resource group
                IEnumerable <Topic> topicsList = this.Client.ListTopicsByResourceGroup(resourceGroupName);

                List <PSTopicListInstance> psTopicsList = new List <PSTopicListInstance>();
                foreach (Topic topic in topicsList)
                {
                    psTopicsList.Add(new PSTopicListInstance(topic));
                }

                this.WriteObject(psTopicsList, true);
            }
            else
            {
                // List all Event Grid topics in the given subscription
                IEnumerable <Topic> topicsList = this.Client.ListTopicsBySubscription();

                List <PSTopicListInstance> psTopicsList = new List <PSTopicListInstance>();
                foreach (Topic topic in topicsList)
                {
                    psTopicsList.Add(new PSTopicListInstance(topic));
                }

                this.WriteObject(psTopicsList, true);
            }
        }
        public override void ExecuteCmdlet()
        {
            // Create a new Event Grid Topic
            Dictionary <string, string> tagDictionary = TagsConversionHelper.CreateTagDictionary(this.Tag, true);

            if (this.ShouldProcess(this.Name, $"Create a new EventGrid topic {this.Name} in Resource Group {this.ResourceGroupName}"))
            {
                Topic   topic   = this.Client.CreateTopic(this.ResourceGroupName, this.Name, this.Location, tagDictionary);
                PSTopic psTopic = new PSTopic(topic);
                this.WriteObject(psTopic);
            }
        }
        public override void ExecuteCmdlet()
        {
            // Create a new Event Grid Topic
            Dictionary <string, string> tagDictionary = TagsConversionHelper.CreateTagDictionary(this.Tag, true);
            Dictionary <string, string> inputMappingFieldsDictionary           = TagsConversionHelper.CreateTagDictionary(this.InputMappingField, true);
            Dictionary <string, string> inputMappingDefaultValuesDictionary    = TagsConversionHelper.CreateTagDictionary(this.InputMappingDefaultValue, true);
            Dictionary <string, string> inboundIpRuleDictionary                = TagsConversionHelper.CreateTagDictionary(this.InboundIpRule, true);
            Dictionary <string, UserIdentityProperties> userAssignedIdentities = null;

            if (IdentityId != null && IdentityId.Length > 0)
            {
                userAssignedIdentities = new Dictionary <string, UserIdentityProperties>();
                foreach (string identityId in IdentityId)
                {
                    userAssignedIdentities.Add(identityId, new UserIdentityProperties());
                }
            }


            EventGridUtils.ValidateInputMappingInfo(this.InputSchema, inputMappingFieldsDictionary, inputMappingDefaultValuesDictionary);

            if (this.ShouldProcess(this.Name, $"Create a new EventGrid topic {this.Name} in Resource Group {this.ResourceGroupName}"))
            {
                Topic topic = this.Client.CreateTopic(
                    this.ResourceGroupName,
                    this.Name,
                    this.Location,
                    tagDictionary,
                    InputSchema,
                    inputMappingFieldsDictionary,
                    inputMappingDefaultValuesDictionary,
                    inboundIpRuleDictionary,
                    this.PublicNetworkAccess,
                    this.IdentityType,
                    userAssignedIdentities);

                PSTopic psTopic = new PSTopic(topic);
                this.WriteObject(psTopic);
            }
        }
        public override void ExecuteCmdlet()
        {
            string resourceGroupName = string.Empty;
            string topicName         = string.Empty;
            IEnumerable <Topic> topicsList;
            string nextLink    = null;
            string newNextLink = null;
            int?   providedTop = null;

            if (MyInvocation.BoundParameters.ContainsKey(nameof(this.Top)))
            {
                providedTop = this.Top;
            }

            if (!string.IsNullOrEmpty(this.ResourceId))
            {
                EventGridUtils.GetResourceGroupNameAndTopicName(this.ResourceId, out resourceGroupName, out topicName);
            }
            else if (!string.IsNullOrEmpty(this.Name))
            {
                // If Name is provided, ResourceGroup should be non-empty as well
                resourceGroupName = this.ResourceGroupName;
                topicName         = this.Name;
            }
            else if (!string.IsNullOrEmpty(this.ResourceGroupName))
            {
                resourceGroupName = this.ResourceGroupName;
            }
            else if (!string.IsNullOrEmpty(this.NextLink))
            {
                // Other parameters should be null or ignored if nextLink is specified.
                nextLink = this.NextLink;
            }

            if (!string.IsNullOrEmpty(nextLink))
            {
                // Get Next page of topics. Get the proper next API to be called based on the nextLink.
                Uri    uri  = new Uri(nextLink);
                string path = uri.AbsolutePath;

                if (path.IndexOf("/resourceGroups/", StringComparison.OrdinalIgnoreCase) != -1)
                {
                    (topicsList, newNextLink) = this.Client.ListTopicsByResourceGroupNext(nextLink);
                }
                else
                {
                    (topicsList, newNextLink) = this.Client.ListTopicBySubscriptionNext(nextLink);
                }

                PSTopicListPagedInstance pSTopicListPagedInstance = new PSTopicListPagedInstance(topicsList, newNextLink);
                this.WriteObject(pSTopicListPagedInstance, true);
            }
            else if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(topicName))
            {
                // Get details of the Event Grid topic
                Topic   topic   = this.Client.GetTopic(resourceGroupName, topicName);
                PSTopic psTopic = new PSTopic(topic);
                this.WriteObject(psTopic);
            }
            else if (!string.IsNullOrEmpty(resourceGroupName) && string.IsNullOrEmpty(topicName))
            {
                // List all Event Grid topics in the given resource group
                (topicsList, newNextLink) = this.Client.ListTopicsByResourceGroup(resourceGroupName, this.ODataQuery, providedTop);
                PSTopicListPagedInstance pSTopicListPagedInstance = new PSTopicListPagedInstance(topicsList, newNextLink);
                this.WriteObject(pSTopicListPagedInstance, true);
            }
            else if (string.IsNullOrEmpty(resourceGroupName) && string.IsNullOrEmpty(topicName))
            {
                // List all Event Grid topics in the given subscription
                (topicsList, newNextLink) = this.Client.ListTopicsBySubscription(this.ODataQuery, providedTop);
                PSTopicListPagedInstance pSTopicListPagedInstance = new PSTopicListPagedInstance(topicsList, newNextLink);
                this.WriteObject(pSTopicListPagedInstance, true);
            }
        }