Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
stevetemple committed Jul 8, 2024
0 parents commit 8f52ac5
Show file tree
Hide file tree
Showing 15 changed files with 803 additions and 0 deletions.
12 changes: 12 additions & 0 deletions EntraIdSetup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Setting up Microsoft Entra ID to work with the module

In the Azure portal under your Azure Active Directory tenant, select App Registrations

![App Registrations Portal View](https://user-images.githubusercontent.com/113788/228666546-633e434a-4466-4f7c-9a6b-666751aae7bc.png)

Click create a new registration

Give that application a meaningful name


TODO
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Umbraco.Community.FrontDoorCache

A package for sites which are sitting behind Azure Front Door as a CDN

First you, or an Microsoft Entra ID administration will need to create an App Registration in the Azure Portal which will be used to give the site permissions to the Front Door API. Follow [these instructions to setup the new App Registration](EntraIdSetup.md)

To install:

`dotnet add package Umbraco.Community.FrontDoorCache`

To configure add the following section to the root of your appsettings.json file and customise as appropriate
```
"FrontDoor": {
"Cache": {
"Enabled": true,
"Mode": "SelfAndAncestors",
"SubscriptionId": "",
"ResourceGroupName": "",
"FrontDoorName": "",
"EndpointName": "",
"TenantId": "",
"ClientId": "",
"ClientSecret": "",
"Domains": [
"www.sitedomain.com"
]
}
},
```

You'll need to configure these settings based on the values in Azure:

| Setting | Description |
| ----------------- | ----------------------------------------------------- |
| SubscriptionId | The ID of the Azure subscription that the Front Door belongs to |
| ResourceGroupName | The name for the Azure resource group that the Front Door belongs to |
| FrontDoorName | The name of the Front Door to purge |
| EndpointName | The name of the endpoint in Front Door to purge |
| TenantId | The value in Directory (tenant) ID on the app registration Overview |
| ClientId | The value in Application (Client) ID on the app registration Overview |
| ClientSecret | The client secret created for the app registration |
| Domains | The client secret created for the app registration |

You can also customise the configuration by setting these settings:

| Setting | Description |
| ------------------------------------- | -------------------------------------------------------------------------------------------- |
| Enabled | |
| Mode | |







199 changes: 199 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
.vs/

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf


#LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml

# =========================
# Windows detritus
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac desktop service store files
.DS_Store

# =========================
# Rider
# =========================
.idea/

# =========================
# Umbraco
# =========================
media/
Cached/
*.Publish.xml
umbraco.config
UmbracoTraceLog*
App_Data/
imageCache/
TEMP/
uSync.Archive/
Umbraco/
Umbraco_client/

# Packages
packages/

# Crystal reports
aspnet_client/

# =========================
# Front end
# =========================

node_modules/

applicationhost.config

#TortoiseGit Merge
*.orig

# ============================
# Web test
# ============================
*.webtestresult
25 changes: 25 additions & 0 deletions src/Umbraco.Community.FrontDoorCache.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Umbraco.Community.FrontDoorCache", "Umbraco.Community.FrontDoorCache\Umbraco.Community.FrontDoorCache.csproj", "{B3C79565-F838-4D8A-B6D1-8C95B042023B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B3C79565-F838-4D8A-B6D1-8C95B042023B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3C79565-F838-4D8A-B6D1-8C95B042023B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3C79565-F838-4D8A-B6D1-8C95B042023B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3C79565-F838-4D8A-B6D1-8C95B042023B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {78B11130-C8D8-48E5-BD36-448321AE7F37}
EndGlobalSection
EndGlobal
58 changes: 58 additions & 0 deletions src/Umbraco.Community.FrontDoorCache/Api/FrontDoorApiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Azure;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Cdn;
using Azure.ResourceManager.Cdn.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Umbraco.Community.FrontDoorCache.Api
{
public class FrontDoorApiClient : IFrontDoorApiClient
{
private ILogger<FrontDoorApiClient> _logger;
private FrontDoorCacheOptions _options;

public FrontDoorApiClient(IOptions<FrontDoorCacheOptions> options, ILogger<FrontDoorApiClient> logger)
{
_options = options.Value;
_logger = logger;
}

public async Task<bool> CheckStatus()
{
var credential = new ClientSecretCredential(_options.TenantId, _options.ClientId, _options.ClientSecret);
var client = new ArmClient(credential);

var frontDoorResourceIdentifier = FrontDoorEndpointResource.CreateResourceIdentifier(_options.SubscriptionId,
_options.ResourceGroupName, _options.FrontDoorName, _options.EndpointName);
var endpoint = client.GetFrontDoorEndpointResource(frontDoorResourceIdentifier);

var fd = await endpoint.GetAsync();
return fd.HasValue;
}

public async Task<bool> SendPurgeRequest(FrontDoorPurgeContent content)
{
var credential = new ClientSecretCredential(_options.TenantId, _options.ClientId, _options.ClientSecret);
var client = new ArmClient(credential);

var frontDoorResourceIdentifier = FrontDoorEndpointResource.CreateResourceIdentifier(_options.SubscriptionId,
_options.ResourceGroupName, _options.FrontDoorName, _options.EndpointName);
var endpoint = client.GetFrontDoorEndpointResource(frontDoorResourceIdentifier);

foreach (var domain in _options.Domains)
{
content.Domains.Add(domain);
}

await endpoint.PurgeContentAsync(WaitUntil.Started, content);
return true;
}

public async Task<bool> SendPurgeAllRequest()
{
return await SendPurgeRequest(new FrontDoorPurgeContent(new[] {"*"}));
}
}
}
11 changes: 11 additions & 0 deletions src/Umbraco.Community.FrontDoorCache/Api/IFrontDoorApiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Azure.ResourceManager.Cdn.Models;

namespace Umbraco.Community.FrontDoorCache.Api
{
public interface IFrontDoorApiClient
{
Task<bool> CheckStatus();
Task<bool> SendPurgeRequest(FrontDoorPurgeContent content);
Task<bool> SendPurgeAllRequest();
}
}
13 changes: 13 additions & 0 deletions src/Umbraco.Community.FrontDoorCache/Composer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;

namespace Umbraco.Community.FrontDoorCache
{
public class FrontDoorCacheComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AddFrontDoorCache();
}
}
}
Loading

0 comments on commit 8f52ac5

Please sign in to comment.