Beispiel #1
0
        internal async Task <bool> RemoveRuleEventAsync(string @event, InstanceName instance, string rule)
        {
            logger.WriteInfo($"Querying the VSTS subscriptions for rule(s) {instance.PlainName}/{rule}");
            var serviceHooksClient = vsts.GetClient <ServiceHooksPublisherHttpClient>();
            var subscriptions      = await serviceHooksClient.QuerySubscriptionsAsync("tfs");

            var ruleSubs = subscriptions
                           // TODO can we trust this?
                           // && s.ActionDescription == $"To host {instance.DnsHostName}"
                           .Where(s => s.ConsumerInputs["url"].ToString().StartsWith(
                                      instance.FunctionAppUrl));

            if (@event != "*")
            {
                ruleSubs = ruleSubs.Where(s => s.EventType == @event);
            }
            if (rule != "*")
            {
                ruleSubs = ruleSubs
                           .Where(s => s.ConsumerInputs["url"].ToString().StartsWith(
                                      AggregatorRules.GetInvocationUrl(instance, rule)));
            }
            foreach (var ruleSub in ruleSubs)
            {
                logger.WriteVerbose($"Deleting subscription {ruleSub.EventDescription}...");
                await serviceHooksClient.DeleteSubscriptionAsync(ruleSub.Id);

                logger.WriteInfo($"Subscription {ruleSub.EventDescription} deleted.");
            }

            return(true);
        }
Beispiel #2
0
        internal async Task <bool> RemoveRuleEventAsync(string @event, InstanceName instance, string projectName, string rule)
        {
            logger.WriteInfo($"Querying the Azure DevOps subscriptions for rule(s) {instance.PlainName}/{rule}");
            var serviceHooksClient = devops.GetClient <ServiceHooksPublisherHttpClient>();
            var subscriptions      = await serviceHooksClient.QuerySubscriptionsAsync(DevOpsEvents.PublisherId);

            var ruleSubs = subscriptions
                           // TODO can we trust this equality?
                           // && s.ActionDescription == $"To host {instance.DnsHostName}"
                           .Where(s => s.ConsumerInputs.GetValue("url", "").StartsWith(
                                      instance.FunctionAppUrl));

            if (@event != "*")
            {
                ruleSubs = ruleSubs.Where(s => string.Equals(s.EventType, @event, StringComparison.OrdinalIgnoreCase));
            }

            if (projectName != "*")
            {
                logger.WriteVerbose($"Reading Azure DevOps project data...");
                var projectClient = devops.GetClient <ProjectHttpClient>();
                var project       = await projectClient.GetProject(projectName);

                logger.WriteInfo($"Project {projectName} data read.");

                ruleSubs = ruleSubs.Where(s => string.Equals(s.PublisherInputs["projectId"], project.Id.ToString(), StringComparison.OrdinalIgnoreCase));
            }

            if (rule != "*")
            {
                var invocationUrl = AggregatorRules.GetInvocationUrl(instance, rule).ToString();
                ruleSubs = ruleSubs.Where(s => s.ConsumerInputs
                                          .GetValue("url", "")
                                          .StartsWith(invocationUrl, StringComparison.OrdinalIgnoreCase));
            }

            foreach (var ruleSub in ruleSubs)
            {
                logger.WriteVerbose($"Deleting subscription {ruleSub.EventDescription} {ruleSub.EventType}...");
                await serviceHooksClient.DeleteSubscriptionAsync(ruleSub.Id);

                logger.WriteInfo($"Subscription {ruleSub.EventDescription} {ruleSub.EventType} deleted.");
            }

            return(true);
        }