Skip to content

Commit 8f52ac5

Browse files
committed
Initial version
0 parents  commit 8f52ac5

15 files changed

+803
-0
lines changed

EntraIdSetup.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Setting up Microsoft Entra ID to work with the module
2+
3+
In the Azure portal under your Azure Active Directory tenant, select App Registrations
4+
5+
![App Registrations Portal View](https://user-images.githubusercontent.com/113788/228666546-633e434a-4466-4f7c-9a6b-666751aae7bc.png)
6+
7+
Click create a new registration
8+
9+
Give that application a meaningful name
10+
11+
12+
TODO

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Umbraco.Community.FrontDoorCache
2+
3+
A package for sites which are sitting behind Azure Front Door as a CDN
4+
5+
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)
6+
7+
To install:
8+
9+
`dotnet add package Umbraco.Community.FrontDoorCache`
10+
11+
To configure add the following section to the root of your appsettings.json file and customise as appropriate
12+
```
13+
"FrontDoor": {
14+
"Cache": {
15+
"Enabled": true,
16+
"Mode": "SelfAndAncestors",
17+
"SubscriptionId": "",
18+
"ResourceGroupName": "",
19+
"FrontDoorName": "",
20+
"EndpointName": "",
21+
"TenantId": "",
22+
"ClientId": "",
23+
"ClientSecret": "",
24+
"Domains": [
25+
"www.sitedomain.com"
26+
]
27+
}
28+
},
29+
```
30+
31+
You'll need to configure these settings based on the values in Azure:
32+
33+
| Setting | Description |
34+
| ----------------- | ----------------------------------------------------- |
35+
| SubscriptionId | The ID of the Azure subscription that the Front Door belongs to |
36+
| ResourceGroupName | The name for the Azure resource group that the Front Door belongs to |
37+
| FrontDoorName | The name of the Front Door to purge |
38+
| EndpointName | The name of the endpoint in Front Door to purge |
39+
| TenantId | The value in Directory (tenant) ID on the app registration Overview |
40+
| ClientId | The value in Application (Client) ID on the app registration Overview |
41+
| ClientSecret | The client secret created for the app registration |
42+
| Domains | The client secret created for the app registration |
43+
44+
You can also customise the configuration by setting these settings:
45+
46+
| Setting | Description |
47+
| ------------------------------------- | -------------------------------------------------------------------------------------------- |
48+
| Enabled | |
49+
| Mode | |
50+
51+
52+
53+
54+
55+
56+

src/.gitignore

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
9+
# Build results
10+
11+
[Dd]ebug/
12+
[Rr]elease/
13+
x64/
14+
build/
15+
[Bb]in/
16+
[Oo]bj/
17+
18+
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
19+
!packages/*/build/
20+
21+
# MSTest test Results
22+
[Tt]est[Rr]esult*/
23+
[Bb]uild[Ll]og.*
24+
25+
*_i.c
26+
*_p.c
27+
*.ilk
28+
*.meta
29+
*.obj
30+
*.pch
31+
*.pdb
32+
*.pgc
33+
*.pgd
34+
*.rsp
35+
*.sbr
36+
*.tlb
37+
*.tli
38+
*.tlh
39+
*.tmp
40+
*.tmp_proj
41+
*.log
42+
*.vspscc
43+
*.vssscc
44+
.builds
45+
*.pidb
46+
*.log
47+
*.scc
48+
.vs/
49+
50+
# Visual C++ cache files
51+
ipch/
52+
*.aps
53+
*.ncb
54+
*.opensdf
55+
*.sdf
56+
*.cachefile
57+
58+
# Visual Studio profiler
59+
*.psess
60+
*.vsp
61+
*.vspx
62+
63+
# Guidance Automation Toolkit
64+
*.gpState
65+
66+
# ReSharper is a .NET coding add-in
67+
_ReSharper*/
68+
*.[Rr]e[Ss]harper
69+
70+
# TeamCity is a build add-in
71+
_TeamCity*
72+
73+
# DotCover is a Code Coverage Tool
74+
*.dotCover
75+
76+
# NCrunch
77+
*.ncrunch*
78+
.*crunch*.local.xml
79+
80+
# Installshield output folder
81+
[Ee]xpress/
82+
83+
# DocProject is a documentation generator add-in
84+
DocProject/buildhelp/
85+
DocProject/Help/*.HxT
86+
DocProject/Help/*.HxC
87+
DocProject/Help/*.hhc
88+
DocProject/Help/*.hhk
89+
DocProject/Help/*.hhp
90+
DocProject/Help/Html2
91+
DocProject/Help/html
92+
93+
# Click-Once directory
94+
publish/
95+
96+
# Publish Web Output
97+
*.Publish.xml
98+
99+
# NuGet Packages Directory
100+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
101+
#packages/
102+
103+
# Windows Azure Build Output
104+
csx
105+
*.build.csdef
106+
107+
# Windows Store app package directory
108+
AppPackages/
109+
110+
# Others
111+
sql/
112+
*.Cache
113+
ClientBin/
114+
[Ss]tyle[Cc]op.*
115+
~$*
116+
*~
117+
*.dbmdl
118+
*.[Pp]ublish.xml
119+
*.pfx
120+
*.publishsettings
121+
122+
# RIA/Silverlight projects
123+
Generated_Code/
124+
125+
# Backup & report files from converting an old project file to a newer
126+
# Visual Studio version. Backup files are not needed, because we have git ;-)
127+
_UpgradeReport_Files/
128+
Backup*/
129+
UpgradeLog*.XML
130+
UpgradeLog*.htm
131+
132+
# SQL Server files
133+
App_Data/*.mdf
134+
App_Data/*.ldf
135+
136+
137+
#LightSwitch generated files
138+
GeneratedArtifacts/
139+
_Pvt_Extensions/
140+
ModelManifest.xml
141+
142+
# =========================
143+
# Windows detritus
144+
# =========================
145+
146+
# Windows image file caches
147+
Thumbs.db
148+
ehthumbs.db
149+
150+
# Folder config file
151+
Desktop.ini
152+
153+
# Recycle Bin used on file shares
154+
$RECYCLE.BIN/
155+
156+
# Mac desktop service store files
157+
.DS_Store
158+
159+
# =========================
160+
# Rider
161+
# =========================
162+
.idea/
163+
164+
# =========================
165+
# Umbraco
166+
# =========================
167+
media/
168+
Cached/
169+
*.Publish.xml
170+
umbraco.config
171+
UmbracoTraceLog*
172+
App_Data/
173+
imageCache/
174+
TEMP/
175+
uSync.Archive/
176+
Umbraco/
177+
Umbraco_client/
178+
179+
# Packages
180+
packages/
181+
182+
# Crystal reports
183+
aspnet_client/
184+
185+
# =========================
186+
# Front end
187+
# =========================
188+
189+
node_modules/
190+
191+
applicationhost.config
192+
193+
#TortoiseGit Merge
194+
*.orig
195+
196+
# ============================
197+
# Web test
198+
# ============================
199+
*.webtestresult
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34607.119
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Umbraco.Community.FrontDoorCache", "Umbraco.Community.FrontDoorCache\Umbraco.Community.FrontDoorCache.csproj", "{B3C79565-F838-4D8A-B6D1-8C95B042023B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B3C79565-F838-4D8A-B6D1-8C95B042023B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B3C79565-F838-4D8A-B6D1-8C95B042023B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B3C79565-F838-4D8A-B6D1-8C95B042023B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B3C79565-F838-4D8A-B6D1-8C95B042023B}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {78B11130-C8D8-48E5-BD36-448321AE7F37}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Azure;
2+
using Azure.Identity;
3+
using Azure.ResourceManager;
4+
using Azure.ResourceManager.Cdn;
5+
using Azure.ResourceManager.Cdn.Models;
6+
using Microsoft.Extensions.Logging;
7+
using Microsoft.Extensions.Options;
8+
9+
namespace Umbraco.Community.FrontDoorCache.Api
10+
{
11+
public class FrontDoorApiClient : IFrontDoorApiClient
12+
{
13+
private ILogger<FrontDoorApiClient> _logger;
14+
private FrontDoorCacheOptions _options;
15+
16+
public FrontDoorApiClient(IOptions<FrontDoorCacheOptions> options, ILogger<FrontDoorApiClient> logger)
17+
{
18+
_options = options.Value;
19+
_logger = logger;
20+
}
21+
22+
public async Task<bool> CheckStatus()
23+
{
24+
var credential = new ClientSecretCredential(_options.TenantId, _options.ClientId, _options.ClientSecret);
25+
var client = new ArmClient(credential);
26+
27+
var frontDoorResourceIdentifier = FrontDoorEndpointResource.CreateResourceIdentifier(_options.SubscriptionId,
28+
_options.ResourceGroupName, _options.FrontDoorName, _options.EndpointName);
29+
var endpoint = client.GetFrontDoorEndpointResource(frontDoorResourceIdentifier);
30+
31+
var fd = await endpoint.GetAsync();
32+
return fd.HasValue;
33+
}
34+
35+
public async Task<bool> SendPurgeRequest(FrontDoorPurgeContent content)
36+
{
37+
var credential = new ClientSecretCredential(_options.TenantId, _options.ClientId, _options.ClientSecret);
38+
var client = new ArmClient(credential);
39+
40+
var frontDoorResourceIdentifier = FrontDoorEndpointResource.CreateResourceIdentifier(_options.SubscriptionId,
41+
_options.ResourceGroupName, _options.FrontDoorName, _options.EndpointName);
42+
var endpoint = client.GetFrontDoorEndpointResource(frontDoorResourceIdentifier);
43+
44+
foreach (var domain in _options.Domains)
45+
{
46+
content.Domains.Add(domain);
47+
}
48+
49+
await endpoint.PurgeContentAsync(WaitUntil.Started, content);
50+
return true;
51+
}
52+
53+
public async Task<bool> SendPurgeAllRequest()
54+
{
55+
return await SendPurgeRequest(new FrontDoorPurgeContent(new[] {"*"}));
56+
}
57+
}
58+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Azure.ResourceManager.Cdn.Models;
2+
3+
namespace Umbraco.Community.FrontDoorCache.Api
4+
{
5+
public interface IFrontDoorApiClient
6+
{
7+
Task<bool> CheckStatus();
8+
Task<bool> SendPurgeRequest(FrontDoorPurgeContent content);
9+
Task<bool> SendPurgeAllRequest();
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Umbraco.Cms.Core.Composing;
2+
using Umbraco.Cms.Core.DependencyInjection;
3+
4+
namespace Umbraco.Community.FrontDoorCache
5+
{
6+
public class FrontDoorCacheComposer : IComposer
7+
{
8+
public void Compose(IUmbracoBuilder builder)
9+
{
10+
builder.AddFrontDoorCache();
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)