Exemplo n.º 1
0
        public async Task Run([QueueTrigger("subscription-validation", Connection = "QueueStorage")] string item, ILogger log)
        {
            Subscription       subscription       = JsonSerializer.Deserialize <Subscription>(item);
            CloudEventEnvelope cloudEventEnvelope = CreateValidateEvent(subscription);
            await _webhookService.Send(cloudEventEnvelope);

            await _validateSubscriptionService.ValidateSubscription(cloudEventEnvelope.SubscriptionId);
        }
Exemplo n.º 2
0
 private async Task AuthorizeAndPush(CloudEvent cloudEvent, Subscription subscription)
 {
     if (await _authorizationHelper.AuthorizeConsumerForAltinnAppEvent(cloudEvent, subscription.Consumer))
     {
         CloudEventEnvelope cloudEventEnvelope = MapToEnvelope(cloudEvent, subscription);
         await _eventsService.PushToConsumer(cloudEventEnvelope);
     }
 }
Exemplo n.º 3
0
 public override async Task <Empty> OnTopicEvent(CloudEventEnvelope request, ServerCallContext context)
 {
     if (request.Topic.Equals("Storage.Reduce"))
     {
         StorageReduceData storageReduceData = StorageReduceData.Parser.ParseJson(request.Data.Value.ToStringUtf8());
         Console.WriteLine("ProductID:" + storageReduceData.ProductID);
         Console.WriteLine("Amount:" + storageReduceData.Amount);
         await HandlerStorageReduce(storageReduceData);
     }
     return(new Empty());
 }
Exemplo n.º 4
0
        private CloudEventEnvelope CreateValidateEvent(Subscription subscription)
        {
            CloudEventEnvelope cloudEventEnvelope = new CloudEventEnvelope();

            cloudEventEnvelope.Consumer          = subscription.Consumer;
            cloudEventEnvelope.Endpoint          = subscription.EndPoint;
            cloudEventEnvelope.SubscriptionId    = subscription.Id;
            cloudEventEnvelope.CloudEvent        = new CloudEvent();
            cloudEventEnvelope.CloudEvent.Source = new Uri(_platformSettings.ApiEventsEndpoint + "subscriptions/" + subscription.Id);
            cloudEventEnvelope.CloudEvent.Type   = "platform.events.validatesubscription";
            return(cloudEventEnvelope);
        }
Exemplo n.º 5
0
        /// <inheritdoc/>
        public async Task PushToConsumer(CloudEventEnvelope cloudEventEnvelope)
        {
            PushQueueReceipt receipt = await _queue.PushToOutboundQueue(JsonSerializer.Serialize(cloudEventEnvelope));

            string cloudEventId   = cloudEventEnvelope.CloudEvent.Id;
            int    subscriptionId = cloudEventEnvelope.SubscriptionId;

            if (!receipt.Success)
            {
                _logger.LogError("// EventsService // StoreCloudEvent // Failed to push event envelope {EventId} to queue. Exception {Exception}", cloudEventId, subscriptionId, receipt.Exception);
            }
        }
Exemplo n.º 6
0
        private CloudEventEnvelope MapToEnvelope(CloudEvent cloudEvent, Subscription subscription)
        {
            CloudEventEnvelope cloudEventEnvelope = new CloudEventEnvelope()
            {
                CloudEvent     = cloudEvent,
                Consumer       = subscription.Consumer,
                Pushed         = DateTime.Now,
                SubscriptionId = subscription.Id,
                Endpoint       = subscription.EndPoint
            };

            return(cloudEventEnvelope);
        }
Exemplo n.º 7
0
        public Task <PushQueueReceipt> PushToOutboundQueue(string content)
        {
            CloudEventEnvelope cloudEventEnvelope = JsonSerializer.Deserialize <CloudEventEnvelope>(content);

            if (!OutboundQueue.ContainsKey(cloudEventEnvelope.CloudEvent.Id))
            {
                OutboundQueue.Add(cloudEventEnvelope.CloudEvent.Id, new List <CloudEventEnvelope>());
            }

            OutboundQueue[cloudEventEnvelope.CloudEvent.Id].Add(cloudEventEnvelope);

            return(Task.FromResult(new PushQueueReceipt {
                Success = true
            }));
        }
Exemplo n.º 8
0
 private string GetPayload(CloudEventEnvelope envelope)
 {
     if (envelope.Endpoint.OriginalString.Contains(_slackUri))
     {
         SlackEnvelope slackEnvelope = new SlackEnvelope
         {
             CloudEvent = envelope.CloudEvent.Serialize()
         };
         return(slackEnvelope.Serialize());
     }
     else
     {
         return(envelope.CloudEvent.Serialize());
     }
 }
Exemplo n.º 9
0
        /// <inheritdoc/>
        public async Task Send(CloudEventEnvelope envelope)
        {
            string        payload     = GetPayload(envelope);
            StringContent httpContent = new StringContent(payload, Encoding.UTF8, "application/json");

            try
            {
                HttpResponseMessage response = await _client.PostAsync(envelope.Endpoint, httpContent);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    string reason = await response.Content.ReadAsStringAsync();

                    _logger.LogError($"// WebhookService // Send // Failed to send cloudevent, subscriptionId: {envelope.SubscriptionId}. Response {response}. \n Reason {reason}.");

                    throw new Exception(reason);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"// Send to webhook with subscriptionId: {envelope.SubscriptionId} failed with errormessage {e.Message}");
                throw e;
            }
        }
Exemplo n.º 10
0
 public override Task <Empty> OnTopicEvent(CloudEventEnvelope request, Grpc.Core.ServerCallContext context)
 {
     return(Task.FromResult(new Empty()));
 }
Exemplo n.º 11
0
 public async Task Run([QueueTrigger("events-outbound", Connection = "QueueStorage")] string item, ILogger log)
 {
     CloudEventEnvelope cloudEventEnvelope = JsonSerializer.Deserialize <CloudEventEnvelope>(item);
     await _webhookService.Send(cloudEventEnvelope);
 }
Exemplo n.º 12
0
 public Task PushToConsumer(CloudEventEnvelope cloudEventEnvelope)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
 public override async Task <Empty> OnTopicEvent(CloudEventEnvelope request, ServerCallContext context)
 {
     return(new Empty());
 }