private string GetRuleFullName(Uri ruleUri) { // HACK need to factor the URL<->rule_name string ruleName = ruleUri.Segments.LastOrDefault() ?? string.Empty; string ruleFullName = $"{naming.FromFunctionAppUrl(ruleUri).PlainName}/{ruleName}"; return(ruleFullName); }
internal async Task <IEnumerable <MappingOutputData> > ListAsync(InstanceName instance, string projectName) { logger.WriteVerbose($"Searching aggregator mappings in Azure DevOps..."); var serviceHooksClient = devops.GetClient <ServiceHooksPublisherHttpClient>(); var subscriptions = await serviceHooksClient.QuerySubscriptionsAsync(); var filteredSubs = instance != null ? subscriptions.Where(s => s.PublisherId == DevOpsEvents.PublisherId && s.ConsumerInputs.GetValue("url", "").StartsWith( instance.FunctionAppUrl, StringComparison.OrdinalIgnoreCase)) : subscriptions.Where(s => s.PublisherId == DevOpsEvents.PublisherId // HACK && s.ConsumerInputs.GetValue("url", "").IndexOf("aggregator.azurewebsites.net") > 8); var projectClient = devops.GetClient <ProjectHttpClient>(); var projects = await projectClient.GetProjects(); var projectsDict = projects.ToDictionary(p => p.Id); var result = new List <MappingOutputData>(); foreach (var subscription in filteredSubs) { var foundProject = projectsDict[ new Guid(subscription.PublisherInputs["projectId"]) ]; if (!string.IsNullOrEmpty(projectName) && foundProject.Name != projectName) { continue; } // HACK need to factor the URL<->rule_name Uri ruleUrl = new Uri(subscription.ConsumerInputs.GetValue("url", MagicConstants.MissingUrl)); string ruleName = ruleUrl.Segments.LastOrDefault() ?? string.Empty; string ruleFullName = $"{naming.FromFunctionAppUrl(ruleUrl).PlainName}/{ruleName}"; result.Add( new MappingOutputData(instance, ruleFullName, ruleUrl.IsImpersonationEnabled(), foundProject.Name, subscription.EventType, subscription.Status.ToString()) ); } return(result); }