public override IEnumerable <Clue> DoProcess(ExecutionContext context, WebhookDataCommand command) { try { if (ConfigurationManager.AppSettings.GetFlag("Feature.Webhooks.Log.Posts", false)) { context.Log.Debug(() => command.HttpPostData); } var configurationDataStore = context.ApplicationContext.Container.Resolve <IConfigurationRepository>(); if (command.WebhookDefinition.ProviderDefinitionId != null) { var providerDefinition = context.Organization.Providers.GetProviderDefinition(context, command.WebhookDefinition.ProviderDefinitionId.Value); var jobDataCheck = context.ApplicationContext.Container.ResolveAll <IProvider>().FirstOrDefault(providerInstance => providerDefinition != null && providerInstance.Id == providerDefinition.ProviderId); var configStoreData = configurationDataStore.GetConfigurationById(context, command.WebhookDefinition.ProviderDefinitionId.Value); // If you have stopped the provider then don't process the webhooks if (providerDefinition?.WebHooks != null) { if (providerDefinition.WebHooks == false || providerDefinition.IsEnabled == false) { return(new List <Clue>()); } } if (jobDataCheck != null) { var crawlJobData = new OneDriveCrawlJobData(); var clues = new List <Clue>(); IAgentJobProcessorArguments jobArgs = new DebugAgentJobProcessorArguments { TaskScheduler = TaskScheduler.Default, Job = new AgentJob(Guid.NewGuid(), AgentJobPriority.Normal, "CluedIn" + OneDriveConstants.ProviderName, ProcessingRestriction.Any, null, null) }; var processorState = new AgentJobProcessorState <OneDriveCrawlJobData>(jobArgs, AppContext) { JobData = crawlJobData, Status = new AgentJobStatus { Statistics = new AgentJobStatusStatistics() } }; throw new NotImplementedException($"TODO: Implement this to populate '{clues.GetType()}' with '{processorState}'"); } } } catch (Exception exception) { context.Log.Error(new { command.HttpHeaders, command.HttpQueryString, command.HttpPostData, command.WebhookDefinitionId }, () => "Could not process web hook message", exception); } return(new List <Clue>()); }
public override async Task <CrawlJobData> GetCrawlJobData( ProviderUpdateContext context, IDictionary <string, object> configuration, Guid organizationId, Guid userId, Guid providerDefinitionId) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var onedriveCrawlJobData = new OneDriveCrawlJobData(configuration); return(await Task.FromResult(onedriveCrawlJobData)); }
public OneDriveClient(ILogger log, OneDriveCrawlJobData onedriveCrawlJobData, IRestClient client) { this.log = log ?? throw new ArgumentNullException(nameof(log)); this.onedriveCrawlJobData = onedriveCrawlJobData ?? throw new ArgumentNullException(nameof(onedriveCrawlJobData)); var confidentialClientApplication = ConfidentialClientApplicationBuilder .Create(onedriveCrawlJobData.ClientID) .WithAuthority($"https://login.microsoftonline.com/{onedriveCrawlJobData.Tenant}/v2.0") .WithClientSecret(onedriveCrawlJobData.ClientSecret) .Build(); graphClient = new GraphServiceClient(new DelegateAuthenticationProvider(async(requestMessage) => { var authResult = await confidentialClientApplication .AcquireTokenForClient(new string[] { "https://graph.microsoft.com/.default" }) .ExecuteAsync(); requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken); }) ); }