Exemplo n.º 1
0
        public async Task Run(
            [TimerTrigger(
                 "0 0 */6 * * *",
                 UseMonitor = false
                 )] TimerInfo timer
            )
        {
            try
            {
                foreach (var region in coreContext.Regions)
                {
                    coreContext.SetRegion(region);

                    var containers = await storageRepository.ListContainers();

                    foreach (var container in containers)
                    {
                        if (DateTime.UtcNow >= container.DeleteWhen)
                        {
                            await transfersService.SuspendTransfer(new GetTransferParameters
                            {
                                TransferToken = container.TransferToken
                            });

                            await container.Delete();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(
                 AuthorizationLevel.Anonymous,
                 "put", "get", "delete",
                 Route = Routes.TransferFileProxy
                 )] HttpRequest request,
            string region,
            string storagePath
            )
        {
            try
            {
                coreContext.SetRegion(region);

                var requestMessage = GetRequestMessage(request, storagePath);

                var responseMessage = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead);

                return(new ProxyResult(responseMessage));
            }
            catch (ProxyException ex)
            {
                return(LogBadRequest(ex));
            }
            catch (Exception ex)
            {
                return(LogException(ex));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Run(
            [HttpTrigger(
                 "post",
                 Route = Routes.ListTransfers
                 )] HttpRequest request,
            IDictionary <string, string> headers,
            string specificRegion
            )
        {
            try
            {
                AccessTokenResult = await accessTokenValidator.ValidateToken(headers);

                switch (AccessTokenResult)
                {
                case ValidAccessTokenResult _:
                    var regions = !string.IsNullOrWhiteSpace(specificRegion)
                            ? new[] { specificRegion }
                            : coreContext.Regions;

                    List <Transfer> transfers = new List <Transfer>();

                    if (regions == default)
                    {
                        throw new ArgumentNullException(nameof(regions));
                    }

                    foreach (var region in regions)
                    {
                        coreContext.SetRegion(region);

                        transfers.AddRange(await transfersService.ListTransfers());
                    }

                    return(LogOkObject(transfers));

                default:
                    return(LogUnauthorized());
                }
            }
            catch (Exception ex)
            {
                return(LogException(ex));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Run(
            [HttpTrigger(
                 "post",
                 Route = Routes.CreateTransfer
                 )] CreateTransferRequest createTransferRequest,
            IDictionary <string, string> headers,
            string region
            )
        {
            try
            {
                coreContext.SetRegion(region);

                AccessTokenResult = await accessTokenValidator.ValidateToken(headers);

                switch (AccessTokenResult)
                {
                case ValidAccessTokenResult _:
                    var(name, customer, template, localization) = createTransferRequest;

                    if (localization != null)
                    {
                        coreContext.Localization = localization;
                    }

                    var transfer = await transfersService.CreateTransfer(new CreateTransferParameters
                    {
                        Name                 = name,
                        Customer             = customer,
                        TemplateItemCodename = template
                    });

                    return(LogOkObject(transfer));

                default:
                    return(LogUnauthorized());
                }
            }
            catch (Exception ex)
            {
                return(LogException(ex));
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Run(
            [HttpTrigger(
                 "post",
                 Route = Routes.KontentWebhook
                 )] string body,
            IDictionary <string, string> headers,
            string region
            )
        {
            try
            {
                coreContext.SetRegion(region);

                var(valid, getWebhook) = webhookValidator.ValidateWebhook(body, headers, region);

                if (!valid)
                {
                    return(LogUnauthorized());
                }

                var(data, message) = getWebhook();

                var(items, _) = data;

                switch (message.Type)
                {
                case "content_item_variant":
                    switch (message.Operation)
                    {
                    case "publish":
                        foreach (var item in items)
                        {
                            if (item.Type == TransferItem.Codename)
                            {
                                var container = await storageRepository.GetContainer(new GetContainerParameters
                                {
                                    ContainerName = storageRepository.GetSafeContainerName(item.Codename)
                                });

                                if (string.IsNullOrEmpty(container.TransferToken))
                                {
                                    container.TransferToken = storageRepository.EncryptTransferToken(new TransferToken
                                    {
                                        Codename     = item.Codename,
                                        Localization = item.Language,
                                        Region       = coreContext.Region.Name
                                    });
                                }

                                container.DeleteWhen = DateTime.MaxValue;

                                await container.Update();
                            }
                        }
                        break;

                    case "unpublish":
                        foreach (var item in items)
                        {
                            if (item.Type == TransferItem.Codename)
                            {
                                var container = await storageRepository.GetContainer(new GetContainerParameters
                                {
                                    ContainerName = storageRepository.GetSafeContainerName(item.Codename)
                                });

                                container.DeleteWhen = DateTime.UtcNow.AddMonths(1);

                                await container.Update();
                            }
                        }
                        break;

                    case "archive":
                        foreach (var item in items)
                        {
                            if (item.Type == TransferItem.Codename)
                            {
                                var container = await storageRepository.GetContainer(new GetContainerParameters
                                {
                                    ContainerName = storageRepository.GetSafeContainerName(item.Codename)
                                });

                                await container.Delete();
                            }
                        }
                        break;
                    }
                    break;
                }

                return(LogOk());
            }
            catch (Exception ex)
            {
                return(LogException(ex));
            }
        }